[base-all] Ajout de beaucoup de chose à la config, mise à zero des configs
[mod-newmember] Utilisation de log et pas de print [mod-panic] Remplacement de nikola par self.client.name (TODO: Vérifier que ca marche) [mod-readrule] Remplacement de la concaténation toute moche par un format [mod-restart] Ajout du todo pour pas oublier cette merde [mod-roles] Suppression des prints
This commit is contained in:
parent
da0cde7800
commit
08d9998f73
6
main.py
6
main.py
@ -236,7 +236,8 @@ class LBI(discord.Client):
|
||||
# Content: {"module_name": {"module": imported module, "class": initialized class}}
|
||||
self.modules = {}
|
||||
self.config = config
|
||||
self.config.init({"modules": ["modules", "errors"], "prefix": "%", "admin_roles": [], "admin_users": []})
|
||||
self.config.init(
|
||||
{"modules": ["modules", "errors"], "prefix": "%", "admin_roles": [], "admin_users": [], "main_guild": 0})
|
||||
self.load_modules()
|
||||
|
||||
@modules_edit
|
||||
@ -468,6 +469,3 @@ t = loop.create_unix_server(Communication,
|
||||
loop.run_until_complete(t)
|
||||
loop.create_task(start_bot())
|
||||
loop.run_forever()
|
||||
|
||||
# loop = asyncio.get_event_loop()
|
||||
# loop.run_forever()
|
||||
|
@ -18,11 +18,6 @@ class BaseClass:
|
||||
|
||||
}
|
||||
}
|
||||
help_active = False
|
||||
color = 0x000000
|
||||
command_text = None
|
||||
authorized_users = []
|
||||
authorized_roles = []
|
||||
|
||||
def __init__(self, client):
|
||||
"""Initialize module class
|
||||
@ -32,22 +27,24 @@ class BaseClass:
|
||||
:param client: client instance
|
||||
:type client: LBI"""
|
||||
self.client = client
|
||||
self.objects = Objects(path=os.path.join("data", self.name))
|
||||
self.config = Config(parent=self.client.config, name="mod-" + self.name)
|
||||
self.config.init({"authorized_roles": self.authorized_roles, "authorized_users": self.authorized_users})
|
||||
self.objects = Objects(path=os.path.join("data", self.name.lower()))
|
||||
self.config = Config(parent=self.client.config, name="mod-" + self.name.lower())
|
||||
self.config.init({"help_active": True, "color": 0x000000, "auth_everyone": False, "authorized_roles": [],
|
||||
"authorized_users": [], "command_text": self.name.lower()})
|
||||
|
||||
async def send_help(self, channel):
|
||||
if not self.help_active:
|
||||
if not self.config.help_active:
|
||||
return
|
||||
|
||||
embed = discord.Embed(
|
||||
title="[{nom}] - Aide".format(nom=self.name),
|
||||
description="*" + self.help["description"].format(prefix=self.client.config['prefix']) + "*",
|
||||
color=self.color
|
||||
color=self.config.color
|
||||
)
|
||||
for command, description in self.help["commands"].items():
|
||||
embed.add_field(name=command.format(prefix=self.client.config['prefix'], command=self.command_text),
|
||||
value="-> " + description.format(prefix=self.client.config['prefix'], command=self.command_text),
|
||||
embed.add_field(name=command.format(prefix=self.client.config['prefix'], command=self.config.command_text),
|
||||
value="-> " + description.format(prefix=self.client.config['prefix'],
|
||||
command=self.config.command_text),
|
||||
inline=False)
|
||||
await channel.send(embed=embed)
|
||||
|
||||
@ -65,6 +62,8 @@ class BaseClass:
|
||||
:type guild: Int
|
||||
:type user: discord.User
|
||||
"""
|
||||
if self.config.auth_everyone:
|
||||
return True
|
||||
if user_list is None:
|
||||
user_list = self.config.authorized_users + self.client.config.admin_users
|
||||
if user.id in user_list:
|
||||
@ -90,10 +89,11 @@ class BaseClass:
|
||||
|
||||
:param message: message to parse
|
||||
:type message: discord.Message"""
|
||||
if message.content.startswith(self.client.config["prefix"] + (self.command_text if self.command_text else "")):
|
||||
if message.content.startswith(
|
||||
self.client.config["prefix"] + (self.config.command_text if self.config.command_text else "")):
|
||||
|
||||
content = message.content.lstrip(
|
||||
self.client.config["prefix"] + (self.command_text if self.command_text else ""))
|
||||
self.client.config["prefix"] + (self.config.command_text if self.config.command_text else ""))
|
||||
sub_command, args, kwargs = self._parse_command_content(content)
|
||||
sub_command = "com_" + sub_command
|
||||
if await self.auth(message.author):
|
||||
|
@ -2,14 +2,12 @@ from modules.base import BaseClassPython
|
||||
|
||||
class MainClass(BaseClassPython):
|
||||
name = "clean"
|
||||
authorized_roles=[522918472548745217]
|
||||
help = {
|
||||
"description": "Supprime des messages",
|
||||
"commands": {
|
||||
"`{prefix}{command}`": "Supprime tous les messages du bot dans le salon"
|
||||
}
|
||||
}
|
||||
command_text = "clean"
|
||||
|
||||
async def command(self, message, args, kwargs):
|
||||
def is_me(m):
|
||||
|
@ -10,17 +10,12 @@ from modules.base import BaseClassPython
|
||||
|
||||
class MainClass(BaseClassPython):
|
||||
name = "errors"
|
||||
help_active = True
|
||||
authorized_users = [431043517217898496]
|
||||
authorized_roles = []
|
||||
color = 0xdb1348
|
||||
help = {
|
||||
"description": "Montre toutes les erreurs du bot dans discord.",
|
||||
"commands": {
|
||||
"`{prefix}{command}`": "Renvoie une erreur de test.",
|
||||
}
|
||||
}
|
||||
command_text = "unicorn"
|
||||
|
||||
def __init__(self, client):
|
||||
super().__init__(client)
|
||||
@ -69,7 +64,7 @@ class MainClass(BaseClassPython):
|
||||
embed = discord.Embed(
|
||||
title="[Erreur] Aïe :/",
|
||||
description="```python\n{0}```".format(traceback.format_exc()),
|
||||
color=self.color)
|
||||
color=self.config.color)
|
||||
embed.set_image(url=random.choice(self.config.memes))
|
||||
message_list = None
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
from pprint import pprint
|
||||
|
||||
import discord
|
||||
|
||||
from modules.base import BaseClassPython
|
||||
@ -7,7 +5,6 @@ from modules.base import BaseClassPython
|
||||
|
||||
class MainClass(BaseClassPython):
|
||||
name = "Aide"
|
||||
help_active = True
|
||||
help = {
|
||||
"description": "Module d'aide",
|
||||
"commands": {
|
||||
@ -16,11 +13,9 @@ class MainClass(BaseClassPython):
|
||||
# "`{prefix}{command} all`": "Affiche l'aide de tous les modules"
|
||||
}
|
||||
}
|
||||
color = 0x3c9653
|
||||
command_text = "help"
|
||||
|
||||
async def com_list(self, message, args, kwargs):
|
||||
embed = discord.Embed(title="[Aide] - Liste des modules", color=self.color)
|
||||
embed = discord.Embed(title="[Aide] - Liste des modules", color=self.config.color)
|
||||
for moduleName in list(self.client.modules.keys()):
|
||||
if self.client.modules[moduleName]["initialized_class"].help_active:
|
||||
embed.add_field(
|
||||
|
@ -9,9 +9,6 @@ from modules.modules.api import Api
|
||||
|
||||
class MainClass(BaseClassPython):
|
||||
name = "modules"
|
||||
help_active = True
|
||||
command_text = "modules"
|
||||
color = 0x000000
|
||||
help = {
|
||||
"description": "Manage bot modules.",
|
||||
"commands": {
|
||||
|
@ -1,12 +1,8 @@
|
||||
import discord
|
||||
import sys
|
||||
from modules.base import BaseClassPython
|
||||
|
||||
|
||||
class MainClass(BaseClassPython):
|
||||
name = "NewMember"
|
||||
color = 0xff071f
|
||||
help_active = False
|
||||
help = {
|
||||
"description": "Module d'accueil",
|
||||
"commands": {
|
||||
@ -15,20 +11,20 @@ class MainClass(BaseClassPython):
|
||||
|
||||
def __init__(self, client):
|
||||
super().__init__(client)
|
||||
self.config.init({"new_role":430845952388104212,
|
||||
"guild":297780867286433792,
|
||||
"motd":"Bienvenue sur le serveur de la communauté d'E-penser. Nous vous prions de lire le règlement afin d'accéder au serveur complet."})
|
||||
self.config.init({"new_role": 0,
|
||||
"motd": "Bienvenue !"})
|
||||
|
||||
async def on_ready(self):
|
||||
guild = self.client.get_guild(self.config.guild)
|
||||
guild = self.client.get_guild(self.client.config.main_guild)
|
||||
for i, member in enumerate(guild.members):
|
||||
if len(member.roles) == 1:
|
||||
await member.add_roles(await self.client.id.get_role(id_=self.config.new_role,
|
||||
guild=guild))
|
||||
if i%50==0:
|
||||
print(i, member)
|
||||
|
||||
guild=self.client.config.main_guild))
|
||||
if i % 50 == 0:
|
||||
self.client.log(f"Attribution des roles automatique manqués... {i}/{len(guild.members)}")
|
||||
|
||||
async def on_member_join(self, member):
|
||||
await member.add_roles(await self.client.id.get_role(id_=self.config.new_role,
|
||||
guild=self.client.get_guild(self.config.guild)))
|
||||
guild=self.client.get_guild(
|
||||
self.client.config.main_guild)))
|
||||
await member.send(self.config.motd)
|
||||
|
@ -1,20 +1,18 @@
|
||||
import subprocess
|
||||
import discord
|
||||
from modules.base import BaseClassPython
|
||||
import time
|
||||
|
||||
import discord
|
||||
|
||||
from modules.base import BaseClassPython
|
||||
|
||||
|
||||
class MainClass(BaseClassPython):
|
||||
name = "Panic"
|
||||
help_active = True
|
||||
help = {
|
||||
"description": "Dans quel état est Nikola Tesla",
|
||||
"commands": {
|
||||
"`{prefix}{command}`": "Donne l'état actuel de Nikola Tesla",
|
||||
}
|
||||
}
|
||||
color = 0x4fffb6
|
||||
command_text = "panic"
|
||||
|
||||
async def command(self, message, args, kwargs):
|
||||
temperature = 0
|
||||
@ -22,7 +20,7 @@ class MainClass(BaseClassPython):
|
||||
temperature = int(f.read().rstrip("\n")) / 1000
|
||||
with open("/proc/cpuinfo") as f:
|
||||
cpu_count = f.read().count('\n\n')
|
||||
embed = discord.Embed(title="[Panic] - Infos", color=self.color)
|
||||
embed = discord.Embed(title="[Panic] - Infos", color=self.config.color)
|
||||
with open("/proc/loadavg") as f:
|
||||
load_average = ["**" + str(round((val / cpu_count) * 100, 1)) + '%**' for val in
|
||||
map(float, f.read().split(' ')[0:3])]
|
||||
@ -37,10 +35,10 @@ class MainClass(BaseClassPython):
|
||||
|
||||
embed.add_field(
|
||||
name="Charge moyenne",
|
||||
value="Nikola est en moyenne, utilisé à :\n sur une minute : %s\n sur cinq minutes : %s\n sur quinze minutes : %s" % tuple(
|
||||
value=f"{self.client.name} est en moyenne, utilisé à :\n sur une minute : %s\n sur cinq minutes : %s\n sur quinze minutes : %s" % tuple(
|
||||
load_average))
|
||||
|
||||
embed.add_field(
|
||||
name="Temps d'éveil",
|
||||
value="Nikola est éveillé depuis {uptime}".format(uptime=uptime))
|
||||
value=f"{self.client.name} est éveillé depuis {uptime}".format(uptime=uptime))
|
||||
await message.channel.send(embed=embed)
|
||||
|
@ -20,9 +20,6 @@ class MainClass(BaseClassPython):
|
||||
"`{prefix}{command} stats history": "Affiche un graphique avec le nombre de pertes."
|
||||
}
|
||||
}
|
||||
help_active = True
|
||||
command_text = "perdu"
|
||||
color = 0xff6ba6
|
||||
|
||||
def __init__(self, client):
|
||||
super().__init__(client)
|
||||
@ -183,4 +180,4 @@ class MainClass(BaseClassPython):
|
||||
)[:2000]
|
||||
await message.channel.send(embed=discord.Embed(title="G-Perdu - Tableau des scores",
|
||||
description=embed_description,
|
||||
color=self.color))
|
||||
color=self.config.color))
|
||||
|
@ -1,19 +1,13 @@
|
||||
import discord
|
||||
import sys
|
||||
from modules.base import BaseClassPython
|
||||
|
||||
class MainClass(BaseClassPython):
|
||||
name = "Purge"
|
||||
color = 0xff0004
|
||||
help_active = True
|
||||
authorized_roles=[522918472548745217]
|
||||
help = {
|
||||
"description": "Suppression de messages en block.",
|
||||
"commands": {
|
||||
"`{prefix}{command} <message_id>`": "Supprime tous les messages du salon jusqu'au message spécifié",
|
||||
}
|
||||
}
|
||||
command_text = "purge"
|
||||
|
||||
async def command(self, message, args, kwargs):
|
||||
message_id = None
|
||||
|
@ -1,5 +1,3 @@
|
||||
import discord
|
||||
import sys
|
||||
from modules.base import BaseClassPython
|
||||
|
||||
|
||||
@ -15,13 +13,13 @@ class MainClass(BaseClassPython):
|
||||
|
||||
def __init__(self, client):
|
||||
super().__init__(client)
|
||||
self.config.init({"accepted_role":430846685380345876,
|
||||
"new_role":430845952388104212,
|
||||
"listen_chan":430995739636793345,
|
||||
"log_chan":429977240202248192,
|
||||
"passwords":["cacahuète","cacahuete","cacahuètes","cacahuetes"],
|
||||
"succes_pm":"Félicitations, vous êtes désormais un **e-penseur** accompli. Bienvenue sur le serveur E-penser.",
|
||||
"succes":" est désormais un **e-penseur** accompli."})
|
||||
self.config.init({"accepted_role": 0,
|
||||
"new_role": 0,
|
||||
"listen_chan": 0,
|
||||
"log_chan": 0,
|
||||
"passwords": [],
|
||||
"succes_pm": "Félicitations, vous savez lire les règles!",
|
||||
"succes": "{user} a désormais accepté."})
|
||||
|
||||
async def on_message(self, message):
|
||||
if message.channel.id == self.config.listen_chan:
|
||||
@ -32,6 +30,7 @@ class MainClass(BaseClassPython):
|
||||
await message.author.add_roles(await self.client.id.get_role(id_=self.config.accepted_role,
|
||||
guild=message.channel.guild))
|
||||
await message.author.send(self.config.succes_pm)
|
||||
await message.channel.guild.get_channel(self.config.log_chan).send(message.author.mention + self.config.succes)
|
||||
await message.channel.guild.get_channel(self.config.log_chan).send(
|
||||
self.config.succes.format(user=message.author.mention))
|
||||
else:
|
||||
await message.author.send(f"Le mot de passe que vous avez entré est incorrect : `{message.content}`.\nNous vous prions de lire le règlement afin d'accéder au serveur complet.")
|
||||
|
@ -1,22 +1,19 @@
|
||||
import discord
|
||||
import sys
|
||||
|
||||
from modules.base import BaseClassPython
|
||||
|
||||
|
||||
class MainClass(BaseClassPython):
|
||||
name = "Restart"
|
||||
color = 0xff071f
|
||||
help_active = True
|
||||
authorized_roles = [431043517217898496]
|
||||
help = {
|
||||
"description": "Module gérant les redémarrages de Nikola Tesla",
|
||||
"commands": {
|
||||
"`{prefix}{command}`": "Redémarre le bot.",
|
||||
}
|
||||
}
|
||||
command_text = "restart"
|
||||
|
||||
async def command(self, message, args, kwargs):
|
||||
await message.channel.send(f"{message.author.mention}, Le bot va redémarrer.")
|
||||
await self.client.logout()
|
||||
# TODO: Faut vraiment faire mieux
|
||||
sys.exit(0)
|
||||
|
@ -5,8 +5,6 @@ from modules.base import BaseClassPython
|
||||
|
||||
class MainClass(BaseClassPython):
|
||||
name = "Roles"
|
||||
color = 0xffb593
|
||||
help_active = True
|
||||
help = {
|
||||
"description": "Module gérant l'attribution des roles",
|
||||
"commands": {
|
||||
@ -17,24 +15,21 @@ class MainClass(BaseClassPython):
|
||||
"`{prefix}{command} <role> [role] ...`": "Alias de `{prefix}{command} toggle`",
|
||||
}
|
||||
}
|
||||
command_text = "roles"
|
||||
|
||||
def __init__(self, client):
|
||||
super().__init__(client)
|
||||
self.config.init({"guild":297780867286433792,
|
||||
"roles": {"435559220860157952":"Rôle mentionné lors des jeux."}})
|
||||
self.config.init({"roles": {}})
|
||||
|
||||
async def com_list(self, message, args, kwargs):
|
||||
response = discord.Embed(title="Roles disponibles", color=self.color)
|
||||
response = discord.Embed(title="Roles disponibles", color=self.config.color)
|
||||
for id_ in self.config.roles.keys():
|
||||
print(id_,type(id_))
|
||||
role = message.guild.get_role(int(id_))
|
||||
if role is not None:
|
||||
response.add_field(name=role.name, value=f" -> `{self.config.roles[id_]}`", inline=True)
|
||||
response.add_field(name=role.name, value=f"-> `{self.config.roles[id_]}`", inline=True)
|
||||
await message.channel.send(embed=response)
|
||||
|
||||
async def com_add(self, message, args, kwargs):
|
||||
guild = self.client.get_guild(self.config.guild)
|
||||
guild = self.client.get_guild(self.client.config.main_guild)
|
||||
member = guild.get_member(message.author.id)
|
||||
if len(args) <= 1:
|
||||
await message.channel.send("Il manque des arguments à la commande")
|
||||
@ -46,7 +41,7 @@ class MainClass(BaseClassPython):
|
||||
await self.tryaddrole(message, member, role)
|
||||
|
||||
async def com_remove(self, message, args, kwargs):
|
||||
guild = self.client.get_guild(self.config.guild)
|
||||
guild = self.client.get_guild(self.client.config.main_guild)
|
||||
member = guild.get_member(message.author.id)
|
||||
if len(args) <= 1:
|
||||
await message.channel.send("Il manque des arguments à la commande")
|
||||
@ -58,7 +53,7 @@ class MainClass(BaseClassPython):
|
||||
await self.tryremoverole(message, member, role)
|
||||
|
||||
async def com_toggle(self, message, args, kwargs):
|
||||
guild = self.client.get_guild(self.config.guild)
|
||||
guild = self.client.get_guild(self.client.config.main_guild)
|
||||
member = guild.get_member(message.author.id)
|
||||
if len(args) <= 1:
|
||||
await message.channel.send("Il manque des arguments à la commande")
|
||||
@ -97,7 +92,7 @@ class MainClass(BaseClassPython):
|
||||
await message.channel.send(f"Je n'ai pas la permission de vous attribuer le rôle {role}.")
|
||||
else:
|
||||
await message.channel.send(f"Vous avez reçu le rôle {role}.")
|
||||
|
||||
|
||||
async def tryremoverole(self, message, member, role):
|
||||
if not role in member.roles:
|
||||
await message.channel.send(f"Vous n'avez pas le rôle {role}.")
|
||||
|
@ -13,10 +13,6 @@ class MainClass(BaseClassPython):
|
||||
"{prefix}{command} <mention>": "Demande gentilment de lire le google doc"
|
||||
}
|
||||
}
|
||||
help_active = True
|
||||
command_text = "rtfgd"
|
||||
|
||||
color = 0xdb1348
|
||||
|
||||
def __init__(self, client):
|
||||
super().__init__(client)
|
||||
@ -26,4 +22,4 @@ class MainClass(BaseClassPython):
|
||||
await message.channel.send(
|
||||
" ".join(member.mention for member in message.mentions),
|
||||
embed=discord.Embed(title="Read da fu**ing GOOGLE DOCS ! (╯°□°)╯︵ ┻━┻",
|
||||
color=self.color).set_image(url=random.choice(self.config.memes)))
|
||||
color=self.config.color).set_image(url=random.choice(self.config.memes)))
|
||||
|
Loading…
Reference in New Issue
Block a user