Merge remote-tracking branch 'origin/development' into development
# Conflicts: # src/cogs/git.py
This commit is contained in:
commit
a3c7f25109
4
.gitignore
vendored
4
.gitignore
vendored
@ -108,8 +108,8 @@ venv.bak/
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
|
||||
/src/config/Config.json
|
||||
/src/config/PrivateConfig.json
|
||||
src/config/Config.json
|
||||
src/config/PrivateConfig.json
|
||||
|
||||
# Ignore dockerfiles
|
||||
docker-compose.yml
|
||||
62
README.md
62
README.md
@ -1,53 +1,57 @@
|
||||
# Sebi-Machine
|
||||
Dedicated discord bot for Sebi's bot tutorial.
|
||||
|
||||
http://discord.gg/GWdhBSp
|
||||
Dedicated Discord bot for [Sebi's bot tutorial](http://discord.gg/GWdhBSp).
|
||||
|
||||
## Important things to know
|
||||
|
||||
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.bot.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.bot.defaultprefix
|
||||
`self.ownerlist` can be used to retrieve a `list` of user ID's. (`int`). Those ID's belong to contributors.
|
||||
|
||||
self.defaultprefix can be used to retrieve a `str` object of the default prefix.
|
||||
> self.bot.version
|
||||
> `self.bot.defaultprefix`
|
||||
|
||||
self.version can be used to retrieve a `float` which represent the version number of the bot.
|
||||
> self.bot.display_name
|
||||
`self.defaultprefix` can be used to retrieve a `str` object of the default prefix.
|
||||
|
||||
self.display_name returns a `str` which represent the display_name of the bot.
|
||||
> self.bot.mainenance
|
||||
> `self.bot.version`
|
||||
|
||||
`self.version` can be used to retrieve a `float` which represent the version number of the bot.
|
||||
|
||||
> `self.bot.display_name`
|
||||
|
||||
`self.display_name` returns a `str` which represent the `display_name` of the bot.
|
||||
|
||||
> `self.bot.mainenance`
|
||||
|
||||
`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. Example:
|
||||
|
||||
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.
|
||||
example:
|
||||
```py
|
||||
if self.bot.mainenance:
|
||||
print('I am in the development branch')
|
||||
|
||||
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.
|
||||
In other words. `self.mainenance` returns `False` in production and `True` in developer modes.
|
||||
|
||||
> self.bot.embed_color
|
||||
> `self.bot.embed_color`
|
||||
|
||||
self.embed_color can be used to use the default color of out embed theme.
|
||||
```
|
||||
`self.embed_color` can be used to use the default color of out embed theme.
|
||||
|
||||
```python
|
||||
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.
|
||||
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. It's 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
|
||||
|
||||
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
|
||||
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.
|
||||
@ -57,10 +61,12 @@ There is a git command available provided by Dusty. `S!git pull` should pull the
|
||||
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
|
||||
- http://discord.gg/GWdhBSp
|
||||
- http://chillout.ueuo.com
|
||||
- http://trello.com/b/x02goBbW/sebis-bot-tutorial-roadmap
|
||||
|
||||
## Deploy to heroku
|
||||
|
||||
For testing purposes you can click the link below to build your own copy of this repo you just pick an app name fill in the config variables then switch it on in resources tab.
|
||||
|
||||
[](https://heroku.com/deploy?template=https://github.com/Annihilator708/Sebi-Machine/tree/development)
|
||||
|
||||
@ -11,6 +11,7 @@ import logging
|
||||
import random
|
||||
import traceback
|
||||
import os
|
||||
import sys
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
@ -27,6 +28,12 @@ logging.basicConfig(level='INFO')
|
||||
# If uvloop is installed, change to that eventloop policy as it
|
||||
# is more efficient
|
||||
try:
|
||||
# https://stackoverflow.com/a/45700730
|
||||
if sys.platform == 'win32':
|
||||
loop = asyncio.ProactorEventLoop()
|
||||
asyncio.set_event_loop(loop)
|
||||
logging.warning('Detected Windows. Changing event loop to ProactorEventLoop.')
|
||||
else:
|
||||
import uvloop
|
||||
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
|
||||
del uvloop
|
||||
@ -80,12 +87,16 @@ class SebiMachine(commands.Bot, LoadConfig, Loggable):
|
||||
# CommandErrors triggered by other propagating errors tend to get wrapped. This means
|
||||
# if we have a cause, we should probably consider unwrapping that so we get a useful
|
||||
# message.
|
||||
|
||||
# If command is not found, return
|
||||
if isinstance(error, discord.ext.commands.errors.CommandNotFound):
|
||||
return
|
||||
|
||||
error = error.__cause__ or error
|
||||
tb = traceback.format_exception(type(error), error, error.__traceback__, limit=2, chain=False)
|
||||
tb = ''.join(tb)
|
||||
joke = random.choice(jokes)
|
||||
fmt = f'**`{self.defaultprefix}{ctx.command}`**\n{joke}\n\n**{type(error).__name__}:**:\n```py\n{tb}\n```'
|
||||
simple_fmt = f'**`{self.defaultprefix}{ctx.command}`**\n{joke}\n\n**{type(error).__name__}:**:\n**`{error}`**'
|
||||
|
||||
# Stops the error handler erroring.
|
||||
try:
|
||||
@ -94,6 +105,31 @@ class SebiMachine(commands.Bot, LoadConfig, Loggable):
|
||||
traceback.print_exc()
|
||||
|
||||
|
||||
async def on_message(self, message):
|
||||
# Make sure people can't change the username
|
||||
if message.guild:
|
||||
if message.guild.me.display_name != self.display_name:
|
||||
try:
|
||||
await message.guild.me.edit(nick=self.display_name)
|
||||
except:
|
||||
pass
|
||||
|
||||
# If author is a bot, ignore the message
|
||||
if message.author.bot: return
|
||||
|
||||
# Make sure the command get processed as if it was typed with lowercase
|
||||
# Split message.content one first space
|
||||
command = message.content.split(None, 1)
|
||||
if command:
|
||||
command[0] = command[0].lower()
|
||||
message.content = ' '.join(command)
|
||||
message.content = ' '.join(command)
|
||||
|
||||
# process command
|
||||
await self.process_commands(message)
|
||||
|
||||
|
||||
|
||||
client = SebiMachine()
|
||||
# Make sure the key stays private.
|
||||
# I am 99% certain this is valid!
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{
|
||||
"version": 0.1,
|
||||
"display_name" : "[S!] Sebi-Machine",
|
||||
"display_name" : "[ds!] Dev-Sebi",
|
||||
"maintenance": "True",
|
||||
"ownerlist": [],
|
||||
"prefix": "S!"
|
||||
"prefix": "ds!"
|
||||
}
|
||||
@ -17,8 +17,6 @@ class LoadConfig:
|
||||
# Initialize config
|
||||
|
||||
self.ownerlist = self.config["ownerlist"]
|
||||
if self.ownerlist == []:
|
||||
self.ownerlist = [int(i) for i in os.getenv('ownerlist').split(',')]
|
||||
self.defaultprefix = self.config["prefix"]
|
||||
self.version = self.config["version"]
|
||||
self.display_name = self.config["display_name"]
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
"""
|
||||
IO stuff.
|
||||
"""
|
||||
import copy
|
||||
import inspect
|
||||
import os
|
||||
|
||||
@ -45,10 +46,17 @@ def in_here(first_path_bit: str, *path_bits: str, stack_depth: int=0) -> str:
|
||||
module = inspect.getmodule(frame[0])
|
||||
assert hasattr(module, '__file__'), 'No `__file__\' attr, welp.'
|
||||
|
||||
# https://docs.python.org/3/library/inspect.html#the-interpreter-stack
|
||||
# If Python caches strings rather than copying when we move them
|
||||
# around or modify them, then this may cause a referential cycle which
|
||||
# will consume more memory and stop the garbage collection system
|
||||
# from working correctly. Best thing to do here is deepcopy anything
|
||||
# we need and prevent this occuring. Del the references to allow them
|
||||
# to be freed.
|
||||
file = module.__file__
|
||||
|
||||
file = copy.deepcopy(file)
|
||||
del module, frame
|
||||
dir_name = os.path.dirname(file)
|
||||
abs_dir_name = os.path.abspath(dir_name)
|
||||
|
||||
pathish = os.path.join(abs_dir_name, first_path_bit, *path_bits)
|
||||
return pathish
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user