From bd048acc951c94467e1fc2e1651522efb9692260 Mon Sep 17 00:00:00 2001 From: Akumatic Date: Wed, 20 Jun 2018 23:39:16 +0200 Subject: [PATCH] Adding maintainer to settings, complete suggest --- README.md | 67 ++++++++++++++++++++++++++++++++++++++++++++-- akuma.py | 11 ++++---- extensions/user.py | 19 ++++++++----- settings.json | 3 ++- 4 files changed, 85 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index df2d84c..2d392c1 100644 --- a/README.md +++ b/README.md @@ -13,17 +13,80 @@ A Discord Bot written in Python using the Rewrite API wrapper Depending on your OS and environment you need to type `python3` or another equivalent instead of `python` -### Setting it up -1. Go [to your Discord's App Overview](https://discordapp.com/developers/applications/me) and create a new app. +### Initial setup +1. Go to [your Discord's App Overview](https://discordapp.com/developers/applications/me) and create a new app. 2. Scroll down and "Create a Bot User" 3. Reveal and copy Token of your new Bot 4. Open [settings.json](settings.json) and paste your Token into the quotes after `"token":` +5. Open Discord, enable Developer Mode (Settings > Appearance) and copy your own ID +6. Open [settings.json](settings.json) and paste your ID into the quotes after `"maintainer":` +6. Start the Bot (see below) +7. Go to [your Discord's App Overview](https://discordapp.com/developers/applications/me) again and open the Bot +8. Click on "Generate OAuth2 URL" and give the bot `Administrator` Bot Permissions +9. Open the generated URL and add the Bot to your Server ### Start the Bot Just open a console and type ```python akuma.py``` Depending on your OS and environment you need to type `python3` or another equivalent instead of `python` +### Configuration + +In your bot folder are two configuration files: `settings.json` and `server.json`. + +##### settings.json + +- `token` + +The bot token your bot is using. + +- `prefix` + +The bot needs a prefix to distinguish messages adressed to him. + +- `description` + +A description of the bot, printed when calling `help`. + +- `game` + +Sets the "Playing" message of your bot, placed after a help command + +- `extensions` + +A list of all extensions the bot will automatically load after starting. You can add more members either manually or by passing `True` as second argument to `load ` + +- `maintainer` + +ID of the user with privileges to maintain the bot. Only this user can load, unload and reload extensions. + +##### server.json +*You can either edit this file manually or use the respective moderation commands.* + +As soon as the bot joins a server, it will fill `server.json` automatically with an dictionary identified by the server ID with the following keys: + +- `adminRole` + +Everyone with the given role has the permissions to run admin commands of the bot + +- `modRole` + +Everyone with the given role has the permissions to run mod commands of the bot + +- `joinMessage` + +A Message every user gets when he joins your server. + +- `suggestionChannel` + +A designated channel for the bot's suggest function. See `help suggest` for more informations + +- `modChannel` + +A channel the bot is using for logging moderation commands. + + + ## Add your own extensions It is easy to create a new extension on your own. First you need to create a new python file in the "extensions" folder. diff --git a/akuma.py b/akuma.py index 4d4ddc9..3b9cce9 100644 --- a/akuma.py +++ b/akuma.py @@ -1,11 +1,10 @@ -import json -import discord +import json, discord from discord.ext import commands +#config files cFile = "settings.json" sFile = "server.json" -#config file c = json.load(open(cFile, "r")) s = json.load(open(sFile, "r")) @@ -49,7 +48,7 @@ async def load(ctx, ext : str = None, json : bool = False): First argument is the name of python file without .py extension. (Optional) If second argument is True, it will be autoloaded""" - if(ctx.author.id != ctx.guild.owner.id): + if(ctx.author.id != c["maintainer"]): return if(ext == None): return await ctx.send("No extension specified") @@ -65,7 +64,7 @@ async def load(ctx, ext : str = None, json : bool = False): @bot.command(hidden=True) async def reload(ctx, ext : str = None): """Reloads an extension""" - if(ctx.author.id != ctx.guild.owner.id): + if(ctx.author.id != c["maintainer"]): return if(ext == None): return await ctx.send("No extension specified") @@ -86,7 +85,7 @@ async def unload(ctx, ext : str = None, json : bool = False): First argument is the name of the extension. (Optional) If second argument is True, it will be removed from autoload""" - if(ctx.author.id != ctx.guild.owner.id): + if(ctx.author.id != c["maintainer"]): return if(ext == None): return await ctx.send("No extension specified") diff --git a/extensions/user.py b/extensions/user.py index f7cd97c..d793c76 100644 --- a/extensions/user.py +++ b/extensions/user.py @@ -16,21 +16,28 @@ class User(): await ctx.send("""Invite Link: \nPlease read for informations""".format(self.bot.user.id)) - @commands.command() - async def suggest(self, ctx, *, msg : str): + async def suggest(self, ctx, *, msg : str = None): """Makes a suggestion to the moderation team. - - Planned: If there's no suggestionChannel specified, send a pm to the owner.""" + + Only callable from a server + + Your original message gets deleted and sent to a private suggestion channel. + If no suggestion channel is specified, it will be sent to the owner instead.""" + + if(ctx.guild == None): + return await ctx.send("This command can only be used within a server") + if(msg == None): + return await ctx.send("Your suggestion can't be empty") await ctx.message.delete() - e = discord.Embed(color=0x6428c8) + e = discord.Embed(description="Server: " + ctx.guild.name, color=0x6428c8) e.set_author(name=ctx.author, icon_url=ctx.author.avatar_url) e.add_field(name="Suggestion", value=msg) if(s[str(ctx.guild.id)]["suggestionChannel"] != 0): chan = self.bot.get_channel(s[str(ctx.guild.id)]["suggestionChannel"]) await chan.send(embed=e) else: - await ctx.send(e) + await ctx.guild.get_member(ctx.guild.owner.id).send(embed=e) #Setup def setup(bot): diff --git a/settings.json b/settings.json index 3bd0d47..c2a572e 100644 --- a/settings.json +++ b/settings.json @@ -7,5 +7,6 @@ "fun", "moderation", "user" - ] + ], + "maintainer": 0 } \ No newline at end of file