aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock263
-rw-r--r--Cargo.toml9
-rw-r--r--src/commands/reactionroles.rs132
-rw-r--r--src/main.rs2
-rw-r--r--src/models.rs2
5 files changed, 168 insertions, 240 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 2e87466..bbfd098 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -14,7 +14,7 @@ version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47"
dependencies = [
- "getrandom 0.2.3",
+ "getrandom",
"once_cell",
"version_check",
]
@@ -41,22 +41,6 @@ dependencies = [
[[package]]
name = "async-tungstenite"
-version = "0.11.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f7cc5408453d37e2b1c6f01d8078af1da58b6cfa6a80fa2ede3bd2b9a6ada9c4"
-dependencies = [
- "futures-io",
- "futures-util",
- "log",
- "pin-project",
- "tokio",
- "tokio-rustls 0.22.0",
- "tungstenite 0.11.1",
- "webpki-roots 0.20.0",
-]
-
-[[package]]
-name = "async-tungstenite"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5682ea0913e5c20780fe5785abacb85a411e7437bf52a1bedb93ddb3972cb8dd"
@@ -67,7 +51,7 @@ dependencies = [
"pin-project-lite",
"tokio",
"tokio-rustls 0.23.2",
- "tungstenite 0.16.0",
+ "tungstenite",
"webpki-roots 0.22.2",
]
@@ -88,12 +72,6 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
name = "base64"
-version = "0.12.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff"
-
-[[package]]
-name = "base64"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
@@ -127,12 +105,6 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]]
name = "bytes"
-version = "0.5.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38"
-
-[[package]]
-name = "bytes"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8"
@@ -164,17 +136,6 @@ dependencies = [
]
[[package]]
-name = "command_attr"
-version = "0.3.7"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8a6c3666f685cb1efc0628b8c984dbad9c372d080450736c7732089c385ed81d"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn",
-]
-
-[[package]]
name = "core-foundation"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -491,24 +452,13 @@ dependencies = [
[[package]]
name = "getrandom"
-version = "0.1.16"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce"
-dependencies = [
- "cfg-if",
- "libc",
- "wasi 0.9.0+wasi-snapshot-preview1",
-]
-
-[[package]]
-name = "getrandom"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753"
dependencies = [
"cfg-if",
"libc",
- "wasi 0.10.0+wasi-snapshot-preview1",
+ "wasi",
]
[[package]]
@@ -519,11 +469,11 @@ dependencies = [
"dotenv",
"log",
"poise",
- "rand 0.8.4",
+ "rand",
"reqwest",
"serde",
"serde_json",
- "serenity 0.10.9 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serenity",
"sqlx",
"tokio",
"tracing",
@@ -536,7 +486,7 @@ version = "0.3.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c9de88456263e249e241fcd211d3954e2c9b0ef7ccfc235a444eb367cae3689"
dependencies = [
- "bytes 1.1.0",
+ "bytes",
"fnv",
"futures-core",
"futures-sink",
@@ -607,7 +557,7 @@ version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31f4c6746584866f0feabcc69893c5b51beef3831656a968ed7ae254cdc4fd03"
dependencies = [
- "bytes 1.1.0",
+ "bytes",
"fnv",
"itoa 1.0.1",
]
@@ -618,7 +568,7 @@ version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ff4f84919677303da5f147645dbea6b1881f368d03ac84e1dc09031ebd7b2c6"
dependencies = [
- "bytes 1.1.0",
+ "bytes",
"http",
"pin-project-lite",
]
@@ -641,7 +591,7 @@ version = "0.14.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7ec3e62bdc98a2f0393a5048e4c30ef659440ea6e0e572965103e72bd836f55"
dependencies = [
- "bytes 1.1.0",
+ "bytes",
"futures-channel",
"futures-core",
"futures-util",
@@ -678,7 +628,7 @@ version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905"
dependencies = [
- "bytes 1.1.0",
+ "bytes",
"hyper",
"native-tls",
"tokio",
@@ -713,15 +663,6 @@ dependencies = [
]
[[package]]
-name = "input_buffer"
-version = "0.3.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "19a8a95243d5a0398cae618ec29477c6e3cb631152be5c19481f80bc71559754"
-dependencies = [
- "bytes 0.5.6",
-]
-
-[[package]]
name = "instant"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1026,26 +967,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
[[package]]
-name = "pin-project"
-version = "1.0.10"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "58ad3879ad3baf4e44784bc6a718a8698867bb991f8ce24d1bcbe2cfb4c3a75e"
-dependencies = [
- "pin-project-internal",
-]
-
-[[package]]
-name = "pin-project-internal"
-version = "1.0.10"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "744b6f092ba29c3650faf274db506afd39944f48420f6c86b17cfe0ee1cb36bb"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn",
-]
-
-[[package]]
name = "pin-project-lite"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1074,7 +995,7 @@ dependencies = [
"once_cell",
"poise_macros",
"regex",
- "serenity 0.10.9 (git+https://github.com/serenity-rs/serenity?branch=next)",
+ "serenity",
"tokio",
]
@@ -1115,37 +1036,14 @@ dependencies = [
[[package]]
name = "rand"
-version = "0.7.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
-dependencies = [
- "getrandom 0.1.16",
- "libc",
- "rand_chacha 0.2.2",
- "rand_core 0.5.1",
- "rand_hc 0.2.0",
-]
-
-[[package]]
-name = "rand"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8"
dependencies = [
"libc",
- "rand_chacha 0.3.1",
- "rand_core 0.6.3",
- "rand_hc 0.3.1",
-]
-
-[[package]]
-name = "rand_chacha"
-version = "0.2.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
-dependencies = [
- "ppv-lite86",
- "rand_core 0.5.1",
+ "rand_chacha",
+ "rand_core",
+ "rand_hc",
]
[[package]]
@@ -1155,16 +1053,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
- "rand_core 0.6.3",
-]
-
-[[package]]
-name = "rand_core"
-version = "0.5.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
-dependencies = [
- "getrandom 0.1.16",
+ "rand_core",
]
[[package]]
@@ -1173,16 +1062,7 @@ version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
dependencies = [
- "getrandom 0.2.3",
-]
-
-[[package]]
-name = "rand_hc"
-version = "0.2.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
-dependencies = [
- "rand_core 0.5.1",
+ "getrandom",
]
[[package]]
@@ -1191,7 +1071,7 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7"
dependencies = [
- "rand_core 0.6.3",
+ "rand_core",
]
[[package]]
@@ -1209,7 +1089,7 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64"
dependencies = [
- "getrandom 0.2.3",
+ "getrandom",
"redox_syscall",
]
@@ -1252,8 +1132,8 @@ version = "0.11.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c4e0a76dc12a116108933f6301b95e83634e0c47b0afbed6abbaa0601e99258"
dependencies = [
- "base64 0.13.0",
- "bytes 1.1.0",
+ "base64",
+ "bytes",
"encoding_rs",
"futures-core",
"futures-util",
@@ -1309,7 +1189,7 @@ version = "0.19.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7"
dependencies = [
- "base64 0.13.0",
+ "base64",
"log",
"ring",
"sct 0.6.1",
@@ -1334,7 +1214,7 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5eebeaeb360c87bfb72e84abdb3447159c0eaececf1bef2aecd65a8be949d1c9"
dependencies = [
- "base64 0.13.0",
+ "base64",
]
[[package]]
@@ -1448,40 +1328,13 @@ dependencies = [
[[package]]
name = "serenity"
version = "0.10.9"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6275d443266aedf2be507a245ddc23db0c07b1b99774e16f3c879e96a78b067a"
-dependencies = [
- "async-trait",
- "async-tungstenite 0.11.0",
- "base64 0.13.0",
- "bitflags",
- "bytes 1.1.0",
- "chrono",
- "command_attr",
- "flate2",
- "futures",
- "percent-encoding",
- "reqwest",
- "serde",
- "serde_json",
- "static_assertions",
- "tokio",
- "tracing",
- "typemap_rev",
- "url",
- "uwl",
-]
-
-[[package]]
-name = "serenity"
-version = "0.10.9"
source = "git+https://github.com/serenity-rs/serenity?branch=next#81fd4cf3911fdfd59dc76ed791a6e33dac8c775b"
dependencies = [
"async-trait",
- "async-tungstenite 0.16.1",
- "base64 0.13.0",
+ "async-tungstenite",
+ "base64",
"bitflags",
- "bytes 1.1.0",
+ "bytes",
"chrono",
"dashmap",
"flate2",
@@ -1600,10 +1453,10 @@ checksum = "518be6f6fff5ca76f985d434f9c37f3662af279642acf730388f271dff7b9016"
dependencies = [
"ahash",
"atoi",
- "base64 0.13.0",
+ "base64",
"bitflags",
"byteorder",
- "bytes 1.1.0",
+ "bytes",
"chrono",
"crc",
"crossbeam-channel",
@@ -1627,7 +1480,7 @@ dependencies = [
"once_cell",
"parking_lot",
"percent-encoding",
- "rand 0.8.4",
+ "rand",
"rustls 0.19.1",
"serde",
"serde_json",
@@ -1677,12 +1530,6 @@ dependencies = [
]
[[package]]
-name = "static_assertions"
-version = "1.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
-
-[[package]]
name = "stringprep"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1723,7 +1570,7 @@ checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22"
dependencies = [
"cfg-if",
"libc",
- "rand 0.8.4",
+ "rand",
"redox_syscall",
"remove_dir_all",
"winapi",
@@ -1765,7 +1612,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
dependencies = [
"libc",
- "wasi 0.10.0+wasi-snapshot-preview1",
+ "wasi",
"winapi",
]
@@ -1790,7 +1637,7 @@ version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbbf1c778ec206785635ce8ad57fe52b3009ae9e0c9f574a728f3049d3e55838"
dependencies = [
- "bytes 1.1.0",
+ "bytes",
"libc",
"memchr",
"mio",
@@ -1862,7 +1709,7 @@ version = "0.6.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e99e1983e5d376cd8eb4b66604d2e99e79f5bd988c3055891dcd8c9e2604cc0"
dependencies = [
- "bytes 1.1.0",
+ "bytes",
"futures-core",
"futures-sink",
"log",
@@ -1960,36 +1807,17 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642"
[[package]]
name = "tungstenite"
-version = "0.11.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f0308d80d86700c5878b9ef6321f020f29b1bb9d5ff3cab25e75e23f3a492a23"
-dependencies = [
- "base64 0.12.3",
- "byteorder",
- "bytes 0.5.6",
- "http",
- "httparse",
- "input_buffer",
- "log",
- "rand 0.7.3",
- "sha-1",
- "url",
- "utf-8",
-]
-
-[[package]]
-name = "tungstenite"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ad3713a14ae247f22a728a0456a545df14acf3867f905adff84be99e23b3ad1"
dependencies = [
- "base64 0.13.0",
+ "base64",
"byteorder",
- "bytes 1.1.0",
+ "bytes",
"http",
"httparse",
"log",
- "rand 0.8.4",
+ "rand",
"rustls 0.20.2",
"sha-1",
"thiserror",
@@ -2084,12 +1912,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
[[package]]
-name = "uwl"
-version = "0.6.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f4bf03e0ca70d626ecc4ba6b0763b934b6f2976e8c744088bb3c1d646fbb1ad0"
-
-[[package]]
name = "vcpkg"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2113,12 +1935,6 @@ dependencies = [
[[package]]
name = "wasi"
-version = "0.9.0+wasi-snapshot-preview1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
-
-[[package]]
-name = "wasi"
version = "0.10.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
@@ -2221,15 +2037,6 @@ dependencies = [
[[package]]
name = "webpki-roots"
-version = "0.20.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0f20dea7535251981a9670857150d571846545088359b28e4951d350bdaf179f"
-dependencies = [
- "webpki 0.21.4",
-]
-
-[[package]]
-name = "webpki-roots"
version = "0.21.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aabe153544e473b775453675851ecc86863d2a81d786d741f6b76778f2a48940"
diff --git a/Cargo.toml b/Cargo.toml
index e17a57c..44b16bc 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -18,19 +18,22 @@ reqwest = "0.11"
chrono = { version = "0.4", features = ["serde"] }
[dependencies.serenity]
-version = "0.10"
+git = "https://github.com/serenity-rs/serenity"
+branch = "next"
default-features = false
features = [
"rustls_backend",
"cache",
"client",
- "framework",
"gateway",
"model",
- "standard_framework",
"utils",
"collector",
]
+[patch.crates-io.serenity]
+git = "https://github.com/serenity-rs/serenity"
+branch = "next"
+
[dependencies.poise]
git = "https://github.com/kangalioo/poise"
diff --git a/src/commands/reactionroles.rs b/src/commands/reactionroles.rs
index 8d448ed..65de61a 100644
--- a/src/commands/reactionroles.rs
+++ b/src/commands/reactionroles.rs
@@ -1,8 +1,10 @@
use std::{str::FromStr, time::Duration};
use crate::{models::ReactionRole, Context, Error};
-use ::serenity::framework::standard::{Args, Delimiter};
-use poise::serenity_prelude::{self as serenity, ArgumentConvert, Emoji, ReactionType};
+use ::serenity::{
+ model::{guild::Role, id::ChannelId},
+};
+use poise::serenity_prelude::{self as serenity, ArgumentConvert, Emoji, ReactionType, RoleId};
#[cfg(debug_assertions)]
async fn allowed_to_create_roles(ctx: Context<'_>) -> Result<bool, Error> {
@@ -174,11 +176,8 @@ pub async fn init(
)
.fetch_all(&pool)
.await?;
- let mut rolelist_formatted =
- String::from("Choose the appropriate reaction to gain the role!\n\n");
- for r in reactions {
- rolelist_formatted.push_str(&format!("{} - <@&{}>\n", r.reaction, r.role_id));
- }
+
+ let rolelist_formatted = gen_reaction_list(reactions);
let title = rolemenu_msg.clone().embeds[0]
.title
@@ -204,6 +203,95 @@ pub async fn init(
Ok(())
}
+/// Adds a reaction role to the message
+///
+/// Usage:
+/// ~rroles add <Message ID> <emoji> <role>
+#[poise::command(prefix_command, check = "allowed_to_create_roles")]
+pub async fn add(
+ ctx: Context<'_>,
+ #[description = "The Message ID"] message_id: u64,
+ #[description = "The emoji to assign to the role"] emoji: ReactionType,
+ #[description = "The role to assign to the emoji"] role_name: String,
+) -> Result<(), Error> {
+ {
+ let pool = ctx.data().pg.lock().unwrap().clone();
+ // Make sure the emoji doesn't already exist
+ if let Ok(_) = sqlx::query!("SELECT * FROM reaction_roles WHERE message_id=$1 AND reaction=$2", message_id.to_string(), emoji.to_string()).fetch_one(&pool).await {
+ ctx.say("Whoops! That emoji already has something assigned to it! Try either removing it or picking a different emoji").await?;
+ return Ok(());
+ }
+ let role_menu = sqlx::query_as!(
+ ReactionRole,
+ "SELECT * FROM reaction_roles WHERE message_id=$1",
+ message_id.to_string()
+ )
+ .fetch_one(&pool)
+ .await?;
+ let guild = ctx.guild().unwrap();
+ let role = guild.role_by_name(&role_name).clone();
+ if let Some(r) = role.clone() {
+ let r = r.clone();
+ let channel_id = ChannelId(role_menu.channel_id.parse::<u64>()?);
+ sqlx::query!("INSERT INTO reaction_roles (channel_id, message_id, guild_id, reaction, role_id) VALUES ($1, $2, $3, $4, $5)", role_menu.channel_id.to_string(), role_menu.message_id.to_string(), ctx.guild_id().unwrap().0.to_string(), emoji.to_string(), r.id.to_string()).execute(&pool).await?;
+ let all_reactions = sqlx::query_as!(
+ ReactionRole,
+ "SELECT * FROM reaction_roles WHERE message_id=$1",
+ message_id.to_string()
+ )
+ .fetch_all(&pool)
+ .await?;
+ let channel = channel_id.to_channel(&ctx.discord()).await?;
+ let mut menu_msg = channel
+ .guild()
+ .unwrap()
+ .message(ctx.discord(), role_menu.message_id.parse::<u64>()?)
+ .await?;
+
+ update_menu(ctx, menu_msg).await?;
+
+ ctx.say("Done! I've added that to the list for you").await?;
+ } else {
+ ctx.say("Whoops! That role doesn't exist!").await?;
+ return Ok(());
+ }
+ }
+
+ Ok(())
+}
+
+/// Removes a reaction from the menu
+///
+/// Usage:
+/// ~rroles del <Message ID> <emoji>
+#[poise::command(prefix_command, check = "allowed_to_create_roles")]
+pub async fn del(ctx: Context<'_>,
+ #[description = "The Message ID of the menu"]
+ message_id: u64,
+ #[description = "The emoji you want to remove"]
+ emoji: ReactionType,
+ ) -> Result<(), Error> {
+ {
+ let pool = ctx.data().pg.lock().unwrap().clone();
+ let reaction_with_menu = sqlx::query_as!(ReactionRole, "SELECT * FROM reaction_roles WHERE message_id=$1 AND reaction=$2", message_id.to_string(), emoji.to_string()).fetch_one(&pool).await?;
+ let channel_id = ChannelId(reaction_with_menu.channel_id.parse::<u64>()?);
+ let channel = channel_id.to_channel(ctx.discord()).await?;
+ let mut message = channel.guild().unwrap().message(ctx.discord(), message_id).await?;
+
+ // Delete from DB
+ // We can just use `ReactionRole.id` here to avoid having to do more complex conditionals
+ sqlx::query!("DELETE FROM reaction_roles WHERE id=$1", reaction_with_menu.id).execute(&pool).await?;
+
+ message.delete_reaction_emoji(ctx.discord(), emoji).await?;
+
+ update_menu(ctx, message).await?;
+ }
+
+ ctx.say("Alright! I've removed that emoji from the menu.").await?;
+
+ Ok(())
+}
+
fn get_reactiontype_display(rt: &ReactionType) -> String {
match rt {
ReactionType::Unicode(emote) => emote.clone(),
@@ -217,3 +305,33 @@ fn get_reactiontype_display(rt: &ReactionType) -> String {
_ => String::new(),
}
}
+
+fn gen_reaction_list(reacts: Vec<ReactionRole>) -> String {
+ let mut rolelist_formatted =
+ String::from("Choose the appropriate reaction to gain the role!\n\n");
+ for r in reacts {
+ rolelist_formatted.push_str(&format!("{} - <@&{}>\n", r.reaction, r.role_id));
+ }
+ rolelist_formatted
+}
+
+async fn update_menu(ctx: Context<'_>, mut msg: serenity::Message) -> Result<serenity::Message, Error> {
+ {
+ let pool = ctx.data().pg.lock().unwrap().clone();
+ let all_reactions = sqlx::query_as!(ReactionRole, "SELECT * FROM reaction_roles WHERE message_id=$1", msg.id.0.to_string()).fetch_all(&pool).await?;
+ let rolelist_formatted = gen_reaction_list(all_reactions.clone());
+ let title = msg.clone().embeds[0].title.clone().unwrap();
+ msg.edit(ctx.discord(), |m| {
+ m.embed(|e| {
+ e.title(title);
+ e.description(rolelist_formatted)
+ })
+ }).await?;
+
+ for r in all_reactions.iter() {
+ msg.react(ctx.discord(), ReactionType::from_str(&r.reaction)?).await?;
+ }
+ }
+
+ Ok(msg)
+}
diff --git a/src/main.rs b/src/main.rs
index 4698fb1..bfd39c7 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -70,7 +70,7 @@ async fn main() {
commands::osu::osup(),
commands::osu::osubm(),
poise::Command {
- subcommands: vec![commands::reactionroles::init()],
+ subcommands: vec![commands::reactionroles::init(), commands::reactionroles::add(), commands::reactionroles::del(),],
..commands::reactionroles::rroles()
},
],
diff --git a/src/models.rs b/src/models.rs
index 4b2e7bb..431204a 100644
--- a/src/models.rs
+++ b/src/models.rs
@@ -1,4 +1,4 @@
-#[derive(Debug)]
+#[derive(Debug, Clone)]
pub struct ReactionRole {
pub id: i32,
pub channel_id: String,