From b3b8b3f49eb4e3fd34d0389c061c8516c29303e9 Mon Sep 17 00:00:00 2001 From: Aaron Kable Date: Sat, 16 Mar 2024 07:43:56 +0800 Subject: [PATCH 01/21] Global About --- aadiscordbot/cogs/about.py | 95 ++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 45 deletions(-) diff --git a/aadiscordbot/cogs/about.py b/aadiscordbot/cogs/about.py index 8f051dc..b90cb0f 100644 --- a/aadiscordbot/cogs/about.py +++ b/aadiscordbot/cogs/about.py @@ -21,10 +21,9 @@ class About(commands.Cog): def __init__(self, bot): self.bot = bot - about_commands = SlashCommandGroup("about", "All about the Bot and Auth", guild_ids=[ - int(settings.DISCORD_GUILD_ID)]) + about_commands = SlashCommandGroup("about", "All about the Bot and Auth") - @about_commands.command(name="discordbot", description="About the Discord Bot", guild_ids=[int(settings.DISCORD_GUILD_ID)]) + @about_commands.command(name="discordbot", description="About the Discord Bot") async def discordbot(self, ctx): """ All about the bot @@ -36,64 +35,70 @@ async def discordbot(self, ctx): embed.colour = Color.blue() embed.description = "This is a multi-de-functional discord bot tailored specifically for Alliance Auth Shenanigans." - regex = r"^(.+)\/d.+" embed.set_footer( text="Lovingly developed for Init.™ by AaronRin and ArielKable") - embed.add_field( - name="Number of Servers:", value=len(self.bot.guilds), inline=True - ) - members = 0 - for g in self.bot.guilds: - members += g.member_count - embed.add_field(name="Unwilling Monitorees:", - value=members, inline=True) - embed.add_field( - name="Auth Link", value=get_site_url(), inline=False - ) + if not ctx.guild: + embed.add_field( + name="Number of Servers:", value=len(self.bot.guilds), inline=True + ) + members = 0 + for g in self.bot.guilds: + members += g.member_count + embed.add_field(name="Unwilling Monitorees:", + value=members, inline=True) + embed.add_field( + name="Auth Link", value=get_site_url(), inline=False + ) + embed.add_field( name="Version", value=f"{__version__}@{__branch__}", inline=False ) return await ctx.respond(embed=embed) - @about_commands.command(name="server", description="About this Discord Server", guild_ids=[int(settings.DISCORD_GUILD_ID)]) + @about_commands.command(name="server", description="About this Discord Server") async def server(self, ctx): """ All about a server """ - embed = Embed(title=ctx.guild.name) - - if ctx.guild.icon: - embed.set_thumbnail( - url=ctx.guild.icon.url + if ctx.guild: + embed = Embed(title=ctx.guild.name) + + if ctx.guild.icon: + embed.set_thumbnail( + url=ctx.guild.icon.url + ) + embed.color = Color.blue() + embed.description = "Alliance Auth Managed EvE Online Discord Server!" + if ctx.guild.description: + embed.description = ctx.guild.description + embed.set_footer( + text="AuthBot Lovingly developed for Init.™ by AaronRin and ArielKable") + + members = ctx.guild.member_count + embed.add_field(name="Unwilling Monitorees:", + value=members, inline=True) + + channels = len(ctx.guild.channels) + cats = len(ctx.guild.categories) + embed.add_field(name="Channel Count:", + value=channels-cats, inline=True) + + roles = len(ctx.guild.roles) + embed.add_field(name="Role Count:", + value=roles, inline=True) + + embed.add_field( + name="Auth Link", value=get_site_url(), inline=False ) - embed.color = Color.blue() - embed.description = "Alliance Auth Managed EvE Online Discord Server!" - if ctx.guild.description: - embed.description = ctx.guild.description - embed.set_footer( - text="AuthBot Lovingly developed for Init.™ by AaronRin and ArielKable") - members = ctx.guild.member_count - embed.add_field(name="Unwilling Monitorees:", - value=members, inline=True) - - channels = len(ctx.guild.channels) - cats = len(ctx.guild.categories) - embed.add_field(name="Channel Count:", - value=channels-cats, inline=True) - - roles = len(ctx.guild.roles) - embed.add_field(name="Role Count:", - value=roles, inline=True) - - embed.add_field( - name="Auth Link", value=get_site_url(), inline=False - ) - - return await ctx.respond(embed=embed) + return await ctx.respond(embed=embed) + else: + return await ctx.respond( + "Sorry, this command cannot be used in DMs." + ) def setup(bot): From 38b33ca8dd6766f929f8d53caac8efd93482497a Mon Sep 17 00:00:00 2001 From: Aaron Kable Date: Sat, 16 Mar 2024 07:44:08 +0800 Subject: [PATCH 02/21] more logging to welcome --- aadiscordbot/cogs/welcomegoodbye.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/aadiscordbot/cogs/welcomegoodbye.py b/aadiscordbot/cogs/welcomegoodbye.py index 817cd8b..a6ca38c 100644 --- a/aadiscordbot/cogs/welcomegoodbye.py +++ b/aadiscordbot/cogs/welcomegoodbye.py @@ -24,6 +24,9 @@ def __init__(self, bot): @commands.Cog.listener("on_member_join") async def on_member_join(self, member: discord.Member): + logger.info( + f"{member} joined {member.guild.name}" + ) channel = member.guild.system_channel if channel is not None: try: @@ -76,6 +79,9 @@ def __init__(self, bot): @commands.Cog.listener("on_member_remove") async def on_member_remove(self, member: discord.Member): + logger.info( + f"{member} joined {member.guild.name}" + ) channel = member.guild.system_channel if channel is not None: try: From da5a05e4eb79a699babde9e4450d1ee9cee1a5e9 Mon Sep 17 00:00:00 2001 From: Aaron Kable Date: Sat, 16 Mar 2024 11:31:04 +0800 Subject: [PATCH 03/21] global auth cog --- aadiscordbot/cogs/auth.py | 51 ++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/aadiscordbot/cogs/auth.py b/aadiscordbot/cogs/auth.py index 4106aa5..32c260f 100644 --- a/aadiscordbot/cogs/auth.py +++ b/aadiscordbot/cogs/auth.py @@ -5,13 +5,8 @@ from discord.embeds import Embed from discord.ext import commands -from django.conf import settings - -from aadiscordbot import __branch__, __version__ # AA Contexts -from aadiscordbot.app_settings import get_admins, get_site_url - -from ..app_settings import discord_active, mumble_active +from aadiscordbot.app_settings import get_site_url logger = logging.getLogger(__name__) @@ -48,39 +43,35 @@ async def auth(self, ctx): return await ctx.send(embed=embed) - @commands.slash_command(name='auth', guild_ids=[int(settings.DISCORD_GUILD_ID)]) + @commands.slash_command(name='auth') async def auth_slash(self, ctx): """ Returns a link to the AllianceAuth Install Used by many other Bots and is a common command that users will attempt to run. """ - embed = Embed(title="AllianceAuth") - embed.set_thumbnail( - url="https://assets.gitlab-static.net/uploads/-/system/project/avatar/6840712/Alliance_auth.png?width=128" - ) - embed.colour = Color.blue() + if ctx.guild: + embed = Embed(title="AllianceAuth") + embed.set_thumbnail( + url="https://assets.gitlab-static.net/uploads/-/system/project/avatar/6840712/Alliance_auth.png?width=128" + ) + embed.colour = Color.blue() - embed.description = "All Authentication functions for this Discord server are handled through our Alliance Auth install" + embed.description = "All Authentication functions for this Discord server are handled through our Alliance Auth install" - url = get_site_url() + url = get_site_url() - embed.add_field( - name="Auth Link", value=url, inline=False - ) - """ - embed.add_field( - name="Number of Servers:", value=len(self.bot.guilds), inline=True - ) - embed.add_field(name="Unwilling Monitorees:", - value=len(self.bot.users), inline=True) - embed.add_field( - name="Version", value="{}@{}".format(__version__, __branch__), inline=False - ) - """ - embed.set_footer( - text="Lovingly developed for Init.™ by AaronRin and ArielKable") + embed.add_field( + name="Auth Link", value=url, inline=False + ) + embed.set_footer( + text="Lovingly developed for Init.™ by AaronRin and ArielKable") + + return await ctx.respond(embed=embed) - return await ctx.respond(embed=embed) + else: + return await ctx.respond( + "Sorry, this command cannot be used in DMs." + ) def setup(bot): From 1d6bbe5164585ee29ee2363aeb4bd6a27ed6f186 Mon Sep 17 00:00:00 2001 From: Aaron Kable Date: Sat, 16 Mar 2024 11:44:57 +0800 Subject: [PATCH 04/21] long lines --- aadiscordbot/cogs/auth.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/aadiscordbot/cogs/auth.py b/aadiscordbot/cogs/auth.py index 32c260f..0946292 100644 --- a/aadiscordbot/cogs/auth.py +++ b/aadiscordbot/cogs/auth.py @@ -23,7 +23,8 @@ def __init__(self, bot): async def auth(self, ctx): """ Returns a link to the AllianceAuth Install - Used by many other Bots and is a common command that users will attempt to run. + Used by many other Bots and is a common command that + users will attempt to run. """ await ctx.trigger_typing() @@ -47,7 +48,8 @@ async def auth(self, ctx): async def auth_slash(self, ctx): """ Returns a link to the AllianceAuth Install - Used by many other Bots and is a common command that users will attempt to run. + Used by many other Bots and is a common command that + users will attempt to run. """ if ctx.guild: embed = Embed(title="AllianceAuth") From 024da90cf352afeb1ede92b3cbc442a1ef623d86 Mon Sep 17 00:00:00 2001 From: Aaron Kable Date: Sat, 16 Mar 2024 11:45:13 +0800 Subject: [PATCH 05/21] global happy birthday --- aadiscordbot/cogs/eastereggs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aadiscordbot/cogs/eastereggs.py b/aadiscordbot/cogs/eastereggs.py index f3e9a51..224f413 100644 --- a/aadiscordbot/cogs/eastereggs.py +++ b/aadiscordbot/cogs/eastereggs.py @@ -19,7 +19,7 @@ class EasterEggs(commands.Cog): def __init__(self, bot): self.bot = bot - @commands.slash_command(name='happybirthday', guild_ids=[int(settings.DISCORD_GUILD_ID)]) + @commands.slash_command(name='happybirthday') async def happybirthday(self, ctx, user: User): """ Takes one Discord User as an argument, Wishes this user a happy birthday From 0b71fbaf6447513e809797dad8435b86a6d6039a Mon Sep 17 00:00:00 2001 From: Aaron Kable Date: Sat, 16 Mar 2024 11:59:56 +0800 Subject: [PATCH 06/21] 8ball global --- aadiscordbot/cogs/eightball.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aadiscordbot/cogs/eightball.py b/aadiscordbot/cogs/eightball.py index dc2c99d..4a93494 100644 --- a/aadiscordbot/cogs/eightball.py +++ b/aadiscordbot/cogs/eightball.py @@ -48,7 +48,7 @@ async def meb(self, message): """ await message.reply(self.eightball()) - @commands.slash_command(name='8ball', guild_ids=[int(settings.DISCORD_GUILD_ID)]) + @commands.slash_command(name='8ball') async def meb_slash(self, ctx, question: str): await ctx.respond(f" You Asked: `{question}`\n\n{self.eightball()}") From 7c48d847d49cec95fbad3150bca3618a67245a0e Mon Sep 17 00:00:00 2001 From: Aaron Kable Date: Sat, 16 Mar 2024 13:48:36 +0800 Subject: [PATCH 07/21] alpha --- aadiscordbot/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aadiscordbot/__init__.py b/aadiscordbot/__init__.py index 58cbe6e..8a2f6a0 100644 --- a/aadiscordbot/__init__.py +++ b/aadiscordbot/__init__.py @@ -4,6 +4,6 @@ default_app_config = 'aadiscordbot.apps.AADiscordBotConfig' -__version__ = '3.7.2' +__version__ = '4.0.0a1' __title__ = "AA Discordbot" -__branch__ = 'stable' +__branch__ = 'Global-Alpha' From 13a1400e6334cc19f3e1bcbfd1196b33fe18b915 Mon Sep 17 00:00:00 2001 From: Aaron Kable Date: Mon, 25 Mar 2024 17:17:24 +0800 Subject: [PATCH 08/21] Add recruit me cog --- aadiscordbot/app_settings.py | 14 ++++++ aadiscordbot/cogs/recruit_me.py | 87 +++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 aadiscordbot/cogs/recruit_me.py diff --git a/aadiscordbot/app_settings.py b/aadiscordbot/app_settings.py index ffa1b2d..87f931a 100644 --- a/aadiscordbot/app_settings.py +++ b/aadiscordbot/app_settings.py @@ -121,3 +121,17 @@ def discord_active(): PRICE_CHECK_HOSTNAME = getattr( settings, 'PRICE_CHECK_HOSTNAME', "evepraisal.com") + +// List of ints to sync commands +DISCORD_GUILD_IDS = getattr(settings, 'DISCORD_GUILD_IDS', []) + +DISCORD_GUILD_ID = getattr(settings, 'DISCORD_GUILD_ID', None) + + +def get_all_servers(): + servers = [] + if DISCORD_GUILD_IDS: + servers += DISCORD_GUILD_IDS + if DISCORD_GUILD_ID and DISCORD_GUILD_ID not in servers: + servers.append(int(DISCORD_GUILD_ID)) + return servers diff --git a/aadiscordbot/cogs/recruit_me.py b/aadiscordbot/cogs/recruit_me.py new file mode 100644 index 0000000..ab38ab1 --- /dev/null +++ b/aadiscordbot/cogs/recruit_me.py @@ -0,0 +1,87 @@ +# Cog Stuff +import logging + +import discord +# AA-Discordbot +from discord.embeds import Embed +from discord.ext import commands + +# AA Contexts +from django.conf import settings +from django.utils import timezone + +from .. import app_settings + +logger = logging.getLogger(__name__) + + +class RecruitMe(commands.Cog): + """ + Thread Tools for recruiting! + """ + + def __init__(self, bot): + self.bot = bot + + async def open_ticket( + self, + ctx: discord.Interaction, + member: discord.Member + ): + sup_channel = settings.RECRUIT_CHANNEL_ID + ch = ctx.guild.get_channel(sup_channel) + th = await ch.create_thread( + name=f"{member.display_name} | {timezone.now().strftime('%Y-%m-%d %H:%M')}", + auto_archive_duration=10080, + type=discord.ChannelType.private_thread, + reason=None + ) + msg = (f"<@{member.id}> is hunting for a recruiter!\n\n" + f"Someone from <@&{settings.RECRUITER_GROUP_ID}> will get in touch soon!") + embd = Embed(title="Private Thread Guide", + description="To add a person to this thread simply `@ping` them. This works with `@groups` as well to bulk add people to the channel. Use wisely, abuse will not be tolerated.\n\nThis is a beta feature if you experience issues please contact the admins. :heart:") + await th.send(msg, embed=embd) + await ctx.response.send_message(content="Recruitment thread created!", view=None, ephemeral=True) + + @commands.slash_command( + name='recruit_me', + guild_ids=app_settings.get_all_servers() + ) + async def slash_halp( + self, + ctx, + ): + """ + Get hold of a recruiter + """ + await self.open_ticket(ctx, ctx.user) + + @commands.message_command( + name="Create Recruitment Thread", + guild_ids=app_settings.get_all_servers() + ) + async def reverse_recruit_msg( + self, + ctx, + message + ): + """ + Help a new guy get recruiter + """ + await self.open_ticket(ctx, message.author) + + @commands.user_command( + name="Recruit Member", + guild_ids=app_settings.get_all_servers() + ) + async def reverse_recruit_user( + self, ctx, user + ): + """ + Help a new guy get recruiter + """ + await self.open_ticket(ctx, user) + + +def setup(bot): + bot.add_cog(RecruitMe(bot)) From f25ed922bbfce85208976d367479987b7e30e43a Mon Sep 17 00:00:00 2001 From: Aaron Kable Date: Mon, 25 Mar 2024 17:19:24 +0800 Subject: [PATCH 09/21] add new exception for unmanaged server --- aadiscordbot/bot.py | 10 ++++++---- aadiscordbot/cogs/utils/exceptions.py | 10 ++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/aadiscordbot/bot.py b/aadiscordbot/bot.py index 29d2297..392b3e6 100644 --- a/aadiscordbot/bot.py +++ b/aadiscordbot/bot.py @@ -29,10 +29,9 @@ DISCORD_BOT_ACCESS_DENIED_REACT, DISCORD_BOT_MESSAGE_INTENT, DISCORD_BOT_PREFIX, ) -from aadiscordbot.cogs.utils.exceptions import NotAuthenticated +from aadiscordbot.cogs.utils.exceptions import NotAuthenticated, NotManaged from . import bot_tasks -from .cogs.utils import context description = """ AuthBot is watching... @@ -285,7 +284,7 @@ async def on_interaction(self, interaction): await self.process_application_commands(interaction) django.db.close_old_connections() except Exception as e: - logger.error("Interaction Failed {e}", stack_info=True) + logger.error(f"Interaction Failed {e}", stack_info=True) async def on_message(self, message): if message.author.bot: @@ -295,7 +294,7 @@ async def on_message(self, message): async def sync_commands(self, *args, **kwargs): try: return await super(__class__, self).sync_commands(*args, **kwargs) - except discord.Forbidden: + except discord.Forbidden as e: logger.error( "******************************************************") logger.error("| AuthBot was Unable to Sync Slash Commands!!!!") @@ -310,6 +309,7 @@ async def sync_commands(self, *args, **kwargs): logger.error("| 3. Restart Bot") logger.error( "******************************************************") + logger.error(e) @tasks.loop(seconds=1.0) async def poll_queue(self): @@ -373,6 +373,8 @@ async def on_application_command_error(self, context: ApplicationContext, except await context.send_response(exception, ephemeral=True) elif isinstance(exception, NotAuthenticated): await context.send_response(exception, ephemeral=True) + elif isinstance(exception, NotManaged): + await context.send_response(exception, ephemeral=True) else: # Catch everything, and close out the interactions gracefully. logger.error(f"Unknown Error {exception}") logger.error("\n".join(traceback.format_tb( diff --git a/aadiscordbot/cogs/utils/exceptions.py b/aadiscordbot/cogs/utils/exceptions.py index e59952c..a1f865d 100644 --- a/aadiscordbot/cogs/utils/exceptions.py +++ b/aadiscordbot/cogs/utils/exceptions.py @@ -14,3 +14,13 @@ def __init__(self, *args: Any) -> None: message = f"You must be an Authenticated user to run this command {get_site_url()}" super().__init__(message, *args) + + +class NotManaged(CheckFailure): + """ + Custom Exception to handle any guild not managed by AA + """ + + def __init__(self, *args: Any, dm: bool = False) -> None: + message = f"Command must be used in a guild managed by {get_site_url()}" + super().__init__(message, *args) From 00026bbf334edb8d9fec66544f36fdd9f9587cf2 Mon Sep 17 00:00:00 2001 From: Aaron Kable Date: Mon, 25 Mar 2024 17:21:55 +0800 Subject: [PATCH 10/21] global some commands --- aadiscordbot/cogs/about.py | 2 -- aadiscordbot/cogs/eastereggs.py | 2 -- aadiscordbot/cogs/eightball.py | 4 ---- 3 files changed, 8 deletions(-) diff --git a/aadiscordbot/cogs/about.py b/aadiscordbot/cogs/about.py index b90cb0f..e731468 100644 --- a/aadiscordbot/cogs/about.py +++ b/aadiscordbot/cogs/about.py @@ -5,8 +5,6 @@ from discord.embeds import Embed from discord.ext import commands -from django.conf import settings - from aadiscordbot import __branch__, __version__ from aadiscordbot.app_settings import get_site_url diff --git a/aadiscordbot/cogs/eastereggs.py b/aadiscordbot/cogs/eastereggs.py index 224f413..45a23be 100644 --- a/aadiscordbot/cogs/eastereggs.py +++ b/aadiscordbot/cogs/eastereggs.py @@ -3,8 +3,6 @@ from discord import User from discord.ext import commands -from django.conf import settings - logger = logging.getLogger(__name__) diff --git a/aadiscordbot/cogs/eightball.py b/aadiscordbot/cogs/eightball.py index 4a93494..f3124f6 100644 --- a/aadiscordbot/cogs/eightball.py +++ b/aadiscordbot/cogs/eightball.py @@ -3,10 +3,6 @@ from discord.ext import commands -from django.conf import settings - -from aadiscordbot import __branch__, __version__ - logger = logging.getLogger(__name__) From 120f5c95e1a26cf9d425d1ec710462ea5771d5ce Mon Sep 17 00:00:00 2001 From: Aaron Kable Date: Mon, 25 Mar 2024 17:22:17 +0800 Subject: [PATCH 11/21] Add new modern decorators --- aadiscordbot/cogs/utils/decorators.py | 65 +++++++++++++++++++++++---- aadiscordbot/utils/auth.py | 61 ++++++++++++++++--------- 2 files changed, 98 insertions(+), 28 deletions(-) diff --git a/aadiscordbot/cogs/utils/decorators.py b/aadiscordbot/cogs/utils/decorators.py index 69f7c7f..a946c1c 100644 --- a/aadiscordbot/cogs/utils/decorators.py +++ b/aadiscordbot/cogs/utils/decorators.py @@ -8,7 +8,8 @@ from allianceauth.services.modules.discord.models import DiscordUser from aadiscordbot.app_settings import get_admins -from aadiscordbot.cogs.utils.exceptions import NotAuthenticated +from aadiscordbot.cogs.utils.exceptions import NotAuthenticated, NotManaged +from aadiscordbot.utils import auth logger = logging.getLogger(__name__) @@ -20,8 +21,8 @@ def has_perm(id, perm: str): if id in get_admins(): return True try: - user = DiscordUser.objects.get(uid=id) - has_perm = user.user.has_perm(perm) + user = auth.get_auth_user(id) + has_perm = user.has_perm(perm) if has_perm: return True @@ -45,11 +46,29 @@ def predicate(ctx): return commands.check(predicate) +def is_guild_managed(): + """ + Managed Guild Decorator: Is the guild managed by Auth + """ + def predicate(ctx): + if hasattr(ctx, "guild"): + managed = auth.guild_is_managed(ctx.guild) + logger.debug(f"Guild is Managed: {managed}") + if not managed: + raise NotManaged() + return managed + else: + return False + + return commands.check(predicate) + + def has_all_perms(id, perms: list): if id in get_admins(): return True try: - has_perm = DiscordUser.objects.get(uid=id).user.has_perms(perms) + user = auth.get_auth_user(id) + has_perm = user.has_perms(perms) if has_perm: return True else: @@ -76,8 +95,9 @@ def has_any_perm(id, perms: list): if id in get_admins(): return True for perm in perms: + user = auth.get_auth_user(id) try: - has_perm = DiscordUser.objects.get(uid=id).user.has_perm(perm) + has_perm = user.has_perm(perm) if has_perm: return True except Exception as e: @@ -100,6 +120,12 @@ def predicate(ctx): def is_admin(id): + """ + Deprecated use `aadiscordbot.utils.auth.user_is_authenticated` instead + """ + logger.warning("aadiscordbot.cogs.utils.is_authenticated is deprecated." + "Use aadiscordbot.utils.auth.user_is_authenticated instead.") + if id in get_admins(): return True else: @@ -127,11 +153,23 @@ def in_channels(channel, channels): def message_in_channels(channels: list): def predicate(ctx): - return in_channels(ctx.message.channel.id, channels) + if hasattr(ctx, "message") and ctx.message is not None: + logger.debug("Decorator message_in_channels .message") + return in_channels(ctx.message.channel.id, channels) + elif hasattr(ctx, "channel") and ctx.channel is not None: + logger.debug("Decorator message_in_channels .channel") + return in_channels(ctx.channel.id, channels) + else: + return False return commands.check(predicate) def is_authenticated(id): + """ + Deprecated use `aadiscordbot.utils.auth.user_is_authenticated` instead + """ + logger.warning("aadiscordbot.cogs.utils.is_authenticated is deprecated." + "Use aadiscordbot.utils.auth.user_is_authenticated instead.") try: DiscordUser.objects.get(uid=id) return True @@ -141,8 +179,19 @@ def is_authenticated(id): def sender_is_authenticated(): """ - Permission Decorator: Is the user Authenticated + Permission Decorator: Is the user Authenticated + Deprecated use `aadiscordbot.utils.auth.user_is_authenticated` instead + """ + + def predicate(ctx): + return auth.user_is_authenticated(ctx.user.id) + return commands.check(predicate) + + +def is_sender_authenticated(): + """ + Permission Decorator: Is the user Authenticated to auth """ def predicate(ctx): - return is_authenticated(ctx.user.id) + return auth.user_is_authenticated(ctx.user.id) return commands.check(predicate) diff --git a/aadiscordbot/utils/auth.py b/aadiscordbot/utils/auth.py index 5755536..ac4f4f1 100644 --- a/aadiscordbot/utils/auth.py +++ b/aadiscordbot/utils/auth.py @@ -17,6 +17,8 @@ from allianceauth.services.modules.discord.models import DiscordUser +from aadiscordbot.app_settings import get_admins + logger = logging.getLogger(__name__) DMV_ACTIVE = False @@ -25,12 +27,14 @@ from aadiscordmultiverse.models import ( DiscordManagedServer, MultiDiscordUser, ) + + # TODO also check for in installed_apps DMV_ACTIVE = True except ImportError: logger.debug("DMV not installed") -def get_dmv_discord_user(user_id, guild_id): +def _get_dmv_discord_user(user_id, guild_id): if DMV_ACTIVE: try: return MultiDiscordUser.objects.get( @@ -43,56 +47,59 @@ def get_dmv_discord_user(user_id, guild_id): return None -def check_for_dmv_user(user: User, guild: Guild): +def _check_for_dmv_user(user: User, guild: Guild): """ Return `True` if a discord user is authenticated to the DMV service module `False` Otherwise """ - user = get_dmv_discord_user(user.id, guild.id) + user = _get_dmv_discord_user(user.id, guild.id) if user: return True else: return False -def get_core_discord_user(user_id): +def _get_core_discord_user(user_id): try: return DiscordUser.objects.get(uid=user_id) except DiscordUser.DoesNotExist: return None -def check_for_core_user(user: User): +def _check_for_core_user(user: User): """ Return `True` if a discord user is authenticated to the core auth service module `False` Otherwise """ - user = get_core_discord_user(user.id) + user = _get_core_discord_user(user.id) if user: return True else: return False -def guild_is_core_module(guild_id): +def _guild_is_core_module(guild_id): """ Check if the guild_id matches the core auth service module's guild """ - return id == getattr(settings, "DISCORD_GUILD_ID", -1) + # May be string in settings so cast to int for check. + # discord returns int for guild.id + + return guild_id == int(getattr(settings, "DISCORD_GUILD_ID", -1)) -def guild_is_dmv_module(guild_id): +def _guild_is_dmv_module(guild_id): """ Check if the guild_id matches the any of the DMV servers """ - guild = get_dmv_guild(guild_id) + guild = _get_dmv_guild(guild_id) if guild: return True else: return False -def get_dmv_guild(guild_id): +def _get_dmv_guild(guild_id): """ Return DMV Guild model if DMV installed and """ @@ -107,18 +114,32 @@ def get_dmv_guild(guild_id): return None -def user_is_authenticated(user: User, guild: Guild): +def is_user_bot_admin(user: User): + """ + Is user a configured Bot Admin + """ + if user.id in get_admins(): + return True + else: + raise False + + +def is_guild_managed(guild: Guild): + return _guild_is_core_module(guild.id) or _guild_is_dmv_module(guild.id) + + +def is_user_authenticated(user: User, guild: Guild): """ Return `True` if a discord user is authenticated to the any service module `False` Otherwise Checks these services depending on the guild_id """ - if guild_is_core_module(guild.id): - return check_for_core_user(user) + if _guild_is_core_module(guild.id): + return _check_for_core_user(user) - elif guild_is_dmv_module(guild.id): - return check_for_dmv_user(user, guild) + elif _guild_is_dmv_module(guild.id): + return _check_for_dmv_user(user, guild) else: return False @@ -129,11 +150,11 @@ def get_auth_user(user: User, guild: Guild): Get auth user from any service module """ discord_user = None - if guild_is_core_module(guild.id): - discord_user = get_core_discord_user(user.id) + if _guild_is_core_module(guild.id): + discord_user = _get_core_discord_user(user.id) - elif guild_is_dmv_module(guild.id): - discord_user = get_dmv_discord_user(user.id, guild.id) + elif _guild_is_dmv_module(guild.id): + discord_user = _get_dmv_discord_user(user.id, guild.id) if discord_user: return discord_user.user From b0e1da856566566240444fed2852d5cd257ccf73 Mon Sep 17 00:00:00 2001 From: Aaron Kable Date: Mon, 25 Mar 2024 17:24:02 +0800 Subject: [PATCH 12/21] refactor members to use modern perms --- aadiscordbot/cogs/members.py | 51 +++++++++++++++++------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/aadiscordbot/cogs/members.py b/aadiscordbot/cogs/members.py index e80f9f7..fd47be7 100644 --- a/aadiscordbot/cogs/members.py +++ b/aadiscordbot/cogs/members.py @@ -15,7 +15,8 @@ from aadiscordbot.app_settings import aastatistics_active from aadiscordbot.cogs.utils.decorators import ( - has_any_perm, in_channels, message_in_channels, sender_has_any_perm, + guild_is_managed, has_any_perm, in_channels, message_in_channels, + sender_has_any_perm, ) logger = logging.getLogger(__name__) @@ -155,6 +156,7 @@ def get_lookup_embed(self, input_name): return embed @commands.command(pass_context=True) + @guild_is_managed() @sender_has_any_perm(['corputils.view_alliance_corpstats', 'corpstats.view_alliance_corpstats', 'aadiscordbot.member_command_access']) @message_in_channels(settings.ADMIN_DISCORD_BOT_CHANNELS) async def lookup(self, ctx): @@ -169,21 +171,18 @@ async def search_characters(ctx: AutocompleteContext): """Returns a list of colors that begin with the characters entered so far.""" return list(EveCharacter.objects.filter(character_name__icontains=ctx.value).values_list('character_name', flat=True)[:10]) - @commands.slash_command(name='lookup', guild_ids=[int(settings.DISCORD_GUILD_ID)]) + @commands.slash_command(name='lookup') + @guild_is_managed() + @sender_has_any_perm(['corputils.view_alliance_corpstats', 'corpstats.view_alliance_corpstats', 'aadiscordbot.member_command_access']) + @message_in_channels(settings.ADMIN_DISCORD_BOT_CHANNELS) @option("character", description="Search for a Character!", autocomplete=search_characters) async def slash_lookup( self, ctx, character: str, ): - try: - in_channels(ctx.channel.id, settings.ADMIN_DISCORD_BOT_CHANNELS) - has_any_perm(ctx.author.id, ['corputils.view_alliance_corpstats', - 'corpstats.view_alliance_corpstats', 'aadiscordbot.member_command_access']) - await ctx.defer() - return await ctx.respond(embed=self.get_lookup_embed(character)) - except commands.MissingPermissions as e: - return await ctx.respond(e.missing_permissions[0], ephemeral=True) + await ctx.defer() + return await ctx.respond(embed=self.get_lookup_embed(character)) async def search_corps_on_characters(ctx: AutocompleteContext): """Returns a list of colors that begin with the characters entered so far.""" @@ -249,31 +248,29 @@ def build_altcorp_embeds(self, input_name): embeds.append(embed) return embeds - @commands.slash_command(name='altcorp', guild_ids=[int(settings.DISCORD_GUILD_ID)]) + @commands.slash_command(name='altcorp') + @guild_is_managed() + @sender_has_any_perm(['aadiscordbot.member_command_access']) + @message_in_channels(settings.ADMIN_DISCORD_BOT_CHANNELS) @option("corporation", description="Search for a Character!", autocomplete=search_corps_on_characters) async def slash_altcorp( self, ctx, corporation: str, ): - try: - in_channels(ctx.channel.id, settings.ADMIN_DISCORD_BOT_CHANNELS) - has_any_perm(ctx.author.id, ['corputils.view_alliance_corpstats', - 'corpstats.view_alliance_corpstats', 'aadiscordbot.member_command_access']) - await ctx.defer() - embeds = self.build_altcorp_embeds(corporation) - if len(embeds): - e = embeds.pop(0) - await ctx.respond(embed=e) - for e in embeds: - await ctx.send(embed=e) - else: - await ctx.respond("No Members Found!") - except commands.MissingPermissions as e: - return await ctx.respond(e.missing_permissions[0], ephemeral=True) + await ctx.defer() + embeds = self.build_altcorp_embeds(corporation) + if len(embeds): + e = embeds.pop(0) + await ctx.respond(embed=e) + for e in embeds: + await ctx.send(embed=e) + else: + await ctx.respond("No Members Found!") @commands.command(pass_context=True) - @sender_has_any_perm(['corputils.view_alliance_corpstats', 'corpstats.view_alliance_corpstats', 'aadiscordbot.member_command_access']) + @guild_is_managed() + @sender_has_any_perm(['aadiscordbot.member_command_access']) @message_in_channels(settings.ADMIN_DISCORD_BOT_CHANNELS) async def altcorp(self, ctx): """ From 044235ee153e078c6d00fc3146179a7847a14c3a Mon Sep 17 00:00:00 2001 From: Aaron Kable Date: Mon, 25 Mar 2024 17:27:29 +0800 Subject: [PATCH 13/21] python... not js... --- aadiscordbot/app_settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aadiscordbot/app_settings.py b/aadiscordbot/app_settings.py index 87f931a..1def823 100644 --- a/aadiscordbot/app_settings.py +++ b/aadiscordbot/app_settings.py @@ -122,7 +122,7 @@ def discord_active(): PRICE_CHECK_HOSTNAME = getattr( settings, 'PRICE_CHECK_HOSTNAME', "evepraisal.com") -// List of ints to sync commands +# List of ints to sync commands DISCORD_GUILD_IDS = getattr(settings, 'DISCORD_GUILD_IDS', []) DISCORD_GUILD_ID = getattr(settings, 'DISCORD_GUILD_ID', None) From b05562469d65dae01c20378be635df1a90a253ee Mon Sep 17 00:00:00 2001 From: Aaron Kable Date: Mon, 25 Mar 2024 17:27:44 +0800 Subject: [PATCH 14/21] add recruit_me to readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5c99793..3f181e1 100644 --- a/README.md +++ b/README.md @@ -150,7 +150,7 @@ corputils.view_alliance_corpstats ## Optional Settings ### Built in Cogs - ```python +```python # Change the bots default Cogs, add or remove if you want to use any of the extra cogs. DISCORD_BOT_COGS = [ @@ -172,6 +172,7 @@ DISCORD_BOT_COGS = [ "aadiscordbot.cogs.quote", # Save and recall messages "aadiscordbot.cogs.prom_export", # Admin Level Logging cog "aadiscordbot.cogs.tickets", # Private thread ticket system with pingable groups. + "aadiscordbot.cogs.recruit_me", # Private thread recruitment ticket system. ] ``` From e33e6eaed801c679b6f56d8a81f774ef034b1ee6 Mon Sep 17 00:00:00 2001 From: Aaron Kable Date: Mon, 25 Mar 2024 17:38:43 +0800 Subject: [PATCH 15/21] renamed some of the decorators --- aadiscordbot/cogs/members.py | 10 +++++----- aadiscordbot/cogs/recruit_me.py | 4 ++-- aadiscordbot/cogs/welcomegoodbye.py | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/aadiscordbot/cogs/members.py b/aadiscordbot/cogs/members.py index fd47be7..5070e60 100644 --- a/aadiscordbot/cogs/members.py +++ b/aadiscordbot/cogs/members.py @@ -15,7 +15,7 @@ from aadiscordbot.app_settings import aastatistics_active from aadiscordbot.cogs.utils.decorators import ( - guild_is_managed, has_any_perm, in_channels, message_in_channels, + has_any_perm, in_channels, is_guild_managed, message_in_channels, sender_has_any_perm, ) @@ -156,7 +156,7 @@ def get_lookup_embed(self, input_name): return embed @commands.command(pass_context=True) - @guild_is_managed() + @is_guild_managed() @sender_has_any_perm(['corputils.view_alliance_corpstats', 'corpstats.view_alliance_corpstats', 'aadiscordbot.member_command_access']) @message_in_channels(settings.ADMIN_DISCORD_BOT_CHANNELS) async def lookup(self, ctx): @@ -172,7 +172,7 @@ async def search_characters(ctx: AutocompleteContext): return list(EveCharacter.objects.filter(character_name__icontains=ctx.value).values_list('character_name', flat=True)[:10]) @commands.slash_command(name='lookup') - @guild_is_managed() + @is_guild_managed() @sender_has_any_perm(['corputils.view_alliance_corpstats', 'corpstats.view_alliance_corpstats', 'aadiscordbot.member_command_access']) @message_in_channels(settings.ADMIN_DISCORD_BOT_CHANNELS) @option("character", description="Search for a Character!", autocomplete=search_characters) @@ -249,7 +249,7 @@ def build_altcorp_embeds(self, input_name): return embeds @commands.slash_command(name='altcorp') - @guild_is_managed() + @is_guild_managed() @sender_has_any_perm(['aadiscordbot.member_command_access']) @message_in_channels(settings.ADMIN_DISCORD_BOT_CHANNELS) @option("corporation", description="Search for a Character!", autocomplete=search_corps_on_characters) @@ -269,7 +269,7 @@ async def slash_altcorp( await ctx.respond("No Members Found!") @commands.command(pass_context=True) - @guild_is_managed() + @is_guild_managed() @sender_has_any_perm(['aadiscordbot.member_command_access']) @message_in_channels(settings.ADMIN_DISCORD_BOT_CHANNELS) async def altcorp(self, ctx): diff --git a/aadiscordbot/cogs/recruit_me.py b/aadiscordbot/cogs/recruit_me.py index ab38ab1..ace9c87 100644 --- a/aadiscordbot/cogs/recruit_me.py +++ b/aadiscordbot/cogs/recruit_me.py @@ -60,7 +60,7 @@ async def slash_halp( name="Create Recruitment Thread", guild_ids=app_settings.get_all_servers() ) - async def reverse_recruit_msg( + async def reverse_recruit_msg_context( self, ctx, message @@ -74,7 +74,7 @@ async def reverse_recruit_msg( name="Recruit Member", guild_ids=app_settings.get_all_servers() ) - async def reverse_recruit_user( + async def reverse_recruit_user_context( self, ctx, user ): """ diff --git a/aadiscordbot/cogs/welcomegoodbye.py b/aadiscordbot/cogs/welcomegoodbye.py index a6ca38c..5f24a10 100644 --- a/aadiscordbot/cogs/welcomegoodbye.py +++ b/aadiscordbot/cogs/welcomegoodbye.py @@ -9,7 +9,7 @@ from aadiscordbot.app_settings import get_site_url from aadiscordbot.models import GoodbyeMessage, WelcomeMessage -from aadiscordbot.utils.auth import user_is_authenticated +from aadiscordbot.utils.auth import is_user_authenticated logger = logging.getLogger(__name__) @@ -32,7 +32,7 @@ async def on_member_join(self, member: discord.Member): try: # Give AA a chance to save the UID for a joiner. await asyncio.sleep(3) - authenticated = user_is_authenticated(member, member.guild) + authenticated = is_user_authenticated(member, member.guild) except Exception: authenticated = False if authenticated: @@ -86,7 +86,7 @@ async def on_member_remove(self, member: discord.Member): if channel is not None: try: # Give AA a chance to save the UID for a joiner. - authenticated = user_is_authenticated(member, member.guild) + authenticated = is_user_authenticated(member, member.guild) except Exception: authenticated = False if authenticated: From ed7c60490ef751dbd351c157696a5be98e0478d6 Mon Sep 17 00:00:00 2001 From: Aaron Kable Date: Sat, 25 May 2024 14:03:28 +0800 Subject: [PATCH 16/21] stable not master --- aadiscordbot/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/aadiscordbot/__init__.py b/aadiscordbot/__init__.py index 8cd0932..1b9f1ab 100644 --- a/aadiscordbot/__init__.py +++ b/aadiscordbot/__init__.py @@ -2,8 +2,7 @@ Alliance Auth Modular Discord Bot """ -default_app_config = 'aadiscordbot.apps.AADiscordBotConfig' __version__ = '4.0.0b1' __title__ = "AA Discordbot" -__branch__ = 'master' +__branch__ = 'stable' From 83b3a4d7206d0552720d66b5562e513d5ef68673 Mon Sep 17 00:00:00 2001 From: Aaron Kable Date: Sat, 25 May 2024 14:04:45 +0800 Subject: [PATCH 17/21] fix hello goodbye --- aadiscordbot/cogs/welcomegoodbye.py | 22 +++++++++++++----- ..._alter_goodbyemessage_guild_id_and_more.py | 23 +++++++++++++++++++ aadiscordbot/models.py | 7 +++--- 3 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 aadiscordbot/migrations/0014_alter_goodbyemessage_guild_id_and_more.py diff --git a/aadiscordbot/cogs/welcomegoodbye.py b/aadiscordbot/cogs/welcomegoodbye.py index 5f24a10..06cb02d 100644 --- a/aadiscordbot/cogs/welcomegoodbye.py +++ b/aadiscordbot/cogs/welcomegoodbye.py @@ -7,6 +7,8 @@ import discord from discord.ext import commands +from django.db.models import Q + from aadiscordbot.app_settings import get_site_url from aadiscordbot.models import GoodbyeMessage, WelcomeMessage from aadiscordbot.utils.auth import is_user_authenticated @@ -38,8 +40,10 @@ async def on_member_join(self, member: discord.Member): if authenticated: try: message = WelcomeMessage.objects.filter( + Q( + Q(guild_id=member.guild.id) | Q(guild_id=None) + ), authenticated=True, - guild_id=member.guild.id ).order_by('?').first().message message_formatted = message.format( user_mention=member.mention, @@ -54,8 +58,10 @@ async def on_member_join(self, member: discord.Member): else: try: message = WelcomeMessage.objects.filter( + Q( + Q(guild_id=member.guild.id) | Q(guild_id=None) + ), unauthenticated=True, - guild_id=member.guild.id ).order_by('?').first().message message_formatted = message.format( user_mention=member.mention, @@ -80,7 +86,7 @@ def __init__(self, bot): @commands.Cog.listener("on_member_remove") async def on_member_remove(self, member: discord.Member): logger.info( - f"{member} joined {member.guild.name}" + f"{member} Left {member.guild.name}" ) channel = member.guild.system_channel if channel is not None: @@ -93,8 +99,10 @@ async def on_member_remove(self, member: discord.Member): # Authenticated try: message = GoodbyeMessage.objects.filter( + Q( + Q(guild_id=member.guild.id) | Q(guild_id=None) + ), authenticated=True, - guild_id=member.guild.id ).order_by('?').first().message message_formatted = message.format( user_mention=member.mention, @@ -111,8 +119,10 @@ async def on_member_remove(self, member: discord.Member): # Un-Authenticated try: message = GoodbyeMessage.objects.filter( + Q( + Q(guild_id=member.guild.id) | Q(guild_id=None) + ), unauthenticated=True, - guild_id=member.guild.id ).order_by('?').first().message message_formatted = message.format( user_mention=member.mention, @@ -123,7 +133,7 @@ async def on_member_remove(self, member: discord.Member): logger.error( 'No Leave Message configured for Discordbot Goodbye cog') except Exception as e: - logger.error(e) + logger.error(e, stack_info=True) def setup(bot): diff --git a/aadiscordbot/migrations/0014_alter_goodbyemessage_guild_id_and_more.py b/aadiscordbot/migrations/0014_alter_goodbyemessage_guild_id_and_more.py new file mode 100644 index 0000000..ae5d6c7 --- /dev/null +++ b/aadiscordbot/migrations/0014_alter_goodbyemessage_guild_id_and_more.py @@ -0,0 +1,23 @@ +# Generated by Django 5.0.3 on 2024-05-25 05:49 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('aadiscordbot', '0013_goodbyemessage_guild_id'), + ] + + operations = [ + migrations.AlterField( + model_name='goodbyemessage', + name='guild_id', + field=models.BigIntegerField(blank=True, default=None, null=True), + ), + migrations.AlterField( + model_name='welcomemessage', + name='guild_id', + field=models.BigIntegerField(blank=True, default=None, null=True), + ), + ] diff --git a/aadiscordbot/models.py b/aadiscordbot/models.py index 28f7f05..ecf3dd4 100644 --- a/aadiscordbot/models.py +++ b/aadiscordbot/models.py @@ -1,6 +1,5 @@ from solo.models import SingletonModel -from django.conf import settings from django.contrib.auth.models import Group from django.core.exceptions import ValidationError from django.db import models @@ -81,7 +80,7 @@ class ReactionRoleBinding(models.Model): def __str__(self): try: b = eval(self.emoji_text).decode('utf-8') - except: + except Exception: b = self.emoji_text return f'{self.message.name}: {b} ({self.group})' @@ -107,7 +106,7 @@ class WelcomeMessage(models.Model): authenticated = models.BooleanField(_("Valid for Authenticated Users")) unauthenticated = models.BooleanField( _("Valid for Un-Authenticated Users")) - guild_id = models.BigIntegerField(default=settings.DISCORD_GUILD_ID) + guild_id = models.BigIntegerField(default=None, null=True, blank=True) class Meta: default_permissions = () @@ -120,7 +119,7 @@ class GoodbyeMessage(models.Model): authenticated = models.BooleanField(_("Valid for Authenticated Users")) unauthenticated = models.BooleanField( _("Valid for Un-Authenticated Users")) - guild_id = models.BigIntegerField(default=settings.DISCORD_GUILD_ID) + guild_id = models.BigIntegerField(default=None, null=True, blank=True) class Meta: default_permissions = () From f8a6730182011d0f3fd3b515c65229dafaaf61b8 Mon Sep 17 00:00:00 2001 From: Aaron Kable Date: Sat, 25 May 2024 14:06:30 +0800 Subject: [PATCH 18/21] not a major bump --- aadiscordbot/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aadiscordbot/__init__.py b/aadiscordbot/__init__.py index 1b9f1ab..c0e60b0 100644 --- a/aadiscordbot/__init__.py +++ b/aadiscordbot/__init__.py @@ -3,6 +3,6 @@ """ -__version__ = '4.0.0b1' +__version__ = '3.8.0' __title__ = "AA Discordbot" __branch__ = 'stable' From 6b265696d0ebbcabfd27195d1cb3d637eafc3913 Mon Sep 17 00:00:00 2001 From: Aaron Kable Date: Sat, 25 May 2024 14:21:34 +0800 Subject: [PATCH 19/21] Tidy up first pass --- aadiscordbot/cogs/abuse.py | 8 ++------ aadiscordbot/cogs/abuse_two.py | 6 ------ aadiscordbot/cogs/members.py | 12 ++++++------ aadiscordbot/cogs/utils/decorators.py | 2 +- 4 files changed, 9 insertions(+), 19 deletions(-) diff --git a/aadiscordbot/cogs/abuse.py b/aadiscordbot/cogs/abuse.py index 22e8c64..1c3d69e 100644 --- a/aadiscordbot/cogs/abuse.py +++ b/aadiscordbot/cogs/abuse.py @@ -3,10 +3,6 @@ from discord.ext import commands -from django.conf import settings - -from aadiscordbot import __branch__, __version__ - logger = logging.getLogger(__name__) @@ -52,7 +48,7 @@ async def respond_to_abuse(self, message): "Pardon me, but you've obviously mistaken me for someone who gives a damn.", "https://media.tenor.com/x8v1oNUOmg4AAAAC/rickroll-roll.gif" ] - rand = randrange(0, len(replies)-1) + rand = randrange(0, len(replies) - 1) if message.mention_everyone: return try: @@ -61,7 +57,7 @@ async def respond_to_abuse(self, message): await message.reply("https://media.tenor.com/x8v1oNUOmg4AAAAC/rickroll-roll.gif") else: await message.reply(replies[rand]) - except: + except Exception: pass diff --git a/aadiscordbot/cogs/abuse_two.py b/aadiscordbot/cogs/abuse_two.py index 1132f67..6b12370 100644 --- a/aadiscordbot/cogs/abuse_two.py +++ b/aadiscordbot/cogs/abuse_two.py @@ -1,15 +1,9 @@ import logging -from discord.colour import Color -from discord.commands import SlashCommandGroup -from discord.embeds import Embed from discord.ext import commands from django.conf import settings -from aadiscordbot import __branch__, __version__ -from aadiscordbot.app_settings import get_site_url - logger = logging.getLogger(__name__) diff --git a/aadiscordbot/cogs/members.py b/aadiscordbot/cogs/members.py index 5070e60..dad327d 100644 --- a/aadiscordbot/cogs/members.py +++ b/aadiscordbot/cogs/members.py @@ -15,8 +15,7 @@ from aadiscordbot.app_settings import aastatistics_active from aadiscordbot.cogs.utils.decorators import ( - has_any_perm, in_channels, is_guild_managed, message_in_channels, - sender_has_any_perm, + is_guild_managed, message_in_channels, sender_has_any_perm, ) logger = logging.getLogger(__name__) @@ -185,7 +184,7 @@ async def slash_lookup( return await ctx.respond(embed=self.get_lookup_embed(character)) async def search_corps_on_characters(ctx: AutocompleteContext): - """Returns a list of colors that begin with the characters entered so far.""" + """Returns a list of corporations that begin with the characters entered so far.""" return list(EveCharacter.objects.filter(corporation_name__icontains=ctx.value).values_list('corporation_name', flat=True).distinct()[:10]) def build_altcorp_embeds(self, input_name): @@ -197,7 +196,6 @@ def build_altcorp_embeds(self, input_name): knowns = 0 for c in chars: corp_id = c.corporation_id - alliance = c.alliance_name if c.alliance_id not in own_ids: alts_in_corp.append(c) @@ -209,7 +207,7 @@ def build_altcorp_embeds(self, input_name): mains[main.character_id] = [main, 0] mains[main.character_id][1] += 1 knowns += 1 - except Exception as e: + except Exception: # logger.error(e) pass output = [] @@ -252,7 +250,9 @@ def build_altcorp_embeds(self, input_name): @is_guild_managed() @sender_has_any_perm(['aadiscordbot.member_command_access']) @message_in_channels(settings.ADMIN_DISCORD_BOT_CHANNELS) - @option("corporation", description="Search for a Character!", autocomplete=search_corps_on_characters) + @option("corporation", + description="Search for a Character!", + autocomplete=search_corps_on_characters) async def slash_altcorp( self, ctx, diff --git a/aadiscordbot/cogs/utils/decorators.py b/aadiscordbot/cogs/utils/decorators.py index a946c1c..f10e328 100644 --- a/aadiscordbot/cogs/utils/decorators.py +++ b/aadiscordbot/cogs/utils/decorators.py @@ -52,7 +52,7 @@ def is_guild_managed(): """ def predicate(ctx): if hasattr(ctx, "guild"): - managed = auth.guild_is_managed(ctx.guild) + managed = auth.is_guild_managed(ctx.guild) logger.debug(f"Guild is Managed: {managed}") if not managed: raise NotManaged() From 2f8d1fe8bba0bad231ff5a931bc852a638cfea06 Mon Sep 17 00:00:00 2001 From: Aaron Kable Date: Sat, 25 May 2024 14:41:18 +0800 Subject: [PATCH 20/21] add a shim for a renamed method --- aadiscordbot/utils/auth.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/aadiscordbot/utils/auth.py b/aadiscordbot/utils/auth.py index ac4f4f1..feeaa3e 100644 --- a/aadiscordbot/utils/auth.py +++ b/aadiscordbot/utils/auth.py @@ -128,6 +128,11 @@ def is_guild_managed(guild: Guild): return _guild_is_core_module(guild.id) or _guild_is_dmv_module(guild.id) +def user_is_authenticated(user: User, guild: Guild): + logger.warning("user_is_authenticated is deprecated use is_user_authenticated instead") + return is_user_authenticated(user, guild) + + def is_user_authenticated(user: User, guild: Guild): """ Return `True` if a discord user is authenticated to the From 87d82aaf2b6d3d9d7895363a0e8b82d249655023 Mon Sep 17 00:00:00 2001 From: Aaron Kable Date: Sat, 25 May 2024 14:59:44 +0800 Subject: [PATCH 21/21] add DeprecationWarning --- aadiscordbot/utils/auth.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/aadiscordbot/utils/auth.py b/aadiscordbot/utils/auth.py index feeaa3e..0f883ef 100644 --- a/aadiscordbot/utils/auth.py +++ b/aadiscordbot/utils/auth.py @@ -10,6 +10,7 @@ """ import logging +import warnings from discord import Guild, User @@ -129,6 +130,11 @@ def is_guild_managed(guild: Guild): def user_is_authenticated(user: User, guild: Guild): + warnings.warn( + "user_is_authenticated is deprecated use is_user_authenticated instead", + DeprecationWarning, + stacklevel=2 + ) logger.warning("user_is_authenticated is deprecated use is_user_authenticated instead") return is_user_authenticated(user, guild)