@@ -14,6 +14,8 @@ use crate::{
1414use kittycat:: perms;
1515use utoipa:: ToSchema ;
1616
17+ const MAX_REASON_LENGTH : usize = 2000 ;
18+
1719/// Helper function to check if a member is on a server, returning a boolean
1820pub fn member_on_guild (
1921 cache_http : & botox:: cache:: CacheHttpImpl ,
@@ -294,6 +296,18 @@ impl RPCMethod {
294296 . into ( ) ) ;
295297 }
296298
299+ // Also ensure that onboarding has happened
300+ if sqlx:: query!(
301+ "SELECT COUNT(*) FROM staff_onboardings WHERE user_id = $1 AND void = false AND state = 'completed' AND NOW() - created_at < INTERVAL '1 month'" ,
302+ & state. user_id,
303+ )
304+ . fetch_one ( & state. pool )
305+ . await ?
306+ . count
307+ . unwrap_or ( 0 ) == 0 {
308+ return Err ( "You need to have completed onboarding in order to use RPC!" . into ( ) ) ;
309+ }
310+
297311 // Insert into rpc_logs
298312 let id = sqlx:: query!(
299313 "INSERT INTO rpc_logs (method, user_id, data) VALUES ($1, $2, $3) RETURNING id" ,
@@ -436,8 +450,8 @@ impl RPCMethod {
436450 Ok ( RPCSuccess :: NoContent )
437451 }
438452 RPCMethod :: Unclaim { target_id, reason } => {
439- if reason. len ( ) > 2000 {
440- return Err ( "Reason must be lower than/equal to 2000 characters" . into ( ) ) ;
453+ if reason. len ( ) > MAX_REASON_LENGTH {
454+ return Err ( format ! ( "Reason must be lower than/equal to {MAX_REASON_LENGTH} characters" ) . into ( ) ) ;
441455 }
442456
443457 // Check if its claimed by someone
@@ -508,8 +522,8 @@ impl RPCMethod {
508522 Ok ( RPCSuccess :: NoContent )
509523 }
510524 RPCMethod :: Approve { target_id, reason } => {
511- if reason. len ( ) > 2000 {
512- return Err ( "Reason must be lower than/equal to 2000 characters" . into ( ) ) ;
525+ if reason. len ( ) > MAX_REASON_LENGTH {
526+ return Err ( format ! ( "Reason must be lower than/equal to {MAX_REASON_LENGTH} characters" ) . into ( ) ) ;
513527 }
514528
515529 let claimed = sqlx:: query!(
@@ -551,7 +565,7 @@ impl RPCMethod {
551565 . await ?;
552566
553567 // Add to cache server using borealis
554- /* #[derive(serde::Serialize, serde::Deserialize)]
568+ #[ derive( serde:: Serialize , serde:: Deserialize ) ]
555569 struct BorealisCacheServer {
556570 guild_id : String ,
557571 name : String ,
@@ -570,12 +584,12 @@ impl RPCMethod {
570584 . json :: < BorealisCacheServer > ( )
571585 . await
572586 . map_err ( |e| format ! ( "Error decoding borealis response: {:?}" , e) ) ?;
573- */
587+
574588 let msg = CreateMessage :: default ( )
575589 . content ( owners. mention_users ( ) )
576590 . embed (
577591 CreateEmbed :: default ( )
578- . title ( "Approved!" )
592+ . title ( " Approved!" )
579593 . url ( format ! (
580594 "{}/bots/{}" ,
581595 crate :: config:: CONFIG . frontend_url. get( ) ,
@@ -587,7 +601,7 @@ impl RPCMethod {
587601 ) )
588602 . field (
589603 "Cache Server" ,
590- "Disabled" ,
604+ format ! ( "[{}](https://discord.gg/{})" , csr . name , csr . invite_code ) ,
591605 true ,
592606 )
593607 . field ( "Feedback" , reason, true )
@@ -664,13 +678,18 @@ impl RPCMethod {
664678
665679 Ok (
666680 RPCSuccess :: Content (
667- "Approved!" . to_string ( )
681+ format ! (
682+ "**Cache Server Invite:** {csr_invite}\n **Invite URL:** https://discord.com/api/v10/oauth2/authorize?client_id={client_id}&permissions=0&scope=bot%20applications.commands&guild_id={guild_id}" ,
683+ csr_invite = "https://discord.gg/" . to_string( ) + & csr. invite_code,
684+ client_id = invite_data. client_id,
685+ guild_id = csr. guild_id
686+ )
668687 )
669688 )
670689 }
671690 RPCMethod :: Deny { target_id, reason } => {
672- if reason. len ( ) > 2000 {
673- return Err ( "Reason must be lower than/equal to 2000 characters" . into ( ) ) ;
691+ if reason. len ( ) > MAX_REASON_LENGTH {
692+ return Err ( format ! ( "Reason must be lower than/equal to {MAX_REASON_LENGTH} characters" ) . into ( ) ) ;
674693 }
675694
676695 let claimed = sqlx:: query!(
@@ -735,8 +754,8 @@ impl RPCMethod {
735754 Ok ( RPCSuccess :: NoContent )
736755 }
737756 RPCMethod :: Unverify { target_id, reason } => {
738- if reason. len ( ) > 2000 {
739- return Err ( "Reason must be lower than/equal to 2000 characters" . into ( ) ) ;
757+ if reason. len ( ) > MAX_REASON_LENGTH {
758+ return Err ( format ! ( "Reason must be lower than/equal to {MAX_REASON_LENGTH} characters" ) . into ( ) ) ;
740759 }
741760
742761 // Ensure the bot actually exists
@@ -786,8 +805,8 @@ impl RPCMethod {
786805 reason,
787806 time_period_hours,
788807 } => {
789- if reason. len ( ) > 2000 {
790- return Err ( "Reason must be lower than/equal to 2000 characters" . into ( ) ) ;
808+ if reason. len ( ) > MAX_REASON_LENGTH {
809+ return Err ( format ! ( "Reason must be lower than/equal to {MAX_REASON_LENGTH} characters" ) . into ( ) ) ;
791810 }
792811
793812 // Ensure the bot actually exists
@@ -831,8 +850,8 @@ impl RPCMethod {
831850 Ok ( RPCSuccess :: NoContent )
832851 }
833852 RPCMethod :: PremiumRemove { target_id, reason } => {
834- if reason. len ( ) > 2000 {
835- return Err ( "Reason must be lower than/equal to 2000 characters" . into ( ) ) ;
853+ if reason. len ( ) > MAX_REASON_LENGTH {
854+ return Err ( format ! ( "Reason must be lower than/equal to {MAX_REASON_LENGTH} characters" ) . into ( ) ) ;
836855 }
837856
838857 // Ensure the bot actually exists
@@ -875,8 +894,8 @@ impl RPCMethod {
875894 Ok ( RPCSuccess :: NoContent )
876895 }
877896 RPCMethod :: VoteBanAdd { target_id, reason } => {
878- if reason. len ( ) > 2000 {
879- return Err ( "Reason must be lower than/equal to 2000 characters" . into ( ) ) ;
897+ if reason. len ( ) > MAX_REASON_LENGTH {
898+ return Err ( format ! ( "Reason must be lower than/equal to {MAX_REASON_LENGTH} characters" ) . into ( ) ) ;
880899 }
881900
882901 // Ensure the bot actually exists
@@ -918,8 +937,8 @@ impl RPCMethod {
918937 Ok ( RPCSuccess :: NoContent )
919938 }
920939 RPCMethod :: VoteBanRemove { target_id, reason } => {
921- if reason. len ( ) > 2000 {
922- return Err ( "Reason must be lower than/equal to 2000 characters" . into ( ) ) ;
940+ if reason. len ( ) > MAX_REASON_LENGTH {
941+ return Err ( format ! ( "Reason must be lower than/equal to {MAX_REASON_LENGTH} characters" ) . into ( ) ) ;
923942 }
924943
925944 // Ensure the bot actually exists
@@ -961,8 +980,8 @@ impl RPCMethod {
961980 Ok ( RPCSuccess :: NoContent )
962981 }
963982 RPCMethod :: VoteReset { target_id, reason } => {
964- if reason. len ( ) > 2000 {
965- return Err ( "Reason must be lower than/equal to 2000 characters" . into ( ) ) ;
983+ if reason. len ( ) > MAX_REASON_LENGTH {
984+ return Err ( format ! ( "Reason must be lower than/equal to {MAX_REASON_LENGTH} characters" ) . into ( ) ) ;
966985 }
967986
968987 sqlx:: query!( "UPDATE entity_votes SET void = TRUE, void_reason = 'Votes (single entity) reset', voided_at = NOW() WHERE target_type = $1 AND target_id = $2 AND void = FALSE" , state. target_type. to_string( ) , target_id)
@@ -989,8 +1008,8 @@ impl RPCMethod {
9891008 Ok ( RPCSuccess :: NoContent )
9901009 }
9911010 RPCMethod :: VoteResetAll { reason } => {
992- if reason. len ( ) > 2000 {
993- return Err ( "Reason must be lower than/equal to 2000 characters" . into ( ) ) ;
1011+ if reason. len ( ) > MAX_REASON_LENGTH {
1012+ return Err ( format ! ( "Reason must be lower than/equal to {MAX_REASON_LENGTH} characters" ) . into ( ) ) ;
9941013 }
9951014
9961015 let mut tx = state. pool . begin ( ) . await ?;
@@ -1024,8 +1043,8 @@ impl RPCMethod {
10241043 reason,
10251044 kick,
10261045 } => {
1027- if reason. len ( ) > 2000 {
1028- return Err ( "Reason must be lower than/equal to 2000 characters" . into ( ) ) ;
1046+ if reason. len ( ) > MAX_REASON_LENGTH {
1047+ return Err ( format ! ( "Reason must be lower than/equal to {MAX_REASON_LENGTH} characters" ) . into ( ) ) ;
10291048 }
10301049
10311050 // Ensure the bot actually exists
@@ -1095,8 +1114,8 @@ impl RPCMethod {
10951114 Ok ( RPCSuccess :: NoContent )
10961115 }
10971116 RPCMethod :: CertifyAdd { target_id, reason } => {
1098- if reason. len ( ) > 2000 {
1099- return Err ( "Reason must be lower than/equal to 2000 characters" . into ( ) ) ;
1117+ if reason. len ( ) > MAX_REASON_LENGTH {
1118+ return Err ( format ! ( "Reason must be lower than/equal to {MAX_REASON_LENGTH} characters" ) . into ( ) ) ;
11001119 }
11011120
11021121 // Ensure the bot actually exists
@@ -1136,8 +1155,8 @@ impl RPCMethod {
11361155 Ok ( RPCSuccess :: NoContent )
11371156 }
11381157 RPCMethod :: CertifyRemove { target_id, reason } => {
1139- if reason. len ( ) > 2000 {
1140- return Err ( "Reason must be lower than/equal to 2000 characters" . into ( ) ) ;
1158+ if reason. len ( ) > MAX_REASON_LENGTH {
1159+ return Err ( format ! ( "Reason must be lower than/equal to {MAX_REASON_LENGTH} characters" ) . into ( ) ) ;
11411160 }
11421161
11431162 // Ensure the bot actually exists
@@ -1183,8 +1202,8 @@ impl RPCMethod {
11831202 new_owner,
11841203 reason,
11851204 } => {
1186- if reason. len ( ) > 2000 {
1187- return Err ( "Reason must be lower than/equal to 2000 characters" . into ( ) ) ;
1205+ if reason. len ( ) > MAX_REASON_LENGTH {
1206+ return Err ( format ! ( "Reason must be lower than/equal to {MAX_REASON_LENGTH} characters" ) . into ( ) ) ;
11881207 }
11891208
11901209 // Ensure the bot actually exists
@@ -1241,8 +1260,8 @@ impl RPCMethod {
12411260 new_team,
12421261 reason,
12431262 } => {
1244- if reason. len ( ) > 2000 {
1245- return Err ( "Reason must be lower than/equal to 2000 characters" . into ( ) ) ;
1263+ if reason. len ( ) > MAX_REASON_LENGTH {
1264+ return Err ( format ! ( "Reason must be lower than/equal to {MAX_REASON_LENGTH} characters" ) . into ( ) ) ;
12461265 }
12471266
12481267 // Ensure the bot actually exists
@@ -1301,8 +1320,8 @@ impl RPCMethod {
13011320 Ok ( RPCSuccess :: NoContent )
13021321 }
13031322 RPCMethod :: AppBanUser { target_id, reason } => {
1304- if reason. len ( ) > 2000 {
1305- return Err ( "Reason must be lower than/equal to 2000 characters" . into ( ) ) ;
1323+ if reason. len ( ) > MAX_REASON_LENGTH {
1324+ return Err ( format ! ( "Reason must be lower than/equal to {MAX_REASON_LENGTH} characters" ) . into ( ) ) ;
13061325 }
13071326
13081327 // Ensure the user actually exists
@@ -1345,8 +1364,8 @@ impl RPCMethod {
13451364 Ok ( RPCSuccess :: NoContent )
13461365 }
13471366 RPCMethod :: AppUnbanUser { target_id, reason } => {
1348- if reason. len ( ) > 2000 {
1349- return Err ( "Reason must be lower than/equal to 2000 characters" . into ( ) ) ;
1367+ if reason. len ( ) > MAX_REASON_LENGTH {
1368+ return Err ( format ! ( "Reason must be lower than/equal to {MAX_REASON_LENGTH} characters" ) . into ( ) ) ;
13501369 }
13511370
13521371 // Ensure the user actually exists
0 commit comments