Merge branch 'master' into espy-gitignore
This commit is contained in:
commit
f03ac6dd68
18
.gitignore
vendored
18
.gitignore
vendored
@ -110,21 +110,3 @@ venv.bak/
|
|||||||
|
|
||||||
/src/config/Config.json
|
/src/config/Config.json
|
||||||
/src/config/PrivateConfig.json
|
/src/config/PrivateConfig.json
|
||||||
|
|
||||||
# IntelliJ stuff
|
|
||||||
.idea/
|
|
||||||
*.iml
|
|
||||||
|
|
||||||
# Sublime stuff
|
|
||||||
# Cache files for Sublime Text
|
|
||||||
*.tmlanguage.cache
|
|
||||||
*.tmPreferences.cache
|
|
||||||
*.stTheme.cache
|
|
||||||
|
|
||||||
# Workspace files are user-specific
|
|
||||||
*.sublime-workspace
|
|
||||||
|
|
||||||
# Project files should be checked into the repository, unless a significant
|
|
||||||
# proportion of contributors will probably not be using Sublime Text
|
|
||||||
# *.sublime-project
|
|
||||||
|
|
||||||
|
|||||||
39
README.md
39
README.md
@ -7,36 +7,57 @@ http://discord.gg/GWdhBSp
|
|||||||
|
|
||||||
This bot extends the rewrite version of discord.py. A couple of variables have been added to give you easy access to a couple of objects listed here.
|
This bot extends the rewrite version of discord.py. A couple of variables have been added to give you easy access to a couple of objects listed here.
|
||||||
|
|
||||||
> self.ownerlist
|
> self.bot.ownerlist
|
||||||
|
|
||||||
self.ownerlist can be used to retrieve a `list` of user ID's. (`int`). Those ID's belong to contributors.
|
self.ownerlist can be used to retrieve a `list` of user ID's. (`int`). Those ID's belong to contributors.
|
||||||
> self.defaultprefix
|
> self.bot.defaultprefix
|
||||||
|
|
||||||
self.defaultprefix can be used to retrieve a `str` object of the default prefix.
|
self.defaultprefix can be used to retrieve a `str` object of the default prefix.
|
||||||
> self.version
|
> self.bot.version
|
||||||
|
|
||||||
self.version can be used to retrieve a `float` which represent the version number of the bot.
|
self.version can be used to retrieve a `float` which represent the version number of the bot.
|
||||||
> self.display_name
|
> self.bot.display_name
|
||||||
|
|
||||||
self.display_name returns a `str` which represent the display_name of the bot.
|
self.display_name returns a `str` which represent the display_name of the bot.
|
||||||
> self.mainenance
|
> self.bot.mainenance
|
||||||
|
|
||||||
self.maintenance is equal to `True` or `False`. If you would like to exclude code in the master branch, use this.
|
self.maintenance is equal to `True` or `False`. If you would like to exclude code in the master branch, use this.
|
||||||
Make sure this one is installed.
|
Make sure this one is installed.
|
||||||
example:
|
example:
|
||||||
```py
|
```py
|
||||||
if self.mainenance:
|
if self.bot.mainenance:
|
||||||
print('I am in the development branch')
|
print('I am in the development branch')
|
||||||
|
|
||||||
if not self.mainenance:
|
if not self.bot.mainenance:
|
||||||
print('I am in the master branch)
|
print('I am in the master branch)
|
||||||
```
|
```
|
||||||
With other words. self.mainenance returns False in production and True in developer modus.
|
With other words. self.mainenance returns False in production and True in developer modus.
|
||||||
|
|
||||||
|
> self.bot.embed_color
|
||||||
|
|
||||||
|
self.embed_color can be used to use the default color of out embed theme.
|
||||||
|
```
|
||||||
|
discord.Embed(title='Foo', description='bar', color=self.bot.embed_color)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Docker environment
|
||||||
|
This bot is heavly based on docker. This means it will run in a container. Other words. The code will run in a jail. Dont be afraid for bugs that cause harm. or commands that could potential restarts the server. Its safe.
|
||||||
|
|
||||||
|
There are a couple of things to know about docker within this project.
|
||||||
|
1. Please read the docs of docker first before editing the docker files
|
||||||
|
2. If you need a pip package, place the name into requirements.txt, docker handles the rest.
|
||||||
|
3. Everything in project folder is the workfolder of the docker container
|
||||||
|
4. Initialize cogs by adding them into cogs.txt. one line is one cogfile
|
||||||
|
|
||||||
## Initialize a cog
|
## Initialize a cog
|
||||||
Cogs can be placed in `./src/cogs`. Overall the `src` folder is the place to put code in.
|
Put your cog in `src/cogs` and edit the `cogs.txt` file. Add the filename of your cog into `cogs.txt`. No absolute path, just the name.
|
||||||
Make sure to update the `requirements.txt` and it is important to add the name of your cog file into the `cogs.txt` list. Otherwise it may turn out that your cog wont load.
|
|
||||||
|
|
||||||
## Update source code
|
## Update source code
|
||||||
There is a git command available provided by Dusty. `S!git pull` should pull the latest commits into the docker container. Make sure afterwards to reload the cog.
|
There is a git command available provided by Dusty. `S!git pull` should pull the latest commits into the docker container. Make sure afterwards to reload the cog.
|
||||||
If you are stuck in any way shape or form you can always contact anyone who works on this project. Dont forget to check `S!help`.
|
If you are stuck in any way shape or form you can always contact anyone who works on this project. Dont forget to check `S!help`.
|
||||||
|
|
||||||
|
## Project links:
|
||||||
|
- http://discord.gg/GWdhBSp
|
||||||
|
- http://chillout.ueuo.com
|
||||||
|
- http://trello.com/b/x02goBbW/sebis-bot-tutorial-roadmap
|
||||||
|
|
||||||
|
|||||||
BIN
avatar.png
Normal file
BIN
avatar.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
@ -1,2 +1,3 @@
|
|||||||
yarl<1.2
|
yarl<1.2
|
||||||
numpy==1.14.0
|
numpy==1.14.0
|
||||||
|
uvloop
|
||||||
|
|||||||
15
run.py
15
run.py
@ -2,6 +2,7 @@
|
|||||||
# -*- coding: utf8 -*-
|
# -*- coding: utf8 -*-
|
||||||
|
|
||||||
# Import packages
|
# Import packages
|
||||||
|
import asyncio
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
import json
|
import json
|
||||||
@ -11,6 +12,18 @@ import random
|
|||||||
# Import custom files
|
# Import custom files
|
||||||
from src.config.config import LoadConfig
|
from src.config.config import LoadConfig
|
||||||
|
|
||||||
|
# If uvloop is installed, change to that eventloop policy as it
|
||||||
|
# is more efficient
|
||||||
|
try:
|
||||||
|
import uvloop
|
||||||
|
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
|
||||||
|
del uvloop
|
||||||
|
except BaseException as ex:
|
||||||
|
print(f'Could not load uvloop. {type(ex).__name__}: {ex};',
|
||||||
|
'reverting to default impl.')
|
||||||
|
else:
|
||||||
|
print(f'Using uvloop for asyncio event loop policy.')
|
||||||
|
|
||||||
|
|
||||||
# Bot Class
|
# Bot Class
|
||||||
class SebiMachine(commands.Bot, LoadConfig):
|
class SebiMachine(commands.Bot, LoadConfig):
|
||||||
@ -19,7 +32,7 @@ class SebiMachine(commands.Bot, LoadConfig):
|
|||||||
# Initialize and attach config / settings
|
# Initialize and attach config / settings
|
||||||
LoadConfig.__init__(self)
|
LoadConfig.__init__(self)
|
||||||
commands.Bot.__init__(self, command_prefix=self.defaultprefix)
|
commands.Bot.__init__(self, command_prefix=self.defaultprefix)
|
||||||
self.embed_color = discord.Color(0x00FFFF)
|
|
||||||
|
|
||||||
# Load plugins
|
# Load plugins
|
||||||
# Add your cog file name in this list
|
# Add your cog file name in this list
|
||||||
|
|||||||
126
src/cogs/code.py
Normal file
126
src/cogs/code.py
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
from discord.ext import commands
|
||||||
|
import traceback
|
||||||
|
import textwrap
|
||||||
|
from contextlib import redirect_stdout
|
||||||
|
import io
|
||||||
|
|
||||||
|
|
||||||
|
class REPL:
|
||||||
|
"""Python in Discords"""
|
||||||
|
def __init__(self, bot):
|
||||||
|
self.bot = bot
|
||||||
|
self._last_result = None
|
||||||
|
self.sessions = set()
|
||||||
|
|
||||||
|
def cleanup_code(self, content):
|
||||||
|
"""
|
||||||
|
Automatically removes code blocks from the code.
|
||||||
|
"""
|
||||||
|
# remove ```py\n```
|
||||||
|
if content.startswith('```') and content.endswith('```'):
|
||||||
|
return '\n'.join(content.split('\n')[1:-1])
|
||||||
|
|
||||||
|
# remove `foo`
|
||||||
|
return content.strip('` \n')
|
||||||
|
|
||||||
|
def get_syntax_error(self, e):
|
||||||
|
if e.text is None:
|
||||||
|
return '{0.__class__.__name__}: {0}'.format(e)
|
||||||
|
return '{0.text}{1:>{0.offset}}\n{2}: {0}'.format(e, '^', type(e).__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@commands.command(name='exec')
|
||||||
|
async def _eval(self, ctx, *, body: str = None):
|
||||||
|
"""
|
||||||
|
Execute python code in discord chat.
|
||||||
|
Only the owner of this bot can use this command.
|
||||||
|
|
||||||
|
Alias:
|
||||||
|
- exec
|
||||||
|
Usage:
|
||||||
|
- exec < python code >
|
||||||
|
Example:
|
||||||
|
- exec print(546132)
|
||||||
|
"""
|
||||||
|
if ctx.author.id not in self.bot.ownerlist:
|
||||||
|
return await ctx.send('Only my contributors can use me like this :blush:', delete_after=10)
|
||||||
|
|
||||||
|
if body is None:
|
||||||
|
return await ctx.send(
|
||||||
|
'Please, use\n'
|
||||||
|
f'`{self.bot.config["prefix"]}exec`\n\n'
|
||||||
|
'\n`\\`\\`\\`py\n[python code]\n\\`\\`\\`\n'
|
||||||
|
'to get the most out of the command')
|
||||||
|
|
||||||
|
env = {
|
||||||
|
'bot': self.bot,
|
||||||
|
'ctx': ctx,
|
||||||
|
'channel': ctx.message.channel,
|
||||||
|
'author': ctx.message.author,
|
||||||
|
'server': ctx.message.guild,
|
||||||
|
'message': ctx.message,
|
||||||
|
'_': self._last_result
|
||||||
|
}
|
||||||
|
|
||||||
|
env.update(globals())
|
||||||
|
|
||||||
|
body = self.cleanup_code(body)
|
||||||
|
stdout = io.StringIO()
|
||||||
|
|
||||||
|
to_compile = 'async def func():\n%s' % textwrap.indent(body, ' ')
|
||||||
|
|
||||||
|
try:
|
||||||
|
exec(to_compile, env)
|
||||||
|
except SyntaxError as e:
|
||||||
|
try:
|
||||||
|
msg = await ctx.send(f'```py\n{self.get_syntax_error(e)}\n```')
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
error = [self.get_syntax_error(e)[i:i+2000] for i in range(0, len(self.get_syntax_error(e)), 2000)]
|
||||||
|
for i in error:
|
||||||
|
msg = await ctx.send(f'```py\n{i}\n```')
|
||||||
|
|
||||||
|
func = env['func']
|
||||||
|
try:
|
||||||
|
with redirect_stdout(stdout):
|
||||||
|
ret = await func()
|
||||||
|
except Exception as e:
|
||||||
|
value = stdout.getvalue()
|
||||||
|
try:
|
||||||
|
msg = await ctx.send(f'```py\n{value}{traceback.format_exc()}\n```')
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
error = [value[i:i + 2000] for i in range(0, len(value), 2000)]
|
||||||
|
for i in error:
|
||||||
|
await ctx.send(f'```py\n{i}\n```')
|
||||||
|
|
||||||
|
tracebackerror = [traceback.format_exc()[i:i + 2000] for i in range(0, len(traceback.format_exc()), 2000)]
|
||||||
|
for i in tracebackerror:
|
||||||
|
msg = await ctx.send(f'```py\n{i}\n```')
|
||||||
|
else:
|
||||||
|
value = stdout.getvalue()
|
||||||
|
if ret is None:
|
||||||
|
if value:
|
||||||
|
try:
|
||||||
|
msg = await ctx.send(f'```py\n{value}\n```')
|
||||||
|
except Exception as e:
|
||||||
|
code = [value[i:i + 1980] for i in range(0, len(value), 1980)]
|
||||||
|
for i in code:
|
||||||
|
msg = await ctx.send(f'```py\n{i}\n```')
|
||||||
|
else:
|
||||||
|
self._last_result = ret
|
||||||
|
try:
|
||||||
|
code = [value[i:i + 1980] for i in range(0, len(value), 1980)]
|
||||||
|
for i in code:
|
||||||
|
msg = await ctx.send(f'```py\n{i}\n```')
|
||||||
|
except Exception as e:
|
||||||
|
code = [value[i:i + 1980] for i in range(0, len(value), 1980)]
|
||||||
|
for i in code:
|
||||||
|
await ctx.send(f'```py\n{i}\n```')
|
||||||
|
modifyd_ret = [ret[i:i + 1980] for i in range(0, len(ret), 1980)]
|
||||||
|
for i in modifyd_ret:
|
||||||
|
msg = await ctx.send(f'```py\n{i}\n```')
|
||||||
|
|
||||||
|
|
||||||
|
def setup(bot):
|
||||||
|
bot.add_cog(REPL(bot))
|
||||||
@ -16,9 +16,9 @@ class Upload:
|
|||||||
@commands.command()
|
@commands.command()
|
||||||
async def reload(self, ctx, *, extension: str):
|
async def reload(self, ctx, *, extension: str):
|
||||||
"""Reload an extension."""
|
"""Reload an extension."""
|
||||||
|
await ctx.trigger_typing()
|
||||||
if ctx.author.id not in self.bot.ownerlist:
|
if ctx.author.id not in self.bot.ownerlist:
|
||||||
return await ctx.send('Only my creator can use me like this :blush:', delete_after=10)
|
return await ctx.send('Only my contributors can use me like this :blush:', delete_after=10)
|
||||||
|
|
||||||
extension = extension.lower()
|
extension = extension.lower()
|
||||||
try:
|
try:
|
||||||
@ -33,8 +33,9 @@ class Upload:
|
|||||||
@commands.command()
|
@commands.command()
|
||||||
async def reloadall(self, ctx):
|
async def reloadall(self, ctx):
|
||||||
"""Reload all extensions."""
|
"""Reload all extensions."""
|
||||||
|
await ctx.trigger_typing()
|
||||||
if ctx.author.id not in self.bot.ownerlist:
|
if ctx.author.id not in self.bot.ownerlist:
|
||||||
return await ctx.send('Only my creator can use me like this :blush:', delete_after=10)
|
return await ctx.send('Only my contributors can use me like this :blush:', delete_after=10)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for extension in self.bot.extensions:
|
for extension in self.bot.extensions:
|
||||||
@ -47,8 +48,9 @@ class Upload:
|
|||||||
@commands.command()
|
@commands.command()
|
||||||
async def unload(self, ctx, *, extension: str):
|
async def unload(self, ctx, *, extension: str):
|
||||||
"""Unload an extension."""
|
"""Unload an extension."""
|
||||||
|
await ctx.trigger_typing()
|
||||||
if ctx.author.id not in self.bot.ownerlist:
|
if ctx.author.id not in self.bot.ownerlist:
|
||||||
return await ctx.send('Only my creator can use me like this :blush:', delete_after=10)
|
return await ctx.send('Only my contributors can use me like this :blush:', delete_after=10)
|
||||||
|
|
||||||
extension = extension.lower()
|
extension = extension.lower()
|
||||||
try:
|
try:
|
||||||
@ -65,8 +67,9 @@ class Upload:
|
|||||||
@commands.command()
|
@commands.command()
|
||||||
async def load(self, ctx, *, extension: str):
|
async def load(self, ctx, *, extension: str):
|
||||||
"""Load an extension."""
|
"""Load an extension."""
|
||||||
|
await ctx.trigger_typing()
|
||||||
if ctx.author.id not in self.bot.ownerlist:
|
if ctx.author.id not in self.bot.ownerlist:
|
||||||
return await ctx.send('Only my creator can use me like this :blush:', delete_after=10)
|
return await ctx.send('Only my contributors can use me like this :blush:', delete_after=10)
|
||||||
|
|
||||||
extension = extension.lower()
|
extension = extension.lower()
|
||||||
try:
|
try:
|
||||||
@ -83,5 +86,7 @@ class Upload:
|
|||||||
"""triggers error to test traceback"""
|
"""triggers error to test traceback"""
|
||||||
await ctx.send(a)
|
await ctx.send(a)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(Upload(bot))
|
bot.add_cog(Upload(bot))
|
||||||
@ -14,7 +14,11 @@ class CogName:
|
|||||||
@commands.command()
|
@commands.command()
|
||||||
async def ping(self, ctx):
|
async def ping(self, ctx):
|
||||||
"""Say pong"""
|
"""Say pong"""
|
||||||
await ctx.send('Pong')
|
now = ctx.message.created_at
|
||||||
|
msg = await ctx.send('Pong')
|
||||||
|
sub = msg.created_at - now
|
||||||
|
await msg.edit(content=f'Pong, {sub.total_seconds() * 1000}')
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(CogName(bot))
|
bot.add_cog(CogName(bot))
|
||||||
44
src/cogs/fun.py
Normal file
44
src/cogs/fun.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: <encoding name> -*-
|
||||||
|
|
||||||
|
from discord.ext import commands
|
||||||
|
import discord
|
||||||
|
import random
|
||||||
|
import aiohttp
|
||||||
|
|
||||||
|
class Fun:
|
||||||
|
"""
|
||||||
|
CogName should be the name of the cog
|
||||||
|
"""
|
||||||
|
def __init__(self, bot):
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
|
@commands.command()
|
||||||
|
async def sebisauce(self, ctx):
|
||||||
|
"""
|
||||||
|
Get a image related to Sebi.
|
||||||
|
Sebi is a random guy with perfect code related jokes.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
- sebisauce
|
||||||
|
"""
|
||||||
|
await ctx.trigger_typing()
|
||||||
|
url = 'http://ikbengeslaagd.com/API/sebisauce.json'
|
||||||
|
async with aiohttp.ClientSession() as session:
|
||||||
|
async with session.get(url) as response:
|
||||||
|
source = await response.json(encoding='utf8')
|
||||||
|
|
||||||
|
total_sebi = 0
|
||||||
|
for key in dict.keys(source):
|
||||||
|
total_sebi += 1
|
||||||
|
|
||||||
|
im = random.randint(0, int(total_sebi) - 1)
|
||||||
|
|
||||||
|
await ctx.send(embed=discord.Embed(
|
||||||
|
title='\t',
|
||||||
|
description='\t',
|
||||||
|
color=self.bot.embed_color).set_image(
|
||||||
|
url=source[str(im)]))
|
||||||
|
|
||||||
|
def setup(bot):
|
||||||
|
bot.add_cog(Fun(bot))
|
||||||
@ -49,7 +49,7 @@ class Git:
|
|||||||
async def pull(self, ctx):
|
async def pull(self, ctx):
|
||||||
await ctx.trigger_typing()
|
await ctx.trigger_typing()
|
||||||
if ctx.author.id not in self.bot.ownerlist:
|
if ctx.author.id not in self.bot.ownerlist:
|
||||||
return await ctx.send('Only my creator can use me like this :blush:', delete_after=10)
|
return await ctx.send('Only my contributors can use me like this :blush:', delete_after=10)
|
||||||
em = discord.Embed(style='rich',
|
em = discord.Embed(style='rich',
|
||||||
title=f'Git Pull',
|
title=f'Git Pull',
|
||||||
color=self.bot.embed_color)
|
color=self.bot.embed_color)
|
||||||
@ -73,9 +73,9 @@ class Git:
|
|||||||
async def status(self, ctx):
|
async def status(self, ctx):
|
||||||
await ctx.trigger_typing()
|
await ctx.trigger_typing()
|
||||||
if ctx.author.id not in self.bot.ownerlist:
|
if ctx.author.id not in self.bot.ownerlist:
|
||||||
return await ctx.send('Only my creator can use me like this :blush:', delete_after=10)
|
return await ctx.send('Only my contributors can use me like this :blush:', delete_after=10)
|
||||||
em = discord.Embed(style='rich',
|
em = discord.Embed(style='rich',
|
||||||
title=f'Git Pull',
|
title=f'Git Status',
|
||||||
color=self.bot.embed_color)
|
color=self.bot.embed_color)
|
||||||
em.set_thumbnail(url=f'{ctx.guild.me.avatar_url}')
|
em.set_thumbnail(url=f'{ctx.guild.me.avatar_url}')
|
||||||
result = await asyncio.wait_for(self.bot.loop.create_task(
|
result = await asyncio.wait_for(self.bot.loop.create_task(
|
||||||
|
|||||||
7
src/config/Config.json
Normal file
7
src/config/Config.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"version": 0.1,
|
||||||
|
"display_name" : "[S!] Sebi-Machine",
|
||||||
|
"maintenance": "True",
|
||||||
|
"ownerlist": [],
|
||||||
|
"prefix": "S!"
|
||||||
|
}
|
||||||
3
src/config/PrivateConfig.json
Normal file
3
src/config/PrivateConfig.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"bot-key": ""
|
||||||
|
}
|
||||||
@ -2,7 +2,7 @@
|
|||||||
# -*- coding: <encoding name> -*-
|
# -*- coding: <encoding name> -*-
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import discord
|
||||||
|
|
||||||
class LoadConfig:
|
class LoadConfig:
|
||||||
"""
|
"""
|
||||||
@ -19,6 +19,7 @@ class LoadConfig:
|
|||||||
self.version = self.config["version"]
|
self.version = self.config["version"]
|
||||||
self.display_name = self.config["display_name"]
|
self.display_name = self.config["display_name"]
|
||||||
self.maintenance = self.config["maintenance"]
|
self.maintenance = self.config["maintenance"]
|
||||||
|
self.embed_color = discord.Color(0x00FFFF)
|
||||||
if self.maintenance == 'False':
|
if self.maintenance == 'False':
|
||||||
self.maintenance = False
|
self.maintenance = False
|
||||||
else:
|
else:
|
||||||
|
|||||||
6
src/shared_libs/aliases.json
Normal file
6
src/shared_libs/aliases.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"sar": "sar",
|
||||||
|
"selfrole": "sar",
|
||||||
|
"selfroles": "sar"
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user