1
0
Fork 0

Help check active extension, permissions and extension's description

This commit is contained in:
Ethanell 2020-07-23 21:34:32 +02:00
parent 14f2ab7e3f
commit 0dc456bfa8
9 changed files with 42 additions and 27 deletions

View file

@ -4,7 +4,7 @@ bot.load_extension("extensions.help")
bot.load_extension("extensions.extension")
bot.load_extension("extensions.purge")
bot.load_extension("extensions.poll")
bot.load_extension("extensions.reminders")
bot.load_extension("extensions.reminder")
bot.load_extension("extensions.greetings")
bot.load_extension("extensions.presentation")
bot.load_extension("extensions.rorec")

View file

@ -12,6 +12,9 @@ class Extension(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
def description(self):
return "Manage bot's extensions"
@commands.group("extension", pass_context=True)
@commands.check(is_owner)
async def extension(self, ctx: commands.Context):

View file

@ -19,6 +19,9 @@ class Greetings(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
def description(self):
return "Setup join and leave message"
@commands.group("greetings", pass_context=True)
@commands.guild_only()
@commands.has_permissions(manage_guild=True)

View file

@ -1,7 +1,7 @@
from discord import Embed
from discord.ext import commands
from discord.ext.commands import CommandNotFound, MissingRequiredArgument, BadArgument, MissingPermissions, \
NoPrivateMessage
NoPrivateMessage, CommandError
from administrator import config
from administrator.logger import logger
@ -16,30 +16,24 @@ class Help(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
def description(self):
return "Give help and command list"
@commands.command("help", pass_context=True)
async def help(self, ctx: commands.Context):
embed = Embed(title="Help")
embed.add_field(name="Poll", value="Create poll with a simple command\n"
f"`{config.get('prefix')}poll help` for more information", inline=False)
embed.add_field(name="Reminders", value="Create reminders\n"
f"`{config.get('prefix')}reminder help` for more information",
inline=False)
permissions = ctx.channel.permissions_for(ctx.author)
if permissions.manage_messages:
embed.add_field(name="Purge", value="Purge all messages between the command and the next add reaction\n"
f"`{config.get('prefix')}purge help` for more information", inline=False)
if permissions.manage_guild:
embed.add_field(name="Greetings", value="Setup join and leave message\n"
f"`{config.get('prefix')}greetings help` for more information",
inline=False)
embed.add_field(name="Presentation", value="Give role to user who make a presentation in a dedicated "
"channel\n"
f"`{config.get('prefix')}presentation help` for more information",
inline=False)
if await is_owner(ctx):
embed.add_field(name="Extension", value="Manage bot extensions\n"
f"`{config.get('prefix')}extension help` for more information",
inline=False)
for c in filter(lambda x: x != "Help", self.bot.cogs):
cog = self.bot.cogs[c]
try:
if await getattr(cog, c.lower()).can_run(ctx):
embed.add_field(name=c,
value=cog.description() + "\n" +
f"`{config.get('prefix')}{c.lower()} help` for more information",
inline=False)
except CommandError:
pass
await ctx.send(embed=embed)
@commands.Cog.listener()

View file

@ -19,6 +19,9 @@ class Poll(commands.Cog):
self.bot = bot
self.polls = {}
def description(self):
return "Create poll with a simple command"
@commands.group("poll", pass_context=True)
@commands.guild_only()
async def poll(self, ctx: commands.Context, name: str, *choices):

View file

@ -14,6 +14,9 @@ class Presentation(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
def description(self):
return "Give role to user who make a presentation in a dedicated channel"
@commands.group("presentation", pass_context=True)
@commands.guild_only()
@commands.has_permissions(manage_guild=True)

View file

@ -15,6 +15,9 @@ class Purge(commands.Cog):
self.bot = bot
self.purges = {}
def description(self):
return "Purge all messages between the command and the next add reaction"
@commands.group("purge", pass_context=True)
@commands.guild_only()
@commands.has_permissions(manage_messages=True)

View file

@ -25,10 +25,13 @@ def time_pars(s: str) -> timedelta:
raise BadArgument()
class Reminders(commands.Cog):
class Reminders(commands.Cog, name="Reminder"):
def __init__(self, bot: commands.Bot):
self.bot = bot
def description(self):
return "Create and manage reminders"
@commands.group("reminder", pass_context=True)
async def reminder(self, ctx: commands.Context):
if ctx.invoked_subcommand is None:
@ -56,9 +59,9 @@ class Reminders(commands.Cog):
hours, seconds = divmod(time.seconds, 3600)
minutes, seconds = divmod(seconds, 60)
await ctx.send(f"""Remind you in {f"{time.days}d {hours}h {minutes}m {seconds}s"
if time.days > 0 else f"{hours}h {minutes}m {seconds}s"
if hours > 0 else f"{minutes}m {seconds}s"
if minutes > 0 else f"{seconds}s"} !""")
if time.days > 0 else f"{hours}h {minutes}m {seconds}s"
if hours > 0 else f"{minutes}m {seconds}s"
if minutes > 0 else f"{seconds}s"} !""")
@reminder.group("list", pass_context=True)
async def reminder_list(self, ctx: commands.Context):

View file

@ -21,6 +21,9 @@ class RoRec(commands.Cog):
self.bot = bot
self.edits = {}
def description(self):
return "Create role-reaction message to give role from a reaction add"
@staticmethod
def get_message(session: db.Session, message_id: int, guild_id: int) -> db.RoRec:
m = session.query(db.RoRec).filter(db.RoRec.message == message_id and db.RoRec.guild == guild_id).first()