Bot base version bump
This commit is contained in:
parent
ea6e11745c
commit
333ac8b732
26
main.py
26
main.py
@ -6,21 +6,21 @@ import traceback
|
||||
import discord
|
||||
|
||||
client = discord.Client()
|
||||
prefix = ";"
|
||||
prefix = ';'
|
||||
modules = {} # format : {'modulename':[module, initializedclass]}
|
||||
owners = [281166473102098433, 318866596502306816, 436105272310759426]
|
||||
|
||||
|
||||
async def auth(user, moduleName):
|
||||
async def auth(user, module_name):
|
||||
if user.id in owners:
|
||||
return True
|
||||
try:
|
||||
modules[moduleName][1].authlist
|
||||
modules[module_name][1].authlist
|
||||
except:
|
||||
return True
|
||||
for guild in client.guilds:
|
||||
if guild.get_member(user.id):
|
||||
for roleid in modules[moduleName][1].authlist:
|
||||
for roleid in modules[module_name][1].authlist:
|
||||
if roleid in [r.id for r in guild.get_member(user.id).roles]:
|
||||
return True
|
||||
|
||||
@ -31,7 +31,7 @@ async def on_ready():
|
||||
panic = False
|
||||
error = None
|
||||
|
||||
async def panicLoad():
|
||||
async def panic_load():
|
||||
print("--PANIC LOAD--")
|
||||
panic = True
|
||||
modules = {}
|
||||
@ -43,13 +43,13 @@ async def on_ready():
|
||||
except:
|
||||
print("[ERROR] Le module {0} n'a pas pu être chargé.".format(filename))
|
||||
# initialisation
|
||||
for moduleName in list(modules.keys()):
|
||||
for module_name in list(modules.keys()):
|
||||
try:
|
||||
modules[moduleName].append(modules[moduleName][0].MainClass(client, modules, owners, prefix))
|
||||
print("Module {0} initialisé.".format(moduleName))
|
||||
modules[module_name].append(modules[module_name][0].MainClass(client, modules, owners, prefix))
|
||||
print("Module {0} initialisé.".format(module_name))
|
||||
except:
|
||||
print("[ERROR] Le module {0} n'a pas pu être initialisé.".format(moduleName))
|
||||
modules.pop(moduleName, None)
|
||||
print("[ERROR] Le module {0} n'a pas pu être initialisé.".format(module_name))
|
||||
modules.pop(module_name, None)
|
||||
|
||||
if 'modules.py' in os.listdir('modules'):
|
||||
try:
|
||||
@ -64,14 +64,14 @@ async def on_ready():
|
||||
error = e
|
||||
except Exception as e:
|
||||
print("[ERROR] Le module {0} n'a pas pu être initialisé.".format('modules'))
|
||||
await panicLoad()
|
||||
await panic_load()
|
||||
error = e
|
||||
except Exception as e:
|
||||
print("[ERROR] Le module {0} n'a pas pu être chargé.".format('modules.py'))
|
||||
await panicLoad()
|
||||
await panic_load()
|
||||
error = e
|
||||
else:
|
||||
await panicLoad()
|
||||
await panic_load()
|
||||
|
||||
if panic:
|
||||
for moduleName in list(modules.keys()):
|
||||
|
@ -1,5 +1,4 @@
|
||||
# dummy module
|
||||
class MainClass():
|
||||
class MainClass:
|
||||
def __init__(self, client, modules, owners, prefix):
|
||||
self.client = client
|
||||
self.modules = modules
|
||||
|
@ -11,33 +11,33 @@ import discord
|
||||
moduleFiles = "errors"
|
||||
|
||||
|
||||
class MainClass():
|
||||
def saveObject(self, object, objectname):
|
||||
with open("storage/%s/" % moduleFiles + objectname + "tmp", "wb") as pickleFile:
|
||||
class MainClass:
|
||||
def save_object(self, object_instance, object_name):
|
||||
with open("storage/%s/" % moduleFiles + object_name + "tmp", "wb") as pickleFile:
|
||||
pickler = pickle.Pickler(pickleFile)
|
||||
pickler.dump(object)
|
||||
call(['mv', "storage/%s/" % moduleFiles + objectname + "tmp", "storage/%s/" % moduleFiles + objectname])
|
||||
pickler.dump(object_instance)
|
||||
call(['mv', "storage/%s/" % moduleFiles + object_name + "tmp", "storage/%s/" % moduleFiles + object_name])
|
||||
|
||||
def loadObject(self, objectname):
|
||||
if self.saveExists(objectname):
|
||||
def load_object(self, objectname):
|
||||
if self.save_exists(objectname):
|
||||
with open("storage/%s/" % moduleFiles + objectname, "rb") as pickleFile:
|
||||
unpickler = pickle.Unpickler(pickleFile)
|
||||
return unpickler.load()
|
||||
|
||||
def saveExists(self, objectname):
|
||||
def save_exists(self, objectname):
|
||||
return os.path.isfile("storage/%s/" % moduleFiles + objectname)
|
||||
|
||||
def __init__(self, client, modules, owners, prefix):
|
||||
if not os.path.isdir("storage/%s" % moduleFiles):
|
||||
call(['mkdir', 'storage/%s' % moduleFiles])
|
||||
self.errorsDeque = None
|
||||
self.devchanids = [549662392120901633]
|
||||
self.developpement_chan_id = [549662392120901633]
|
||||
self.memes = [
|
||||
"https://cdn.discordapp.com/avatars/436105272310759426/6e6850c03fba976f45295a76410a6699.png?size=64",
|
||||
"https://cdn.discordapp.com/avatars/281166473102098433/6e92bff42c9f409334e1580c9f666228.png?size=64",
|
||||
"https://cdn.discordapp.com/avatars/318866596502306816/8e1792132f5b9ceaca6f7aea1fd489f0.png?size=64"
|
||||
]
|
||||
self.icon = "https://moriya.zapto.org/avatars/5?s=140"
|
||||
self.icon = "https://cdn.discordapp.com/attachments/340620490009739265/431569015664803840/photo.png"
|
||||
self.client = client
|
||||
self.modules = modules
|
||||
self.owners = owners
|
||||
@ -48,7 +48,7 @@ class MainClass():
|
||||
self.name = "Error Handling"
|
||||
self.description = "Module de gestions des erreurs"
|
||||
self.interactive = True
|
||||
self.authlist = []
|
||||
self.super_users_list = [431043517217898496]
|
||||
self.color = 0xdb1348
|
||||
self.help = """\
|
||||
</prefix>licorne
|
||||
@ -56,8 +56,8 @@ class MainClass():
|
||||
"""
|
||||
|
||||
async def on_ready(self):
|
||||
if self.saveExists('errorsDeque'):
|
||||
self.errorsDeque = self.loadObject('errorsDeque')
|
||||
if self.save_exists('errorsDeque'):
|
||||
self.errorsDeque = self.load_object('errorsDeque')
|
||||
else:
|
||||
self.errorsDeque = collections.deque()
|
||||
for i in range(len(self.errorsDeque)):
|
||||
@ -68,7 +68,7 @@ class MainClass():
|
||||
await delete_message.delete()
|
||||
except:
|
||||
raise
|
||||
self.saveObject(self.errorsDeque, 'errorsDeque')
|
||||
self.save_object(self.errorsDeque, 'errorsDeque')
|
||||
|
||||
async def on_message(self, message):
|
||||
5 / 0
|
||||
@ -76,37 +76,37 @@ class MainClass():
|
||||
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
|
||||
message_list = 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)
|
||||
message_list = [message.channel.id, message.id]
|
||||
self.errorsDeque.append(message_list)
|
||||
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)
|
||||
message_list = [message.channel.id, message.id]
|
||||
self.errorsDeque.append(message_list)
|
||||
except:
|
||||
pass
|
||||
for chanid in self.devchanids:
|
||||
for chanid in self.developpement_chan_id:
|
||||
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')
|
||||
self.save_object(self.errorsDeque, 'errorsDeque')
|
||||
await asyncio.sleep(60)
|
||||
try:
|
||||
channel = self.client.get_channel(messagelst[0])
|
||||
delete_message = await channel.get_message(messagelst[1])
|
||||
channel = self.client.get_channel(message_list[0])
|
||||
delete_message = await channel.get_message(message_list[1])
|
||||
await delete_message.delete()
|
||||
except:
|
||||
raise
|
||||
finally:
|
||||
try:
|
||||
self.errorsDeque.remove(messagelst)
|
||||
except:
|
||||
self.errorsDeque.remove(message_list)
|
||||
except ValueError:
|
||||
pass
|
||||
self.saveObject(self.errorsDeque, 'errorsDeque')
|
||||
self.save_object(self.errorsDeque, 'errorsDeque')
|
||||
|
@ -1,8 +1,7 @@
|
||||
# dummy module
|
||||
import os
|
||||
|
||||
|
||||
class MainClass():
|
||||
class MainClass:
|
||||
def __init__(self, client, modules, owners, prefix):
|
||||
self.client = client
|
||||
self.modules = modules
|
||||
@ -27,12 +26,12 @@ class MainClass():
|
||||
async def on_message(self, message):
|
||||
args = message.content.split(' ')
|
||||
if len(args) == 2 and args[1] == 'update':
|
||||
with os.popen('git fetch --all') as stdin:
|
||||
await message.channel.send(stdin.read())
|
||||
with os.popen('git symbolic-ref HEAD 2>/dev/null') as stdin:
|
||||
branch = stdin.read().replace('refs/heads/', '')
|
||||
with os.popen('git reset --hard origin/%s' % branch) as stdin:
|
||||
await message.channel.send(stdin.read())
|
||||
with os.popen('git fetch --all') as std_out:
|
||||
await message.channel.send(std_out.read())
|
||||
with os.popen('git symbolic-ref HEAD 2>/dev/null') as std_out:
|
||||
branch = std_out.read().replace('refs/heads/', '')
|
||||
with os.popen('git reset --hard origin/%s' % branch) as std_out:
|
||||
await message.channel.send(std_out.read())
|
||||
await message.channel.send(message.author.mention + ", Le dépôt a été mis à jour (fetch + reset --hard).")
|
||||
else:
|
||||
await self.modules['help'][1].send_help(message.channel, self)
|
||||
|
@ -1,8 +1,8 @@
|
||||
import discord
|
||||
|
||||
|
||||
class MainClass():
|
||||
async def auth(self, user, moduleName):
|
||||
class MainClass:
|
||||
def auth(self, user, moduleName):
|
||||
if user.id in self.owners:
|
||||
return True
|
||||
try:
|
||||
@ -11,8 +11,8 @@ class MainClass():
|
||||
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]:
|
||||
for role_id in self.modules[moduleName][1].authlist:
|
||||
if role_id in [r.id for r in guild.get_member(user.id).roles]:
|
||||
return True
|
||||
|
||||
def __init__(self, client, modules, owners, prefix):
|
||||
@ -43,31 +43,36 @@ class MainClass():
|
||||
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):
|
||||
if self.modules[moduleName][1].interactive and \
|
||||
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]):
|
||||
elif len(args) == 2 and args[1] in list(self.modules.keys()) and \
|
||||
self.modules[args[1]][1].interactive and \
|
||||
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))
|
||||
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):
|
||||
if self.modules[moduleName][1].interactive and \
|
||||
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))
|
||||
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]:
|
||||
for name, list_module_instance in self.modules.items():
|
||||
if module == list_module_instance[1]:
|
||||
moduleName = name
|
||||
break
|
||||
await channel.send(embed=discord.Embed(title="[{0}] - Aide".format(moduleName.capitalize()),
|
||||
|
@ -10,7 +10,7 @@ temp_dir = "temp_load"
|
||||
moduleFiles = "modules"
|
||||
|
||||
|
||||
class MainClass():
|
||||
class MainClass:
|
||||
def __init__(self, client, modules, owners, prefix):
|
||||
if os.path.exists("storage/" + moduleFiles + "/" + temp_dir):
|
||||
shutil.rmtree("storage/" + moduleFiles + "/" + temp_dir)
|
||||
@ -60,7 +60,9 @@ class MainClass():
|
||||
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,'))))
|
||||
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(','):
|
||||
@ -81,8 +83,9 @@ class MainClass():
|
||||
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))
|
||||
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)
|
||||
@ -95,8 +98,9 @@ class MainClass():
|
||||
for moduleName in args[2].split(','):
|
||||
if moduleName == 'modules':
|
||||
await message.channel.send(
|
||||
message.author.mention + ", le module {0} ne peut pas être rechargé car il est nécéssaire pour gérer les modules.".format(
|
||||
moduleName))
|
||||
message.author.mention + ", le module {0} ne peut pas être rechargé car il est nécéssaire "
|
||||
"pour gérer les modules.".format(moduleName)
|
||||
)
|
||||
else:
|
||||
if moduleName in self.modules.keys():
|
||||
self.unload_module(moduleName)
|
||||
@ -114,10 +118,13 @@ class MainClass():
|
||||
error = e
|
||||
await message.channel.send(
|
||||
message.author.mention + ", le module {0} **n'a pas pu être activé**".format(
|
||||
moduleName))
|
||||
moduleName)
|
||||
)
|
||||
else:
|
||||
await message.channel.send(
|
||||
message.author.mention + ", le module {0} n'existe pas.".format(moduleName))
|
||||
message.author.mention + ", le module {0} n'existe pas.".format(moduleName)
|
||||
)
|
||||
|
||||
else:
|
||||
await self.modules['help'][1].send_help(message.channel, self)
|
||||
if error:
|
||||
@ -140,14 +147,15 @@ class MainClass():
|
||||
|
||||
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':
|
||||
if moduleName not in list(self.states.keys()) or self.states[moduleName] == 'not loaded':
|
||||
try:
|
||||
tmpstr = str(
|
||||
"storage/" + moduleFiles + "/" + temp_dir + "/" + moduleName + "-%s.py") % random.randint(1,
|
||||
100000000000000000000000000000000)
|
||||
shutil.copy2("modules/%s.py" % moduleName, tmpstr)
|
||||
new_file_name = str(
|
||||
"storage/" +
|
||||
moduleFiles + "/" +
|
||||
temp_dir + "/" + moduleName + "-%s.py") % random.randint(1, 100000000000000000000000000000000)
|
||||
shutil.copy2("modules/%s.py" % moduleName, new_file_name)
|
||||
time.sleep(0.1)
|
||||
self.modules.update({moduleName: [importlib.import_module(tmpstr.replace('/', '.')[:-3:])]})
|
||||
self.modules.update({moduleName: [importlib.import_module(new_file_name.replace('/', '.')[:-3:])]})
|
||||
print("Module {0} chargé.".format(moduleName))
|
||||
self.states[moduleName] = 'loaded'
|
||||
except:
|
||||
|
@ -1,4 +1,4 @@
|
||||
class MainClass():
|
||||
class MainClass:
|
||||
def __init__(self, client, modules, owners, prefix):
|
||||
self.client = client
|
||||
self.modules = modules
|
||||
@ -17,5 +17,10 @@ class MainClass():
|
||||
"""
|
||||
|
||||
async def on_message(self, message):
|
||||
await message.channel.send(message.author.mention + ", Le bot va redémarrer...")
|
||||
await self.client.logout()
|
||||
args = message.content.split(" ")
|
||||
if args[0] == '%srestart' % self.prefix:
|
||||
if 'py' in args:
|
||||
await message.channel.send(message.author.mention + ", Le bot va redémarrer...")
|
||||
await self.client.logout()
|
||||
else:
|
||||
await self.modules['help'][1].send_help(message.channel, self)
|
||||
|
Loading…
Reference in New Issue
Block a user