From 3d9f7163fc50b3bacfc26e5bd09eebdd41214f46 Mon Sep 17 00:00:00 2001 From: ctrl-os Date: Thu, 15 Sep 2022 19:36:50 -0700 Subject: [PATCH 1/2] Update dependencies, working version modified secrets.py to use dotenv for easier cloud deployment Add slash commands --- .gitignore | 4 +- bot.py | 1 - cogs/admin.py | 10 +- cogs/config.py | 23 +- cogs/db_api.py | 4 +- cogs/eval.py | 11 +- cogs/help.py | 12 +- cogs/poll_controls.py | 55 ++-- essentials/secrets.py | 12 + models/phvr8a.afm | 612 ++++++++++++++++++++++++++++++++++++++++++ models/poll.py | 21 +- pollmaster.icon.webp | Bin 0 -> 3204 bytes pollmaster.jpg | Bin 0 -> 4490 bytes pollmaster.py | 45 +++- requirements.txt | 30 +-- utils/afm.py | 442 ++++++++++++++++++++++++++++++ 16 files changed, 1181 insertions(+), 101 deletions(-) create mode 100644 essentials/secrets.py create mode 100644 models/phvr8a.afm create mode 100644 pollmaster.icon.webp create mode 100644 pollmaster.jpg create mode 100644 utils/afm.py diff --git a/.gitignore b/.gitignore index 02c3087..cdc7ff5 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,6 @@ export/ *.pyc #backup -backup/ \ No newline at end of file +backup/ + +.env \ No newline at end of file diff --git a/bot.py b/bot.py index d123924..47141b3 100644 --- a/bot.py +++ b/bot.py @@ -50,7 +50,6 @@ def __init__(self, **kwargs): self.load_extension(ext) self.message_cache = MessageCache(self) - self.member_cache = MemberCache() self.refresh_blocked = {} self.refresh_queue = {} diff --git a/cogs/admin.py b/cogs/admin.py index ab62502..81b3185 100644 --- a/cogs/admin.py +++ b/cogs/admin.py @@ -22,7 +22,7 @@ async def cog_command_error(self, ctx, error): else: logger.warning(error) - @commands.command(aliases=['r']) + @commands.hybrid_command(aliases=['r'], description="Reloads cogs") async def reload(self, ctx, *, cog): if cog == 'c': cog = 'poll_controls' @@ -31,7 +31,7 @@ async def reload(self, ctx, *, cog): reply = '' try: - self.bot.reload_extension('cogs.'+cog) + await self.bot.reload_extension('cogs.'+cog) reply = f'Extension "cogs.{cog}" successfully reloaded.' except commands.ExtensionNotFound: reply = f'Extension "cogs.{cog}" not found.' @@ -42,7 +42,7 @@ async def reload(self, ctx, *, cog): except commands.ExtensionNotLoaded: reply = f'Extension "cogs.{cog}" is not loaded... trying to load it. ' try: - self.bot.load_extension('cogs.'+cog) + await self.bot.load_extension('cogs.'+cog) except commands.ExtensionAlreadyLoaded: reply += f'Could not load or reload extension since it is already loaded...' except commands.ExtensionNotFound: @@ -54,7 +54,7 @@ async def reload(self, ctx, *, cog): await ctx.send(reply) -def setup(bot): +async def setup(bot): global logger logger = logging.getLogger('discord') - bot.add_cog(Admin(bot)) \ No newline at end of file + await bot.add_cog(Admin(bot)) \ No newline at end of file diff --git a/cogs/config.py b/cogs/config.py index 0bc13b4..c400814 100644 --- a/cogs/config.py +++ b/cogs/config.py @@ -1,14 +1,15 @@ import logging from discord.ext import commands +from discord import app_commands +from discord import Role class Config(commands.Cog): def __init__(self, bot): self.bot = bot - @commands.command() + @commands.hybrid_command(name="prefix", description="""Set a custom prefix for the server.""") @commands.has_permissions(manage_guild=True) - async def prefix(self, ctx, *, pre): - """Set a custom prefix for the server.""" + async def prefix(self, ctx, *, pre:str): server = ctx.message.guild if pre.endswith('\w'): pre = pre[:-2]+' ' @@ -25,10 +26,9 @@ async def prefix(self, ctx, *, pre): self.bot.pre[str(server.id)] = str(pre) await ctx.send(msg) - @commands.command() + @commands.hybrid_command(name="adminrole", description="Set or show the Admin Role. Members with this role can create polls and manage ALL polls.") @commands.has_permissions(manage_guild=True) - async def adminrole(self, ctx, *, role=None): - """Set or show the Admin Role. Members with this role can create polls and manage ALL polls. Parameter: (optional)""" + async def adminrole(self, ctx, *, role: Role = None): server = ctx.message.guild if not role: @@ -47,11 +47,10 @@ async def adminrole(self, ctx, *, role=None): else: await ctx.send(f'Server role `{role}` not found.') - @commands.command() + @commands.hybrid_command(name="userrole", description="Set or show the User Role. Members with this role can create polls and manage their own polls.") @commands.has_permissions(manage_guild=True) - async def userrole(self, ctx, *, role=None): - """Set or show the User Role. Members with this role can create polls and manage their own polls. - Parameter: (optional)""" + async def userrole(self, ctx, *, role: Role=None): + server = ctx.message.guild if not role: @@ -71,7 +70,7 @@ async def userrole(self, ctx, *, role=None): await ctx.send(f'Server role `{role}` not found.') -def setup(bot): +async def setup(bot): global logger logger = logging.getLogger('discord') - bot.add_cog(Config(bot)) \ No newline at end of file + await bot.add_cog(Config(bot)) \ No newline at end of file diff --git a/cogs/db_api.py b/cogs/db_api.py index 5b28758..6adec36 100644 --- a/cogs/db_api.py +++ b/cogs/db_api.py @@ -34,7 +34,7 @@ async def update_stats(self): logger.exception('Failed to post server count\n{}: {}'.format(type(e).__name__, e)) -def setup(bot): +async def setup(bot): global logger logger = logging.getLogger('discord') - bot.add_cog(DiscordBotsOrgAPI(bot)) + await bot.add_cog(DiscordBotsOrgAPI(bot)) diff --git a/cogs/eval.py b/cogs/eval.py index a5d0ecc..3bc2210 100644 --- a/cogs/eval.py +++ b/cogs/eval.py @@ -6,13 +6,14 @@ from contextlib import redirect_stdout from discord.ext import commands +from discord import app_commands class Eval(commands.Cog): def __init__(self, bot): self.bot = bot - @commands.command() + @commands.hybrid_command(name="eval", description="""Evaluates a code""") @commands.is_owner() async def evall(self, ctx, *, body: str): self.bot.eval_wait = True @@ -29,10 +30,10 @@ async def evall(self, ctx, *, body: str): finally: self.bot.eval_wait = False - @commands.command(hidden=True, name='eval') + @commands.hybrid_command(hidden=True, name='eval', description="""Evaluates a code""") @commands.is_owner() async def _eval(self, ctx, *, body: str): - """Evaluates a code""" + env = { 'bot': self.bot, @@ -78,5 +79,5 @@ async def _eval(self, ctx, *, body: str): await ctx.send(f'```py\n{value}{ret}\n```') -def setup(bot): - bot.add_cog(Eval(bot)) \ No newline at end of file +async def setup(bot): + await bot.add_cog(Eval(bot)) \ No newline at end of file diff --git a/cogs/help.py b/cogs/help.py index c368dd8..a8e117d 100644 --- a/cogs/help.py +++ b/cogs/help.py @@ -3,6 +3,7 @@ import discord from discord.ext import commands +from discord import app_commands from essentials.multi_server import get_server_pre, ask_for_server from essentials.settings import SETTINGS @@ -43,7 +44,6 @@ def check(rct, usr): return reaction def get_help_embed(self, page, pre): - title = f' Pollmaster Help - React with an emoji to learn more about a topic!' embed = discord.Embed(title='', description='', colour=SETTINGS.color) embed.set_author(name=title, icon_url=SETTINGS.author_icon) @@ -235,8 +235,10 @@ def get_help_embed(self, page, pre): return embed - @commands.command() - async def help(self, ctx): + # @commands.hybrid_command(name="pmhelp",description="Display commands") + + @commands.hybrid_command(name="help", description="Display commands") + async def pmhelp(self, ctx): server = await ask_for_server(self.bot, ctx.message) if not server: return @@ -365,7 +367,7 @@ async def on_message(self, message): await channel.send(status_msg) -def setup(bot): +async def setup(bot): global logger logger = logging.getLogger('discord') - bot.add_cog(Help(bot)) + await bot.add_cog(Help(bot)) diff --git a/cogs/poll_controls.py b/cogs/poll_controls.py index a0b18e1..f220365 100644 --- a/cogs/poll_controls.py +++ b/cogs/poll_controls.py @@ -10,7 +10,7 @@ import pytz from bson import ObjectId from discord.ext import tasks, commands - +from discord import app_commands from essentials.exceptions import StopWizard from essentials.multi_server import get_server_pre, ask_for_server, ask_for_channel from essentials.settings import SETTINGS @@ -191,7 +191,7 @@ async def say_embed(self, ctx, say_text='', title='Pollmaster', footer_text=None # p = await Poll.load_from_db(self.bot, str(server.id), 'test', ctx=ctx) # print(await Vote.load_number_of_voters_for_poll(self.bot, p.id)) - @commands.command() + @commands.hybrid_command(name="activate") async def activate(self, ctx, *, short=None): """Activate a prepared poll. Parameter: