removed guild only hook. permissions on commands. fix for macro command count.
This commit is contained in:
@ -6,7 +6,6 @@ use poise::CreateReply;
|
||||
use crate::{
|
||||
component_models::pager::{MacroPager, Pager},
|
||||
consts::{EMBED_DESCRIPTION_MAX_LENGTH, THEME_COLOR},
|
||||
hooks::guild_only,
|
||||
models::{
|
||||
command_macro::{guild_command_macro, CommandMacro},
|
||||
CtxData,
|
||||
@ -153,7 +152,8 @@ WHERE
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
rename = "macro",
|
||||
check = "guild_only",
|
||||
guild_only = true,
|
||||
default_member_permissions = "MANAGE_GUILD",
|
||||
identifying_name = "macro_base"
|
||||
)]
|
||||
pub async fn macro_base(_ctx: Context<'_>) -> Result<(), Error> {
|
||||
@ -164,7 +164,8 @@ pub async fn macro_base(_ctx: Context<'_>) -> Result<(), Error> {
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
rename = "record",
|
||||
check = "guild_only",
|
||||
guild_only = true,
|
||||
default_member_permissions = "MANAGE_GUILD",
|
||||
identifying_name = "record_macro"
|
||||
)]
|
||||
pub async fn record_macro(
|
||||
@ -244,7 +245,8 @@ Please use `/macro finish` to end this recording before starting another.",
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
rename = "finish",
|
||||
check = "guild_only",
|
||||
guild_only = true,
|
||||
default_member_permissions = "MANAGE_GUILD",
|
||||
identifying_name = "finish_macro"
|
||||
)]
|
||||
pub async fn finish_macro(ctx: Context<'_>) -> Result<(), Error> {
|
||||
@ -301,7 +303,8 @@ pub async fn finish_macro(ctx: Context<'_>) -> Result<(), Error> {
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
rename = "list",
|
||||
check = "guild_only",
|
||||
guild_only = true,
|
||||
default_member_permissions = "MANAGE_GUILD",
|
||||
identifying_name = "list_macro"
|
||||
)]
|
||||
pub async fn list_macro(ctx: Context<'_>) -> Result<(), Error> {
|
||||
@ -322,7 +325,8 @@ pub async fn list_macro(ctx: Context<'_>) -> Result<(), Error> {
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
rename = "run",
|
||||
check = "guild_only",
|
||||
guild_only = true,
|
||||
default_member_permissions = "MANAGE_GUILD",
|
||||
identifying_name = "run_macro"
|
||||
)]
|
||||
pub async fn run_macro(
|
||||
@ -365,7 +369,8 @@ pub async fn run_macro(
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
rename = "delete",
|
||||
check = "guild_only",
|
||||
guild_only = true,
|
||||
default_member_permissions = "MANAGE_GUILD",
|
||||
identifying_name = "delete_macro"
|
||||
)]
|
||||
pub async fn delete_macro(
|
||||
|
@ -39,7 +39,11 @@ use crate::{
|
||||
};
|
||||
|
||||
/// Pause all reminders on the current channel until a certain time or indefinitely
|
||||
#[poise::command(slash_command, identifying_name = "pause")]
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
identifying_name = "pause",
|
||||
default_member_permissions = "MANAGE_GUILD"
|
||||
)]
|
||||
pub async fn pause(
|
||||
ctx: Context<'_>,
|
||||
#[description = "When to pause until"] until: Option<String>,
|
||||
@ -90,7 +94,11 @@ pub async fn pause(
|
||||
}
|
||||
|
||||
/// Move all reminders in the current server by a certain amount of time. Times get added together
|
||||
#[poise::command(slash_command, identifying_name = "offset")]
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
identifying_name = "offset",
|
||||
default_member_permissions = "MANAGE_GUILD"
|
||||
)]
|
||||
pub async fn offset(
|
||||
ctx: Context<'_>,
|
||||
#[description = "Number of hours to offset by"] hours: Option<isize>,
|
||||
@ -147,7 +155,11 @@ WHERE FIND_IN_SET(channels.`channel`, ?)",
|
||||
}
|
||||
|
||||
/// Nudge all future reminders on this channel by a certain amount (don't use for DST! See `/offset`)
|
||||
#[poise::command(slash_command, identifying_name = "nudge")]
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
identifying_name = "nudge",
|
||||
default_member_permissions = "MANAGE_GUILD"
|
||||
)]
|
||||
pub async fn nudge(
|
||||
ctx: Context<'_>,
|
||||
#[description = "Number of minutes to nudge new reminders by"] minutes: Option<isize>,
|
||||
@ -170,7 +182,11 @@ pub async fn nudge(
|
||||
}
|
||||
|
||||
/// View reminders on a specific channel
|
||||
#[poise::command(slash_command, identifying_name = "look")]
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
identifying_name = "look",
|
||||
default_member_permissions = "MANAGE_GUILD"
|
||||
)]
|
||||
pub async fn look(
|
||||
ctx: Context<'_>,
|
||||
#[description = "Channel to view reminders on"] channel: Option<Channel>,
|
||||
@ -260,7 +276,12 @@ pub async fn look(
|
||||
}
|
||||
|
||||
/// Delete reminders
|
||||
#[poise::command(slash_command, rename = "del", identifying_name = "delete")]
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
rename = "del",
|
||||
identifying_name = "delete",
|
||||
default_member_permissions = "MANAGE_GUILD"
|
||||
)]
|
||||
pub async fn delete(ctx: Context<'_>) -> Result<(), Error> {
|
||||
let timezone = ctx.timezone().await;
|
||||
|
||||
@ -422,13 +443,23 @@ fn time_difference(start_time: NaiveDateTime) -> String {
|
||||
}
|
||||
|
||||
/// Manage timers
|
||||
#[poise::command(slash_command, rename = "timer", identifying_name = "timer_base")]
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
rename = "timer",
|
||||
identifying_name = "timer_base",
|
||||
default_member_permissions = "MANAGE_GUILD"
|
||||
)]
|
||||
pub async fn timer_base(_ctx: Context<'_>) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// List the timers in this server or DM channel
|
||||
#[poise::command(slash_command, rename = "list", identifying_name = "list_timer")]
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
rename = "list",
|
||||
identifying_name = "list_timer",
|
||||
default_member_permissions = "MANAGE_GUILD"
|
||||
)]
|
||||
pub async fn list_timer(ctx: Context<'_>) -> Result<(), Error> {
|
||||
let owner = ctx.guild_id().map(|g| g.0).unwrap_or_else(|| ctx.author().id.0);
|
||||
|
||||
@ -452,7 +483,12 @@ pub async fn list_timer(ctx: Context<'_>) -> Result<(), Error> {
|
||||
}
|
||||
|
||||
/// Start a new timer from now
|
||||
#[poise::command(slash_command, rename = "start", identifying_name = "start_timer")]
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
rename = "start",
|
||||
identifying_name = "start_timer",
|
||||
default_member_permissions = "MANAGE_GUILD"
|
||||
)]
|
||||
pub async fn start_timer(
|
||||
ctx: Context<'_>,
|
||||
#[description = "Name for the new timer"] name: String,
|
||||
@ -482,7 +518,12 @@ pub async fn start_timer(
|
||||
}
|
||||
|
||||
/// Delete a timer
|
||||
#[poise::command(slash_command, rename = "delete", identifying_name = "delete_timer")]
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
rename = "delete",
|
||||
identifying_name = "delete_timer",
|
||||
default_member_permissions = "MANAGE_GUILD"
|
||||
)]
|
||||
pub async fn delete_timer(
|
||||
ctx: Context<'_>,
|
||||
#[description = "Name of timer to delete"] name: String,
|
||||
@ -509,7 +550,11 @@ pub async fn delete_timer(
|
||||
}
|
||||
|
||||
/// Create a new reminder
|
||||
#[poise::command(slash_command, identifying_name = "remind")]
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
identifying_name = "remind",
|
||||
default_member_permissions = "MANAGE_GUILD"
|
||||
)]
|
||||
pub async fn remind(
|
||||
ctx: Context<'_>,
|
||||
#[description = "A description of the time to set the reminder for"] time: String,
|
||||
|
@ -6,12 +6,16 @@ use crate::{
|
||||
ComponentDataModel, TodoSelector,
|
||||
},
|
||||
consts::{EMBED_DESCRIPTION_MAX_LENGTH, SELECT_MAX_ENTRIES, THEME_COLOR},
|
||||
hooks::guild_only,
|
||||
Context, Error,
|
||||
};
|
||||
|
||||
/// Manage todo lists
|
||||
#[poise::command(slash_command, rename = "todo", identifying_name = "todo_base")]
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
rename = "todo",
|
||||
identifying_name = "todo_base",
|
||||
default_member_permissions = "MANAGE_GUILD"
|
||||
)]
|
||||
pub async fn todo_base(_ctx: Context<'_>) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
@ -20,8 +24,9 @@ pub async fn todo_base(_ctx: Context<'_>) -> Result<(), Error> {
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
rename = "server",
|
||||
check = "guild_only",
|
||||
identifying_name = "todo_guild_base"
|
||||
guild_only = true,
|
||||
identifying_name = "todo_guild_base",
|
||||
default_member_permissions = "MANAGE_GUILD"
|
||||
)]
|
||||
pub async fn todo_guild_base(_ctx: Context<'_>) -> Result<(), Error> {
|
||||
Ok(())
|
||||
@ -31,8 +36,9 @@ pub async fn todo_guild_base(_ctx: Context<'_>) -> Result<(), Error> {
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
rename = "add",
|
||||
check = "guild_only",
|
||||
identifying_name = "todo_guild_add"
|
||||
guild_only = true,
|
||||
identifying_name = "todo_guild_add",
|
||||
default_member_permissions = "MANAGE_GUILD"
|
||||
)]
|
||||
pub async fn todo_guild_add(
|
||||
ctx: Context<'_>,
|
||||
@ -57,8 +63,9 @@ VALUES ((SELECT id FROM guilds WHERE guild = ?), ?)",
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
rename = "view",
|
||||
check = "guild_only",
|
||||
identifying_name = "todo_guild_view"
|
||||
guild_only = true,
|
||||
identifying_name = "todo_guild_view",
|
||||
default_member_permissions = "MANAGE_GUILD"
|
||||
)]
|
||||
pub async fn todo_guild_view(ctx: Context<'_>) -> Result<(), Error> {
|
||||
let values = sqlx::query!(
|
||||
@ -89,8 +96,9 @@ WHERE guilds.guild = ?",
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
rename = "channel",
|
||||
check = "guild_only",
|
||||
identifying_name = "todo_channel_base"
|
||||
guild_only = true,
|
||||
identifying_name = "todo_channel_base",
|
||||
default_member_permissions = "MANAGE_GUILD"
|
||||
)]
|
||||
pub async fn todo_channel_base(_ctx: Context<'_>) -> Result<(), Error> {
|
||||
Ok(())
|
||||
@ -100,8 +108,9 @@ pub async fn todo_channel_base(_ctx: Context<'_>) -> Result<(), Error> {
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
rename = "add",
|
||||
check = "guild_only",
|
||||
identifying_name = "todo_channel_add"
|
||||
guild_only = true,
|
||||
identifying_name = "todo_channel_add",
|
||||
default_member_permissions = "MANAGE_GUILD"
|
||||
)]
|
||||
pub async fn todo_channel_add(
|
||||
ctx: Context<'_>,
|
||||
@ -127,8 +136,9 @@ VALUES ((SELECT id FROM guilds WHERE guild = ?), (SELECT id FROM channels WHERE
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
rename = "view",
|
||||
check = "guild_only",
|
||||
identifying_name = "todo_channel_view"
|
||||
guild_only = true,
|
||||
identifying_name = "todo_channel_view",
|
||||
default_member_permissions = "MANAGE_GUILD"
|
||||
)]
|
||||
pub async fn todo_channel_view(ctx: Context<'_>) -> Result<(), Error> {
|
||||
let values = sqlx::query!(
|
||||
|
10
src/hooks.rs
10
src/hooks.rs
@ -2,16 +2,6 @@ use poise::serenity::model::channel::Channel;
|
||||
|
||||
use crate::{consts::MACRO_MAX_COMMANDS, models::command_macro::RecordedCommand, Context, Error};
|
||||
|
||||
pub async fn guild_only(ctx: Context<'_>) -> Result<bool, Error> {
|
||||
if ctx.guild_id().is_some() {
|
||||
Ok(true)
|
||||
} else {
|
||||
let _ = ctx.say("This command can only be used in servers").await;
|
||||
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
|
||||
async fn macro_check(ctx: Context<'_>) -> bool {
|
||||
if let Context::Application(app_ctx) = ctx {
|
||||
if let Some(guild_id) = ctx.guild_id() {
|
||||
|
@ -59,7 +59,7 @@ impl Data {
|
||||
guild_id: GuildId,
|
||||
) -> Result<Vec<CommandMacro<Data, Error>>, Error> {
|
||||
let rows = sqlx::query!(
|
||||
"SELECT name, description FROM macro WHERE guild_id = (SELECT id FROM guilds WHERE guild = ?)",
|
||||
"SELECT name, description, commands FROM macro WHERE guild_id = (SELECT id FROM guilds WHERE guild = ?)",
|
||||
guild_id.0
|
||||
)
|
||||
.fetch_all(&self.database)
|
||||
@ -67,7 +67,7 @@ impl Data {
|
||||
guild_id,
|
||||
name: row.name.clone(),
|
||||
description: row.description.clone(),
|
||||
commands: vec![]
|
||||
commands: serde_json::from_str(&row.commands).unwrap(),
|
||||
}).collect();
|
||||
|
||||
Ok(rows)
|
||||
|
Reference in New Issue
Block a user