create reminders :)

This commit is contained in:
jude 2022-03-19 17:41:34 +00:00
parent e2e5b022a0
commit d0d2d50966
14 changed files with 232 additions and 128 deletions

160
Cargo.lock generated
View File

@ -49,7 +49,7 @@ version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47"
dependencies = [
"getrandom 0.2.4",
"getrandom 0.2.5",
"once_cell",
"version_check",
]
@ -74,9 +74,9 @@ dependencies = [
[[package]]
name = "async-stream"
version = "0.3.2"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "171374e7e3b2504e0e5236e3b59260560f9fe94bfe9ac39ba5e4e929c5590625"
checksum = "dad5c83079eae9969be7fadefe640a1c566901f05ff91ab221de4b6f68d9507e"
dependencies = [
"async-stream-impl",
"futures-core",
@ -84,9 +84,9 @@ dependencies = [
[[package]]
name = "async-stream-impl"
version = "0.3.2"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "648ed8c8d2ce5409ccd57453d9d1b214b342a0d69376a6feda1fd6cae3299308"
checksum = "10f203db73a71dfa2fb6dd22763990fa26f3d2625a6da2da900d23b87d26be27"
dependencies = [
"proc-macro2",
"quote",
@ -387,9 +387,9 @@ checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
[[package]]
name = "cpufeatures"
version = "0.2.1"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95059428f66df56b63431fdb4e1947ed2190586af5c5a8a8b71122bdf5a7f469"
checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b"
dependencies = [
"libc",
]
@ -420,9 +420,9 @@ dependencies = [
[[package]]
name = "crossbeam-queue"
version = "0.3.4"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4dd435b205a4842da59efd07628f921c096bc1cc0a156835b4fa0bcb9a19bcce"
checksum = "1f25d8400f4a7a5778f0e4e52384a48cbd9b5c495d110786187fc750075277a2"
dependencies = [
"cfg-if 1.0.0",
"crossbeam-utils",
@ -430,9 +430,9 @@ dependencies = [
[[package]]
name = "crossbeam-utils"
version = "0.8.7"
version = "0.8.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5e5bed1f1c269533fa816a0a5492b3545209a205ca1a54842be180eb63a16a6"
checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38"
dependencies = [
"cfg-if 1.0.0",
"lazy_static",
@ -505,12 +505,13 @@ dependencies = [
[[package]]
name = "dashmap"
version = "4.0.2"
version = "5.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e77a43b28d0668df09411cb0bc9a8c2adc40f9a048afe863e05fd43251e8e39c"
checksum = "4c8858831f7781322e539ea39e72449c46b059638250c14344fec8d0aa6e539c"
dependencies = [
"cfg-if 1.0.0",
"num_cpus",
"parking_lot 0.12.0",
"serde",
]
@ -866,9 +867,9 @@ dependencies = [
[[package]]
name = "getrandom"
version = "0.2.4"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c"
checksum = "d39cd93900197114fa1fcb7ae84ca742095eed9442088988ae74fa744e930e77"
dependencies = [
"cfg-if 1.0.0",
"js-sys",
@ -919,9 +920,9 @@ dependencies = [
[[package]]
name = "h2"
version = "0.3.11"
version = "0.3.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9f1f717ddc7b2ba36df7e871fd88db79326551d3d6f1fc406fbfd28b582ff8e"
checksum = "62eeb471aa3e3c9197aa4bfeabfe02982f6dc96f750486c0bb0009ac58b26d2b"
dependencies = [
"bytes",
"fnv",
@ -1184,9 +1185,9 @@ dependencies = [
[[package]]
name = "ipnet"
version = "2.3.1"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68f2d64f2edebec4ce84ad108148e67e1064789bee435edc5b60ad398714a3a9"
checksum = "35e70ee094dc02fd9c13fdad4940090f22dbd6ac7c9e7094a46cf0232a50bc7c"
[[package]]
name = "itertools"
@ -1245,9 +1246,9 @@ checksum = "db13adb97ab515a3691f56e4dbab09283d0b86cb45abd991d8634a9d6f501760"
[[package]]
name = "libc"
version = "0.2.118"
version = "0.2.121"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06e509672465a0504304aa87f9f176f2b2b716ed8fb105ebe5c02dc6dce96a94"
checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f"
[[package]]
name = "libm"
@ -1368,14 +1369,15 @@ dependencies = [
[[package]]
name = "mio"
version = "0.8.0"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba272f85fa0b41fc91872be579b3bbe0f56b792aa361a380eb669469f68dafb2"
checksum = "52da4364ffb0e4fe33a9841a98a3f3014fb964045ce4f7a45a398243c8d6b0c9"
dependencies = [
"libc",
"log",
"miow 0.3.7",
"ntapi",
"wasi 0.11.0+wasi-snapshot-preview1",
"winapi 0.3.9",
]
@ -1463,13 +1465,12 @@ dependencies = [
[[package]]
name = "nom"
version = "7.1.0"
version = "7.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b1d11e1ef389c76fe5b81bcaf2ea32cf88b62bc494e19f493d0b30e7a930109"
checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36"
dependencies = [
"memchr",
"minimal-lexical",
"version_check",
]
[[package]]
@ -1580,9 +1581,9 @@ dependencies = [
[[package]]
name = "num_threads"
version = "0.1.3"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97ba99ba6393e2c3734791401b66902d981cb03bf190af674ca69949b6d5fb15"
checksum = "aba1801fb138d8e85e11d0fc70baf4fe1cdfffda7c6cd34a854905df588e5ed0"
dependencies = [
"libc",
]
@ -1595,7 +1596,7 @@ checksum = "80e47cfc4c0a1a519d9a025ebfbac3a2439d1b5cdf397d72dcb79b11d9920dab"
dependencies = [
"base64",
"chrono",
"getrandom 0.2.4",
"getrandom 0.2.5",
"http",
"rand 0.8.5",
"reqwest",
@ -1609,9 +1610,9 @@ dependencies = [
[[package]]
name = "once_cell"
version = "1.9.0"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5"
checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9"
[[package]]
name = "opaque-debug"
@ -1658,6 +1659,15 @@ dependencies = [
"vcpkg",
]
[[package]]
name = "ordered-float"
version = "2.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7940cf2ca942593318d07fcf2596cdca60a85c9e7fab408a5e21a4f9dcd40d87"
dependencies = [
"num-traits",
]
[[package]]
name = "parking_lot"
version = "0.11.2"
@ -1886,10 +1896,12 @@ checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe"
[[package]]
name = "poise"
version = "0.1.0"
source = "git+https://github.com/kangalioo/poise?branch=master#0fc5d548e32fc7e3c8ea490afe95db00ec17ec24"
dependencies = [
"async-trait",
"futures-core",
"futures-util",
"log",
"once_cell",
"poise_macros",
"regex",
@ -1900,6 +1912,7 @@ dependencies = [
[[package]]
name = "poise_macros"
version = "0.1.0"
source = "git+https://github.com/kangalioo/poise?branch=master#0fc5d548e32fc7e3c8ea490afe95db00ec17ec24"
dependencies = [
"darling",
"proc-macro2",
@ -1965,9 +1978,9 @@ dependencies = [
[[package]]
name = "quote"
version = "1.0.15"
version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145"
checksum = "b4af2ec4714533fcdf07e886f17025ace8b997b9ce51204ee69b6da831c3da57"
dependencies = [
"proc-macro2",
]
@ -2031,7 +2044,7 @@ version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
dependencies = [
"getrandom 0.2.4",
"getrandom 0.2.5",
]
[[package]]
@ -2045,9 +2058,9 @@ dependencies = [
[[package]]
name = "redox_syscall"
version = "0.2.10"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff"
checksum = "8380fe0152551244f0747b1bf41737e0f8a74f97a14ccefd1148187271634f3c"
dependencies = [
"bitflags",
]
@ -2074,9 +2087,9 @@ dependencies = [
[[package]]
name = "regex"
version = "1.5.4"
version = "1.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461"
checksum = "1a11647b6b25ff05a515cb92c365cec08801e83423a235b51e231e1808747286"
dependencies = [
"aho-corasick",
"memchr",
@ -2134,6 +2147,7 @@ dependencies = [
"lazy_static",
"log",
"oauth2",
"rand 0.7.3",
"reqwest",
"rocket",
"rocket_dyn_templates",
@ -2153,9 +2167,9 @@ dependencies = [
[[package]]
name = "reqwest"
version = "0.11.9"
version = "0.11.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87f242f1488a539a79bac6dbe7c8609ae43b7914b7736210f239a37cccb32525"
checksum = "46a1f7aa4f35e5e8b4160449f51afc758f0ce6454315a9fa7d0d113e958c41eb"
dependencies = [
"base64",
"bytes",
@ -2233,7 +2247,7 @@ dependencies = [
[[package]]
name = "rocket"
version = "0.5.0-rc.1"
source = "git+https://github.com/SergioBenitez/Rocket?branch=master#66d18bf66517e2765494d082629e9b9748ff8ad6"
source = "git+https://github.com/SergioBenitez/Rocket?branch=master#ae0ccf43f11be5c00bb9cd49996c8bb06a7e1651"
dependencies = [
"async-stream",
"async-trait",
@ -2271,7 +2285,7 @@ dependencies = [
[[package]]
name = "rocket_codegen"
version = "0.5.0-rc.1"
source = "git+https://github.com/SergioBenitez/Rocket?branch=master#66d18bf66517e2765494d082629e9b9748ff8ad6"
source = "git+https://github.com/SergioBenitez/Rocket?branch=master#ae0ccf43f11be5c00bb9cd49996c8bb06a7e1651"
dependencies = [
"devise",
"glob",
@ -2286,7 +2300,7 @@ dependencies = [
[[package]]
name = "rocket_dyn_templates"
version = "0.1.0-rc.1"
source = "git+https://github.com/SergioBenitez/Rocket?branch=master#66d18bf66517e2765494d082629e9b9748ff8ad6"
source = "git+https://github.com/SergioBenitez/Rocket?branch=master#ae0ccf43f11be5c00bb9cd49996c8bb06a7e1651"
dependencies = [
"glob",
"normpath",
@ -2298,7 +2312,7 @@ dependencies = [
[[package]]
name = "rocket_http"
version = "0.5.0-rc.1"
source = "git+https://github.com/SergioBenitez/Rocket?branch=master#66d18bf66517e2765494d082629e9b9748ff8ad6"
source = "git+https://github.com/SergioBenitez/Rocket?branch=master#ae0ccf43f11be5c00bb9cd49996c8bb06a7e1651"
dependencies = [
"cookie",
"either",
@ -2311,14 +2325,15 @@ dependencies = [
"percent-encoding",
"pin-project-lite",
"ref-cast",
"rustls 0.19.1",
"rustls 0.20.4",
"rustls-pemfile",
"serde",
"smallvec",
"stable-pattern",
"state",
"time 0.3.7",
"tokio",
"tokio-rustls 0.22.0",
"tokio-rustls 0.23.2",
"uncased",
]
@ -2369,9 +2384,9 @@ dependencies = [
[[package]]
name = "rustls-pemfile"
version = "0.2.1"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5eebeaeb360c87bfb72e84abdb3447159c0eaececf1bef2aecd65a8be949d1c9"
checksum = "1ee86d63972a7c661d1536fefe8c3c8407321c3df668891286de28abcd087360"
dependencies = [
"base64",
]
@ -2471,6 +2486,16 @@ dependencies = [
"serde_derive",
]
[[package]]
name = "serde-value"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3a1a3341211875ef120e117ea7fd5228530ae7e7036a779fdc9117be6b3282c"
dependencies = [
"ordered-float",
"serde",
]
[[package]]
name = "serde_derive"
version = "1.0.136"
@ -2528,7 +2553,7 @@ dependencies = [
[[package]]
name = "serenity"
version = "0.10.10"
source = "git+https://github.com/serenity-rs/serenity?branch=next#85b3d8c665d9c15f47aeb7afeb738c58a32a5e64"
source = "git+https://github.com/serenity-rs/serenity?branch=next#56c40fc53cab1ebda43d1efc0fcd4ab37a73a3d2"
dependencies = [
"async-trait",
"async-tungstenite",
@ -2545,6 +2570,7 @@ dependencies = [
"percent-encoding",
"reqwest",
"serde",
"serde-value",
"serde_json",
"tokio",
"tracing",
@ -2621,9 +2647,9 @@ dependencies = [
[[package]]
name = "siphasher"
version = "0.3.9"
version = "0.3.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a86232ab60fa71287d7f2ddae4a7073f6b7aac33631c3015abb556f08c6d0a3e"
checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de"
[[package]]
name = "slab"
@ -2819,9 +2845,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
[[package]]
name = "syn"
version = "1.0.86"
version = "1.0.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b"
checksum = "ea297be220d52398dcc07ce15a209fce436d361735ac1db700cab3b6cdfb9f54"
dependencies = [
"proc-macro2",
"quote",
@ -2878,9 +2904,9 @@ dependencies = [
[[package]]
name = "termcolor"
version = "1.1.2"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
dependencies = [
"winapi-util",
]
@ -2966,7 +2992,7 @@ dependencies = [
"bytes",
"libc",
"memchr",
"mio 0.8.0",
"mio 0.8.2",
"num_cpus",
"once_cell",
"parking_lot 0.12.0",
@ -3076,9 +3102,9 @@ checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6"
[[package]]
name = "tracing"
version = "0.1.31"
version = "0.1.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6c650a8ef0cd2dd93736f033d21cbd1224c5a967aa0c258d00fcf7dafef9b9f"
checksum = "4a1bdf54a7c28a2bbf701e1d2233f6c77f473486b94bee4f9678da5a148dca7f"
dependencies = [
"cfg-if 1.0.0",
"log",
@ -3089,9 +3115,9 @@ dependencies = [
[[package]]
name = "tracing-attributes"
version = "0.1.19"
version = "0.1.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8276d9a4a3a558d7b7ad5303ad50b53d58264641b82914b7ada36bd762e7a716"
checksum = "2e65ce065b4b5c53e73bb28912318cb8c9e9ad3921f1d669eb0e68b4c8143a2b"
dependencies = [
"proc-macro2",
"quote",
@ -3100,9 +3126,9 @@ dependencies = [
[[package]]
name = "tracing-core"
version = "0.1.22"
version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03cfcb51380632a72d3111cb8d3447a8d908e577d31beeac006f836383d29a23"
checksum = "aa31669fa42c09c34d94d8165dd2012e8ff3c66aca50f3bb226b68f216f2706c"
dependencies = [
"lazy_static",
"valuable",
@ -3379,6 +3405,12 @@ version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-bindgen"
version = "0.2.79"
@ -3581,9 +3613,9 @@ checksum = "504a2476202769977a040c6364301a3f65d0cc9e3fb08600b2bda150a0488316"
[[package]]
name = "winreg"
version = "0.7.0"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69"
checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d"
dependencies = [
"winapi 0.3.9",
]

View File

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

View File

@ -122,7 +122,7 @@ impl ComponentDataModel {
.create_interaction_response(&ctx, |r| {
r.kind(InteractionResponseType::UpdateMessage).interaction_response_data(
|response| {
response.embeds(vec![embed]).components(|comp| {
response.set_embeds(vec![embed]).components(|comp| {
pager.create_button_row(pages, comp);
comp

View File

@ -88,7 +88,7 @@ pub fn send_as_initial_response(
if let Some(content) = content {
f.content(content);
}
f.embeds(embeds);
f.set_embeds(embeds);
if let Some(allowed_mentions) = allowed_mentions {
f.allowed_mentions(|f| {
*f = allowed_mentions.clone();

View File

@ -16,3 +16,4 @@ sqlx = { version = "0.5", features = ["runtime-tokio-rustls", "macros", "mysql",
chrono = "0.4"
chrono-tz = "0.5"
lazy_static = "1.4.0"
rand = "0.7"

View File

@ -18,6 +18,8 @@ pub const MINUTE: usize = 60;
pub const HOUR: usize = 60 * MINUTE;
pub const DAY: usize = 24 * HOUR;
pub const CHARACTERS: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
use std::{collections::HashSet, env, iter::FromIterator};
use lazy_static::lazy_static;

View File

@ -24,7 +24,7 @@ macro_rules! check_length_opt {
macro_rules! check_url {
($field:expr) => {
if $field.starts_with("http://") || $field.starts_with("https://") {
if !($field.starts_with("http://") || $field.starts_with("https://")) {
return json!({ "error": "URL invalid" });
}
};

View File

@ -18,7 +18,9 @@ use crate::{
MAX_EMBED_DESCRIPTION_LENGTH, MAX_EMBED_FOOTER_LENGTH, MAX_EMBED_TITLE_LENGTH,
MAX_URL_LENGTH, MAX_USERNAME_LENGTH, MIN_INTERVAL,
},
routes::dashboard::{create_database_channel, DeleteReminder, Reminder},
routes::dashboard::{
create_database_channel, generate_uid, name_default, DeleteReminder, Reminder,
},
};
#[derive(Serialize)]
@ -193,11 +195,13 @@ pub async fn create_reminder(
if reminder.utc_time < Utc::now().naive_utc() {
return json!({"error": "Time must be in the future"});
}
if reminder.interval_months.unwrap_or(0) * 30 * DAY as u32
+ reminder.interval_seconds.unwrap_or(0)
< *MIN_INTERVAL
{
return json!({"error": "Interval too short"});
if reminder.interval_seconds.is_some() || reminder.interval_months.is_some() {
if reminder.interval_months.unwrap_or(0) * 30 * DAY as u32
+ reminder.interval_seconds.unwrap_or(0)
< *MIN_INTERVAL
{
return json!({"error": "Interval too short"});
}
}
// check patreon if necessary
@ -209,9 +213,12 @@ pub async fn create_reminder(
}
}
let name = if reminder.name.is_empty() { name_default() } else { reminder.name.clone() };
// write to db
match sqlx::query!(
"INSERT INTO reminders (
uid,
channel_id,
avatar,
content,
@ -234,30 +241,8 @@ pub async fn create_reminder(
tts,
username,
`utc_time`
) VALUES (
channel_id = ?,
avatar = ?,
content = ?,
embed_author = ?,
embed_author_url = ?,
embed_color = ?,
embed_description = ?,
embed_footer = ?,
embed_footer_url = ?,
embed_image_url = ?,
embed_thumbnail_url = ?,
embed_title = ?,
enabled = ?,
expires = ?,
interval_seconds = ?,
interval_months = ?,
name = ?,
pin = ?,
restartable = ?,
tts = ?,
username = ?,
`utc_time` = ?
)",
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
generate_uid(),
channel,
reminder.avatar,
reminder.content,
@ -274,7 +259,7 @@ pub async fn create_reminder(
reminder.expires,
reminder.interval_seconds,
reminder.interval_months,
reminder.name,
name,
reminder.pin,
reminder.restartable,
reminder.tts,

View File

@ -1,17 +1,17 @@
use std::collections::HashMap;
use chrono::naive::NaiveDateTime;
use rand::{rngs::OsRng, seq::IteratorRandom};
use rocket::{http::CookieJar, response::Redirect};
use rocket_dyn_templates::Template;
use serde::{Deserialize, Serialize};
use serenity::{
client::Context,
http::{CacheHttp, Http},
model::id::ChannelId,
};
use sqlx::{Executor, Pool};
use serenity::{http::Http, model::id::ChannelId};
use sqlx::Executor;
use crate::{consts::DEFAULT_AVATAR, Database, Error};
use crate::{
consts::{CHARACTERS, DEFAULT_AVATAR},
Database, Error,
};
pub mod guild;
pub mod user;
@ -37,21 +37,30 @@ pub struct Reminder {
embed_image_url: Option<String>,
embed_thumbnail_url: Option<String>,
embed_title: String,
enabled: i8,
enabled: bool,
expires: Option<NaiveDateTime>,
interval_seconds: Option<u32>,
interval_months: Option<u32>,
#[serde(default = "name_default")]
name: String,
pin: i8,
restartable: i8,
tts: i8,
pin: bool,
restartable: bool,
tts: bool,
#[serde(default)]
uid: String,
username: Option<String>,
utc_time: NaiveDateTime,
}
pub fn generate_uid() -> String {
let mut generator: OsRng = Default::default();
(0..64)
.map(|_| CHARACTERS.chars().choose(&mut generator).unwrap().to_owned().to_string())
.collect::<Vec<String>>()
.join("")
}
// https://github.com/serde-rs/json/issues/329#issuecomment-305608405
mod string {
use std::{fmt::Display, str::FromStr};

View File

@ -282,7 +282,7 @@ pub async fn get_reminders(
if let Some(channel_id) = dm_channel {
let reminders = sqlx::query_as!(
Reminder,
"SELECT
r#"SELECT
reminders.attachment,
reminders.attachment_name,
reminders.avatar,
@ -297,18 +297,18 @@ pub async fn get_reminders(
reminders.embed_image_url,
reminders.embed_thumbnail_url,
reminders.embed_title,
reminders.enabled,
reminders.enabled as "enabled:_",
reminders.expires,
reminders.interval_seconds,
reminders.interval_months,
reminders.name,
reminders.pin,
reminders.restartable,
reminders.tts,
reminders.pin as "pin:_",
reminders.restartable as "restartable:_",
reminders.tts as "tts:_",
reminders.uid,
reminders.username,
reminders.utc_time
FROM reminders INNER JOIN channels ON channels.id = reminders.channel_id WHERE channels.channel = ?",
FROM reminders INNER JOIN channels ON channels.id = reminders.channel_id WHERE channels.channel = ?"#,
channel_id
)
.fetch_all(pool.inner())

View File

@ -114,7 +114,7 @@
<br>
Your browser timezone is: <strong><span class="browser-timezone">%browsertimezone%</span></strong> (<span class="browser-time">HH:mm</span>)
<br>
Your bot timezone is: <strong><span class="bot-timezone">%bottimezone</span></strong> (<span class="bot-time">HH:mm</span>)
Your bot timezone is: <strong><span class="bot-timezone">%bottimezone%</span></strong> (<span class="bot-time">HH:mm</span>)
</p>
<br>
<div class="has-text-centered">
@ -414,6 +414,7 @@
// populate channels
newFrame.querySelector('select.channel-selector');
// populate majority of items
for (let prop in reminder) {
if (reminder.hasOwnProperty(prop) && reminder[prop] !== null) {
let $input = newFrame.querySelector(`*[name="${prop}"]`);
@ -427,6 +428,10 @@
}
}
let timeInput = newFrame.querySelector('input[name="time"]');
let localTime = luxon.DateTime.fromISO(reminder["utc_time"]).setZone(timezone);
timeInput.value = localTime.toFormat("yyyy-LL-dd'T'HH:mm:ss");
$reminderBox.appendChild(newFrame);
}
}
@ -668,6 +673,62 @@
});
});
let $createReminder = document.querySelector('#reminderCreator');
$createReminder.querySelector('button#createReminder').addEventListener('click', () => {
// create reminder object
let seconds = parseInt($createReminder.querySelector('input[name="interval_seconds"]').value) || null;
let months = parseInt($createReminder.querySelector('input[name="interval_months"]').value) || null;
let rgb_color = window.getComputedStyle($createReminder.querySelector('div.discord-embed')).borderLeftColor;
let rgb = rgb_color.match(/\d+/g);
let color = colorToInt(parseInt(rgb[0]), parseInt(rgb[1]), parseInt(rgb[2]));
let utc_time = luxon.DateTime.fromISO($createReminder.querySelector('input[name="time"]').value).setZone('UTC');
let reminder = {
avatar: $createReminder.querySelector('img.discord-avatar').src,
channel: $createReminder.querySelector('select.channel-selector').value,
content: $createReminder.querySelector('textarea#messageContent').value,
embed_author_url: $createReminder.querySelector('img.embed_author_url').src,
embed_author: $createReminder.querySelector('textarea#embedAuthor').value,
embed_color: color,
embed_description: $createReminder.querySelector('textarea#embedDescription').value,
embed_footer: $createReminder.querySelector('textarea#embedFooter').value,
embed_footer_url: $createReminder.querySelector('img.embed_footer_url').src,
embed_image_url: $createReminder.querySelector('img.embed_image_url').src,
embed_thumbnail_url: $createReminder.querySelector('img.embed_thumbnail_url').src,
embed_title: $createReminder.querySelector('textarea#embedTitle').value,
enabled: true,
expires: null,
interval_seconds: seconds,
interval_months: months,
name: $createReminder.querySelector('input[name="name"]').value,
pin: $createReminder.querySelector('input[name="pin"]').checked,
restartable: false,
tts: $createReminder.querySelector('input[name="tts"]').checked,
username: $createReminder.querySelector('input#reminderUsername').value,
utc_time: utc_time.toFormat("yyyy-LL-dd'T'HH:mm:ss")
}
console.log(reminder);
// send to server
let guild = document.querySelector('.guildList a.is-active').dataset['guild'];
fetch(`/dashboard/api/guild/${guild}/reminders`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(reminder)
}).then(response => response.json()).then(data => console.log(data))
// process response
// reset inputs
});
document.querySelectorAll('textarea.autoresize').forEach((element) => {
element.addEventListener('input', () => {
element.style.height = "";
@ -696,6 +757,10 @@
});
});
function colorToInt(r, g, b) {
return (r << 16) + (g << 8) + (b);
}
document.querySelectorAll('.customizable').forEach((element) => {
element.querySelector('a').addEventListener('click', (e) => {
e.preventDefault();

View File

@ -28,7 +28,7 @@
<div class="a">
<p class="image is-24x24 customizable">
<a>
<img class="is-rounded" src="">
<img class="is-rounded embed_author_url" src="">
</a>
</p>
</div>
@ -77,7 +77,7 @@
<div class="b">
<p class="image thumbnail customizable">
<a>
<img class="" src="" alt="Square thumbnail embedded image">
<img class="embed_thumbnail_url" src="" alt="Square thumbnail embedded image">
</a>
</p>
</div>
@ -85,21 +85,21 @@
<p class="image is-400x300 customizable">
<a>
<img class="" src="" alt="Large embedded image">
<img class="embed_image_url" src="" alt="Large embedded image">
</a>
</p>
<div class="embed-footer-box">
<p class="image is-20x20 customizable">
<a>
<img class="is-rounded " src="" alt="Footer profile-like image">
<img class="is-rounded embed_footer_url" src="" alt="Footer profile-like image">
</a>
</p>
<label class="is-sr-only" for="embedFooter">Embed Footer text</label>
<textarea class="discord-embed-footer message-input autoresize "
placeholder="Embed Footer..."
maxlength="2048" id="embedFooter" name="embed_author" rows="1"></textarea>
maxlength="2048" id="embedFooter" name="embed_footer" rows="1"></textarea>
</div>
</div>
</div>
@ -128,7 +128,7 @@
<div class="field">
<label class="label">Time</label>
<div class="control">
<input class="input" type="datetime-local" name="time">
<input class="input" type="datetime-local" step="1" name="time">
</div>
</div>
@ -140,13 +140,13 @@
<input class="input" type="number" name="interval_months" placeholder="Months">
</div>
<div class="column">
<input class="input" type="number" name="interval_seconds" placeholder="Days">
<input class="input" type="number" name="interval_days" placeholder="Days">
</div>
<div class="column">
<input class="input" type="number" name="interval_seconds" placeholder="Hours">
<input class="input" type="number" name="interval_hours" placeholder="Hours">
</div>
<div class="column">
<input class="input" type="number" name="interval_seconds" placeholder="Minutes">
<input class="input" type="number" name="interval_minutes" placeholder="Minutes">
</div>
<div class="column">
<input class="input" type="number" name="interval_seconds" placeholder="Seconds">

View File

@ -6,6 +6,7 @@
<div id="reminderCreator">
{% set creating = true %}
{% include "reminder_dashboard/guild_reminder" %}
{% set creating = false %}
</div>
<div class="buttons has-addons" style="margin-top: 1rem;">

View File

@ -45,10 +45,20 @@
<h2 class="title">JellyWX's Home</h2>
<ul class="is-size-5 pl-6">
<li>Do not discuss politics, harass other users, or use language intended to upset other users</li>
<li>Do not send malicious links</li>
<li>Do not share personal information about yourself or any other user. This includes but is not
limited to real names<sup>1</sup>, addresses, phone numbers, country of origin<sup>2</sup>, religion, email address,
IP address.</li>
<li>Do not send malicious links or attachments</li>
<li>Do not advertise</li>
<li>Do not send unwarranted direct messages</li>
</ul>
<p class="small">
<sup>1</sup> Some users may use their real name on their account. In this case, do not assert that
this is a user's real name, or use it to try and identify a user.
<br>
<sup>2</sup> Country of current residence may be discussed, as this is relevant to timezone and
DST selection.
</p>
</div>
</section>