async def add_map(self, ctx, old_name, new_name): old_name = old_name.title() new_name = new_name.title() map_id = db.translate(old_name) if map_id is None: await ctx.send( "Sorry, I could not find `{}` in the database 🙁".format( old_name)) return else: # change in the translation file the map file and the channel name on the discord # Maps maps = db.get("maps") maps[map_id]["name"] = new_name db.set("maps", maps) # Translation translations = db.get("translations") translations[new_name] = translations.pop(old_name) db.set("translations", translations) # Channel in discord await ctx.guild.get_channel(maps[map_id]["category_id"] ).edit(name=new_name) await ctx.message.add_reaction('✅')
async def archive_map(self, ctx, map_name): map_name = map_name.title() map_id = db.translate(map_name) if map_id is None: await ctx.send("Sorry, I could not find `{}` in the database 🙁".format(map_name)) return else: # Detect/Make the archived channel archive_channel = discord.utils.get(ctx.guild.channels, name=archive_name) if archive_channel is None: await ctx.guild.create_category(name=archive_name) archive_channel = discord.utils.get(ctx.guild.channels, name=archive_name) # Get the data maps = db.get("maps") map_info = maps[map_id] map_name = map_info["name"] map_id = map_info["id"] # Do things with the data await ctx.guild.get_role(map_info["role_id_mute"]).delete() await ctx.guild.get_role(map_info["role_id"]).delete() await ctx.guild.get_channel(map_info["project_info_channel_id"]).edit(category=archive_channel, name="{}-dissusion".format(map_name)) await ctx.guild.get_channel(map_info["discussion_channel_id"]).edit(category=archive_channel, name="{}-discussion".format(map_name)) await ctx.guild.get_channel(map_info["category_id"]).delete() archive_channel = discord.utils.get(ctx.guild.channels, name=archive_name) # Remove the map from the maps database maps.pop(map_id) db.set("maps", maps) await ctx.message.add_reaction('✅') return
async def show_interest(self, ctx, map_name=None): map_name = map_name.title() if map_name in ("All", "*"): roles = ctx.guild.roles interested_roles = [] for role in roles: if map_role_pattern.match(role.name): interested_roles.append(role) output_string = "Here are all the maps with the interested people:\n" for role in interested_roles: output_string += '`-= {} =-`\n'.format( db.get("maps")[role.name]["name"]) for member in role.members: output_string += '● {}\n'.format(member.nick) output_string += "\n" await ctx.send(output_string) else: map_id = db.translate(map_name) if map_id is None: await ctx.send( "Sorry, I could not find `{}` in the database 🙁".format( map_name)) return interested_list = [] role_id = db.translate(map_id) for member in ctx.guild.members: if ctx.guild.get_role(role_id) in member.roles: interested_list.append(member.nick) # Quite ugly way to patch sting together # intrested_list.sort() message_string = """`-= {} =-`\n""".format(map_name) for name in interested_list: message_string += "● {}\n".format(name) # message_string += "``" await ctx.send(message_string)
def get_map_types(): """ This function exist to get a list of all the map id's registered. This way the bot does not have to be restart """ bot_config = db.get("bot_config") map_types_list = [] for i in bot_config["map_types"].items(): map_types_list.extend([i[0], i[1]]) return map_types_list
async def add_map(self, ctx, map_type, map_name): map_type = map_type.lower() map_name = map_name.title() if map_name in db.get("translations"): await ctx.send("This map name is already taken") return if map_type not in get_map_types(): # Check if map type given is registered await ctx.send("Please only have: `{}` as maptype".format(get_map_types())) return bot_config = get_bot_config() if map_type in bot_config["map_types"]: # If the map type is registered and long turn it short map_type = bot_config["map_types"][map_type] map_id = generate_map_id(bot_config, map_type) # Generate the id role_names = (map_id, ("!{}".format(map_id))) # await ctx.send("{}".format(map_id)) new_roles = [] # Add the new roles for role_name in role_names: new_roles.append( await ctx.guild.create_role(reason="Added '{}' for the new map called '{}'".format(role_name, map_name), name=role_name, color=discord.Color.dark_grey(), hoist=False, mentionable=False)) # Add the permissions for the category non_read = discord.PermissionOverwrite(read_messages=False) read = discord.PermissionOverwrite(read_messages=True) category_permissions = { ctx.guild.default_role: read, new_roles[1]: non_read, new_roles[0]: read } # New roles is and should alwyas be like [read_role,non_read_role] # Add the category new_category = await ctx.guild.create_category(name=map_name, overwrites=category_permissions, reason="Made the catogory for the new '{}' map".format(map_name)) # Add the 2 channels to the category dissucion_channel = await ctx.guild.create_text_channel(name="project-info", category=new_category, topic="The project info for {}".format(map_name)) project_info_channel = await ctx.guild.create_text_channel(name="discussion", category=new_category, topic="The discussion channel for {}".format( map_name)) # Write map data to database new_map_data = { "name": map_name, "id": map_id, "discussion_channel_id": dissucion_channel.id, "project_info_channel_id": project_info_channel.id, "role_id": new_roles[0].id, "role_id_mute": new_roles[1].id, "category_id": new_category.id } maps = db.get("maps") maps[map_id] = new_map_data db.set("maps", maps) # Write translation data to database translations = db.get("translations") translations[map_name] = map_id translations[map_id] = map_name db.set("translations", translations) await ctx.message.add_reaction('✅') await ctx.send('The Role names are: `{}` and `{}`'.format(map_id, '!' + map_id), delete_after=600)
def get_command_prefix(): return db.get("bot_config")["command_prefix"]
def get_bot_config(): return db.get("bot_config")
# bot.py import discord from discord.ext import commands from databases.database_manager import db from utils.utils import get_bot_config, get_command_prefix bot_config = get_bot_config() token = db.get("bot_token") if token is None: print(''' NO TOKEN FOUND! Please add the bot token in: 'databases/bot_token.json' with: {"token": "Your token here"}''') exit() token = token["token"] # Have a file called bot_token.json with {"token":"token here"} bot = commands.Bot(command_prefix=get_command_prefix()) # bot.load_extension("commands.test") bot.load_extension("commands.add_map") bot.load_extension("commands.archive_map") bot.load_extension("commands.change_prefix") bot.load_extension("commands.get_map_id") bot.load_extension("commands.rename") bot.load_extension("commands.roll_dice") bot.load_extension("commands.show_interest")