Initial
This commit is contained in:
commit
6781e22b2b
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 Akumatic
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
68
README.md
Normal file
68
README.md
Normal file
@ -0,0 +1,68 @@
|
||||
# Akuma Matata
|
||||
|
||||
A Discord Bot written in Python using the Rewrite API wrapper
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Prerequisites
|
||||
- Python 3.6
|
||||
- Discord Rewrite API Wrapper
|
||||
|
||||
##### You can get the Wrapper with pip:
|
||||
`python -m pip install -U https://github.com/Rapptz/discord.py/archive/rewrite.zip`
|
||||
|
||||
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.
|
||||
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 and go to Settings > Appearance and activate "Developer Mode"
|
||||
6. Go to any Server you're in, right click your profile name in the user list and click "Copy ID"
|
||||
7. Open [settings.json](settings.json), replace the 0 after `"owner":` and paste it into the brackets after `"admins":` and `"mods":`
|
||||
|
||||
### 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`
|
||||
|
||||
## 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.
|
||||
|
||||
You'll need this code in the newly created file:
|
||||
```
|
||||
class Name():
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
#Setup
|
||||
def setup(bot):
|
||||
bot.add_cog(Name(bot))
|
||||
```
|
||||
|
||||
Just replace "Name" in Line 1 and 6 by an own class name. A new command needs to be a member of this class.
|
||||
|
||||
Instead of using `@bot.command()` you'll need to use `@commands.command()`.
|
||||
|
||||
The first argument of a method needs to be `self`.
|
||||
|
||||
##### An Example:
|
||||
```
|
||||
from discord.ext import commands
|
||||
|
||||
class PingPong():
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
@commands.command()
|
||||
async def ping(self, ctx):
|
||||
await ctx.send("Pong")
|
||||
|
||||
#Setup
|
||||
def setup(bot):
|
||||
bot.add_cog(PingPong(bot))
|
||||
```
|
||||
|
||||
## License
|
||||
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details
|
93
akuma.py
Normal file
93
akuma.py
Normal file
@ -0,0 +1,93 @@
|
||||
import json
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
|
||||
#config file
|
||||
c = json.load(open("settings.json", "r"))
|
||||
#The Bot itself
|
||||
bot = commands.Bot(description=c["description"], command_prefix=c["prefix"], pm_help=c["pmHelp"])
|
||||
|
||||
#Function to write changed config to JSON file
|
||||
def writeJSON(data):
|
||||
with open("settings.json", "w") as file:
|
||||
json.dump(data, file, indent=4)
|
||||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
print("Bot is running!")
|
||||
game = (c["prefix"] + "help" if (c["game"] == "") else c["prefix"] + "help | " + c["game"])
|
||||
return await bot.change_presence(status=discord.Status.online,activity=discord.Game(name=game))
|
||||
|
||||
@bot.command(hidden=True)
|
||||
async def printExt(ctx):
|
||||
"""Prints out every loaded extension"""
|
||||
s = []
|
||||
for ext in bot.extensions:
|
||||
s.append(ext.split(".")[1])
|
||||
await ctx.send("Loaded extensions: " + ", ".join(s))
|
||||
|
||||
@bot.command(hidden=True)
|
||||
async def load(ctx, ext : str = None, json : bool = False):
|
||||
"""Loads a new python file from \"extension\" folder.
|
||||
|
||||
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 != c["owner"]):
|
||||
return
|
||||
if(ext == None):
|
||||
return await ctx.send("No extension specified")
|
||||
try:
|
||||
bot.load_extension("extensions." + ext)
|
||||
await ctx.send("Loaded " + ext)
|
||||
if(json):
|
||||
c["extensions"].append(ext)
|
||||
writeJSON(c)
|
||||
except Exception as e:
|
||||
await ctx.send("Failed to load extension \"{}\": {}".format(ext, "{} ({})".format(type(e).__name__, e)))
|
||||
|
||||
@bot.command(hidden=True)
|
||||
async def reload(ctx, ext : str = None):
|
||||
"""Reloads an extension"""
|
||||
if(ctx.author.id != c["owner"]):
|
||||
return
|
||||
if(ext == None):
|
||||
return await ctx.send("No extension specified")
|
||||
if(("extensions." + ext) in bot.extensions):
|
||||
bot.unload_extension("extensions." + ext)
|
||||
await ctx.send("Unloaded " + ext)
|
||||
try:
|
||||
bot.load_extension("extensions." + ext)
|
||||
await ctx.send("Loaded " + ext)
|
||||
except Exception as e:
|
||||
await ctx.send("Failed to load extension \"{}\": {}".format(ext, "{} ({})".format(type(e).__name__, e)))
|
||||
else:
|
||||
await ctx.send("Extension " + ext + " not loaded")
|
||||
|
||||
@bot.command(hidden=True)
|
||||
async def unload(ctx, ext : str = None, json : bool = False):
|
||||
"""Unloads an extension.
|
||||
|
||||
First argument is the name of the extension.
|
||||
(Optional) If second argument is True, it will be removed from autoload"""
|
||||
if(ctx.author.id != c["owner"]):
|
||||
return
|
||||
if(ext == None):
|
||||
return await ctx.send("No extension specified")
|
||||
if(("extensions." + ext) in bot.extensions):
|
||||
bot.unload_extension("extensions." + ext)
|
||||
await ctx.send("Unloaded " + ext)
|
||||
if(json):
|
||||
c["extensions"].remove(ext)
|
||||
writeJSON(c)
|
||||
else:
|
||||
await ctx.send("Extension " + ext + " not loaded")
|
||||
|
||||
if __name__ == "__main__":
|
||||
#loads all extensions mentioned in settings.json
|
||||
for ext in c["extensions"]:
|
||||
try:
|
||||
bot.load_extension("extensions." + ext)
|
||||
except Exception as e:
|
||||
print("Failed to load extension \"{}\": {}".format(ext, "{} ({})".format(type(e).__name__, e)))
|
||||
|
||||
bot.run(c["token"])
|
13
settings.json
Normal file
13
settings.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"token": "",
|
||||
"prefix": "~",
|
||||
"description": "A Discord Bot written by Akuma#7346",
|
||||
"game": "",
|
||||
"owner": 0,
|
||||
"admins": [],
|
||||
"mods": [],
|
||||
"extensions": [
|
||||
],
|
||||
"joinMessage": "",
|
||||
"suggestionChannel": 0
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user