removed guild only hook. permissions on commands. fix for macro command count.

This commit is contained in:
jude 2022-05-13 08:59:46 +01:00
parent ded750aa2d
commit 1c1f5662d3
8 changed files with 104 additions and 52 deletions

14
Cargo.lock generated
View File

@ -1900,8 +1900,9 @@ checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae"
[[package]] [[package]]
name = "poise" name = "poise"
version = "0.1.0" version = "0.2.0"
source = "git+https://github.com/kangalioo/poise?branch=master#0f526b77e5e354fa2a7d2a3fb6bdfac5bf0fb226" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c2eb79ba8241eb65b549e778e22a242ea30f5829f7487f10d8d95cfff9a4729"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"derivative", "derivative",
@ -1917,8 +1918,9 @@ dependencies = [
[[package]] [[package]]
name = "poise_macros" name = "poise_macros"
version = "0.1.0" version = "0.2.0"
source = "git+https://github.com/kangalioo/poise?branch=master#0f526b77e5e354fa2a7d2a3fb6bdfac5bf0fb226" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15b786b4bdc58345204469420c306d8c638e465b4b1ecad7e27bf9c8a45096cf"
dependencies = [ dependencies = [
"darling", "darling",
"proc-macro2", "proc-macro2",
@ -2563,9 +2565,9 @@ dependencies = [
[[package]] [[package]]
name = "serenity" name = "serenity"
version = "0.11.1" version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96455fdd03a3cb8c3270c47adf21d748b65067affc6c911ed4ed4ae05f097cab" checksum = "246008828de84241202b092316c4729da36c3edd8f0c17ed6893df8e414c3c9b"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"async-tungstenite", "async-tungstenite",

View File

@ -5,7 +5,7 @@ authors = ["jellywx <judesouthworth@pm.me>"]
edition = "2018" edition = "2018"
[dependencies] [dependencies]
poise = { git = "https://github.com/kangalioo/poise", branch = "master" } poise = "0.2"
dotenv = "0.15" dotenv = "0.15"
tokio = { version = "1", features = ["process", "full"] } tokio = { version = "1", features = ["process", "full"] }
reqwest = "0.11" reqwest = "0.11"

View File

@ -6,7 +6,6 @@ use poise::CreateReply;
use crate::{ 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},
hooks::guild_only,
models::{ models::{
command_macro::{guild_command_macro, CommandMacro}, command_macro::{guild_command_macro, CommandMacro},
CtxData, CtxData,
@ -153,7 +152,8 @@ WHERE
#[poise::command( #[poise::command(
slash_command, slash_command,
rename = "macro", rename = "macro",
check = "guild_only", guild_only = true,
default_member_permissions = "MANAGE_GUILD",
identifying_name = "macro_base" identifying_name = "macro_base"
)] )]
pub async fn macro_base(_ctx: Context<'_>) -> Result<(), Error> { pub async fn macro_base(_ctx: Context<'_>) -> Result<(), Error> {
@ -164,7 +164,8 @@ pub async fn macro_base(_ctx: Context<'_>) -> Result<(), Error> {
#[poise::command( #[poise::command(
slash_command, slash_command,
rename = "record", rename = "record",
check = "guild_only", guild_only = true,
default_member_permissions = "MANAGE_GUILD",
identifying_name = "record_macro" identifying_name = "record_macro"
)] )]
pub async fn record_macro( pub async fn record_macro(
@ -244,7 +245,8 @@ Please use `/macro finish` to end this recording before starting another.",
#[poise::command( #[poise::command(
slash_command, slash_command,
rename = "finish", rename = "finish",
check = "guild_only", guild_only = true,
default_member_permissions = "MANAGE_GUILD",
identifying_name = "finish_macro" identifying_name = "finish_macro"
)] )]
pub async fn finish_macro(ctx: Context<'_>) -> Result<(), Error> { pub async fn finish_macro(ctx: Context<'_>) -> Result<(), Error> {
@ -301,7 +303,8 @@ pub async fn finish_macro(ctx: Context<'_>) -> Result<(), Error> {
#[poise::command( #[poise::command(
slash_command, slash_command,
rename = "list", rename = "list",
check = "guild_only", guild_only = true,
default_member_permissions = "MANAGE_GUILD",
identifying_name = "list_macro" identifying_name = "list_macro"
)] )]
pub async fn list_macro(ctx: Context<'_>) -> Result<(), Error> { pub async fn list_macro(ctx: Context<'_>) -> Result<(), Error> {
@ -322,7 +325,8 @@ pub async fn list_macro(ctx: Context<'_>) -> Result<(), Error> {
#[poise::command( #[poise::command(
slash_command, slash_command,
rename = "run", rename = "run",
check = "guild_only", guild_only = true,
default_member_permissions = "MANAGE_GUILD",
identifying_name = "run_macro" identifying_name = "run_macro"
)] )]
pub async fn run_macro( pub async fn run_macro(
@ -365,7 +369,8 @@ pub async fn run_macro(
#[poise::command( #[poise::command(
slash_command, slash_command,
rename = "delete", rename = "delete",
check = "guild_only", guild_only = true,
default_member_permissions = "MANAGE_GUILD",
identifying_name = "delete_macro" identifying_name = "delete_macro"
)] )]
pub async fn delete_macro( pub async fn delete_macro(

View File

@ -39,7 +39,11 @@ use crate::{
}; };
/// Pause all reminders on the current channel until a certain time or indefinitely /// 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( pub async fn pause(
ctx: Context<'_>, ctx: Context<'_>,
#[description = "When to pause until"] until: Option<String>, #[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 /// 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( pub async fn offset(
ctx: Context<'_>, ctx: Context<'_>,
#[description = "Number of hours to offset by"] hours: Option<isize>, #[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`) /// 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( pub async fn nudge(
ctx: Context<'_>, ctx: Context<'_>,
#[description = "Number of minutes to nudge new reminders by"] minutes: Option<isize>, #[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 /// 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( pub async fn look(
ctx: Context<'_>, ctx: Context<'_>,
#[description = "Channel to view reminders on"] channel: Option<Channel>, #[description = "Channel to view reminders on"] channel: Option<Channel>,
@ -260,7 +276,12 @@ pub async fn look(
} }
/// Delete reminders /// 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> { pub async fn delete(ctx: Context<'_>) -> Result<(), Error> {
let timezone = ctx.timezone().await; let timezone = ctx.timezone().await;
@ -422,13 +443,23 @@ fn time_difference(start_time: NaiveDateTime) -> String {
} }
/// Manage timers /// 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> { pub async fn timer_base(_ctx: Context<'_>) -> Result<(), Error> {
Ok(()) Ok(())
} }
/// List the timers in this server or DM channel /// 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> { 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); 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 /// 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( pub async fn start_timer(
ctx: Context<'_>, ctx: Context<'_>,
#[description = "Name for the new timer"] name: String, #[description = "Name for the new timer"] name: String,
@ -482,7 +518,12 @@ pub async fn start_timer(
} }
/// Delete a 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( pub async fn delete_timer(
ctx: Context<'_>, ctx: Context<'_>,
#[description = "Name of timer to delete"] name: String, #[description = "Name of timer to delete"] name: String,
@ -509,7 +550,11 @@ pub async fn delete_timer(
} }
/// Create a new reminder /// 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( pub async fn remind(
ctx: Context<'_>, ctx: Context<'_>,
#[description = "A description of the time to set the reminder for"] time: String, #[description = "A description of the time to set the reminder for"] time: String,

View File

@ -6,12 +6,16 @@ use crate::{
ComponentDataModel, TodoSelector, ComponentDataModel, TodoSelector,
}, },
consts::{EMBED_DESCRIPTION_MAX_LENGTH, SELECT_MAX_ENTRIES, THEME_COLOR}, consts::{EMBED_DESCRIPTION_MAX_LENGTH, SELECT_MAX_ENTRIES, THEME_COLOR},
hooks::guild_only,
Context, Error, Context, Error,
}; };
/// Manage todo lists /// 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> { pub async fn todo_base(_ctx: Context<'_>) -> Result<(), Error> {
Ok(()) Ok(())
} }
@ -20,8 +24,9 @@ pub async fn todo_base(_ctx: Context<'_>) -> Result<(), Error> {
#[poise::command( #[poise::command(
slash_command, slash_command,
rename = "server", rename = "server",
check = "guild_only", guild_only = true,
identifying_name = "todo_guild_base" identifying_name = "todo_guild_base",
default_member_permissions = "MANAGE_GUILD"
)] )]
pub async fn todo_guild_base(_ctx: Context<'_>) -> Result<(), Error> { pub async fn todo_guild_base(_ctx: Context<'_>) -> Result<(), Error> {
Ok(()) Ok(())
@ -31,8 +36,9 @@ pub async fn todo_guild_base(_ctx: Context<'_>) -> Result<(), Error> {
#[poise::command( #[poise::command(
slash_command, slash_command,
rename = "add", rename = "add",
check = "guild_only", guild_only = true,
identifying_name = "todo_guild_add" identifying_name = "todo_guild_add",
default_member_permissions = "MANAGE_GUILD"
)] )]
pub async fn todo_guild_add( pub async fn todo_guild_add(
ctx: Context<'_>, ctx: Context<'_>,
@ -57,8 +63,9 @@ VALUES ((SELECT id FROM guilds WHERE guild = ?), ?)",
#[poise::command( #[poise::command(
slash_command, slash_command,
rename = "view", rename = "view",
check = "guild_only", guild_only = true,
identifying_name = "todo_guild_view" identifying_name = "todo_guild_view",
default_member_permissions = "MANAGE_GUILD"
)] )]
pub async fn todo_guild_view(ctx: Context<'_>) -> Result<(), Error> { pub async fn todo_guild_view(ctx: Context<'_>) -> Result<(), Error> {
let values = sqlx::query!( let values = sqlx::query!(
@ -89,8 +96,9 @@ WHERE guilds.guild = ?",
#[poise::command( #[poise::command(
slash_command, slash_command,
rename = "channel", rename = "channel",
check = "guild_only", guild_only = true,
identifying_name = "todo_channel_base" identifying_name = "todo_channel_base",
default_member_permissions = "MANAGE_GUILD"
)] )]
pub async fn todo_channel_base(_ctx: Context<'_>) -> Result<(), Error> { pub async fn todo_channel_base(_ctx: Context<'_>) -> Result<(), Error> {
Ok(()) Ok(())
@ -100,8 +108,9 @@ pub async fn todo_channel_base(_ctx: Context<'_>) -> Result<(), Error> {
#[poise::command( #[poise::command(
slash_command, slash_command,
rename = "add", rename = "add",
check = "guild_only", guild_only = true,
identifying_name = "todo_channel_add" identifying_name = "todo_channel_add",
default_member_permissions = "MANAGE_GUILD"
)] )]
pub async fn todo_channel_add( pub async fn todo_channel_add(
ctx: Context<'_>, ctx: Context<'_>,
@ -127,8 +136,9 @@ VALUES ((SELECT id FROM guilds WHERE guild = ?), (SELECT id FROM channels WHERE
#[poise::command( #[poise::command(
slash_command, slash_command,
rename = "view", rename = "view",
check = "guild_only", guild_only = true,
identifying_name = "todo_channel_view" identifying_name = "todo_channel_view",
default_member_permissions = "MANAGE_GUILD"
)] )]
pub async fn todo_channel_view(ctx: Context<'_>) -> Result<(), Error> { pub async fn todo_channel_view(ctx: Context<'_>) -> Result<(), Error> {
let values = sqlx::query!( let values = sqlx::query!(

View File

@ -2,16 +2,6 @@ use poise::serenity::model::channel::Channel;
use crate::{consts::MACRO_MAX_COMMANDS, models::command_macro::RecordedCommand, Context, Error}; 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 { async fn macro_check(ctx: Context<'_>) -> bool {
if let Context::Application(app_ctx) = ctx { if let Context::Application(app_ctx) = ctx {
if let Some(guild_id) = ctx.guild_id() { if let Some(guild_id) = ctx.guild_id() {

View File

@ -59,7 +59,7 @@ impl Data {
guild_id: GuildId, guild_id: GuildId,
) -> Result<Vec<CommandMacro<Data, Error>>, Error> { ) -> Result<Vec<CommandMacro<Data, Error>>, Error> {
let rows = sqlx::query!( 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 guild_id.0
) )
.fetch_all(&self.database) .fetch_all(&self.database)
@ -67,7 +67,7 @@ impl Data {
guild_id, guild_id,
name: row.name.clone(), name: row.name.clone(),
description: row.description.clone(), description: row.description.clone(),
commands: vec![] commands: serde_json::from_str(&row.commands).unwrap(),
}).collect(); }).collect();
Ok(rows) Ok(rows)

View File

@ -186,12 +186,12 @@
<div class="modal-background"></div> <div class="modal-background"></div>
<div class="modal-card"> <div class="modal-card">
<header class="modal-card-head"> <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> <button class="delete close-modal" aria-label="close"></button>
</header> </header>
<section class="modal-card-body"> <section class="modal-card-body">
<p> <p>
This reminder will be permenantly deleted. Are you sure? This reminder will be permanently deleted. Are you sure?
</p> </p>
<br> <br>
<div class="has-text-centered"> <div class="has-text-centered">