Skip to content

Commit

Permalink
Refactor settings, py-cord local, typos
Browse files Browse the repository at this point in the history
  • Loading branch information
MattsBos committed Sep 2, 2022
1 parent a906678 commit 2d252f2
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 75 deletions.
51 changes: 41 additions & 10 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,16 +1,47 @@
# Discord Token
# General Bot settings
# BOT Login Token
BOT_TOKEN =
# ID of the discord guild
# ID of your Discord Server/Guild
GUILD_ID =
# ID for the voice channel bot its category
# ID of the text channel where the bot sends logs
LOG_CHANNEL =


# User permission settings
# ID for the role required to execute slash commands (full permissions)
COMMAND_PERMISSION_ROLE =


# Voice Auto Scaler settings
# Enable or Disable Voice Auto Scaler, true/false
VOICE_SCALER_ENABLE = true
# ID of the category to auto scale voice channels in
VOICE_CHANNEL_CATEGORY =
# Default name for channels in the voice channel bot category
# Default name for auto scaling voice channels
VOICE_CHANNEL_DEFAULT_NAME = 'Voice Channel'
# id of the log channel
LOG_CHANNEL =
# ID of the rolebot channel the settings appear in


# Self-Role text channel subscription settings
# Enable or Disable Self-Role channel subscriptions, true/false
ROLEBOT_ENABLE = true
# ID of the text channel where subscription options should appear
ROLEBOT_SETTINGS_CHANNEL =
# ID for the role required to execute slash commands
COMMAND_PERMISSION_ROLE =
# Roles to add to members that join the server, comma separated


# Auto-Role settings
# Enable or Disable Auto-Role, true/false
AUTO_ROLE_ENABLE = true
# Roles to instantly add to new members joining the server, comma separated
AUTO_ROLES = Role1,Role2,etc


# Poll settings
# Enable or Disable Polls, true/false
POLL_ENABLE = false
# We are not allowed to redistribute fonts, please provide your own in the data folder. (TrueType/.ttf only!)
# Font Regular (default = Helvetica.ttf)
POLL_FONT_REGULAR = Helvetica.ttf
# Font Bold (default = Helvetica-Bold-Font.ttf)
POLL_FONT_BOLD = Helvetica-Bold-Font.ttf
# If fonts other than the default are used, scaling might be required. (default = 10)
POLL_FONT_SCALE = 10
18 changes: 9 additions & 9 deletions clanbotjas/cogmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ async def logCommand(channel, ctx, *args, **kwargs):
@client.event
async def on_command_error(ctx: commands.Context, error: commands.CommandError):
"""
Give feedback to the user when he has no rights to use the command
:param ctx: original command context
:param error: Eroor
Give feedback to the user when user has no perms to use the command
:param ctx: Original command context
:param error: Error
:return:
"""

Expand All @@ -36,9 +36,9 @@ async def on_command_error(ctx: commands.Context, error: commands.CommandError):
@client.event
async def on_application_command_error(ctx: commands.Context, error: commands.CommandError):
"""
Give feedback to the user when he has no rights to use the command
:param ctx: original command context
:param error: Eroor
Give feedback to the user when user has no perms to use the command
:param ctx: Original command context
:param error: Error
:return:
"""
await on_command_error(ctx, error)
Expand Down Expand Up @@ -70,8 +70,8 @@ async def wrapped(ctx, cog: str):
async def load(ctx: discord.ApplicationContext, cog: str):
"""
Load a cog
:param ctx: slash command context
:param cog: name of the cog
:param ctx: Original slash command context
:param cog: Name of the cog to load
:return:
"""
cog, className = cog.lower(), cog
Expand Down Expand Up @@ -121,7 +121,7 @@ async def unload(ctx, cog: str):
async def reload(ctx, cog: str):
"""
Reload a cog
:param ctx: original slash command context
:param ctx: Original slash command context
:param cog: Name of the cog to reload
:return:
"""
Expand Down
2 changes: 1 addition & 1 deletion clanbotjas/cogs/autorole.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async def on_ready(self):
await self.logChannel.send(":white_check_mark: Cog: \"autorole\" ready.")

"""
When someone joins the server, cycle through the configured roles.
When new member joins the server, cycle through the configured roles.
Get the role ID of the roles by name.
Add the role to the newly joined member.
:return:
Expand Down
2 changes: 1 addition & 1 deletion clanbotjas/cogs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async def ping(self, ctx: discord.ApplicationContext):
@slashcommandlogger
async def getid(self, ctx: discord.ApplicationContext):
"""
Give the user its ID.
Prints the User ID of the requester
:param ctx: Object of the original command
:return:
"""
Expand Down
60 changes: 35 additions & 25 deletions clanbotjas/cogs/rolebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,36 @@


class RoleButton(discord.ui.Button):
def __init__(self,
guild : discord.Guild,
log_channel = None
settings_channel = None

def __init__(self,
guild : discord.Guild,
role : discord.Role,
channel_name : str):
channel_name : str,
client):
super().__init__(label=role.name)
self.client = client
self.guild = guild
self.role = role
self.channel_name = channel_name

async def callback(self, interaction: discord.Interaction):
pass

self.settings_channel = self.client.get_channel(settings.DISCORD_ROLEBOT_SETTINGS_CHANNEL)
self.log_channel = self.client.get_channel(settings.DISCORD_LOG_CHANNEL)

# Toggle the role on the member
member = await self.guild.fetch_member(interaction.user.id)
if self.role in member.roles:
await member.remove_roles(self.role)
message = f"{self.channel_name} is now invisible."
await self.log_channel.send(f":radio_button: Button clicked | {self.settings_channel.mention} | {member.name} removed role \"{self.role.name}\".")
else:
await member.add_roles(self.role)
message = f"{self.channel_name} is now visible."
await self.log_channel.send(f":radio_button: Button clicked | {self.settings_channel.mention} | {member.name} added role \"{self.role.name}\".")
await interaction.response.send_message(content=message, ephemeral=True)


Expand Down Expand Up @@ -77,7 +88,7 @@ async def on_ready(self):
@staticmethod
def open_menu():
"""
Open the menu file that represent the roles
Open the menu file that represents the categories and roles
:return:
"""
try:
Expand Down Expand Up @@ -143,7 +154,7 @@ async def get_or_create_role(self, role_name):
async def get_or_create_text_channel(self, text_channel_name, category, role):
"""
Function that returns the text channel by name if it exists.
Otherwise, it gets created in the category and can only be viewed with the given role.
If it doesn't, it will be created in the corresponding category and can only be viewed with the given role.
:param text_channel_name: The name of the text channel te be created
:param category: The category the channel will be posted in.
Expand All @@ -161,10 +172,10 @@ async def get_or_create_text_channel(self, text_channel_name, category, role):

async def create_channels(self, menujson):
"""
Synchronize the menujson file with the discord channels.
yield the role and channel name.
Synchronize the menu.json file with the discord channels.
Yield the role and channel name.
:param menujson: Menu json
:param menujson: The config file
:return:
"""

Expand All @@ -182,14 +193,14 @@ async def create_rolebot_messages(self, menujson):
:param menujson: The config file
:return:
"""
view = discord.ui.View()
view = discord.ui.View(timeout=None)
channel = self.client.get_channel(settings.DISCORD_ROLEBOT_SETTINGS_CHANNEL)
title = f"** {menujson['title']} **"

# Create all of the button components
async for role, channel_name in self.create_channels(menujson):
view.add_item(RoleButton(self.guild, role, channel_name))
view.add_item(RoleButton(self.guild, role, channel_name, self.client))

# Replace an existing message
async for message in channel.history():
if title in message.content:
Expand All @@ -206,7 +217,7 @@ async def create_rolebot_messages(self, menujson):
@staticmethod
def sync_menu(menu):
"""
Write the menu to the menu.json file
Write the menu to file
:param menu:
:return:
"""
Expand Down Expand Up @@ -235,7 +246,7 @@ def get_or_create_text_channel_menu(category, channel_name, role_name):
Create a channel in the category, return success status
:param category: category containing channels
:param channel_name: name of the channel
:param role_name: name of the rol
:param role_name: name of the role
:return: True if Channel exists, False if channel was created
"""
for channel in category["channels"]:
Expand Down Expand Up @@ -269,12 +280,12 @@ async def rolebot_add(self, ctx: discord.ApplicationContext, category_name : str
modified = self.get_or_create_text_channel_menu(category, channel_name, role_name)
if modified:
self.sync_menu(menu)
await ctx.respond(f"created \"{channel_name}\".")
await ctx.respond(f"Created \"{channel_name}\".")
else:
await ctx.respond(f"\"{channel_name}\" already exists.")

@rolebot.command( name="delete",
description="delete channel from role bot",
description="Delete channel from role bot",
guild_ids=settings.DISCORD_GUILD_IDS,
default_permission=False)
@commands.has_role(settings.DISCORD_COMMAND_PERMISSION_ROLE)
Expand All @@ -283,8 +294,8 @@ async def rolebot_add(self, ctx: discord.ApplicationContext, category_name : str
async def rolebot_delete(self, ctx: discord.ApplicationContext, channel_name : str):
"""
Command for deleting a channel from the rolebot
:param ctx:
:param channel_name:
:param ctx: slash command context
:param channel_name: name of the channel
:return:
"""
modified = False
Expand All @@ -298,26 +309,26 @@ async def rolebot_delete(self, ctx: discord.ApplicationContext, channel_name : s

if modified:
self.sync_menu(menu)
await ctx.respond(f"deleted \"{channel_name}\".", ephemeral=True)
await ctx.respond(f"Deleted \"{channel_name}\".", ephemeral=True)
else:
await ctx.respond(f"Could not find \"{channel_name}\".", ephemeral=True)

@rolebot.command( name="show",
description="show rolebot static/running config",
description="Show rolebot static/running config",
guild_ids=settings.DISCORD_GUILD_IDS,
default_permission=False)
@commands.has_role(settings.DISCORD_COMMAND_PERMISSION_ROLE)
@option(name="config_type",
description="Type of config",
@option(name="config_type",
description="Type of config",
required=False,
choices=[ "running", "static" ],
default="static",
)
)
@slashcommandlogger
async def rolebot_show(self, ctx: discord.ApplicationContext, config_type: str):
"""
Show the running/static config in yaml format (More compact than JSON)
:param ctx: original commoand context
:param ctx: original command context
:param config_type: static/running config
:return:
"""
Expand All @@ -330,10 +341,9 @@ async def rolebot_show(self, ctx: discord.ApplicationContext, config_type: str):
if menu:
await ctx.respond(f"```{yaml.dump(menu)}```")
else:
message = f"{config_type} is an incorrect type"
message = f"{config_type} is an incorrect type."
await ctx.respond(message, ephemeral=True)
assert False, message



def setup(client):
Expand Down
10 changes: 5 additions & 5 deletions clanbotjas/cogs/voicechannelbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async def on_voice_state_update(self, member, before, after):
channels.add(after.channel)

await self.sync_channel_names(channels)
# Make sure This is not an event within the same channel
# Make sure this is not an event within the same channel

@commands.Cog.listener()
async def on_member_update(self, before, after):
Expand All @@ -60,7 +60,7 @@ async def on_member_update(self, before, after):

async def sync_channel_names(self, args):
"""
Make sure all voice channels in the args have the right voice channel names
Make sure all voice channels in the args have the correct voice channel names
:param args:
:return:
"""
Expand All @@ -75,8 +75,8 @@ async def sync_channel_names(self, args):

async def autoscale(self):
"""
Get all empty channels.
Delete empty channels if there is more than one.
Get all empty channels
Delete empty channels if there is more than one
If no empty channels exist, create one
Manually create a channel if none exist
:return:
Expand All @@ -86,7 +86,7 @@ async def autoscale(self):
empty_channel = None
delete_channels = []

# if all empty channels
# add empty voice channels to the delete list
for voice_channel in voice_channels:
if not voice_channel.members:
if not empty_channel:
Expand Down
51 changes: 41 additions & 10 deletions clanbotjas/data/.env.example
Original file line number Diff line number Diff line change
@@ -1,16 +1,47 @@
# Discord Token
# General Bot settings
# BOT Login Token
BOT_TOKEN =
# ID of the discord guild
# ID of your Discord Server/Guild
GUILD_ID =
# ID for the voice channel bot its category
# ID of the text channel where the bot sends logs
LOG_CHANNEL =


# User permission settings
# ID for the role required to execute slash commands (full permissions)
COMMAND_PERMISSION_ROLE =


# Voice Auto Scaler settings
# Enable or Disable Voice Auto Scaler, true/false
VOICE_SCALER_ENABLE = true
# ID of the category to auto scale voice channels in
VOICE_CHANNEL_CATEGORY =
# Default name for channels in the voice channel bot category
# Default name for auto scaling voice channels
VOICE_CHANNEL_DEFAULT_NAME = 'Voice Channel'
# id of the log channel
LOG_CHANNEL =
# ID of the rolebot channel the settings appear in


# Self-Role text channel subscription settings
# Enable or Disable Self-Role channel subscriptions, true/false
ROLEBOT_ENABLE = true
# ID of the text channel where subscription options should appear
ROLEBOT_SETTINGS_CHANNEL =
# ID for the role required to execute slash commands
COMMAND_PERMISSION_ROLE =
# Roles to add to members that join the server, comma separated


# Auto-Role settings
# Enable or Disable Auto-Role, true/false
AUTO_ROLE_ENABLE = true
# Roles to instantly add to new members joining the server, comma separated
AUTO_ROLES = Role1,Role2,etc


# Poll settings
# Enable or Disable Polls, true/false
POLL_ENABLE = false
# We are not allowed to redistribute fonts, please provide your own in the data folder. (TrueType/.ttf only!)
# Font Regular (default = Helvetica.ttf)
POLL_FONT_REGULAR = Helvetica.ttf
# Font Bold (default = Helvetica-Bold-Font.ttf)
POLL_FONT_BOLD = Helvetica-Bold-Font.ttf
# If fonts other than the default are used, scaling might be required. (default = 10)
POLL_FONT_SCALE = 10
Loading

0 comments on commit 2d252f2

Please sign in to comment.