async def update(self, ctx: discord.ext.commands.context.Context, variable: str, *value): """ Updating a specific value in the config. """ # turn value argument into string value = " ".join(value) # if the variable is not in the config an error message will be send if variable not in self.bot.config: await ctx.send(embed=discord.Embed( title=f"The variable `{variable}` does not exits in the config of the bot! Therefore it was not updated.", colour=int(self.bot.config["embed-colours"]["default"], 16) )) return # if the variable is a string it will be converted to a string else the json converter will handle it if isinstance(self.bot.config, str): value = str(value) else: try: value = loads(value) except: raise commands.BadArgument # updating the config self.bot.config[variable] = value json_helper.write_json("config", self.bot.config) await ctx.send(embed=discord.Embed( title=f"Successfully updated `{variable}` to `{value}`.", colour=int(self.bot.config["embed-colours"]["default"], 16) ))
async def update_data(self): self.bot.total_server = len(self.bot.guilds) self.bot.total_user = len([u for u in self.bot.users if not u.bot]) async with asyncio.Lock(): data = json_helper.read_json("stats") data["executed_commands"] = self.bot.total_executed_commands json_helper.write_json("stats", data)
async def on(self, ctx: discord.ext.commands.context.Context): """ Turns the devmode of this bot on so that other users cannot interact with it. """ self.bot.config["devmode"] = True json_helper.write_json("config", self.bot.config) await ctx.send(embed=discord.Embed( description="```diff\n+ Devmode has been turned on```", colour=int(self.bot.config["embed-colours"]["confirm"], 16) ))
async def quote_channel(self, ctx: commands.context.Context, channel: discord.TextChannel): """ This command updated the quote channel for this server. You need to provide a channel id for the quote channel. """ channel_ids = self.bot.channel_ids channel_ids["quotes"][str(ctx.guild.id)] = channel.id await ctx.channel.send(embed=discord.Embed( colour=int(self.bot.config["embed-colours"]["default"], 16), title= f"I have updated the quote channel to \"{channel.name}\" ({channel.id})!" )) async with asyncio.Lock(): json_helper.write_json("channel", channel_ids)
async def prefix(self, ctx: discord.ext.commands.context.Context, *, prefix='-'): """ Changes the bot prefix for this server. The prefix is used for all commands for this bot. """ async with asyncio.Lock(): data = json_helper.read_json("prefixes") data[str(ctx.message.guild.id)] = prefix json_helper.write_json("prefixes", data) await ctx.send(embed=discord.Embed( title= f"The server prefix has been set to `{prefix}`. To change it again use `{prefix}prefix <prefix>`!", colour=int(self.bot.config["embed-colours"]["default"], 16)))
async def add(self, ctx: discord.ext.commands.context.Context, user: discord.Member): """ Blacklists users from the bot. The blacklisted users cannot use any commands from this bot. """ if user.id in self.bot.blacklisted_users: await ctx.send(embed=discord.Embed( title=f"`{user.display_name}` was already in the blacklist.", colour=int(self.bot.config["embed-colours"]["error"], 16) )) return self.bot.blacklisted_users.append(user.id) async with asyncio.Lock(): data = json_helper.read_json("blacklist") data["commandBlacklistedUsers"].append(user.id) json_helper.write_json("blacklist", data) await ctx.send(embed=discord.Embed( title=f"`{user.display_name}` has been added to the blacklist.", colour=int(self.bot.config["embed-colours"]["default"], 16) ))
async def remove(self, ctx: discord.ext.commands.context.Context, user: discord.Member): """ Removes users from blacklist for bot commands. """ if user.id not in self.bot.blacklisted_users: await ctx.send(embed=discord.Embed( title=f"`{user.display_name}` was not found in the blacklist and therefore could not be removed from it.", colour=int(self.bot.config["embed-colours"]["error"], 16) )) await ctx.send( f"{user.display_name} was not found in the blacklist and therefore could not be removed from it.") return self.bot.blacklisted_users.remove(user.id) async with asyncio.Lock(): data = json_helper.read_json("blacklist") data["commandBlacklistedUsers"].remove(user.id) json_helper.write_json("blacklist", data) await ctx.send(embed=discord.Embed( title=f"`{user.display_name}` has been removed from the blacklist.", colour=int(self.bot.config["embed-colours"]["default"], 16) ))