Skip to content

Commit

Permalink
Merge pull request #86 from Solar-Helix-Independent-Transport/global-…
Browse files Browse the repository at this point in the history
…commands

Global commands
  • Loading branch information
pvyParts authored May 25, 2024
2 parents 32156b0 + 87d82aa commit 5b7abe2
Show file tree
Hide file tree
Showing 18 changed files with 385 additions and 177 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,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 = [
Expand All @@ -209,6 +208,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.
]
```

Expand Down
3 changes: 1 addition & 2 deletions aadiscordbot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
Alliance Auth Modular Discord Bot
"""

default_app_config = 'aadiscordbot.apps.AADiscordBotConfig'

__version__ = '3.7.3'
__version__ = '3.8.0'
__title__ = "AA Discordbot"
__branch__ = 'stable'
14 changes: 14 additions & 0 deletions aadiscordbot/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 6 additions & 4 deletions aadiscordbot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down Expand Up @@ -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:
Expand All @@ -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!!!!")
Expand All @@ -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):
Expand Down Expand Up @@ -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(
Expand Down
97 changes: 50 additions & 47 deletions aadiscordbot/cogs/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -21,10 +19,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
Expand All @@ -36,64 +33,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):
Expand Down
8 changes: 2 additions & 6 deletions aadiscordbot/cogs/abuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@

from discord.ext import commands

from django.conf import settings

from aadiscordbot import __branch__, __version__

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -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:
Expand All @@ -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


Expand Down
6 changes: 0 additions & 6 deletions aadiscordbot/cogs/abuse_two.py
Original file line number Diff line number Diff line change
@@ -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__)


Expand Down
57 changes: 25 additions & 32 deletions aadiscordbot/cogs/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -28,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()

Expand All @@ -48,39 +44,36 @@ 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.
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):
Expand Down
4 changes: 1 addition & 3 deletions aadiscordbot/cogs/eastereggs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from discord import User
from discord.ext import commands

from django.conf import settings

logger = logging.getLogger(__name__)


Expand All @@ -19,7 +17,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
Expand Down
6 changes: 1 addition & 5 deletions aadiscordbot/cogs/eightball.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@

from discord.ext import commands

from django.conf import settings

from aadiscordbot import __branch__, __version__

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -48,7 +44,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()}")

Expand Down
Loading

0 comments on commit 5b7abe2

Please sign in to comment.