Skip to content

Commit

Permalink
Merge pull request #38 from soratidus999/master
Browse files Browse the repository at this point in the history
0.5.0
  • Loading branch information
soratidus999 authored Jul 9, 2021
2 parents f84424d + 10e055d commit 34f5fa4
Show file tree
Hide file tree
Showing 15 changed files with 273 additions and 74 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@ DISCORD_BOT_ADM_REGIONS = [10000002] # The Forge Example
DISCORD_BOT_ADM_SYSTEMS = [30000142] # Jita Example
DISCORD_BOT_ADM_CONSTELLATIONS = [20000020] # Kimitoro Example
```

```python
## 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
```python
# configure the bots cogs.
Expand Down
2 changes: 1 addition & 1 deletion aadiscordbot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default_app_config = 'aadiscordbot.apps.AADiscordBotConfig'

__version__ = '0.4.0'
__version__ = '0.5.0'
__title__ = "AA Discordbot"
__branch__ = 'Stable'
31 changes: 24 additions & 7 deletions aadiscordbot/app_settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from inspect import getgeneratorlocals
from django.conf import settings
from django.apps import apps
import re
Expand Down Expand Up @@ -26,14 +27,15 @@ def timerboard_active():
return apps.is_installed("allianceauth.timerboard")


def get_admins():
admin = getattr(settings, 'DISCORD_BOT_ADMIN_USER', [])
if isinstance(admin, int):
return [admin]
else:
return admin
def mumble_active():
return 'allianceauth.services.modules.mumble' in settings.INSTALLED_APPS

DISCORD_BOT_COGS = getattr(settings, 'DISCORD_BOT_COGS',[ "aadiscordbot.cogs.about",

def discord_active():
return 'allianceauth.services.modules.discord' in settings.INSTALLED_APPS


DISCORD_BOT_COGS = getattr(settings, 'DISCORD_BOT_COGS', ["aadiscordbot.cogs.about",
"aadiscordbot.cogs.members",
"aadiscordbot.cogs.timers",
"aadiscordbot.cogs.auth",
Expand All @@ -42,3 +44,18 @@ def get_admins():
"aadiscordbot.cogs.eastereggs",
"aadiscordbot.cogs.remind",
"aadiscordbot.cogs.price_check",])

DISCORD_BOT_ACCESS_DENIED_REACT = getattr(settings, 'DISCORD_BOT_ACCESS_DENIED_REACT', 0x1F44E )

DISCORD_BOT_ADMIN_USER = getattr(settings, 'DISCORD_BOT_ADMIN_USER', [])

ADMIN_DISCORD_BOT_CHANNELS = getattr(settings, 'ADMIN_DISCORD_BOT_CHANNELS', [])
SOV_DISCORD_BOT_CHANNELS = getattr(settings, 'SOV_DISCORD_BOT_CHANNELS', [])
ADM_DISCORD_BOT_CHANNELS = getattr(settings, 'ADM_DISCORD_BOT_CHANNELS', [])

DISCORD_BOT_SOV_STRUCTURE_OWNER_IDS = getattr(settings, 'DISCORD_BOT_SOV_STRUCTURE_OWNER_IDS', [])
DISCORD_BOT_MEMBER_ALLIANCES = getattr(settings, 'DISCORD_BOT_MEMBER_ALLIANCES', [])
DISCORD_BOT_ADM_REGIONS = getattr(settings, 'DISCORD_BOT_ADM_REGIONS', [])
DISCORD_BOT_ADM_SYSTEMS = getattr(settings, 'DISCORD_BOT_ADM_SYSTEMS', [])
DISCORD_BOT_ADM_CONSTELLATIONS = getattr(settings, 'DISCORD_BOT_ADM_CONSTELLATIONS', [])

6 changes: 4 additions & 2 deletions aadiscordbot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import json

from .cogs.utils import context
from . import bot_tasks, app_settings
from . import bot_tasks
from aadiscordbot.app_settings import DISCORD_BOT_ACCESS_DENIED_REACT

import discord
from discord.ext import commands, tasks
Expand Down Expand Up @@ -185,7 +186,8 @@ async def on_command_error(self, ctx, error):
"Sorry, I don't have the required permissions to do that here:\n{0}".format(error.missing_perms)
)
elif isinstance(error, commands.MissingPermissions):
await ctx.send("Sorry, you do not have permission to do that here.")
await ctx.message.add_reaction(chr(DISCORD_BOT_ACCESS_DENIED_REACT))
await ctx.message.reply("Sorry, you do not have permission to do that here.")
elif isinstance(error, commands.NotOwner):
print(error)
await ctx.send(error)
Expand Down
28 changes: 8 additions & 20 deletions aadiscordbot/cogs/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
from discord.utils import get
# AA Contexts
from django.conf import settings
from aadiscordbot.cogs.utils.decorators import sender_is_admin
from aadiscordbot import app_settings, __version__, __branch__

import pendulum
import re

import logging
import traceback
logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -43,7 +43,7 @@ async def about(self, ctx):

for m in matches:
url = m.groups()
embed.set_footer(text="Lovingly developed for Init.™ by AaronKable")
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
Expand All @@ -63,27 +63,23 @@ async def about(self, ctx):
return await ctx.send(embed=embed)

@commands.command(hidden=True)
@sender_is_admin()
async def uptime(self, ctx):
"""
Returns the uptime
"""
if ctx.message.author.id not in app_settings.get_admins(): # https://media1.tenor.com/images/1796f0fa0b4b07e51687fad26a2ce735/tenor.gif
return await ctx.message.add_reaction(chr(0x1F44E))

await ctx.send(
pendulum.now(tz="UTC").diff_for_humans(
self.bot.currentuptime, absolute=True
)
)

@commands.command(hidden=True)
@sender_is_admin()
async def get_webhooks(self, ctx):
"""
Returns the webhooks for the channel
"""
if ctx.message.author.id not in app_settings.get_admins(): # https://media1.tenor.com/images/1796f0fa0b4b07e51687fad26a2ce735/tenor.gif
return await ctx.message.add_reaction(chr(0x1F44E))

hooks = await ctx.message.channel.webhooks()
if len(hooks) == 0:
name = "{}_webhook".format(ctx.message.channel.name.replace(" ", "_"))
Expand All @@ -105,13 +101,11 @@ async def get_webhooks(self, ctx):
return await ctx.message.delete()

@commands.command(hidden=True)
@sender_is_admin()
async def new_channel(self, ctx):
"""
create a new channel in a category.
"""
if ctx.message.author.id not in app_settings.get_admins(): # https://media1.tenor.com/images/1796f0fa0b4b07e51687fad26a2ce735/tenor.gif
return await ctx.message.add_reaction(chr(0x1F44E))

await ctx.message.channel.trigger_typing()

input_string = ctx.message.content[13:].split(' ')
Expand All @@ -138,13 +132,11 @@ async def new_channel(self, ctx):
return await ctx.message.add_reaction(chr(0x1F44D))

@commands.command(hidden=True)
@sender_is_admin()
async def add_role(self, ctx):
"""
add a role from a channel.
"""
if ctx.message.author.id not in app_settings.get_admins(): # https://media1.tenor.com/images/1796f0fa0b4b07e51687fad26a2ce735/tenor.gif
return await ctx.message.add_reaction(chr(0x1F44E))

await ctx.message.channel.trigger_typing()

input_string = ctx.message.content[10:].split(' ')
Expand All @@ -161,13 +153,11 @@ async def add_role(self, ctx):
return await ctx.message.add_reaction(chr(0x1F44D))

@commands.command(hidden=True)
@sender_is_admin()
async def rem_role(self, ctx):
"""
remove a role from a channel.
"""
if ctx.message.author.id not in app_settings.get_admins(): # https://media1.tenor.com/images/1796f0fa0b4b07e51687fad26a2ce735/tenor.gif
return await ctx.message.add_reaction(chr(0x1F44E))

await ctx.message.channel.trigger_typing()

input_string = ctx.message.content[10:].split(' ')
Expand All @@ -185,13 +175,11 @@ async def rem_role(self, ctx):


@commands.command(hidden=True)
@sender_is_admin()
async def list_role(self, ctx):
"""
list roles from a channel.
"""
if ctx.message.author.id not in app_settings.get_admins(): # https://media1.tenor.com/images/1796f0fa0b4b07e51687fad26a2ce735/tenor.gif
return await ctx.message.add_reaction(chr(0x1F44E))

await ctx.message.channel.trigger_typing()

input_string = ctx.message.content[11:]
Expand Down
22 changes: 13 additions & 9 deletions aadiscordbot/cogs/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
from discord.ext import commands
from discord.embeds import Embed
from discord.colour import Color
from ..app_settings import mumble_active, discord_active
# AA Contexts
from aadiscordbot.app_settings import get_site_url, get_admins
from aadiscordbot.app_settings import get_site_url, DISCORD_BOT_ADMIN_USER
from aadiscordbot.cogs.utils.decorators import sender_is_admin
from allianceauth.services.modules.discord.models import DiscordUser
from django.contrib.auth.models import User

import re
import logging
import pendulum
import traceback
logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -46,13 +46,11 @@ async def auth(self, ctx):
return await ctx.send(embed=embed)

@commands.command(pass_context=True)
@sender_is_admin()
async def orphans(self, ctx):
"""
Returns a list of users on this server, who are not known to AA
"""
if ctx.message.author.id not in get_admins(): # https://media1.tenor.com/images/1796f0fa0b4b07e51687fad26a2ce735/tenor.gif
return await ctx.message.add_reaction(chr(0x1F44E))

await ctx.trigger_typing()
await ctx.send('Searching for Orphaned Discord Users')
await ctx.trigger_typing()
Expand Down Expand Up @@ -86,14 +84,20 @@ async def orphans(self, ctx):
# lets also ignore bots here
pass
else:
# Dump the payload if it gets too big
if len(payload) > 1000:
try:
await ctx.send(payload)
payload = "The following Users cannot be located in Alliance Auth \n"
except Exception as e:
logger.error(e)
# keep building the payload
payload = payload + member.mention + "\n"

try:
await ctx.send(payload)
except Exception as e:
logger.error(e)
await ctx.send(payload[0:1999])
await ctx.send("Maximum Discord message length reached")


def setup(bot):
Expand Down
2 changes: 0 additions & 2 deletions aadiscordbot/cogs/eastereggs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import re

import logging
import pendulum
import traceback
logger = logging.getLogger(__name__)


Expand Down
11 changes: 3 additions & 8 deletions aadiscordbot/cogs/members.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
from allianceauth.eveonline.models import EveCharacter
from allianceauth.eveonline.evelinks import evewho
# AA-Discordbot
from aadiscordbot.cogs.utils.decorators import sender_has_perm
from aadiscordbot.cogs.utils.decorators import message_in_channels, sender_has_perm
from aadiscordbot.app_settings import aastatistics_active

import logging
import pendulum
import traceback
logger = logging.getLogger(__name__)


Expand All @@ -28,14 +26,12 @@ def __init__(self, bot):

@commands.command(pass_context=True)
@sender_has_perm('corputils.view_alliance_corpstats')
@message_in_channels(settings.ADMIN_DISCORD_BOT_CHANNELS)
async def lookup(self, ctx):
"""
Gets Auth data about a character
Input: a Eve Character Name
"""
if ctx.message.channel.id not in settings.ADMIN_DISCORD_BOT_CHANNELS:
return await ctx.message.add_reaction(chr(0x1F44E))

input_name = ctx.message.content[8:]

embed = Embed(
Expand Down Expand Up @@ -152,13 +148,12 @@ async def lookup(self, ctx):

@commands.command(pass_context=True)
@sender_has_perm('corputils.view_alliance_corpstats')
@message_in_channels(settings.ADMIN_DISCORD_BOT_CHANNELS)
async def altcorp(self, ctx):
"""
Gets Auth data about an altcorp
Input: a Eve Character Name
"""
if ctx.message.channel.id not in settings.ADMIN_DISCORD_BOT_CHANNELS:
return await ctx.message.add_reaction(chr(0x1F44E))

input_name = ctx.message.content[9:]
chars = EveCharacter.objects.filter(corporation_name=input_name)
Expand Down
2 changes: 1 addition & 1 deletion aadiscordbot/cogs/price_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Market Price Checks
"""

import logging
import requests

# Cog Stuff
Expand All @@ -11,6 +10,7 @@
from discord.colour import Color


import logging
logger = logging.getLogger(__name__)


Expand Down
2 changes: 0 additions & 2 deletions aadiscordbot/cogs/remind.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from datetime import datetime

import logging
import pendulum
import traceback
logger = logging.getLogger(__name__)


Expand Down
Loading

0 comments on commit 34f5fa4

Please sign in to comment.