1
0
Fork 0

Rename project to Administrator and fix some error handler

This commit is contained in:
Ethanell 2020-07-23 21:22:47 +02:00
parent 3c6e394ccc
commit b6350cf0aa
14 changed files with 55 additions and 87 deletions

View file

@ -1,2 +1,2 @@
# BotBDE
A discord bot for my BDE server
# Administrator
A discord bot for server administration

View file

@ -1,4 +1,4 @@
from bot_bde.config import config
from administrator.config import config
import db
from discord.ext import commands

View file

@ -1,5 +1,5 @@
from discord.ext import commands
from bot_bde import config
from administrator import config
class NotOwner(commands.CheckFailure):

View file

@ -1,4 +1,4 @@
from bot_bde.logger import logger
from administrator.logger import logger
from os.path import isfile
from json import load

View file

@ -12,7 +12,7 @@ logging.basicConfig(
format=log_format,
level=logging.INFO
)
logger = logging.getLogger("BotBDE")
logger = logging.getLogger("Administrator")
handler = handlers.TimedRotatingFileHandler("../logs/current.log", when="d", interval=1)
handler.suffix = "%Y-%m-%d"
handler.style = log_format

View file

@ -1,4 +1,4 @@
from bot_bde.config import config
from administrator.config import config
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base

View file

@ -1,7 +1,6 @@
from bot_bde import bot
from administrator import bot
bot.load_extension("extensions.help")
bot.load_extension("extensions.speak")
bot.load_extension("extensions.extension")
bot.load_extension("extensions.purge")
bot.load_extension("extensions.poll")

View file

@ -1,8 +1,7 @@
from discord.ext import commands
from discord.ext.commands.errors import CommandNotFound
from discord import Embed
from bot_bde.check import is_owner, NotOwner
from bot_bde.logger import logger
from administrator.check import is_owner
from administrator.logger import logger
extension_name = "extension"
@ -53,18 +52,6 @@ class Extension(commands.Cog):
else:
await ctx.message.add_reaction("\U0001f44d")
@commands.Cog.listener()
async def on_command_error(self, ctx: commands.Context, error):
if ctx.invoked_with == extension_name or \
(ctx.command.root_parent is not None and ctx.command.root_parent.name == extension_name):
if isinstance(error, NotOwner):
await ctx.message.add_reaction("\u274C")
elif isinstance(error, CommandNotFound):
await ctx.message.add_reaction("\u2753")
else:
await ctx.send("An error occurred !")
raise error
def setup(bot):
logger.info(f"Loading...")

View file

@ -1,21 +1,42 @@
from discord.ext import commands
from bot_bde.logger import logger
from discord.ext.commands import CommandNotFound, MissingRequiredArgument, BadArgument
from administrator.logger import logger
from administrator.check import NotOwner
extension_name = "help"
logger = logger.getChild(extension_name)
@commands.command("help")
async def help_cmd(ctx):
await ctx.send("Help !")
class Help(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
self.purges = {}
@commands.command("help", pass_context=True)
async def help(self, ctx: commands.Context):
await ctx.send("HALP !")
@commands.Cog.listener()
async def on_command_error(self, ctx: commands.Context, error):
if isinstance(error, CommandNotFound):
await ctx.message.add_reaction("\u2753")
elif isinstance(error, MissingRequiredArgument) or isinstance(error, BadArgument):
await ctx.message.add_reaction("\u274C")
elif isinstance(error, NotOwner):
await ctx.message.add_reaction("\u274C")
else:
await ctx.send("An error occurred !")
raise error
await ctx.message.delete(delay=30)
def setup(bot):
logger.info(f"Loading...")
try:
bot.help_command = None
bot.add_command(help_cmd)
bot.add_cog(Help(bot))
except Exception as e:
logger.error(f"Error loading: {e}")
else:
@ -25,7 +46,7 @@ def setup(bot):
def teardown(bot):
logger.info(f"Unloading...")
try:
bot.remove_command("help")
bot.remove_cog("Help")
except Exception as e:
logger.error(f"Error unloading: {e}")
else:

View file

@ -2,9 +2,8 @@ from datetime import datetime
from discord.ext import commands
from discord import Member, Embed, Reaction
from discord.ext.commands import CommandNotFound, MissingRequiredArgument
from bot_bde.logger import logger
from administrator.logger import logger
extension_name = "poll"
@ -90,20 +89,6 @@ class Poll(commands.Cog):
await message.edit(embed=embed)
del self.polls[id]
@commands.Cog.listener()
async def on_command_error(self, ctx: commands.Context, error):
if ctx.invoked_with == extension_name or \
(ctx.command.root_parent is not None and ctx.command.root_parent.name == extension_name):
if isinstance(error, CommandNotFound):
await ctx.message.add_reaction("\u2753")
await ctx.message.delete(delay=30)
if isinstance(error, MissingRequiredArgument):
await ctx.message.add_reaction("\u274C")
await ctx.message.delete(delay=30)
else:
await ctx.send("An error occurred !")
raise error
def setup(bot):
logger.info(f"Loading...")

View file

@ -2,9 +2,8 @@ from asyncio import sleep
from discord.ext import commands
from discord import Embed, RawReactionActionEvent
from discord.ext.commands import CommandNotFound
from bot_bde.logger import logger
from administrator.logger import logger
extension_name = "purge"
@ -56,16 +55,6 @@ class Purge(commands.Cog):
await message.delete()
del self.purges[user.id]
@commands.Cog.listener()
async def on_command_error(self, ctx: commands.Context, error):
if ctx.invoked_with == extension_name or \
(ctx.command.root_parent is not None and ctx.command.root_parent.name == extension_name):
if isinstance(error, CommandNotFound):
await ctx.message.add_reaction("\u2753")
else:
await ctx.send("An error occurred !")
raise error
def setup(bot):
logger.info(f"Loading...")
@ -80,7 +69,7 @@ def setup(bot):
def teardown(bot):
logger.info(f"Unloading...")
try:
bot.remove_cog("Speak")
bot.remove_cog("Purge")
except Exception as e:
logger.error(f"Error unloading: {e}")
else:

View file

@ -3,11 +3,11 @@ from datetime import datetime, timedelta
from discord.ext import commands
from discord import Embed
from discord.ext.commands import CommandNotFound, BadArgument, MissingRequiredArgument
from discord.ext.commands import CommandNotFound, BadArgument
from discord.ext import tasks
from bot_bde.logger import logger
from bot_bde import db
from administrator.logger import logger
from administrator import db
extension_name = "reminders"
@ -37,11 +37,11 @@ class Reminders(commands.Cog):
@reminder.group("help", pass_context=True)
async def reminder_help(self, ctx: commands.Context):
embed = Embed(title="Reminder help")
embed.add_field(name="speak add <message> <time>", value="Add a reminder to your reminders list\n"
"Time: ?D?H?M?S", inline=False)
embed.add_field(name="speak list", value="Show your tasks list", inline=False)
embed.add_field(name="speak remove [N°]", value="Show your tasks list with if no id given\n"
"Remove the task withe the matching id", inline=False)
embed.add_field(name="reminder add <message> <time>", value="Add a reminder to your reminders list\n"
"Time: ?D?H?M?S", inline=False)
embed.add_field(name="reminder list", value="Show your tasks list", inline=False)
embed.add_field(name="reminder remove [N°]", value="Show your tasks list with if no id given\n"
"Remove the task withe the matching id", inline=False)
await ctx.send(embed=embed)
@reminder.group("add", pass_context=True)
@ -65,7 +65,7 @@ class Reminders(commands.Cog):
embed = Embed(title="Tasks list")
s = db.Session()
for t in s.query(db.Task).filter(db.Task.user == ctx.author.id).all():
embed.add_field(name=f"{t.id} | {t.date}", value=f"{t.message}", inline=False)
embed.add_field(name=f"{t.id} | {t.date.strftime('%d/%m/%Y %H:%M')}", value=f"{t.message}", inline=False)
s.close()
await ctx.send(embed=embed)
@ -99,22 +99,9 @@ class Reminders(commands.Cog):
embed = Embed(title="You have a reminder !")
user = self.bot.get_user(task.user)
embed.set_author(name=f"{user.name}#{user.discriminator}", icon_url=user.avatar_url)
embed.add_field(name=str(task.creation_date), value=task.message)
embed.add_field(name=str(task.creation_date.strftime('%d/%m/%Y %H:%M')), value=task.message)
await (await self.bot.get_channel(task.channel).send(f"{user.mention}", embed=embed)).edit(content="")
@commands.Cog.listener()
async def on_command_error(self, ctx: commands.Context, error):
if ctx.invoked_with == "reminder" or \
(ctx.command.root_parent and ctx.command.root_parent.name == "reminder"):
if isinstance(error, CommandNotFound)\
or isinstance(error, BadArgument)\
or isinstance(error, MissingRequiredArgument):
await ctx.message.add_reaction("\u2753")
await ctx.message.delete(delay=30)
else:
await ctx.send("An error occurred !")
raise error
def cog_unload(self):
self.reminders_loop.stop()

View file

@ -1 +1 @@
import bot_bde
import administrator

View file

@ -3,9 +3,9 @@ async-timeout==3.0.1
attrs==19.3.0
chardet==3.0.4
discord==1.0.1
discord.py==1.3.3
idna==2.9
multidict==4.7.5
discord.py==1.3.4
idna==2.10
multidict==4.7.6
SQLAlchemy==1.3.18
websockets==8.1
yarl==1.4.2
SQLAlchemy~=1.3.17