added check for guild only commands
This commit is contained in:
		
							
								
								
									
										2
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							@@ -1187,7 +1187,7 @@ dependencies = [
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
[[package]]
 | 
					[[package]]
 | 
				
			||||||
name = "reminder_rs"
 | 
					name = "reminder_rs"
 | 
				
			||||||
version = "1.6.0-beta0"
 | 
					version = "1.6.0-beta1"
 | 
				
			||||||
dependencies = [
 | 
					dependencies = [
 | 
				
			||||||
 "base64",
 | 
					 "base64",
 | 
				
			||||||
 "chrono",
 | 
					 "chrono",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
[package]
 | 
					[package]
 | 
				
			||||||
name = "reminder_rs"
 | 
					name = "reminder_rs"
 | 
				
			||||||
version = "1.6.0-beta0"
 | 
					version = "1.6.0-beta1"
 | 
				
			||||||
authors = ["jellywx <judesouthworth@pm.me>"]
 | 
					authors = ["jellywx <judesouthworth@pm.me>"]
 | 
				
			||||||
edition = "2018"
 | 
					edition = "2018"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,7 +8,7 @@ use crate::{
 | 
				
			|||||||
    component_models::pager::{MacroPager, Pager},
 | 
					    component_models::pager::{MacroPager, Pager},
 | 
				
			||||||
    consts::{EMBED_DESCRIPTION_MAX_LENGTH, THEME_COLOR},
 | 
					    consts::{EMBED_DESCRIPTION_MAX_LENGTH, THEME_COLOR},
 | 
				
			||||||
    framework::{CommandInvoke, CommandOptions, CreateGenericResponse, OptionValue},
 | 
					    framework::{CommandInvoke, CommandOptions, CreateGenericResponse, OptionValue},
 | 
				
			||||||
    hooks::CHECK_GUILD_PERMISSIONS_HOOK,
 | 
					    hooks::{CHECK_GUILD_PERMISSIONS_HOOK, GUILD_ONLY_HOOK},
 | 
				
			||||||
    models::{command_macro::CommandMacro, CtxData},
 | 
					    models::{command_macro::CommandMacro, CtxData},
 | 
				
			||||||
    PopularTimezones, RecordingMacros, RegexFramework, SQLPool,
 | 
					    PopularTimezones, RecordingMacros, RegexFramework, SQLPool,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
@@ -146,6 +146,7 @@ You may want to use one of the popular timezones below, otherwise click [here](h
 | 
				
			|||||||
#[description("Delete a recorded macro")]
 | 
					#[description("Delete a recorded macro")]
 | 
				
			||||||
#[arg(name = "name", description = "Name of the macro to delete", kind = "String", required = true)]
 | 
					#[arg(name = "name", description = "Name of the macro to delete", kind = "String", required = true)]
 | 
				
			||||||
#[supports_dm(false)]
 | 
					#[supports_dm(false)]
 | 
				
			||||||
 | 
					#[hook(GUILD_ONLY_HOOK)]
 | 
				
			||||||
#[hook(CHECK_GUILD_PERMISSIONS_HOOK)]
 | 
					#[hook(CHECK_GUILD_PERMISSIONS_HOOK)]
 | 
				
			||||||
async fn macro_cmd(ctx: &Context, invoke: &mut CommandInvoke, args: CommandOptions) {
 | 
					async fn macro_cmd(ctx: &Context, invoke: &mut CommandInvoke, args: CommandOptions) {
 | 
				
			||||||
    let pool = ctx.data.read().await.get::<SQLPool>().cloned().unwrap();
 | 
					    let pool = ctx.data.read().await.get::<SQLPool>().cloned().unwrap();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -48,7 +48,9 @@ impl ComponentDataModel {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn from_custom_id(data: &String) -> Self {
 | 
					    pub fn from_custom_id(data: &String) -> Self {
 | 
				
			||||||
        let buf = base64::decode(data).unwrap();
 | 
					        let buf = base64::decode(data)
 | 
				
			||||||
 | 
					            .map_err(|e| format!("Could not decode `custom_id' {}: {:?}", data, e))
 | 
				
			||||||
 | 
					            .unwrap();
 | 
				
			||||||
        let cur = Cursor::new(buf);
 | 
					        let cur = Cursor::new(buf);
 | 
				
			||||||
        rmp_serde::from_read(cur).unwrap()
 | 
					        rmp_serde::from_read(cur).unwrap()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										20
									
								
								src/hooks.rs
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								src/hooks.rs
									
									
									
									
									
								
							@@ -7,6 +7,26 @@ use crate::{
 | 
				
			|||||||
    moderation_cmds, RecordingMacros,
 | 
					    moderation_cmds, RecordingMacros,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[check]
 | 
				
			||||||
 | 
					pub async fn guild_only(
 | 
				
			||||||
 | 
					    ctx: &Context,
 | 
				
			||||||
 | 
					    invoke: &mut CommandInvoke,
 | 
				
			||||||
 | 
					    _args: &CommandOptions,
 | 
				
			||||||
 | 
					) -> HookResult {
 | 
				
			||||||
 | 
					    if invoke.guild_id().is_some() {
 | 
				
			||||||
 | 
					        HookResult::Continue
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        let _ = invoke
 | 
				
			||||||
 | 
					            .respond(
 | 
				
			||||||
 | 
					                &ctx,
 | 
				
			||||||
 | 
					                CreateGenericResponse::new().content("This command can only be used in servers"),
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					            .await;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        HookResult::Halt
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[check]
 | 
					#[check]
 | 
				
			||||||
pub async fn macro_check(
 | 
					pub async fn macro_check(
 | 
				
			||||||
    ctx: &Context,
 | 
					    ctx: &Context,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user