Skip to main content

Alliance Auth Discord Bot

Project description

AA-Discordbot

AA-Discordbot for Alliance Auth.

PyPi

Features

  • Bot Framework, easily extensible with more Cogs
  • Integration with Alliance Auth, able to fetch data directly from its django project.
  • Channel/Direct messaging feature, with Tasks and a Queue/Consumer
  • Current Cogs
    • About
      • !about - Bot Information and Statistics
      • !uptime - Shows the uptime of the bot
      • !get_webhooks - Get or create a webhook for the current channel and DM it to the requestor
      • !new_channel [category id] [channel name] - Create a new channel and close it to public access
      • !add_role [channel name] [role name] - Add a role to a channel
      • !rem_role [channel name] [role name] - Remove a role from a channel
    • Auth
      • !auth - A direct link to the Auth Install to catch users familiar with other bots.
      • !orphans - Returns a list of users on this server without a matched AA account.
    • !timers - The next upcoming timer
    • Members
      • !lookup - Fetch a users Main, Affiliation, State, Groups and linked characters from any character.
      • !altcorp [search string] - search for users with characters in an altcorp
    • Remind
      • !remindme [5s/m/h/d text] - Sets a simple non-persistent reminder timer when the bot will respond with the text
    • Sov
      • !vuln [context] - Returns a list of Vulnerable sov structures for a Region/Constellation/Solar_System or alliance
      • !sov [context] - Returns a list of all sov structures for a Region/Constellation/Solar_System or alliance
      • !lowadm - Lists sov in need of ADM-ing, context provided in settings.
    • Time
      • !time - Returns the current EVE Time.
    • Timers
      • !timer - Returns the next Structure timer from allianceauth.timerboard.
    • PriceCheck:
      • amarr - Check an item price on Amarr market
      • jita - Check an item price on Jita market
      • price - Check an item price on Jita and Amarr market
    • Easter Eggs,
      • !happybirthday [text] - Wishes the text a happy birthday, works with user mentions

Installation

  • Update your Discord Developer Application to include the Privileged Intents that we call. Please add Server Members and Presence (for future development).

screenshot

  • Install the app with your venv active
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
DISCORD_BOT_ADMIN_USER = [140706470856622080] #This UserID is allowed to run any command
# 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
## Insert AADiscorcbot'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'}
  • Optional Settings
# configure the bots cogs.
DISCORD_BOT_COGS =[ "aadiscordbot.cogs.about",
                   "aadiscordbot.cogs.members",
                   "aadiscordbot.cogs.timers",
                   "aadiscordbot.cogs.auth",
                   "aadiscordbot.cogs.sov",
                   "aadiscordbot.cogs.time",
                   "aadiscordbot.cogs.eastereggs",
                   "aadiscordbot.cogs.remind",
                   "aadiscordbot.cogs.price_check",]
  • Add the below lines to 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'}}
  • Run migrations python manage.py migrate (There should be none from this app)

  • Gather your staticfiles python manage.py collectstatic (There should be none from this app)

  • Fetch bot_conf.py from the Git Repo into the root of your AA install, beside manage.py

wget https://raw.githubusercontent.com/pvyParts/allianceauth-discordbot/master/bot_conf.py
  • Amend your supervisor.conf, correcting paths as required and add authbot to the launch group at the end of the conf
[program:authbot]
command=/home/allianceserver/venv/auth/bin/python /home/allianceserver/myauth/bot_conf.py
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

Settings

Setting Default Description
DISCORD_BOT_PREFIX "!" Prefix for all Discord commands
DISCORD_BOT_COGS refer to app_settings chonky list Loaded Base Cogs, other apps may load via hooks
DISCORD_BOT_ACCESS_DENIED_REACT 0x1F44E Reacts when permissions are denied, exadecimal unicode emoji, default is a thumbs down
DISCORD_BOT_ADMIN_USER [] List of Discord IDs, these users can run any command as well as admin things
ADMIN_DISCORD_BOT_CHANNELS [] Admin commands can only be run in these channels
SOV_DISCORD_BOT_CHANNELS [] Sov commands can only be run in these channels
ADM_DISCORD_BOT_CHANNELS [] ADM commands can only be run in these channels
DISCORD_BOT_SOV_STRUCTURE_OWNER_IDS [] These sov structures are "owned" not hostile
DISCORD_BOT_MEMBER_ALLIANCES [] filters "mains" from alts
DISCORD_BOT_ADM_REGIONS [] Regions we care about ADM in
DISCORD_BOT_ADM_SYSTEMs [] Systems we care about ADM in
DISCORD_BOT_ADM_CONSTELLATIONS [] Constellations we care about ADM in

Integrations

  • Statistics
    • Adds zkill Monthly/Yearly stats to !lookup

Using AA-Discordbot from my project

Send Messages

aadiscordbot/tasks.py

## Use a small helper to check if AA-Discordbot is installs
def discord_bot_active():
    return 'aadiscordbot' in settings.INSTALLED_APPS

## Only import it, if it is installed
if discord_bot_active():
    import aadiscordbot.tasks

## These two tasks can be called to Queue up a Message
## AA Should not act on these, only AA-DiscordBot will consume them
if discord_bot_active():
    aadiscordbot.tasks.send_direct_message_by_user_id.delay(user_pk, message_content)
    aadiscordbot.tasks.send_direct_message_by_discord_id.delay(discord_user_id, message_content)
    aadiscordbot.tasks.send_channel_message_by_discord_id.delay(channel_id, message_content, embed=False)

Register Cogs (Handling Commands)

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"]

Issues

Please remember to report any aa-discordbot related issues using the issues on this repository.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

allianceauth-discordbot-0.5.1.tar.gz (23.4 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page