Skip to content

Commit a0dde43

Browse files
Refactor debug_team_match command to improve participant matching logic; enhance feedback on unmatched users and API participants
1 parent 0bf974b commit a0dde43

File tree

1 file changed

+41
-38
lines changed

1 file changed

+41
-38
lines changed

cogs/teams_cog.py

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -184,32 +184,31 @@ async def debug_team_match(self, interaction: discord.Interaction):
184184
await interaction.followup.send("No users with Matcherino usernames found in database.", ephemeral=True)
185185
return
186186

187-
# Get all team members from Matcherino API
187+
# Get participants from Matcherino
188188
from matcherino_scraper import MatcherinoScraper
189189
async with MatcherinoScraper() as scraper:
190+
# First get team data
190191
teams_data = await scraper.get_teams_data(self.bot.TOURNAMENT_ID)
191192

192-
if not teams_data:
193-
await interaction.followup.send("No teams found in the Matcherino tournament.", ephemeral=True)
193+
# Then get participant data
194+
participants = await scraper.get_tournament_participants(self.bot.TOURNAMENT_ID)
195+
196+
if not teams_data and not participants:
197+
await interaction.followup.send("No teams or participants found in the Matcherino tournament.", ephemeral=True)
194198
return
195-
196-
# Extract all unique member names from all teams
197-
api_members = set()
198-
for team in teams_data:
199-
for member in team.get('members', []):
200-
api_members.add(member)
201-
202-
# Compare registered usernames with API member names
203-
matched_users = []
204-
unmatched_users = []
205-
206-
for user in db_users:
207-
matcherino_username = user.get('matcherino_username', '')
208-
if matcherino_username in api_members:
209-
matched_users.append(user)
210-
else:
211-
unmatched_users.append(user)
212-
199+
200+
# Get the Matcherino cog to use its matching function
201+
matcherino_cog = self.bot.get_cog("MatcherinoCog")
202+
if not matcherino_cog:
203+
await interaction.followup.send("MatcherinoCog not found.", ephemeral=True)
204+
return
205+
206+
# Use the same matching logic as match-free-agents
207+
(exact_matches, name_only_matches, ambiguous_matches,
208+
unmatched_participants, unmatched_db_users) = await matcherino_cog.match_participants_with_db_users(
209+
participants, db_users
210+
)
211+
213212
# Create embed with debugging information
214213
embed = discord.Embed(
215214
title="Team Matching Debug Info",
@@ -218,20 +217,24 @@ async def debug_team_match(self, interaction: discord.Interaction):
218217
)
219218

220219
# Add summary stats
220+
matched_users = exact_matches + name_only_matches
221221
embed.add_field(
222222
name="Summary",
223223
value=f"• **{len(db_users)}** users with Matcherino usernames in database\n"
224-
f"• **{len(api_members)}** team members from API\n"
225-
f"• **{len(matched_users)}** users with matching usernames\n"
226-
f"• **{len(unmatched_users)}** users with non-matching usernames",
224+
f"• **{len(participants)}** participants from API\n"
225+
f"• **{len(exact_matches)}** exact matches (with tag)\n"
226+
f"• **{len(name_only_matches)}** name-only matches (without tag)\n"
227+
f"• **{len(ambiguous_matches)}** ambiguous matches\n"
228+
f"• **{len(unmatched_participants)}** unmatched participants\n"
229+
f"• **{len(unmatched_db_users)}** unmatched database users",
227230
inline=False
228231
)
229232

230233
# Add matched users (limited to avoid embed limits)
231234
if matched_users:
232235
matched_text = "\n".join([
233-
f"• Discord: **{u['username']}** → Matcherino: `{u['matcherino_username']}`"
234-
for u in matched_users[:10]
236+
f"• Discord: **{m['discord_username']}** → Matcherino: `{m['participant']}`"
237+
for m in (exact_matches + name_only_matches)[:10]
235238
])
236239
if len(matched_users) > 10:
237240
matched_text += f"\n... and {len(matched_users) - 10} more"
@@ -243,28 +246,28 @@ async def debug_team_match(self, interaction: discord.Interaction):
243246
)
244247

245248
# Add unmatched users (limited to avoid embed limits)
246-
if unmatched_users:
249+
if unmatched_db_users:
247250
unmatched_text = "\n".join([
248-
f"• Discord: **{u['username']}** → Matcherino: `{u['matcherino_username']}`"
249-
for u in unmatched_users[:10]
251+
f"• Discord: **{u['discord_username']}** → Matcherino: `{u['matcherino_username']}`"
252+
for u in unmatched_db_users[:10]
250253
])
251-
if len(unmatched_users) > 10:
252-
unmatched_text += f"\n... and {len(unmatched_users) - 10} more"
254+
if len(unmatched_db_users) > 10:
255+
unmatched_text += f"\n... and {len(unmatched_db_users) - 10} more"
253256

254257
embed.add_field(
255-
name=f"Unmatched Users ({len(unmatched_users)})",
258+
name=f"Unmatched Users ({len(unmatched_db_users)})",
256259
value=unmatched_text,
257260
inline=False
258261
)
259262

260-
# Add API member names (limited to avoid embed limits)
261-
if api_members:
262-
api_text = "\n".join([f"• `{member}`" for member in list(api_members)[:15]])
263-
if len(api_members) > 15:
264-
api_text += f"\n... and {len(api_members) - 15} more"
263+
# Add API participant names (limited to avoid embed limits)
264+
if unmatched_participants:
265+
api_text = "\n".join([f"• `{p['name']}`" for p in unmatched_participants[:15]])
266+
if len(unmatched_participants) > 15:
267+
api_text += f"\n... and {len(unmatched_participants) - 15} more"
265268

266269
embed.add_field(
267-
name=f"API Member Names ({len(api_members)})",
270+
name=f"Unmatched Participants ({len(unmatched_participants)})",
268271
value=api_text,
269272
inline=False
270273
)

0 commit comments

Comments
 (0)