update(application|bot): add prefixes, blacklist,... confs and command processing

This commit is contained in:
Romain J 2019-09-09 22:40:17 +02:00
commit 30e7906f3f
12 changed files with 92 additions and 61 deletions

View file

@ -1,6 +1,5 @@
import platform
import socket
import subprocess
import discord
from discord.ext import commands
@ -10,33 +9,14 @@ from discord.http import Route
class Basics(commands.Cog):
"""Commandes générales."""
def __init__(self, bot):
def __init__(self, bot: discord.ext.commands.AutoShardedBot):
self.bot = bot
@commands.command()
async def ping(self, ctx):
ping_res = str(subprocess.Popen(["/bin/ping", "-c1", "discordapp.com"],
stdout=subprocess.PIPE).stdout.read())
formated_res = [item for item in ping_res.split() if 'time=' in item]
result = str(formated_res[0])[5:]
if float(result) >= 200:
em = discord.Embed(title="Ping : " + str(result) + "ms",
description="... c'est quoi ce ping !",
colour=0xFF1111)
await ctx.send(embed=em)
elif float(result) > 100 < 200:
em = discord.Embed(title="Ping : " + str(result) + "ms",
description="Ca va, ça peut aller, mais j'ai "
"l'impression d'avoir 40 ans !",
colour=0xFFA500)
await ctx.send(embed=em)
else:
em = discord.Embed(title="Ping : " + str(result) + "ms",
description="Wow c'te vitesse de réaction, "
"je m'épate moi-même !",
colour=0x11FF11)
await ctx.send(embed=em)
async def ping(self, ctx: discord.ext.commands.context.Context):
delta = await ctx.send(self.bot.latency * 1000)
await ctx.send((delta.created_at-ctx.message.created_at)
.microseconds/1000)
"""---------------------------------------------------------------------"""
@ -63,7 +43,7 @@ class Basics(commands.Cog):
text = open('texts/help.md').read().split("[split]")
for txt in text:
em = discord.Embed(title='Commandes de TuxBot', description=txt,
colour=0x89C4F9)
colour=0x89C4F9)
await ctx.send(embed=em)

27
cogs/utils/config.py Normal file
View file

@ -0,0 +1,27 @@
import json
class Config:
__slots__ = ('name', '_db')
def __init__(self, name):
self.name = name
try:
with open(self.name, 'r') as f:
self._db = json.load(f)
except FileNotFoundError:
self._db = {}
def __contains__(self, item):
return item in self._db
def __getitem__(self, item):
return self._db[str(item)]
def get(self, key, *args):
"""Retrieves a config entry."""
return self._db.get(str(key), *args)
def all(self) -> dict:
return self._db

View file

@ -5,4 +5,4 @@ lang = gettext.translation('base', localedir='locales',
languages=[config.lang])
lang.install()
_ = lang.gettext
gettext = lang.gettext