removed guild only hook. permissions on commands. fix for macro command count.
This commit is contained in:
		
							
								
								
									
										14
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										14
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							@@ -1900,8 +1900,9 @@ checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "poise"
 | 
			
		||||
version = "0.1.0"
 | 
			
		||||
source = "git+https://github.com/kangalioo/poise?branch=master#0f526b77e5e354fa2a7d2a3fb6bdfac5bf0fb226"
 | 
			
		||||
version = "0.2.0"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "3c2eb79ba8241eb65b549e778e22a242ea30f5829f7487f10d8d95cfff9a4729"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "async-trait",
 | 
			
		||||
 "derivative",
 | 
			
		||||
@@ -1917,8 +1918,9 @@ dependencies = [
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "poise_macros"
 | 
			
		||||
version = "0.1.0"
 | 
			
		||||
source = "git+https://github.com/kangalioo/poise?branch=master#0f526b77e5e354fa2a7d2a3fb6bdfac5bf0fb226"
 | 
			
		||||
version = "0.2.0"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "15b786b4bdc58345204469420c306d8c638e465b4b1ecad7e27bf9c8a45096cf"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "darling",
 | 
			
		||||
 "proc-macro2",
 | 
			
		||||
@@ -2563,9 +2565,9 @@ dependencies = [
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "serenity"
 | 
			
		||||
version = "0.11.1"
 | 
			
		||||
version = "0.11.2"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "96455fdd03a3cb8c3270c47adf21d748b65067affc6c911ed4ed4ae05f097cab"
 | 
			
		||||
checksum = "246008828de84241202b092316c4729da36c3edd8f0c17ed6893df8e414c3c9b"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "async-trait",
 | 
			
		||||
 "async-tungstenite",
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,7 @@ authors = ["jellywx <judesouthworth@pm.me>"]
 | 
			
		||||
edition = "2018"
 | 
			
		||||
 | 
			
		||||
[dependencies]
 | 
			
		||||
poise = { git = "https://github.com/kangalioo/poise", branch = "master" }
 | 
			
		||||
poise = "0.2"
 | 
			
		||||
dotenv = "0.15"
 | 
			
		||||
tokio = { version = "1", features = ["process", "full"] }
 | 
			
		||||
reqwest = "0.11"
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
@@ -186,12 +186,12 @@
 | 
			
		||||
    <div class="modal-background"></div>
 | 
			
		||||
    <div class="modal-card">
 | 
			
		||||
        <header class="modal-card-head">
 | 
			
		||||
            <label class="modal-card-title" for="urlInput">Delete Reminder</label>
 | 
			
		||||
            <label class="modal-card-title">Delete Reminder</label>
 | 
			
		||||
            <button class="delete close-modal" aria-label="close"></button>
 | 
			
		||||
        </header>
 | 
			
		||||
        <section class="modal-card-body">
 | 
			
		||||
            <p>
 | 
			
		||||
                This reminder will be permenantly deleted. Are you sure?
 | 
			
		||||
                This reminder will be permanently deleted. Are you sure?
 | 
			
		||||
            </p>
 | 
			
		||||
            <br>
 | 
			
		||||
            <div class="has-text-centered">
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user