Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
allianceauth-discordbot
Advanced tools
AA-Discordbot for Alliance Auth.
/admin [command]
Ensure you have installed and configured the Alliance Auth Discord Service, https://allianceauth.readthedocs.io/en/latest/features/services/discord.html
Update your Discord Developer Application to include the Privileged Intents that we call. Please enable all intents.
pip install allianceauth-discordbot
Add 'aadiscordbot',
to your INSTALLED_APPS list in local.py.
Add the below lines to your local.py
settings file, Changing the contexts to yours.
## Settings for Allianceauth-Discordbot
# Admin Commands
ADMIN_DISCORD_BOT_CHANNELS = [111, 222, 333]
# Sov Commands
SOV_DISCORD_BOT_CHANNELS = [111, 222, 333]
# Adm Commands
ADM_DISCORD_BOT_CHANNELS = [111, 222, 333]
DISCORD_BOT_SOV_STRUCTURE_OWNER_IDS = [1000169] # Centre for Advanced Studies example
DISCORD_BOT_MEMBER_ALLIANCES = [111, 222, 333] # A list of alliances to be considered "Mains"
DISCORD_BOT_ADM_REGIONS = [10000002] # The Forge Example
DISCORD_BOT_ADM_SYSTEMS = [30000142] # Jita Example
DISCORD_BOT_ADM_CONSTELLATIONS = [20000020] # Kimitoro Example
PRICE_CHECK_HOSTNAME = "evepraisal.com" # Point to your favorite evepraisal
## Insert AADiscordBot's logging into Django Logging config
LOGGING['handlers']['bot_log_file']= {
'level': 'INFO',
'class': 'logging.handlers.RotatingFileHandler',
'filename': os.path.join(BASE_DIR, 'log/discord_bot.log'),
'formatter': 'verbose',
'maxBytes': 1024 * 1024 * 5,
'backupCount': 5,
}
LOGGING['loggers']['aadiscordbot'] = {'handlers': ['bot_log_file'],'level': 'DEBUG'}
myauth/celery.py
somewhere above the app.autodiscover_tasks...
line
## Route AA Discord bot tasks away from AllianceAuth
app.conf.task_routes = {'aadiscordbot.tasks.*': {'queue': 'aadiscordbot'}}
alianceauth-discordbot=version.number
to your requirements.txt and rebuild your containers and restart auth.python manage.py migrate
Add a service to run the Discordbot
allianceauth_discordbot:
container_name: allianceauth_discordbot
<<: [ *allianceauth-base ]
restart: on-failure
entrypoint: [ "auth", "run_authbot" ]
docker compose up -d
to start the bot.authbot
to the launch group at the end of the conf[program:authbot]
command=/home/allianceserver/venv/auth/bin/python /home/allianceserver/myauth/manage.py run_authbot
directory=/home/allianceserver/myauth
user=allianceserver
numprocs=1
autostart=true
autorestart=true
stopwaitsecs=600
stdout_logfile=/home/allianceserver/myauth/log/authbot.log
stderr_logfile=/home/allianceserver/myauth/log/authbot.log
#This block should already exist, add authbot to it
[group:myauth]
programs=beat,worker,gunicorn,authbot
priority=999
[Bare metal only] Restart and reload supervisor sudo service supervisord reload
Go to admin and configure your admin users in the bot config model.
Enable groups/states/users to utilize the lookup command by adding permissions under corputils | corp stats |
corputils.view_alliance_corpstats
or
aadiscordbot.member_command_access "aadiscordbot | DiscordBot | can access the member commands"
# Change the bots default Cogs, add or remove if you want to use any of the extra cogs.
DISCORD_BOT_COGS = [
"aadiscordbot.cogs.about", # about the bot
"aadiscordbot.cogs.admin", # Discord server admin helpers
"aadiscordbot.cogs.members", # Member lookup commands
"aadiscordbot.cogs.timers", # timer board integration
"aadiscordbot.cogs.auth", # return auth url
"aadiscordbot.cogs.sov", # some sov helpers
"aadiscordbot.cogs.time", # whats the time Mr Eve Server
"aadiscordbot.cogs.eastereggs", # some "fun" commands from ariel...
"aadiscordbot.cogs.remind", # very Basic in memory reminder tool
"aadiscordbot.cogs.reaction_roles", # auth group integrated reaction roles
"aadiscordbot.cogs.services", # service activation data
"aadiscordbot.cogs.price_check", # Price Checks
"aadiscordbot.cogs.eightball", # 8ball should i install this cog
"aadiscordbot.cogs.welcomegoodbye", # Customizable user join/leave messages
"aadiscordbot.cogs.models", # Populate and Maintain Django Models for Channels and Servers
"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.
]
# configure the optional rate limited
# this is a bot_task function and how many / time period
# 100/s equates to 100 per second max
# 10/m equates to 10 per minute or 1 every 6 seconds max
# 60/h equates to 60 per hour or one per minute max
DISCORD_BOT_TASK_RATE_LIMITS = {
"send_channel_message_by_discord_id": "100/s",
"send_direct_message_by_discord_id": "1/s",
"send_direct_message_by_user_id": "1/s"
}
❗❗❗ This will bypass the Group Leadership/Join Request System: This is intended for open groups but not limited to it! ❗❗❗
The bot is able to run a reaction roles system that is compatible with auth and public users on a discord.
Setup the inital Message you wish to use buy using the command !rr
Admin > Discord Bot > Reaction Role Messages
React to the message with the reactions you wish to use.
The bot will counter react to the reactions when it creates the binding in auth.
Goto Admin > Discord Bot > Reaction Role Bindings
Assign the groups you want for each reaction
time
command to have all timezones configured in auth.where_is
to allow users to find assets quicklylocate
to find all characters and show location and shipsroute
to show a route with known JB'sWith the WelcomeGoodbye Cog activated, Discordbot will grab a random message from the Welcome or Goodbye Message Model and send it to the Guild System channel
These can be configured in admin under /admin/aadiscordbot/welcomemessage/
and /admin/aadiscordbot/goodbyemessage/
The messages support some string formatting
Welcome {user_mention} to {guild_name}, I hope you enjoy your stay.
You can Authenticate for more access {auth_url}
With the aadiscordbot.cogs.tickets
Cog activated, users will be able to issue the /help
command to pick a group to get help from.
The groups available for selection are configurable in the site admin under
Discord Bot > Ticket Cog Configuration
You also need to choose a channel to create the threads in from the site admin Discord Bot > Ticket Cog Configuration
:
/help
command must have View and Send Message permissions on this channel otherwise they will not be able to see the tickets authbot creates for themWhen using authbot from your application, best practive is to use the provided helper functions for fetching users or checcking permisions to ensure compatability with new versions of the bot, Alliance Auth and potential 3rd party service modules like discord-multiverse
from aadiscordbot.utils.auth import is_user_bot_admin, is_user_authenticated, get_discord_user_id, get_auth_user
# etc
More details can be found here
You can use the send_message helper to send a message with text/embed to:
from django.contrib.auth.models import User
from django.apps import apps
## Use a small helper to check if AA-Discordbot is installs
def discord_bot_active():
return apps.is_installed('aadiscordbot')
## Only import it, if it is installed
if discord_bot_active():
from aadiscordbot.tasks import send_message
# if you want to send discord embed import them too.
from discord import Embed, Color
## this helper can be called to Queue up a Message
## AA Should not act on these, only AA-DiscordBot will consume them
if discord_bot_active():
usr = User.objects.get(pk=1)
# discord ID of user
msg = "Channel ID Tests"
e = Embed(title="Channel ID Tests!",
description="This is a Test Embed.\n\n```Discord Channel ID```",
color=Color.yellow())
e.add_field(name="Test Field 1", value="Value of some kind goes here")
send_message(channel_id=639252062818926642, embed=e) # Embed
send_message(channel_id=639252062818926642, message=msg) # Message
send_message(channel_id=639252062818926642, message=msg, embed=e) # Both
# Discord ID of channel
msg = "User ID Tests"
e = Embed(title="User ID Tests!",
description="This is a Test Embed.\n\n```Discord User ID```",
color=Color.nitro_pink())
e.add_field(name="Test Field 1", value="Value of some kind goes here")
send_message(user_id=318309023478972417, embed=e) # Embed
send_message(user_id=318309023478972417, message=msg) # Message
send_message(user_id=318309023478972417, message=msg, embed=e) # Both
# User model
msg = "Auth User Model Tests"
e = Embed(title="Auth User Model Tests!",
description="This is a Test Embed.\n\n```Auth User Model```",
color=Color.dark_orange())
e.add_field(name="Test Field 1", value="Value of some kind goes here")
send_message(user=usr, embed=e) # Embed
send_message(user=usr, message=msg) # Message
send_message(user=usr, message=msg, embed=e) # Both
# User PK id
msg = "Auth User PK Tests"
e = Embed(title="Auth User PK Tests!",
description="This is a Test Embed.\n\n```Auth User PK```",
color=Color.brand_green())
e.add_field(name="Test Field 1", value="Value of some kind goes here")
send_message(user_pk=1, embed=e) # Embed
send_message(user_pk=1, message=msg) # Message
send_message(user_pk=1, message=msg, embed=e) # Both
# Mixture of all of the above
msg = "All Together Tests"
e = Embed(title="All Together Tests!",
description="This is a Test Embed.\n\n```All Together```",
color=Color.blurple())
e.add_field(name="Test Field 1", value="Value of some kind goes here")
send_message(channel_id=639252062818926642,
user_id=318309023478972417,
user=User.objects.get(pk=1),
message=msg,
embed=e)
In auth_hooks.py
, define a function that returns an array of cog modules, and register it as a discord_cogs_hook
:
@hooks.register('discord_cogs_hook')
def register_cogs():
return ["yourapp.cogs.cog_a", "yourapp.cogs.cog_b"]
Create your async task, the function must have a bot instance as its first arg, otherwise you are fine to use any args/kwargs
Basic example task and how to run it
# file > aadiscordbot.tests.task_test.py
async def send_configuration_to_log(bot, message, commands=False):
logger.error(f"{bot.user} {message} - (commands: {commands})")
logger.error(f"Guilds: {len(bot.guilds)}")
logger.error(f"Users: {len(bot.users)}")
Call the your task by using the shim task. Source and the bot side async context shown here
from aadiscordbot.tasks import run_task_function
run_task_function.delay(
"aadiscordbot.tests.task_tests.send_configuration_to_log",
["TESTING a custom function!"],
{"commands":True}
)
you will need to manage your own error handling. but TLDR these run just like any other celery task. you can also use apply_async
and countdown
to delay the running of the task.
AUTHBOT_DISCORD_APP_ID = 'App ID for dedicated bot'
AUTHBOT_DISCORD_BOT_TOKEN = 'Token for dedicated bot'
Please remember to report any aa-discordbot related issues using the issues on this repository.
Problem:
Something has gone funny with my venv after i installed another app that wanted discord.py
Reason:
This is due to the Py-cord lib sharing the discord
namespace. Py-Cord is however a drop in replacement. So no issues should arise from using it over the now legacy discord.py lib. YMMV
Fix:
discord.py
by running pip uninstall discord.py
with your venv active.py-cord
by running pip install -U py-cord==2.0.0b3
with your venv active.FAQs
Alliance Auth Modular Discord Bot
We found that allianceauth-discordbot demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.