Initial commit
This commit is contained in:
commit
8441a17eb7
50
.gitignore
vendored
Normal file
50
.gitignore
vendored
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
# ---> Vim
|
||||||
|
[._]*.s[a-w][a-z]
|
||||||
|
[._]s[a-w][a-z]
|
||||||
|
*.un~
|
||||||
|
Session.vim
|
||||||
|
.netrwhist
|
||||||
|
*~
|
||||||
|
|
||||||
|
# ---> Emacs
|
||||||
|
# -*- mode: gitignore; -*-
|
||||||
|
*~
|
||||||
|
\#*\#
|
||||||
|
/.emacs.desktop
|
||||||
|
/.emacs.desktop.lock
|
||||||
|
*.elc
|
||||||
|
auto-save-list
|
||||||
|
tramp
|
||||||
|
.\#*
|
||||||
|
|
||||||
|
# Org-mode
|
||||||
|
.org-id-locations
|
||||||
|
*_archive
|
||||||
|
|
||||||
|
# flymake-mode
|
||||||
|
*_flymake.*
|
||||||
|
|
||||||
|
# eshell files
|
||||||
|
/eshell/history
|
||||||
|
/eshell/lastdir
|
||||||
|
|
||||||
|
# elpa packages
|
||||||
|
/elpa/
|
||||||
|
|
||||||
|
# reftex files
|
||||||
|
*.rel
|
||||||
|
|
||||||
|
# AUCTeX auto folder
|
||||||
|
/auto/
|
||||||
|
|
||||||
|
# cask packages
|
||||||
|
.cask/
|
||||||
|
|
||||||
|
tmp/
|
||||||
|
__pycache__/*
|
||||||
|
*/__pycache__/*
|
||||||
|
.directory
|
||||||
|
storage/*
|
||||||
|
*.sha512
|
||||||
|
|
||||||
|
log
|
62
Makefile
Executable file
62
Makefile
Executable file
@ -0,0 +1,62 @@
|
|||||||
|
mainDir := $(shell pwd)
|
||||||
|
|
||||||
|
run: storage/libs/python storage/libs/finaltouch
|
||||||
|
cd $(mainDir);\
|
||||||
|
export LD_LIBRARY_PATH=$(mainDir)/storage/libs/libgit2/libgit2-0.27.0/installed/lib;\
|
||||||
|
export PYTHONPATH=$(mainDir)/storage/libs/python:${PYTHONPATH};\
|
||||||
|
export LIBGIT2=$(mainDir)/storage/libs/libgit2/libgit2-0.27.0/installed/;\
|
||||||
|
python3 -u main.py
|
||||||
|
python: storage/libs/python storage/libs/finaltouch
|
||||||
|
cd $(mainDir);\
|
||||||
|
export LD_LIBRARY_PATH=$(mainDir)/storage/libs/libgit2/libgit2-0.27.0/installed/lib;\
|
||||||
|
export PYTHONPATH=$(mainDir)/storage/libs/python:${PYTHONPATH};\
|
||||||
|
export LIBGIT2=$(mainDir)/storage/libs/libgit2/libgit2-0.27.0/installed/;\
|
||||||
|
python3
|
||||||
|
storage/libs/finaltouch: storage/libs/python
|
||||||
|
touch storage/libs/python storage/libs/get-pip.py
|
||||||
|
storage/libs/libgit2: storage/libs
|
||||||
|
cd $(mainDir);\
|
||||||
|
cd $(mainDir)/storage/libs;\
|
||||||
|
mkdir libgit2;\
|
||||||
|
cd libgit2;\
|
||||||
|
wget https://github.com/libgit2/libgit2/archive/v0.27.0.tar.gz;\
|
||||||
|
tar xzf v0.27.0.tar.gz;\
|
||||||
|
cd libgit2-0.27.0/;\
|
||||||
|
cmake . -DCMAKE_INSTALL_PREFIX=$(mainDir)/storage/libs/libgit2/libgit2-0.27.0/installed;\
|
||||||
|
make;\
|
||||||
|
make install;\
|
||||||
|
touch $(mainDir)/storage/libs/libgit2
|
||||||
|
|
||||||
|
storage/libs/get-pip.py: storage/libs
|
||||||
|
cd $(mainDir);\
|
||||||
|
cd storage/libs;\
|
||||||
|
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py;\
|
||||||
|
export PYTHONPATH=$(mainDir)/storage/libs/python:${PYTHONPATH};\
|
||||||
|
python3 get-pip.py --user
|
||||||
|
|
||||||
|
storage/libs/python: storage/libs storage/libs/get-pip.py storage/libs/dependencies.sha512
|
||||||
|
cd $(mainDir);\
|
||||||
|
mkdir storage/libs/python;\
|
||||||
|
rm -r storage/libs/python;\
|
||||||
|
mkdir storage/libs/python;\
|
||||||
|
export LD_LIBRARY_PATH=$(mainDir)/storage/libs/libgit2/libgit2-0.27.0/installed/lib;\
|
||||||
|
export LIBGIT2=$(mainDir)/storage/libs/libgit2/libgit2-0.27.0/installed/;\
|
||||||
|
export PYTHONPATH=$(mainDir)/storage/libs/python:${PYTHONPATH};\
|
||||||
|
~/.local/bin/pip3 install -U -t storage/libs/python -r dependencies
|
||||||
|
touch $(mainDir)/storage/libs/python
|
||||||
|
storage:
|
||||||
|
cd $(mainDir);\
|
||||||
|
mkdir storage;\
|
||||||
|
echo .
|
||||||
|
storage/libs: storage
|
||||||
|
cd $(mainDir);\
|
||||||
|
mkdir storage/libs;\
|
||||||
|
echo .
|
||||||
|
|
||||||
|
storage/libs/dependencies.sha512: dependencies storage/libs
|
||||||
|
cd $(mainDir);\
|
||||||
|
sha512sum $< | cmp -s $@ -; if test $$? -ne 0; then sha512sum $< > $@; fi
|
||||||
|
|
||||||
|
clean:
|
||||||
|
cd $(mainDir);\
|
||||||
|
rm -r storage
|
2
dependencies
Normal file
2
dependencies
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
https://github.com/Rapptz/discord.py/archive/rewrite.zip#egg=discord.py[voice]
|
||||||
|
Pillow==5.2.0
|
343
main.py
Executable file
343
main.py
Executable file
@ -0,0 +1,343 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
import discord
|
||||||
|
import os
|
||||||
|
import importlib
|
||||||
|
import traceback
|
||||||
|
client = discord.Client()
|
||||||
|
prefix='//'
|
||||||
|
modules={} # format : {'modulename':[module, initializedclass]}
|
||||||
|
owners=[281166473102098433]
|
||||||
|
async def auth(user, moduleName):
|
||||||
|
if user.id in owners:
|
||||||
|
return True
|
||||||
|
try:
|
||||||
|
modules[moduleName][1].authlist
|
||||||
|
except:
|
||||||
|
return True
|
||||||
|
for guild in client.guilds:
|
||||||
|
if guild.get_member(user.id):
|
||||||
|
for roleid in modules[moduleName][1].authlist:
|
||||||
|
if roleid in [r.id for r in guild.get_member(user.id).roles]:
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_ready():
|
||||||
|
print("Bienvenue, {0.user}, l'heure est venue de faire des fractales.".format(client))
|
||||||
|
panic=False
|
||||||
|
async def panicLoad():
|
||||||
|
print("--PANIC LOAD--")
|
||||||
|
panic=True
|
||||||
|
modules={}
|
||||||
|
for filename in os.listdir('modules'):
|
||||||
|
if filename.endswith('.py'):
|
||||||
|
try:
|
||||||
|
modules.update({filename[:-3:]:[importlib.import_module('modules.' + filename[:-3:])]})
|
||||||
|
print("Module {0} chargé.".format(filename[:-3:]))
|
||||||
|
except:
|
||||||
|
print("[ERROR] Le module {0} n'a pas pu être chargé.".format(filename))
|
||||||
|
#initialisation
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
try:
|
||||||
|
modules[moduleName].append(modules[moduleName][0].MainClass(client, modules, owners, prefix))
|
||||||
|
print("Module {0} initialisé.".format(moduleName))
|
||||||
|
except:
|
||||||
|
print("[ERROR] Le module {0} n'a pas pu être initialisé.".format(moduleName))
|
||||||
|
modules.pop(moduleName, None)
|
||||||
|
|
||||||
|
if 'modules.py' in os.listdir('modules'):
|
||||||
|
try:
|
||||||
|
modules.update({'modules':[importlib.import_module('modules.' + 'modules')]})
|
||||||
|
print("Module {0} chargé.".format('modules'))
|
||||||
|
try:
|
||||||
|
modules['modules'].append(modules['modules'][0].MainClass(client, modules, owners, prefix))
|
||||||
|
print("Module {0} initialisé.".format('modules'))
|
||||||
|
try:
|
||||||
|
await modules['modules'][1].on_ready()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
except:
|
||||||
|
print("[ERROR] Le module {0} n'a pas pu être initialisé.".format('modules'))
|
||||||
|
await panicLoad()
|
||||||
|
except:
|
||||||
|
print("[ERROR] Le module {0} n'a pas pu être chargé.".format('modules.py'))
|
||||||
|
await panicLoad()
|
||||||
|
else:
|
||||||
|
await panicLoad()
|
||||||
|
|
||||||
|
if panic:
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_ready' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_ready()
|
||||||
|
else:
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if (not moduleName=='modules') and 'on_ready' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_ready()
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_error(event, *args, **kwargs):
|
||||||
|
print(traceback.format_exc())
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_error' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_error(event, *args, **kwargs)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_socket_raw_receive(msg):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_socket_raw_receive' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_socket_raw_receive(msg)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_socket_raw_send(payload):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_socket_raw_send' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_socket_raw_send(payload)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_typing(channel, user, when):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_typing' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_typing(channel, user, when)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_message(message):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_message' in modules[moduleName][1].events and message.content.startswith(modules[moduleName][1].command):
|
||||||
|
if await auth(message.author, moduleName):
|
||||||
|
await modules[moduleName][1].on_message(message)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_message_delete(message):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_message_delete' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_message_delete(message)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_raw_message_delete(payload):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_raw_message_delete' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_raw_message_delete(payload)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_raw_bulk_message_delete(payload):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_raw_bulk_message_delete' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_raw_bulk_message_delete(payload)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_message_edit(before, after):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_message_edit' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_message_edit(before, after)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_raw_message_edit(payload):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_raw_message_edit' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_raw_message_edit(payload)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_reaction_add(reaction, user):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_reaction_add' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_reaction_add(reaction, user)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_raw_reaction_add(payload):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_raw_reaction_add' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_raw_reaction_add(payload)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_reaction_remove(reaction, user):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_reaction_remove' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_reaction_remove(reaction, user)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_raw_reaction_remove(payload):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_raw_reaction_remove' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_raw_reaction_remove(payload)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_reaction_clear(message, reactions):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_reaction_clear' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_reaction_clear(message, reactions)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_raw_reaction_clear(payload):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_raw_reaction_clear' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_raw_reaction_clear(payload)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_private_channel_delete(channel):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_private_channel_delete' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_private_channel_delete(channel)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_private_channel_create(channel):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_private_channel_create' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_private_channel_create(channel)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_private_channel_update(before, after):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_private_channel_update' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_private_channel_update(before, after)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_private_channel_pins_update(channel, last_pin):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_private_channel_pins_update' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_private_channel_pins_update(channel, last_pin)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_guild_channel_delete(channel):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_guild_channel_delete' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_guild_channel_delete(channel)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_guild_channel_create(channel):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_guild_channel_create' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_guild_channel_create(channel)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_guild_channel_update(before, after):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_guild_channel_update' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_guild_channel_update(before, after)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_guild_channel_pins_update(channel, last_pin):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_guild_channel_pins_update' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_guild_channel_pins_update(channel, last_pin)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_member_join(member):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_member_join' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_member_join(member)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_member_remove(member):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_member_remove' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_member_remove(member)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_member_update(before, after):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_member_update' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_member_update(before, after)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_guild_join(guild):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_guild_join' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_guild_join(guild)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_guild_remove(guild):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_guild_remove' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_guild_remove(guild)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_guild_update(before, after):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_guild_update' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_guild_update(before, after)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_guild_role_create(role):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_guild_role_create' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_guild_role_create(role)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_guild_role_delete(role):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_guild_role_delete' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_guild_role_delete(role)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_guild_role_update(before, after):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_guild_role_update' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_guild_role_update(before, after)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_guild_emojis_update(guild, before, after):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_guild_emojis_update' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_guild_emojis_update(guild, before, after)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_guild_available(guild):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_guild_available' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_guild_available(guild)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_guild_unavailable(guild):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_guild_unavailable' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_guild_unavailable(guild)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_voice_state_update(member, before, after):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_voice_state_update' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_voice_state_update(member, before, after)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_member_ban(guild, user):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_member_ban' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_member_ban(guild, user)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_member_unban(guild, user):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_member_unban' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_member_unban(guild, user)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_group_join(channel, user):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_group_join' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_group_join(channel, user)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_group_remove(channel, user):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_group_remove' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_group_remove(channel, user)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_relationship_add(relationship):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_relationship_add' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_relationship_add(relationship)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_relationship_remove(relationship):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_relationship_remove' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_relationship_remove(relationship)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_relationship_update(before, after):
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if 'on_relationship_update' in modules[moduleName][1].events:
|
||||||
|
await modules[moduleName][1].on_relationship_update(before, after)
|
||||||
|
|
||||||
|
client.run(os.environ['DISCORD_TOKEN'])
|
20
modules/dummy.py
Normal file
20
modules/dummy.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#dummy module
|
||||||
|
import asyncio
|
||||||
|
class MainClass():
|
||||||
|
def __init__(self, client, modules, owners, prefix):
|
||||||
|
self.client = client
|
||||||
|
self.modules = modules
|
||||||
|
self.owners = owners
|
||||||
|
self.prefix = prefix
|
||||||
|
self.events=['on_message'] #events list
|
||||||
|
self.command="%sdummy"%self.prefix #command prefix (can be empty to catch every single messages)
|
||||||
|
|
||||||
|
self.name="Dummy"
|
||||||
|
self.description="Module d'exemple"
|
||||||
|
self.interactive=False
|
||||||
|
self.color=0x000000
|
||||||
|
self.help="""\
|
||||||
|
Aucune fonction.
|
||||||
|
"""
|
||||||
|
async def on_message(self, message):
|
||||||
|
print(message.content)
|
98
modules/errors.py
Normal file
98
modules/errors.py
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
import asyncio
|
||||||
|
import traceback
|
||||||
|
import discord
|
||||||
|
import random
|
||||||
|
import pickle
|
||||||
|
import os.path
|
||||||
|
import collections
|
||||||
|
from subprocess import call
|
||||||
|
moduleFiles="errors"
|
||||||
|
class MainClass():
|
||||||
|
def saveObject(self, object, objectname):
|
||||||
|
with open("storage/%s/"%moduleFiles + objectname + "tmp", "wb") as pickleFile:
|
||||||
|
pickler = pickle.Pickler(pickleFile)
|
||||||
|
pickler.dump(object)
|
||||||
|
call(['mv', "storage/%s/"%moduleFiles + objectname + "tmp", "storage/%s/"%moduleFiles + objectname])
|
||||||
|
def loadObject(self, objectname):
|
||||||
|
if self.saveExists(objectname):
|
||||||
|
with open("storage/%s/"%moduleFiles + objectname, "rb") as pickleFile:
|
||||||
|
unpickler = pickle.Unpickler(pickleFile)
|
||||||
|
return unpickler.load()
|
||||||
|
|
||||||
|
def saveExists(self, objectname):
|
||||||
|
return os.path.isfile("storage/%s/"%moduleFiles + objectname)
|
||||||
|
def __init__(self, client, modules, owners):
|
||||||
|
if not os.path.isdir("storage/%s"%moduleFiles):
|
||||||
|
call(['mkdir', 'storage/%s'%moduleFiles])
|
||||||
|
self.errorsDeque=None
|
||||||
|
self.devchanids=[549662392120901633]
|
||||||
|
self.memes=[
|
||||||
|
"https://moriya.zapto.org/avatars/5?s=140"
|
||||||
|
]
|
||||||
|
self.icon="https://moriya.zapto.org/avatars/5?s=140"
|
||||||
|
self.client = client
|
||||||
|
self.modules = modules
|
||||||
|
self.owners = owners
|
||||||
|
self.prefix = prefix
|
||||||
|
self.events=['on_error', 'on_message', 'on_ready'] #events list
|
||||||
|
self.command="%slicorne"%self.prefix #command prefix (can be empty to catch every single messages)
|
||||||
|
|
||||||
|
self.name="Error Handling"
|
||||||
|
self.description="Module de gestions des erreurs"
|
||||||
|
self.interactive=True
|
||||||
|
self.authlist=[]
|
||||||
|
self.color=0xdb1348
|
||||||
|
self.help="""\
|
||||||
|
</prefix>licorne
|
||||||
|
=> Crée une erreur.
|
||||||
|
"""
|
||||||
|
async def on_ready(self):
|
||||||
|
if self.saveExists('errorsDeque'):
|
||||||
|
self.errorsDeque=self.loadObject('errorsDeque')
|
||||||
|
else:
|
||||||
|
self.errorsDeque=collections.deque()
|
||||||
|
for i in range(len(self.errorsDeque)):
|
||||||
|
try:
|
||||||
|
messagelst=self.errorsDeque.popleft()
|
||||||
|
channel = self.client.get_channel(messagelst[0])
|
||||||
|
delete_message = await channel.get_message(messagelst[1])
|
||||||
|
await delete_message.delete()
|
||||||
|
except:
|
||||||
|
raise
|
||||||
|
self.saveObject(self.errorsDeque, 'errorsDeque')
|
||||||
|
async def on_message(self, message):
|
||||||
|
5/0
|
||||||
|
|
||||||
|
async def on_error(self, event, *args, **kwargs):
|
||||||
|
embed = discord.Embed(title="Aïe :/", description="```PYTHON\n{0}```".format(traceback.format_exc()), color=self.color).set_image(url=random.choice(self.memes))
|
||||||
|
messagelst = None
|
||||||
|
try:
|
||||||
|
message = await args[0].channel.send(embed=embed.set_footer(text="Ce message s'autodétruira dans une minute.", icon_url=self.icon))
|
||||||
|
messagelst=[message.channel.id, message.id]
|
||||||
|
self.errorsDeque.append(messagelst)
|
||||||
|
except:
|
||||||
|
try:
|
||||||
|
message = args[1].channel.send(embed=embed.set_footer(text="Ce message s'autodétruira dans une minute.", icon_url=self.icon))
|
||||||
|
messagelst=[message.channel.id, message.id]
|
||||||
|
self.errorsDeque.append(messagelst)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
for chanid in self.devchanids:
|
||||||
|
try:
|
||||||
|
await self.client.get_channel(chanid).send(embed=embed.set_footer(text="Ce message ne s'autodétruira pas.", icon_url=self.icon))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
self.saveObject(self.errorsDeque, 'errorsDeque')
|
||||||
|
await asyncio.sleep(60)
|
||||||
|
try:
|
||||||
|
channel = self.client.get_channel(messagelst[0])
|
||||||
|
delete_message = await channel.get_message(messagelst[1])
|
||||||
|
await delete_message.delete()
|
||||||
|
except:
|
||||||
|
raise
|
||||||
|
finally:
|
||||||
|
try:
|
||||||
|
self.errorsDeque.remove(messagelst)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
self.saveObject(self.errorsDeque, 'errorsDeque')
|
62
modules/help.py
Normal file
62
modules/help.py
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
import asyncio
|
||||||
|
import discord
|
||||||
|
class MainClass():
|
||||||
|
async def auth(self, user, moduleName):
|
||||||
|
if user.id in self.owners:
|
||||||
|
return True
|
||||||
|
try:
|
||||||
|
self.modules[moduleName][1].authlist
|
||||||
|
except:
|
||||||
|
return True
|
||||||
|
for guild in self.client.guilds:
|
||||||
|
if guild.get_member(user.id):
|
||||||
|
for roleid in self.modules[moduleName][1].authlist:
|
||||||
|
if roleid in [r.id for r in guild.get_member(user.id).roles]:
|
||||||
|
return True
|
||||||
|
def __init__(self, client, modules, owners, prefix):
|
||||||
|
self.client = client
|
||||||
|
self.modules = modules
|
||||||
|
self.owners = owners
|
||||||
|
self.prefix = prefix
|
||||||
|
self.events=['on_message'] #events list
|
||||||
|
self.command="%shelp"%self.prefix #command prefix (can be empty to catch every single messages)
|
||||||
|
|
||||||
|
self.name="Aide"
|
||||||
|
self.description="Module d'aide"
|
||||||
|
self.interactive=True
|
||||||
|
self.color=0x3c9653
|
||||||
|
self.help="""\
|
||||||
|
</prefix>help list
|
||||||
|
=> Affiche une liste des modules ainsi qu'une description
|
||||||
|
|
||||||
|
</prefix>help <nom du module>
|
||||||
|
=> Affiche l'aide spécifique d'un module.
|
||||||
|
|
||||||
|
</prefix>help all
|
||||||
|
=> Affiche les aides de tous les modules
|
||||||
|
"""
|
||||||
|
async def on_message(self, message):
|
||||||
|
args=message.content.lower().split(' ')
|
||||||
|
if len(args)==2 and args[1]=='list':
|
||||||
|
embed=discord.Embed(title="[Aide] - Liste des modules", color=self.color)
|
||||||
|
for moduleName in list(self.modules.keys()):
|
||||||
|
if self.modules[moduleName][1].interactive and await self.auth(message.author, moduleName):
|
||||||
|
embed.add_field(name=moduleName.capitalize(), value=self.modules[moduleName][1].description)
|
||||||
|
await message.channel.send(embed=embed)
|
||||||
|
elif len(args)==2 and args[1] in list(self.modules.keys()) and self.modules[args[1]][1].interactive and await self.auth(message.author, args[1]):
|
||||||
|
await message.channel.send(embed=discord.Embed(title="[{0}] - Aide".format(args[1].capitalize()), description=self.modules[args[1]][1].help.replace("</prefix>", self.prefix), color=self.modules[args[1]][1].color))
|
||||||
|
elif len(args)==2 and args[1]=='all':
|
||||||
|
async with message.channel.typing():
|
||||||
|
for moduleName in list(self.modules.keys()):
|
||||||
|
if self.modules[moduleName][1].interactive and await self.auth(message.author, moduleName):
|
||||||
|
await message.channel.send(embed=discord.Embed(title="[{0}] - Aide".format(moduleName.capitalize()), description=self.modules[moduleName][1].help.replace("</prefix>", self.prefix), color=self.modules[moduleName][1].color))
|
||||||
|
else:
|
||||||
|
await self.modules['help'][1].send_help(message.channel, self)
|
||||||
|
|
||||||
|
async def send_help(self, channel, module):
|
||||||
|
moduleName=None
|
||||||
|
for name, listpck in self.modules.items():
|
||||||
|
if module == listpck[1]:
|
||||||
|
moduleName=name
|
||||||
|
break
|
||||||
|
await channel.send(embed=discord.Embed(title="[{0}] - Aide".format(moduleName.capitalize()), description=self.modules[moduleName][1].help.replace("</prefix>", self.prefix), color=self.modules[moduleName][1].color))
|
111
modules/modules.py
Normal file
111
modules/modules.py
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
import discord
|
||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
import importlib
|
||||||
|
class MainClass():
|
||||||
|
def __init__(self, client, modules, owners, prefix):
|
||||||
|
self.states={}
|
||||||
|
for moduleName in os.listdir('modules'):
|
||||||
|
if moduleName.endswith(".py"):
|
||||||
|
self.states.update({moduleName[:-3:]:'not loaded'})
|
||||||
|
for moduleName in list(modules.keys()):
|
||||||
|
if len(modules[moduleName]) == 2 :
|
||||||
|
self.states.update({moduleName:'initialized'})
|
||||||
|
self.client = client
|
||||||
|
self.modules = modules
|
||||||
|
self.owners = owners
|
||||||
|
self.prefix=prefix
|
||||||
|
self.events=['on_message', 'on_ready'] #events list
|
||||||
|
self.command="%smodule"%self.prefix #command prefix (can be empty to catch every single messages)
|
||||||
|
|
||||||
|
self.name="Modules"
|
||||||
|
self.description="Module de gestion des modules"
|
||||||
|
self.interactive=True
|
||||||
|
self.authlist=[431043517217898496]
|
||||||
|
self.color=0x8f3196
|
||||||
|
self.help="""\
|
||||||
|
</prefix>modules list
|
||||||
|
=> Liste les modules ainsi que leurs états
|
||||||
|
|
||||||
|
</prefix>modules enable <module/modules>
|
||||||
|
=> Charge et active le / les modules spécifié(s)
|
||||||
|
|
||||||
|
</prefix>modules disable <module/modules>
|
||||||
|
=> Désactive et décharge le / les modules spécifié(s)
|
||||||
|
|
||||||
|
=> <module/modules>
|
||||||
|
==> Unique module ou liste de module séparés par des virgules
|
||||||
|
"""
|
||||||
|
self.states.update({'modules': 'initialized'})
|
||||||
|
async def on_message(self, message):
|
||||||
|
error=None
|
||||||
|
args = message.content.split(" ")
|
||||||
|
if len(args) == 2 and args[1]=='list':
|
||||||
|
await message.channel.send(embed=discord.Embed(title="[Modules] - Modules list", description="```PYTHON\n{0}```".format(str(self.states).replace(',', '\n,'))))
|
||||||
|
elif len(args) == 3 and args[1] in ['enable', 'disable', 'reload']:
|
||||||
|
if args[1]=='enable':
|
||||||
|
for moduleName in args[2].split(','):
|
||||||
|
if moduleName + '.py' in os.listdir('modules'):
|
||||||
|
try:
|
||||||
|
self.enable_module(moduleName)
|
||||||
|
await message.channel.send(message.author.mention + ", le module {0} a été activé".format(moduleName))
|
||||||
|
except Exception as e:
|
||||||
|
error=e
|
||||||
|
await message.channel.send(message.author.mention + ", le module {0} **n'a pas pu être activé**".format(moduleName))
|
||||||
|
else:
|
||||||
|
await message.channel.send(message.author.mention + ", le module {0} n'existe pas.".format(moduleName))
|
||||||
|
elif args[1]=='disable':
|
||||||
|
for moduleName in args[2].split(','):
|
||||||
|
if moduleName == 'modules':
|
||||||
|
await message.channel.send(message.author.mention + ", le module {0} ne peut pas être désactivé car il est nécéssaire pour gérer les modules.".format(moduleName))
|
||||||
|
else:
|
||||||
|
if moduleName + '.py' in os.listdir('modules'):
|
||||||
|
self.unload_module(moduleName)
|
||||||
|
await message.channel.send(message.author.mention + ", le module {0} a été désactivé.".format(moduleName))
|
||||||
|
else:
|
||||||
|
await message.channel.send(message.author.mention + ", le module {0} n'existe pas.".format(moduleName))
|
||||||
|
else:
|
||||||
|
await self.modules['help'][1].send_help(message.channel, self)
|
||||||
|
if error:
|
||||||
|
raise error
|
||||||
|
async def on_ready(self):
|
||||||
|
error=None
|
||||||
|
for fileName in os.listdir('modules'):
|
||||||
|
try:
|
||||||
|
self.load_module(fileName[:-3:])
|
||||||
|
self.init_module(fileName[:-3:])
|
||||||
|
except Exception as e:
|
||||||
|
error=e
|
||||||
|
if error:
|
||||||
|
raise error
|
||||||
|
def enable_module(self, moduleName):
|
||||||
|
self.load_module(moduleName)
|
||||||
|
self.init_module(moduleName)
|
||||||
|
|
||||||
|
def load_module(self, moduleName):
|
||||||
|
if moduleName + ".py" in os.listdir('modules'):
|
||||||
|
if not moduleName in list(self.states.keys()) or self.states[moduleName] == 'not loaded':
|
||||||
|
try:
|
||||||
|
self.modules.update({moduleName:[importlib.import_module('modules.' + moduleName)]})
|
||||||
|
print("Module {0} chargé.".format(moduleName))
|
||||||
|
self.states[moduleName] = 'loaded'
|
||||||
|
except:
|
||||||
|
print("[ERROR] Le module {0} n'a pas pu être chargé.".format(moduleName))
|
||||||
|
self.unload_module(moduleName)
|
||||||
|
raise
|
||||||
|
def init_module(self, moduleName):
|
||||||
|
if moduleName + ".py" in os.listdir('modules'):
|
||||||
|
if self.states[moduleName] == 'loaded':
|
||||||
|
try:
|
||||||
|
self.modules[moduleName].append(self.modules[moduleName][0].MainClass(self.client, self.modules, self.owners, self.prefix))
|
||||||
|
print("Module {0} initialisé.".format(moduleName))
|
||||||
|
self.states[moduleName] = 'initialized'
|
||||||
|
except:
|
||||||
|
print("[ERROR] Le module {0} n'a pas pu être initialisé.".format(moduleName))
|
||||||
|
self.unload_module(moduleName)
|
||||||
|
raise
|
||||||
|
def unload_module(self, moduleName):
|
||||||
|
if moduleName + ".py" in os.listdir('modules'):
|
||||||
|
self.states[moduleName] = 'not loaded'
|
||||||
|
self.modules.pop(moduleName, None)
|
||||||
|
print("Module {0} déchargé.".format(moduleName))
|
25
modules/restart.py
Normal file
25
modules/restart.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import asyncio
|
||||||
|
|
||||||
|
class MainClass():
|
||||||
|
def __init__(self, client, modules, owners, prefix):
|
||||||
|
self.client = client
|
||||||
|
self.modules = modules
|
||||||
|
self.owners = owners
|
||||||
|
self.prefix=prefix
|
||||||
|
self.events=['on_message'] #events list
|
||||||
|
self.command="%srestart"%self.prefix #command prefix (can be empty to catch every single messages)
|
||||||
|
|
||||||
|
self.name="Restart"
|
||||||
|
self.description="Module gérant les redémarrages du bot"
|
||||||
|
self.interactive=True
|
||||||
|
self.authlist=[431043517217898496]
|
||||||
|
self.color=0x000000
|
||||||
|
self.help="""\
|
||||||
|
</prefix>restart
|
||||||
|
"""
|
||||||
|
async def on_message(self, message):
|
||||||
|
args=message.content.split(" ")
|
||||||
|
if args[0]=='%srestart'%self.prefix:
|
||||||
|
await message.channel.send(message.author.mention + ", Le bot va redémarrer...")
|
||||||
|
else:
|
||||||
|
await self.modules['help'][1].send_help(message.channel, self)
|
Loading…
Reference in New Issue
Block a user