Skip to content

Commit

Permalink
Fixes for auth.utils and readme updates
Browse files Browse the repository at this point in the history
  • Loading branch information
pvyParts committed May 25, 2024
1 parent 57e5740 commit d013f4a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ wget https://raw.githubusercontent.com/pvyParts/allianceauth-discordbot/master/b

## Running Discordbot with Docker

Update base image to have bot_conf.py mapped
* To download the `bot_conf.py` file into your `conf/` folder, run the following from your aa-docker folder
```bash
wget https://raw.githubusercontent.com/pvyParts/allianceauth-discordbot/master/bot_conf.py -O conf/bot_conf.py
```
* Update base image to have bot_conf.py mapped

```dockerfile
x-allianceauth-base:
Expand Down
6 changes: 0 additions & 6 deletions aadiscordbot/cogs/utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,6 @@ 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:
Expand Down
32 changes: 18 additions & 14 deletions aadiscordbot/utils/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@

logger = logging.getLogger(__name__)


DMV_ACTIVE = dmv_active()
DISCORD_ACTIVE = discord_active()
try:
if discord_active():
if DISCORD_ACTIVE:
# this needs to be imported safely incase only DMV installed
from allianceauth.services.modules.discord.models import DiscordUser
except ImportError:
logger.debug("Discord not installed?")


try:
if dmv_active():
if DMV_ACTIVE:
# this needs to be imported safely incase only Core service installed
from aadiscordmultiverse.models import (
DiscordManagedServer, MultiDiscordUser,
Expand All @@ -40,7 +41,7 @@


def _get_dmv_discord_user(user_id, guild_id):
if dmv_active():
if DMV_ACTIVE:
try:
return MultiDiscordUser.objects.get(
guild_id=guild_id,
Expand All @@ -65,9 +66,12 @@ def _check_for_dmv_user(user: User, guild: Guild):


def _get_core_discord_user(user_id):
try:
return DiscordUser.objects.get(uid=user_id)
except DiscordUser.DoesNotExist:
if DISCORD_ACTIVE:
try:
return DiscordUser.objects.get(uid=user_id)
except DiscordUser.DoesNotExist:
return None
else:
return None


Expand All @@ -89,11 +93,9 @@ def _guild_is_core_module(guild_id):
"""
# 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)) and discord_active()
)
)
gid = int(getattr(settings, "DISCORD_GUILD_ID", -1))

return guild_id == gid and DISCORD_ACTIVE


def _guild_is_dmv_module(guild_id):
Expand All @@ -111,7 +113,7 @@ def _get_dmv_guild(guild_id):
"""
Return DMV Guild model if DMV installed and
"""
if dmv_active():
if DMV_ACTIVE:
try:
return DiscordManagedServer.objects.get(
guild_id=guild_id,
Expand All @@ -133,7 +135,9 @@ def is_user_bot_admin(user: User):


def is_guild_managed(guild: Guild):
return _guild_is_core_module(guild.id) or _guild_is_dmv_module(guild.id)
core = _guild_is_core_module(guild.id)
dmv = _guild_is_dmv_module(guild.id)
return core or dmv


def user_is_authenticated(user: User, guild: Guild):
Expand Down

0 comments on commit d013f4a

Please sign in to comment.