File tree 4 files changed +67
-0
lines changed
trackscape-discord-bot/src
trackscape-discord-shared/src/database
4 files changed +67
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ pub mod info;
4
4
pub ( crate ) mod manually_run_wom_sync_command;
5
5
pub mod name_change_command;
6
6
pub mod reset_broadcasts_thresholds;
7
+ pub mod reset_verification_code;
7
8
pub mod set_broadcast_channel;
8
9
pub mod set_clan_chat_channel;
9
10
pub mod set_diary_min_command;
Original file line number Diff line number Diff line change
1
+ use crate :: database:: BotMongoDb ;
2
+ use serenity:: all:: { CommandDataOption , CreateCommand } ;
3
+ use serenity:: client:: Context ;
4
+ use serenity:: model:: prelude:: Permissions ;
5
+
6
+ pub fn register ( ) -> CreateCommand {
7
+ CreateCommand :: new ( "reset_verification_code" )
8
+ . description (
9
+ "Resets the verification code for the server. MUST UPDATE THE NEW CODE IN THE PLUGIN." ,
10
+ )
11
+ . default_member_permissions ( Permissions :: MANAGE_GUILD )
12
+ }
13
+
14
+ pub async fn run (
15
+ _options : & [ CommandDataOption ] ,
16
+ _ctx : & Context ,
17
+ db : & BotMongoDb ,
18
+ guild_id : u64 ,
19
+ ) -> Option < String > {
20
+ let reset_code = db. guilds . reset_verification_code ( guild_id) . await ;
21
+ match reset_code {
22
+ Ok ( new_code) => Some ( format ! ( "The new verification code is: {}" , new_code) ) ,
23
+ Err ( e) => {
24
+ eprintln ! ( "Failed to reset verification code: {:?}" , e) ;
25
+ Some ( "Failed to reset verification code." . to_string ( ) )
26
+ }
27
+ }
28
+ }
Original file line number Diff line number Diff line change @@ -307,6 +307,15 @@ impl EventHandler for Bot {
307
307
)
308
308
. await
309
309
}
310
+ "reset_verification_code" => {
311
+ commands:: reset_verification_code:: run (
312
+ & command. data . options ,
313
+ & ctx,
314
+ & self . mongo_db ,
315
+ command. guild_id . unwrap ( ) . get ( ) ,
316
+ )
317
+ . await
318
+ }
310
319
_ => {
311
320
info ! ( "not implemented :(" ) ;
312
321
None
@@ -349,6 +358,7 @@ fn get_commands() -> Vec<CreateCommand> {
349
358
commands. push ( commands:: manually_run_wom_sync_command:: register ( ) ) ;
350
359
commands. push ( commands:: set_leagues_broadcast_channel:: register ( ) ) ;
351
360
commands. push ( commands:: stop_leagues_notifications:: register ( ) ) ;
361
+ commands. push ( commands:: reset_verification_code:: register ( ) ) ;
352
362
commands
353
363
}
354
364
pub async fn create_commands_for_guild ( guild_id : & GuildId , ctx : Context ) {
Original file line number Diff line number Diff line change @@ -134,6 +134,34 @@ impl GuildsDb {
134
134
}
135
135
}
136
136
137
+ pub async fn reset_verification_code ( & self , guild_id : u64 ) -> Result < String , anyhow:: Error > {
138
+ let saved_guild_query = self . get_by_guild_id ( guild_id) . await ;
139
+ match saved_guild_query {
140
+ Ok ( saved_guild) => match saved_guild {
141
+ Some ( mut guild) => {
142
+ let check_for_unique_code = self
143
+ . recursive_check_for_unique_code ( guild. verification_code . clone ( ) )
144
+ . await ;
145
+ match check_for_unique_code {
146
+ Ok ( new_code) => {
147
+ guild. verification_code = new_code. clone ( ) ;
148
+ guild. hashed_verification_code = hash_string ( new_code. clone ( ) ) ;
149
+ self . update_guild ( guild) . await ;
150
+ Ok ( new_code)
151
+ }
152
+ Err ( _) => Err ( anyhow:: Error :: msg ( "Failed to reset verification code." ) ) ,
153
+ }
154
+ }
155
+ None => Err ( anyhow:: Error :: msg (
156
+ "Could not find a clan with that guild id." ,
157
+ ) ) ,
158
+ } ,
159
+ Err ( _) => Err ( anyhow:: Error :: msg (
160
+ "Failed to get the saved guild to reset verification code." ,
161
+ ) ) ,
162
+ }
163
+ }
164
+
137
165
pub async fn get_guild_by_code_and_clan_name (
138
166
& self ,
139
167
code : String ,
You can’t perform that action at this time.
0 commit comments