Help check active extension, permissions and extension's description
This commit is contained in:
parent
14f2ab7e3f
commit
0dc456bfa8
9 changed files with 42 additions and 27 deletions
|
@ -4,7 +4,7 @@ bot.load_extension("extensions.help")
|
||||||
bot.load_extension("extensions.extension")
|
bot.load_extension("extensions.extension")
|
||||||
bot.load_extension("extensions.purge")
|
bot.load_extension("extensions.purge")
|
||||||
bot.load_extension("extensions.poll")
|
bot.load_extension("extensions.poll")
|
||||||
bot.load_extension("extensions.reminders")
|
bot.load_extension("extensions.reminder")
|
||||||
bot.load_extension("extensions.greetings")
|
bot.load_extension("extensions.greetings")
|
||||||
bot.load_extension("extensions.presentation")
|
bot.load_extension("extensions.presentation")
|
||||||
bot.load_extension("extensions.rorec")
|
bot.load_extension("extensions.rorec")
|
||||||
|
|
|
@ -12,6 +12,9 @@ class Extension(commands.Cog):
|
||||||
def __init__(self, bot: commands.Bot):
|
def __init__(self, bot: commands.Bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
|
def description(self):
|
||||||
|
return "Manage bot's extensions"
|
||||||
|
|
||||||
@commands.group("extension", pass_context=True)
|
@commands.group("extension", pass_context=True)
|
||||||
@commands.check(is_owner)
|
@commands.check(is_owner)
|
||||||
async def extension(self, ctx: commands.Context):
|
async def extension(self, ctx: commands.Context):
|
||||||
|
|
|
@ -19,6 +19,9 @@ class Greetings(commands.Cog):
|
||||||
def __init__(self, bot: commands.Bot):
|
def __init__(self, bot: commands.Bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
|
def description(self):
|
||||||
|
return "Setup join and leave message"
|
||||||
|
|
||||||
@commands.group("greetings", pass_context=True)
|
@commands.group("greetings", pass_context=True)
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@commands.has_permissions(manage_guild=True)
|
@commands.has_permissions(manage_guild=True)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from discord import Embed
|
from discord import Embed
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from discord.ext.commands import CommandNotFound, MissingRequiredArgument, BadArgument, MissingPermissions, \
|
from discord.ext.commands import CommandNotFound, MissingRequiredArgument, BadArgument, MissingPermissions, \
|
||||||
NoPrivateMessage
|
NoPrivateMessage, CommandError
|
||||||
|
|
||||||
from administrator import config
|
from administrator import config
|
||||||
from administrator.logger import logger
|
from administrator.logger import logger
|
||||||
|
@ -16,30 +16,24 @@ class Help(commands.Cog):
|
||||||
def __init__(self, bot: commands.Bot):
|
def __init__(self, bot: commands.Bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
|
def description(self):
|
||||||
|
return "Give help and command list"
|
||||||
|
|
||||||
@commands.command("help", pass_context=True)
|
@commands.command("help", pass_context=True)
|
||||||
async def help(self, ctx: commands.Context):
|
async def help(self, ctx: commands.Context):
|
||||||
embed = Embed(title="Help")
|
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)
|
for c in filter(lambda x: x != "Help", self.bot.cogs):
|
||||||
embed.add_field(name="Reminders", value="Create reminders\n"
|
cog = self.bot.cogs[c]
|
||||||
f"`{config.get('prefix')}reminder help` for more information",
|
try:
|
||||||
inline=False)
|
if await getattr(cog, c.lower()).can_run(ctx):
|
||||||
permissions = ctx.channel.permissions_for(ctx.author)
|
embed.add_field(name=c,
|
||||||
if permissions.manage_messages:
|
value=cog.description() + "\n" +
|
||||||
embed.add_field(name="Purge", value="Purge all messages between the command and the next add reaction\n"
|
f"`{config.get('prefix')}{c.lower()} help` for more information",
|
||||||
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)
|
inline=False)
|
||||||
|
except CommandError:
|
||||||
|
pass
|
||||||
|
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
|
|
|
@ -19,6 +19,9 @@ class Poll(commands.Cog):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.polls = {}
|
self.polls = {}
|
||||||
|
|
||||||
|
def description(self):
|
||||||
|
return "Create poll with a simple command"
|
||||||
|
|
||||||
@commands.group("poll", pass_context=True)
|
@commands.group("poll", pass_context=True)
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
async def poll(self, ctx: commands.Context, name: str, *choices):
|
async def poll(self, ctx: commands.Context, name: str, *choices):
|
||||||
|
|
|
@ -14,6 +14,9 @@ class Presentation(commands.Cog):
|
||||||
def __init__(self, bot: commands.Bot):
|
def __init__(self, bot: commands.Bot):
|
||||||
self.bot = 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.group("presentation", pass_context=True)
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@commands.has_permissions(manage_guild=True)
|
@commands.has_permissions(manage_guild=True)
|
||||||
|
|
|
@ -15,6 +15,9 @@ class Purge(commands.Cog):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.purges = {}
|
self.purges = {}
|
||||||
|
|
||||||
|
def description(self):
|
||||||
|
return "Purge all messages between the command and the next add reaction"
|
||||||
|
|
||||||
@commands.group("purge", pass_context=True)
|
@commands.group("purge", pass_context=True)
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@commands.has_permissions(manage_messages=True)
|
@commands.has_permissions(manage_messages=True)
|
||||||
|
|
|
@ -25,10 +25,13 @@ def time_pars(s: str) -> timedelta:
|
||||||
raise BadArgument()
|
raise BadArgument()
|
||||||
|
|
||||||
|
|
||||||
class Reminders(commands.Cog):
|
class Reminders(commands.Cog, name="Reminder"):
|
||||||
def __init__(self, bot: commands.Bot):
|
def __init__(self, bot: commands.Bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
|
def description(self):
|
||||||
|
return "Create and manage reminders"
|
||||||
|
|
||||||
@commands.group("reminder", pass_context=True)
|
@commands.group("reminder", pass_context=True)
|
||||||
async def reminder(self, ctx: commands.Context):
|
async def reminder(self, ctx: commands.Context):
|
||||||
if ctx.invoked_subcommand is None:
|
if ctx.invoked_subcommand is None:
|
|
@ -21,6 +21,9 @@ class RoRec(commands.Cog):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.edits = {}
|
self.edits = {}
|
||||||
|
|
||||||
|
def description(self):
|
||||||
|
return "Create role-reaction message to give role from a reaction add"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_message(session: db.Session, message_id: int, guild_id: int) -> db.RoRec:
|
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()
|
m = session.query(db.RoRec).filter(db.RoRec.message == message_id and db.RoRec.guild == guild_id).first()
|
||||||
|
|
Reference in a new issue