@@ -22,41 +22,48 @@ public partial class SteamCommand
2222 [ SlashCommand ( "sync" , "WARNING! This command overrides all current roles and grants roles based off owned games" ) ]
2323 public async Task Sync ( )
2424 {
25- SteamLink ? existingLink = await _database . FetchOneAsync < SteamLink > ( x => x . UserId == Context . User . Id ) ;
26- if ( existingLink is null )
25+ try
2726 {
28- await RespondAsync ( "No steam link found." ) ;
29- return ;
30- }
27+ SteamLink ? existingLink = await _database . FetchOneAsync < SteamLink > ( x => x . UserId == Context . User . Id ) ;
28+ if ( existingLink is null )
29+ {
30+ await RespondAsync ( "No steam link found." ) ;
31+ return ;
32+ }
3133
32- var ownedGames = await _steamLinkService . GetOwnedGamesAsync ( existingLink ) ;
33- if ( ownedGames is null )
34- {
35- ownedGames = existingLink . KnownGames ;
36- Log . Warn ( "Using cached owned games to sync due to GetOwnedGamesAsync returning null." ) ;
37- }
34+ var ownedGames = await _steamLinkService . GetOwnedGamesAsync ( existingLink ) ;
35+ if ( ownedGames is null )
36+ {
37+ ownedGames = existingLink . KnownGames ;
38+ Log . Warn ( "Using cached owned games to sync due to GetOwnedGamesAsync returning null." ) ;
39+ }
3840
39- List < IRole > toRemove = new ( ) ;
40- List < IRole > toAdd = new ( ) ;
41+ List < IRole > toRemove = new ( ) ;
42+ List < IRole > toAdd = new ( ) ;
4143
42- SocketGuildUser socketGuildUser = Context . Guild . GetUser ( Context . User . Id ) ;
43- IEnumerable < Category > categories = await _database . FetchAsync < Category > ( x => x . GuildId == Context . Guild . Id ) ;
44- foreach ( var category in categories )
45- {
46- if ( category . GameId == 0 )
47- continue ;
44+ SocketGuildUser socketGuildUser = Context . Guild . GetUser ( Context . User . Id ) ;
45+ IEnumerable < Category > categories = await _database . FetchAsync < Category > ( x => x . GuildId == Context . Guild . Id ) ;
46+ foreach ( var category in categories )
47+ {
48+ if ( category . GameId == 0 )
49+ continue ;
4850
49- if ( ownedGames . Contains ( category . GameId ) )
50- toAdd . Add ( Context . Guild . GetRole ( category . RoleId ) ) ;
51- else
52- toRemove . Add ( Context . Guild . GetRole ( category . RoleId ) ) ;
53- }
51+ if ( ownedGames . Contains ( category . GameId ) )
52+ toAdd . Add ( Context . Guild . GetRole ( category . RoleId ) ) ;
53+ else
54+ toRemove . Add ( Context . Guild . GetRole ( category . RoleId ) ) ;
55+ }
5456
55- await DeferAsync ( ) ;
57+ await DeferAsync ( ) ;
5658
57- await socketGuildUser . AddRolesAsync ( toAdd ) ;
58- await socketGuildUser . RemoveRolesAsync ( toRemove ) ;
59+ await socketGuildUser . AddRolesAsync ( toAdd ) ;
60+ await socketGuildUser . RemoveRolesAsync ( toRemove ) ;
5961
60- await FollowupAsync ( "Successfully synced games." ) ;
62+ await FollowupAsync ( "Successfully synced games." ) ;
63+ }
64+ catch ( Exception e )
65+ {
66+ Log . Error ( e ) ;
67+ }
6168 }
6269}
0 commit comments