This project contains an enhanced STFC player data scraper that extracts alliance rank information, and a full Discord bot for managing alliance ranks in your STFC server's Discord community.
- STFC Scraper (
stfc_scraper.py): Fetches player data from stfc.pro/stfc.wtf including rank - Rank-Based Discord Bot (
bot.py): Discord bot for verification and rank management
- ✅ Extracted player data from metadata tags only (title, description)
- ✅ Retrieved: player_id, username, level, alliance_tag, server
- ✅ Did NOT extract player rank (Agent, Operative, Premier, Commodore, Admiral)
- ✅ All original functionality preserved
- ✅ NEW: Extracts player rank from HTML body using regex pattern
- ✅ NEW: Handles players without alliance tags (makes alliance_tag optional)
- ✅ Rank field in PlayerData:
Optional[str]with possible values:Agent,Operative,Premier,Commodore,Admiral
# Before: alliance_tag required
player_id: str
username: str
level: int
alliance_tag: str # Always required
server: int
# After: alliance_tag optional, rank added
player_id: str
username: str
level: int
server: int
alliance_tag: Optional[str] = None # Optional (players can have no alliance)
rank: Optional[str] = None # NEW: Player rankAdded regex pattern to extract rank from HTML body:
rank_match = re.search(r'>(Agent|Operative|Premier|Commodore|Admiral)</span>', response.text)
rank = rank_match.group(1) if rank_match else NoneUpdated to gracefully handle players without an alliance:
- First tries:
"of [ALLIANCE], server X"pattern - Falls back to:
", server X"pattern (no alliance) - Returns
alliance_tag = Noneif not present
from stfc_scraper import STFCProScraper
# Fetch player data
result = STFCProScraper.fetch_player_data("2659122580")
# Result includes rank
print(result)
# Output: PlayerData(id=2659122580, name=DarthHαywire, level=77, server=118, alliance=[SITH], rank=Commodore)- ID:
2659122580(DarthHαywire) - Result:
rank=Commodore,alliance=[SITH]
- ID:
1689521808(CmdrRetiredByeBye) - Result:
rank=Agent,alliance=None
- Python 3.x
- Virtual environment:
venv/(pre-configured) - Dependencies:
requests,beautifulsoup4,discord.py,python-dotenv
cd /home/ubuntu/rank-fetch
source venv/bin/activate
pip install -r requirements.txt- Player Verification: Users submit their STFC player URL/ID with a screenshot
- Rank Management: Automatically assigns Discord roles based on alliance rank:
- Agent/Operative/Premier → Base role (assigned immediately)
- Commodore → Commodore role (requires admin confirmation)
- Admiral → Admiral role (requires admin confirmation)
- Nickname Management: Sets user nickname to
[TAG] usernameformat - Server Validation: Verifies player is on the correct STFC server
- Rank Change Detection: Daily updates detect rank changes and request admin confirmation for any change (promotion or demotion)
- Admin Confirmation UI: Interactive buttons for admins to accept/reject rank changes
- Screenshot Logging: Stores verification screenshots in log channel for record-keeping
-
Copy
.env.exampleto.env:cp .env.example .env
-
Fill in the required values:
DISCORD_TOKEN: Your Discord bot tokenGUILD_ID: Your Discord server IDSTFC_SERVER_ID: The STFC server ID to verify against (e.g., 118)- Role IDs:
MEMBER_ROLE_ID,COMMODORE_ROLE_ID,ADMIRAL_ROLE_ID,ADMIN_ROLE_ID - Channel IDs:
VERIFY_CHANNEL_ID,LOG_CHANNEL_ID
cd /home/ubuntu/rank-fetch
source venv/bin/activate
python3 bot.py- /verify - Verify your STFC player account
- Requires: Player URL/ID (e.g.,
https://stfc.pro/players/2659122580) - Requires: Screenshot of your player profile
- Returns: Confirmation of verification and nickname update
- Requires: Player URL/ID (e.g.,
- User runs
/verifywith their player URL and screenshot - Bot fetches data and verifies server ID matches
- Nickname is set to
[TAG] username - Base role is assigned immediately (for Agent/Operative/Premier)
- For Commodore/Admiral, bot posts confirmation request to log channel
- Admin accepts/rejects via buttons
- Bot checks all verified players every 24 hours (configurable)
- If rank changes detected, bot posts confirmation request
- ANY rank change (promotion or demotion) requires confirmation
- Admin accepts/rejects, roles are updated accordingly
- Agent → Base tier
- Operative → Base tier
- Premier → Base tier
- Commodore → Leadership tier (requires confirmation)
- Admiral → Leadership tier (requires confirmation)
Player data is stored in SQLite database (stfc_players.db by default):
- Discord user ID
- STFC player ID and username
- Server ID, level, alliance tag, rank
- Screenshot URL for verification record