Wip commit

This commit is contained in:
jude
2024-01-06 19:48:17 +00:00
parent cce0de7c75
commit e4e9af2bb4
37 changed files with 1051 additions and 1366 deletions
+1 -1
View File
@@ -18,7 +18,7 @@ pub async fn delete_macro(
match sqlx::query!(
"
SELECT id FROM macro WHERE guild_id = (SELECT id FROM guilds WHERE guild = ?) AND name = ?",
ctx.guild_id().unwrap().0,
ctx.guild_id().unwrap().get(),
name
)
.fetch_one(&ctx.data().database)
+17 -28
View File
@@ -1,4 +1,7 @@
use poise::CreateReply;
use poise::{
serenity_prelude::{CreateEmbed, CreateEmbedFooter},
CreateReply,
};
use crate::{
component_models::pager::{MacroPager, Pager},
@@ -20,11 +23,7 @@ pub async fn list_macro(ctx: Context<'_>) -> Result<(), Error> {
let resp = show_macro_page(&macros, 0);
ctx.send(|m| {
*m = resp;
m
})
.await?;
ctx.send(resp).await?;
Ok(())
}
@@ -37,15 +36,12 @@ pub fn show_macro_page<U, E>(macros: &[CommandMacro<U, E>], page: usize) -> Crea
let pager = MacroPager::new(page);
if macros.is_empty() {
let mut reply = CreateReply::default();
reply.embed(|e| {
e.title("Macros")
return CreateReply::default().embed(
CreateEmbed::new()
.title("Macros")
.description("No Macros Set Up. Use `/macro record` to get started.")
.color(*THEME_COLOR)
});
return reply;
.color(*THEME_COLOR),
);
}
let pages = max_macro_page(macros);
@@ -70,20 +66,13 @@ pub fn show_macro_page<U, E>(macros: &[CommandMacro<U, E>], page: usize) -> Crea
}
});
let mut reply = CreateReply::default();
reply
.embed(|e| {
e.title("Macros")
CreateReply::default()
.embed(
CreateEmbed::new()
.title("Macros")
.fields(fields)
.footer(|f| f.text(format!("Page {} of {}", page + 1, pages)))
.color(*THEME_COLOR)
})
.components(|comp| {
pager.create_button_row(pages, comp);
comp
});
reply
.footer(CreateEmbedFooter::new(format!("Page {} of {}", page + 1, pages))),
)
.components(vec![pager.create_button_row(pages)])
}
+4 -4
View File
@@ -1,5 +1,5 @@
use lazy_regex::regex;
use poise::serenity_prelude::CommandOptionType;
use poise::{serenity_prelude::CommandOptionType, CreateReply};
use regex::Captures;
use serde_json::{json, Value};
@@ -25,7 +25,7 @@ pub async fn migrate_macro(ctx: Context<'_>) -> Result<(), Error> {
let aliases = sqlx::query_as!(
Alias,
"SELECT name, command FROM command_aliases WHERE guild_id = (SELECT id FROM guilds WHERE guild = ?)",
guild_id.0
guild_id.get()
)
.fetch_all(&mut *transaction)
.await?;
@@ -37,7 +37,7 @@ pub async fn migrate_macro(ctx: Context<'_>) -> Result<(), Error> {
Some(cmd_macro) => {
sqlx::query!(
"INSERT INTO macro (guild_id, name, description, commands) VALUES ((SELECT id FROM guilds WHERE guild = ?), ?, ?, ?)",
cmd_macro.guild_id.0,
cmd_macro.guild_id.get(),
cmd_macro.name,
cmd_macro.description,
cmd_macro.commands
@@ -54,7 +54,7 @@ pub async fn migrate_macro(ctx: Context<'_>) -> Result<(), Error> {
transaction.commit().await?;
ctx.send(|b| b.content(format!("Added {} macros.", added_aliases))).await?;
ctx.send(CreateReply::default().content(format!("Added {} macros.", added_aliases))).await?;
Ok(())
}
+39 -32
View File
@@ -1,5 +1,7 @@
use std::collections::hash_map::Entry;
use poise::{serenity_prelude::CreateEmbed, CreateReply};
use crate::{consts::THEME_COLOR, models::command_macro::CommandMacro, Context, Error};
/// Start recording up to 5 commands to replay
@@ -32,23 +34,24 @@ pub async fn record_macro(
let row = sqlx::query!(
"
SELECT 1 as _e FROM macro WHERE guild_id = (SELECT id FROM guilds WHERE guild = ?) AND name = ?",
guild_id.0,
guild_id.get(),
name
)
.fetch_one(&ctx.data().database)
.await;
if row.is_ok() {
ctx.send(|m| {
m.ephemeral(true).embed(|e| {
e.title("Unique Name Required")
ctx.send(
CreateReply::default().ephemeral(true).embed(
CreateEmbed::new()
.title("Unique Name Required")
.description(
"A macro already exists under this name.
Please select a unique name for your macro.",
)
.color(*THEME_COLOR)
})
})
.color(*THEME_COLOR),
),
)
.await?;
} else {
let okay = {
@@ -63,28 +66,30 @@ Please select a unique name for your macro.",
};
if okay {
ctx.send(|m| {
m.ephemeral(true).embed(|e| {
e.title("Macro Recording Started")
ctx.send(
CreateReply::default().ephemeral(true).embed(
CreateEmbed::new()
.title("Macro Recording Started")
.description(
"Run up to 5 commands, or type `/macro finish` to stop at any point.
Any commands ran as part of recording will be inconsequential",
)
.color(*THEME_COLOR)
})
})
.color(*THEME_COLOR),
),
)
.await?;
} else {
ctx.send(|m| {
m.ephemeral(true).embed(|e| {
e.title("Macro Already Recording")
ctx.send(
CreateReply::default().ephemeral(true).embed(
CreateEmbed::new()
.title("Macro Already Recording")
.description(
"You are already recording a macro in this server.
Please use `/macro finish` to end this recording before starting another.",
)
.color(*THEME_COLOR)
})
})
.color(*THEME_COLOR),
),
)
.await?;
}
}
@@ -108,13 +113,14 @@ pub async fn finish_macro(ctx: Context<'_>) -> Result<(), Error> {
let contained = lock.get(&key);
if contained.map_or(true, |cmacro| cmacro.commands.is_empty()) {
ctx.send(|m| {
m.embed(|e| {
e.title("No Macro Recorded")
ctx.send(
CreateReply::default().embed(
CreateEmbed::new()
.title("No Macro Recorded")
.description("Use `/macro record` to start recording a macro")
.color(*THEME_COLOR)
})
})
.color(*THEME_COLOR),
),
)
.await?;
} else {
let command_macro = contained.unwrap();
@@ -122,7 +128,7 @@ pub async fn finish_macro(ctx: Context<'_>) -> Result<(), Error> {
sqlx::query!(
"INSERT INTO macro (guild_id, name, description, commands) VALUES ((SELECT id FROM guilds WHERE guild = ?), ?, ?, ?)",
command_macro.guild_id.0,
command_macro.guild_id.get(),
command_macro.name,
command_macro.description,
json
@@ -131,13 +137,14 @@ pub async fn finish_macro(ctx: Context<'_>) -> Result<(), Error> {
.await
.unwrap();
ctx.send(|m| {
m.embed(|e| {
e.title("Macro Recorded")
ctx.send(
CreateReply::default().embed(
CreateEmbed::new()
.title("Macro Recorded")
.description("Use `/macro run` to execute the macro")
.color(*THEME_COLOR)
})
})
.color(*THEME_COLOR),
),
)
.await?;
}
}
+11 -6
View File
@@ -1,3 +1,8 @@
use poise::{
serenity_prelude::{CommandOption, CreateEmbed},
CreateReply,
};
use super::super::autocomplete::macro_name_autocomplete;
use crate::{models::command_macro::guild_command_macro, Context, Data, Error, THEME_COLOR};
@@ -18,15 +23,15 @@ pub async fn run_macro(
match guild_command_macro(&Context::Application(ctx), &name).await {
Some(command_macro) => {
Context::Application(ctx)
.send(|b| {
b.embed(|e| {
e.title("Running Macro").color(*THEME_COLOR).description(format!(
.send(CreateReply::default().embed(
CreateEmbed::new().title("Running Macro").color(*THEME_COLOR).description(
format!(
"Running macro {} ({} commands)",
command_macro.name,
command_macro.commands.len()
))
})
})
),
),
))
.await?;
for command in command_macro.commands {