Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Check auth role members instead of config, store Discord ID, Albion I…
…D, and name

Co-authored-by: psykzz <1134201+psykzz@users.noreply.github.com>
  • Loading branch information
Copilot and psykzz committed Nov 18, 2025
commit 86b0b6c79f305af7b6a4ec32b6030908b9c15ea3
17 changes: 13 additions & 4 deletions albion_auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,14 @@ This will immediately verify if the user's Discord nickname matches their Albion
## How Daily Verification Works

1. **Background Task**: A background task runs every hour
2. **24-Hour Interval**: Users are checked approximately once every 24 hours
3. **Staggered Checks**: Users are checked in batches to avoid rate limiting
4. **Mismatch Detection**: The bot compares the user's Discord nickname with their current Albion Online name
5. **Report Generation**: If mismatches are found, a detailed report is sent to the bot owner via DM
2. **Role-Based Discovery**: The bot checks all members with the configured auth role
3. **Auto-Registration**: Users with the auth role who aren't in the verified users list are automatically added
4. **24-Hour Interval**: Users are checked approximately once every 24 hours
5. **Staggered Checks**: Users are checked in batches to avoid rate limiting
6. **Mismatch Detection**: The bot compares the user's Discord nickname with their current Albion Online name
7. **Report Generation**: If mismatches are found, a detailed report is sent to the bot owner via DM

**Note**: The bot will automatically discover and track users who were verified before this feature was added, as long as they have the configured auth role.

### Mismatch Scenarios

Expand Down Expand Up @@ -132,6 +136,8 @@ Configure a role to be automatically assigned when users authenticate:
The cog stores the following data per guild using Red's Config system:
- `auth_role`: Role ID to assign upon authentication (optional)
- `verified_users`: Dictionary mapping user IDs to their verification data:
- `discord_id`: The Discord user ID
- `albion_id`: The Albion Online player ID
- `name`: The Albion Online character name
- `last_checked`: Timestamp of the last verification check
- `enable_daily_check`: Boolean flag to enable/disable daily verification
Expand All @@ -148,7 +154,10 @@ The cog uses the Albion Online official game info API:
The background task:
- Starts when the cog is loaded (`cog_load`)
- Runs every hour
- Discovers all guild members with the configured auth role
- Automatically adds any missing users to the verified users list
- Checks users that haven't been verified in the last 24 hours
- Queries the Albion API to verify current character names
- Cancels gracefully when the cog is unloaded (`cog_unload`)

## Support
Expand Down
57 changes: 50 additions & 7 deletions albion_auth/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def __init__(self, bot):
self.config = Config.get_conf(self, identifier=73601, force_registration=True)
self.config.register_guild(
auth_role=None,
verified_users={}, # {user_id: {"name": str, "last_checked": timestamp}}
# {user_id: {"discord_id": int, "albion_id": str, "name": str, "last_checked": timestamp}}
verified_users={},
enable_daily_check=True
)
self._check_task = None
Expand Down Expand Up @@ -106,17 +107,57 @@ async def _check_users_batch(self):
log.debug(f"Daily check disabled for guild {guild.name}")
continue

verified_users = await self.config.guild(guild).verified_users()
if not verified_users:
log.debug(f"No verified users in guild {guild.name}")
# Get the auth role
auth_role_id = await self.config.guild(guild).auth_role()
if not auth_role_id:
log.debug(f"No auth role configured for guild {guild.name}")
continue

auth_role = guild.get_role(auth_role_id)
if not auth_role:
log.warning(f"Configured auth role ID {auth_role_id} not found in guild {guild.name}")
continue

# Get users that need checking (haven't been checked in 24 hours)
# Get all members with the auth role
members_with_role = [member for member in guild.members if auth_role in member.roles]
if not members_with_role:
log.debug(f"No members with auth role in guild {guild.name}")
continue

verified_users = await self.config.guild(guild).verified_users()
now = datetime.now(timezone.utc).timestamp()
users_to_check = []

for user_id_str, user_data in verified_users.items():
# Build list of users to check, adding missing ones to config
for member in members_with_role:
user_id_str = str(member.id)

# If user not in verified_users, add them with their current nickname
if user_id_str not in verified_users:
log.info(
f"Adding previously verified user {member} to config "
f"with nickname {member.display_name}"
)
# Search for the player to get their Albion ID
player = await self.search_player(member.display_name)
albion_id = player.get("Id") if player else None
albion_name = player.get("Name") if player else member.display_name

async with self.config.guild(guild).verified_users() as verified_users_dict:
verified_users_dict[user_id_str] = {
"discord_id": member.id,
"albion_id": albion_id,
"name": albion_name,
"last_checked": 0 # Set to 0 to ensure they get checked
}
# Refresh verified_users after update
verified_users = await self.config.guild(guild).verified_users()
# Small delay to avoid rate limiting when adding users
await asyncio.sleep(2)

user_data = verified_users[user_id_str]
last_checked = user_data.get("last_checked", 0)

# Check if it's been at least 24 hours
if now - last_checked >= 86400: # 24 hours in seconds
users_to_check.append((user_id_str, user_data))
Expand Down Expand Up @@ -302,10 +343,12 @@ async def auth(self, ctx, name: str):
# Store verified user information
async with self.config.guild(ctx.guild).verified_users() as verified_users:
verified_users[str(ctx.author.id)] = {
"discord_id": ctx.author.id,
"albion_id": player_id,
"name": player_name,
"last_checked": datetime.now(timezone.utc).timestamp()
}
log.info(f"Stored verified user: {ctx.author.id} -> {player_name}")
log.info(f"Stored verified user: {ctx.author.id} -> {player_name} (Albion ID: {player_id})")

success_msg = (
f"✅ Successfully authenticated! "
Expand Down