Compare commits

..
Author SHA1 Message Date
jude 9a6b65f3a3 Don't delete guild data when guild becomes unavailable 2024-09-17 23:47:27 +01:00
jude b6ff149d51 Fix macro list/delete 2024-09-14 12:07:09 +01:00
jude 748e33566b Fix patreon not sharing between guild members 2024-08-19 21:50:14 +01:00
jude d7e90614c8 Bump ver 2024-07-07 16:35:32 +01:00
jude b5dbfe336d Don't set activity in ready event 2024-07-07 16:31:23 +01:00
jude 218be2f0b1 Bump ver 2024-06-18 19:32:47 +01:00
jude d7515f3611 Don't require View Channel permission 2024-06-18 19:28:53 +01:00
jude 6ae1096d79 Bump ver 2024-06-12 17:44:55 +01:00
jude 1f0d7adae3 Correct service file 2024-06-12 17:21:42 +01:00
jude fc96ae526f Default permission checks to true 2024-06-10 18:30:55 +01:00
jude 8881ef0f85 Fix DM reminders trying to load guild data 2024-06-06 16:56:19 +01:00
jude 5e82a687f9 Increase watchdog 2024-06-04 22:34:58 +01:00
jude de4ecf8dd6 QoL
* Made todo added responses ephemeral if /settings ephemeral is on
* Enabled systemd watchdog
* Move metrics to rocket
2024-06-04 18:40:49 +01:00
jude 064efd4386 Bump version 2024-06-04 16:48:26 +01:00
jude 65b8ba3b47 Redirect old dashboard routes to new routes 2024-06-04 16:42:42 +01:00
jude 9d452ed8cb Fix role selector 2024-05-10 17:37:27 +01:00
jude 441419b92b Bump ver 2024-05-04 13:00:30 +01:00
jude aecf2c15be Store times as local time not UTC 2024-05-04 10:24:20 +01:00
jude 79da56c794 Bump ver 2024-05-03 16:26:52 +01:00
jude ef10902c1e Fix todo list deletion not working properly 2024-05-03 16:21:27 +01:00
jude c277f85c2a Bump dependencies 2024-05-03 16:07:34 +01:00
jude 035653c7fa Bump ver 2024-04-29 08:57:47 +01:00
jude 6358bc3deb Partially revert timezone change 2024-04-29 08:49:01 +01:00
jude 9f5066f982 Bump ver 2024-04-29 08:46:36 +01:00
jude 1d06999e41 Fix bugs with time picker
* Load UTC time correctly at page load
* Don't translate to/from timezone when using the browser date/time
  input
2024-04-16 12:44:19 +01:00
jude 1cf707140c Bump version 2024-04-16 12:22:02 +01:00
jude e38c63f5ba Don't show empty channels 2024-04-16 11:42:19 +01:00
jude d52b8b26f2 Upgrade dependencies 2024-04-16 11:19:21 +01:00
jude bb2128a7ed Tweaks
* Don't show @everyone in the role picker
* Show some text on the image picker talking about Discord CDN
* Correct == in todos
2024-04-11 15:40:50 +01:00
jude 5e99a6f9de Add create todo under each channel
Sort channels for consistency
2024-04-11 15:32:34 +01:00
jude 5406e6b8ec Show all channels and filter todos accordingly 2024-04-11 15:26:24 +01:00
jude 4ee0bc4e37 Bump ver 2024-04-11 12:43:22 +01:00
jude b99bb7dcbf Fix todo sorting 2024-04-11 12:39:02 +01:00
jude 98f925dc84 Bump version 2024-04-10 18:54:30 +01:00
jude 24e316b12f Add delete/patch todos 2024-04-10 18:42:29 +01:00
jude 4063334953 More work on todo list 2024-04-09 21:21:46 +01:00
jude e128b9848f More work on todo list support 2024-04-07 20:20:16 +01:00
jude 9989ab3b35 Start work on todo list support for dashboard 2024-04-06 14:27:58 +01:00
jude b951db3f55 Bump version 2024-03-31 13:30:30 +01:00
jude 884a47bf36 Always show remaining time in top bar 2024-03-31 12:54:48 +01:00
jude b0f932445c Add server emoji picker 2024-03-31 12:49:52 +01:00
jude 2861cdda0b Bump version 2024-03-29 16:28:09 +00:00
jude 7ba8fcd6b7 Add note to the server data page that states the bot might be restarting 2024-03-29 16:24:24 +00:00
jude 850f0fad57 Bump version 2024-03-29 16:22:13 +00:00
jude a770a17ee7 Don't invalidate reminders when saving 2024-03-29 16:15:01 +00:00
jude d15a66d9d9 Bump version 2024-03-28 19:36:23 +00:00
jude 30f011fcd5 Don't send attachments over API 2024-03-28 19:34:30 +00:00
jude 15dbed2f0f Bump version 2024-03-27 17:28:35 +00:00
jude 18cac0345b Allow removing attachments
Show HTTP errors
2024-03-27 17:19:19 +00:00
jude 334b1bc084 Bump version 2024-03-26 17:46:56 +00:00
jude ba3c76c25f Fix import/export showing "Malformed base64" 2024-03-26 17:43:35 +00:00
jude 67b6f30c62 Add IDs to metrics 2024-03-25 16:41:49 +00:00
jude 8ae311190f Fix panic????????? 2024-03-25 06:07:30 +00:00
jude 016164affb Remove unused javascript/css 2024-03-24 21:00:27 +00:00
jude 2c0aeef700 Fix build. Bump version 2024-03-24 20:55:07 +00:00
jude ecd75d6f55 Add metrics 2024-03-24 20:38:19 +00:00
jude 4a80d42f86 Move postman and web inside src 2024-03-24 20:23:16 +00:00
jude 075fde71df Bump version 2024-03-11 18:17:22 +00:00
jude 55136aecdc Set default embed color correctly 2024-03-11 18:14:27 +00:00
jude 63fc2cdcbc Block editing username and avatar on DMs 2024-03-10 19:43:57 +00:00
jude 3190738fc5 Extend user reminder API endpoints 2024-03-09 16:17:55 +00:00
jude 8f4810b532 Convert to/from timezone 2024-03-08 16:36:24 +00:00
jude a5e6c41fa5 Bump ver
Update build file
2024-03-05 20:55:20 +00:00
jude 5f0aa0f834 Add routes for getting/posting user reminders 2024-03-05 20:36:38 +00:00
jude dbe8e8e358 Add mentioning for channels 2024-03-04 20:36:37 +00:00
jude 85a114e55c Start adding stuff for user reminders 2024-03-03 21:58:48 +00:00
jude 329492b244 Add mention support
Allow vertical resizing of inputs
2024-03-03 21:44:35 +00:00
jude 66135ecd08 Show time until on collapsed reminders 2024-03-03 20:38:17 +00:00
jude 382c2a5a1e Stick options 2024-03-03 19:43:02 +00:00
jude b91245a3f7 Build dashboard with bot 2024-03-03 13:21:06 +00:00
jude 6f0bdf9852 Support sending reminders to threads 2024-03-03 13:04:50 +00:00
jude dcee9e0d2a Begin to work on thread support 2024-03-03 11:58:22 +00:00
jude 8e6e1a18b7 Bump ver 2024-03-01 18:04:34 +00:00
jude 72af0532fa Fix timezones 2024-03-01 17:54:05 +00:00
jude e83b643d86 Show error for files that are too large 2024-03-01 16:56:31 +00:00
jude 0e0ab053f3 Fix time inputs 2024-03-01 16:54:56 +00:00
jude 8c2296b9c8 Bump versions 2024-02-28 21:37:10 +00:00
jude 1c6103142f Fix color picker not working 2024-02-28 21:30:53 +00:00
jude 328127c55e Fix images not setting properly 2024-02-28 21:30:49 +00:00
jude b0e37b56c0 Bump version 2024-02-26 10:42:46 +00:00
jude 45f5b6261a Convert times to/from UTC 2024-02-26 10:26:07 +00:00
jude 5f6326179c Move styles into Vite
Make sidebar work better
2024-02-25 09:50:10 +00:00
jude 6254f91841 Bump version 2024-02-25 09:18:04 +00:00
jude 60b90a61d4 Adjust permission check
Correct response code for oauth redirect
2024-02-25 09:09:00 +00:00
jude 90f05758d0 Bypass self permission check for DMs 2024-02-24 22:27:29 +00:00
jude 74b7b5d711 Remove glob patterns from static file includes 2024-02-24 17:56:27 +00:00
jude 90550dc2c7 Add loader 2024-02-24 17:47:00 +00:00
jude 79e6498245 Add overlay when data fetching 2024-02-24 17:31:39 +00:00
jude a8ef3d03f9 Add dashboard to build 2024-02-24 16:12:34 +00:00
jude 53e13844f9 Add unit tests 2024-02-24 15:02:34 +00:00
jude dd7e681285 Update rust 2024-02-22 18:35:37 +00:00
jude 6c20bf2a0f Bump version 2024-02-22 17:47:40 +00:00
jude 15aa9ccffd Update help text 2024-02-22 17:42:29 +00:00
jude 525471bcad Correct help text 2024-02-22 17:35:50 +00:00
jude 86d53b63b6 Bump deps 2024-02-20 17:09:50 +00:00
jude d8f266852a Add remaining commands 2024-02-18 14:32:58 +00:00
jude 76a286076b Link all top-level commands with macro recording/replaying logic 2024-02-18 13:24:37 +00:00
jude 5e39e16060 Add option types for top-level commands 2024-02-18 11:04:43 +00:00
jude c1305cfb36 Extract trait 2024-02-17 20:25:14 +00:00
jude 4823754955 Move all commands to their own files 2024-02-17 18:55:16 +00:00
jude eb92eacb90 Rearranged some commands
Working on a macro to automatically add option wrappers
2024-02-17 14:09:01 +00:00
jude d0833b7bca Add macro for extracting arguments 2024-02-16 20:09:32 +00:00
jude b81c3c80c1 Record some parameters for /remind 2024-02-15 17:28:43 +00:00
jude 2f6d035efe Rename table references 2024-02-14 19:44:53 +00:00
jude 96012ce43c Add migration script 2024-02-14 19:35:23 +00:00
jude fa7ec8731b Fix hook 2024-02-09 17:03:04 +00:00
jude def43bfa78 Refactor macros 2024-02-06 20:08:59 +00:00
jude e4e9af2bb4 Wip commit 2024-01-07 17:10:22 +00:00
jude cce0de7c75 wip bump versions 2023-12-22 19:12:42 +00:00
jude e7803b98e8 Merge pull request 'jude/react-dashboard' (#3) from jude/react-dashboard into current
Reviewed-on: #3
2023-12-22 16:58:30 +00:00
jude 7aae246388 Remove submodule 2023-12-22 16:58:30 +00:00
jude a2d442bc54 Reset intervals correctly 2023-12-22 16:58:30 +00:00
jude 59982df827 Correct merge errors 2023-12-22 16:58:30 +00:00
jude 7a6372ed02 Update styles for notification flash 2023-12-22 16:58:30 +00:00
jude 14a54471f7 Build dashboard 2023-12-22 16:58:30 +00:00
jude 5d3b77f1cd Add metrics
Change dashboards to load an index.html file compiled otherwise
2023-12-22 16:58:30 +00:00
jude 1d64c8bb79 Remove stat table 2023-12-22 16:58:03 +00:00
jude 8ba0f02b98 Bump version 2023-11-12 10:00:46 +00:00
jude d36438c6ce Bump package lock. Add attachment serializer 2023-11-12 09:39:45 +00:00
jude e0c60e2ce3 Decode attachments correctly when patching a reminder 2023-11-11 15:05:35 +00:00
jude e7160215b0 Defer offset response 2023-11-11 13:36:40 +00:00
jude 6eaa6f0f28 Bump version 2023-10-19 20:32:01 +01:00
jude 9db0fa2513 Fix attachment decoding 2023-10-19 20:10:40 +01:00
jude ca13fd4fa7 Restructure code 2023-10-08 18:24:04 +01:00
jude 55acc8fd16 Bump ver 2023-10-08 12:39:31 +01:00
jude 145711fa5d Add version strings to files 2023-10-08 12:21:38 +01:00
jude 5524215786 Bump ver 2023-10-07 16:10:01 +01:00
jude e8bd05893f Transmit guild name with patreon information 2023-10-07 16:08:25 +01:00
jude e3d3418f99 Change routing. Remove a macro 2023-10-05 18:54:53 +01:00
jude 2681280a39 Fix interval parsing for different cases 2023-10-01 09:42:58 +01:00
jude 00579428a1 Bump version 2023-09-25 18:20:22 +01:00
jude b8ef999710 Reload reminders after import 2023-09-25 18:17:19 +01:00
jude e8f84e281a Bump version 2023-09-24 14:53:16 +01:00
jude 8ddff698e5 Show messages when imports succeed. 2023-09-24 14:14:21 +01:00
jude 541633270c Fix margin on bottom of collapsed reminders 2023-09-24 13:58:24 +01:00
jude 25286da5e0 Use transactions for certain routes 2023-09-24 13:57:27 +01:00
jude 4bad1324b9 Restructure
Move some code out to other files. Add transaction guard
2023-09-24 13:11:53 +01:00
jude bd1462a00c Reposition "options"
Fix import/export
2023-09-23 23:38:16 +01:00
jude 56ffc43616 Store intervals in templates 2023-09-23 22:47:21 +01:00
jude 52cf642455 Send edit button to beta dashboard 2023-09-23 20:32:57 +01:00
jude 0bf578357a Bump version 2023-09-23 18:31:51 +01:00
jude 6e9eccb62e Update dependencies 2023-09-23 18:29:25 +01:00
jude 6ea28284ce Bump ver 2023-09-23 18:24:39 +01:00
jude a6525f3052 Move button row down. Correct image sizes on some browsers 2023-09-23 18:14:01 +01:00
jude 348639270d Move button row down 2023-09-23 18:05:26 +01:00
jude 37177c2431 Update styles for mobile 2023-09-23 18:04:41 +01:00
368 changed files with 84044 additions and 6909 deletions

No files matched your search

+27 -2
View File
@@ -1,5 +1,30 @@
/target
target
.env
/venv
.cargo
/.idea
.idea
web/static/index.html
web/static/assets
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
Generated
+1335 -905
View File
File diff suppressed because it is too large. Load diff
+31 -18
View File
@@ -1,22 +1,21 @@
[package]
name = "reminder-rs"
version = "1.6.40"
version = "1.7.27"
authors = ["Jude Southworth <judesouthworth@pm.me>"]
edition = "2021"
license = "AGPL-3.0 only"
description = "Reminder Bot for Discord, now in Rust"
[dependencies]
poise = "0.5"
poise = "0.6.1"
dotenv = "0.15"
tokio = { version = "1", features = ["process", "full"] }
reqwest = "0.11"
lazy-regex = "3.0"
regex = "1.9"
reqwest = { version = "0.12", features = ["json"] }
regex = "1.10"
log = "0.4"
env_logger = "0.10"
env_logger = "0.11"
chrono = "0.4"
chrono-tz = { version = "0.8", features = ["serde"] }
chrono-tz = { version = "0.9", features = ["serde"] }
lazy_static = "1.4"
num-integer = "0.1"
serde = "1.0"
@@ -25,14 +24,23 @@ serde_repr = "0.1"
rmp-serde = "1.1"
rand = "0.8"
levenshtein = "1.0"
sqlx = { version = "0.7", features = ["runtime-tokio-rustls", "macros", "mysql", "bigdecimal", "chrono", "migrate"]}
base64 = "0.21.0"
sqlx = { version = "0.7", features = ["runtime-tokio-rustls", "macros", "mysql", "bigdecimal", "chrono", "migrate"] }
base64 = "0.22"
secrecy = "0.8.0"
futures = "0.3.30"
prometheus = "0.13.3"
rocket = { version = "0.5.0", features = ["tls", "secrets", "json"] }
rocket_dyn_templates = { version = "0.1.0", features = ["tera"] }
serenity = { version = "0.12", default-features = false, features = ["builder", "cache", "client", "gateway", "http", "model", "utils", "rustls_backend"] }
oauth2 = "4"
csv = "1.2"
sd-notify = "0.4.1"
[dependencies.postman]
path = "postman"
[dependencies.extract_derive]
path = "extract_derive"
[dependencies.reminder_web]
path = "web"
[dependencies.recordable_derive]
path = "recordable_derive"
[package.metadata.deb]
depends = "$auto, python3-dateparser (>= 1.0.0)"
@@ -40,13 +48,18 @@ suggests = "mysql-server-8.0, nginx"
maintainer-scripts = "debian"
assets = [
["target/release/reminder-rs", "usr/bin/reminder-rs", "755"],
["static/css/*", "lib/reminder-rs/static/css", "644"],
["static/favicon/*", "lib/reminder-rs/static/favicon", "644"],
["static/img/*", "lib/reminder-rs/static/img", "644"],
["static/js/*", "lib/reminder-rs/static/js", "644"],
["static/webfonts/*", "lib/reminder-rs/static/webfonts", "644"],
["static/site.webmanifest", "lib/reminder-rs/static/site.webmanifest", "644"],
["templates/**/*", "lib/reminder-rs/templates", "644"],
["reminder-dashboard/dist/static/assets/*", "lib/reminder-rs/static/assets", "644"],
["reminder-dashboard/dist/index.html", "lib/reminder-rs/static/index.html", "644"],
["conf/default.env", "etc/reminder-rs/config.env", "600"],
["conf/Rocket.toml", "etc/reminder-rs/Rocket.toml", "600"],
["web/static/**/*", "lib/reminder-rs/static", "644"],
["web/templates/**/*", "lib/reminder-rs/templates", "644"],
["healthcheck", "lib/reminder-rs/healthcheck", "755"],
["cron.d/reminder_health", "etc/cron.d/reminder_health", "644"],
# ["nginx/reminder-rs", "etc/nginx/sites-available/reminder-rs", "755"]
# ["nginx/reminder-rs", "etc/nginx/sites-available/reminder-rs", "755"]
]
conf-files = [
"/etc/reminder-rs/config.env",
+1 -1
View File
@@ -4,6 +4,6 @@ ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH
RUN apt update && DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt install -y gcc gcc-multilib cmake pkg-config libssl-dev curl mysql-client-8.0
RUN apt update && DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt install -y gcc gcc-multilib cmake pkg-config libssl-dev curl mysql-client-8.0 npm
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --profile minimal --default-toolchain nightly
RUN cargo install cargo-deb
+11 -11
View File
@@ -1,28 +1,28 @@
[default]
address = "0.0.0.0"
port = 18920
template_dir = "web/templates"
template_dir = "templates"
limits = { json = "10MiB" }
[debug]
secret_key = "tR8krio5FXTnnyIZNiJDXPondz0kI1v6X6BXZcBGIRY="
[debug.tls]
certs = "web/private/rsa_sha256_cert.pem"
key = "web/private/rsa_sha256_key.pem"
certs = "private/rsa_sha256_cert.pem"
key = "private/rsa_sha256_key.pem"
[debug.rsa_sha256.tls]
certs = "web/private/rsa_sha256_cert.pem"
key = "web/private/rsa_sha256_key.pem"
certs = "private/rsa_sha256_cert.pem"
key = "private/rsa_sha256_key.pem"
[debug.ecdsa_nistp256_sha256.tls]
certs = "web/private/ecdsa_nistp256_sha256_cert.pem"
key = "web/private/ecdsa_nistp256_sha256_key_pkcs8.pem"
certs = "private/ecdsa_nistp256_sha256_cert.pem"
key = "private/ecdsa_nistp256_sha256_key_pkcs8.pem"
[debug.ecdsa_nistp384_sha384.tls]
certs = "web/private/ecdsa_nistp384_sha384_cert.pem"
key = "web/private/ecdsa_nistp384_sha384_key_pkcs8.pem"
certs = "private/ecdsa_nistp384_sha384_cert.pem"
key = "private/ecdsa_nistp384_sha384_key_pkcs8.pem"
[debug.ed25519.tls]
certs = "web/private/ed25519_cert.pem"
key = "eb/private/ed25519_key.pem"
certs = "private/ed25519_cert.pem"
key = "private/ed25519_key.pem"
+10
View File
@@ -1,3 +1,13 @@
use std::{path::Path, process::Command};
fn main() {
println!("cargo:rerun-if-changed=migrations");
println!("cargo:rerun-if-changed=reminder-dashboard");
Command::new("npm")
.arg("run")
.arg("build")
.current_dir(Path::new("reminder-dashboard"))
.spawn()
.expect("Failed to build NPM");
}
+46
View File
@@ -0,0 +1,46 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "extract_macro"
version = "0.1.0"
dependencies = [
"quote",
"syn",
]
[[package]]
name = "proc-macro2"
version = "1.0.78"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
dependencies = [
"proc-macro2",
]
[[package]]
name = "syn"
version = "2.0.49"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "915aea9e586f80826ee59f8453c1101f9d1c4b3964cd2460185ee8e299ada496"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
+11
View File
@@ -0,0 +1,11 @@
[package]
name = "extract_derive"
version = "0.1.0"
edition = "2021"
[lib]
proc-macro = true
[dependencies]
quote = "1.0.35"
syn = { version = "2.0.49", features = ["full"] }
+53
View File
@@ -0,0 +1,53 @@
use proc_macro::TokenStream;
use syn::{spanned::Spanned, Data, Fields};
#[proc_macro_derive(Extract)]
pub fn extract(input: TokenStream) -> TokenStream {
let ast = syn::parse_macro_input!(input);
impl_extract(&ast)
}
fn impl_extract(ast: &syn::DeriveInput) -> TokenStream {
let name = &ast.ident;
match &ast.data {
// Dispatch over struct: extract args directly from context
Data::Struct(st) => match &st.fields {
Fields::Named(fields) => {
let extracted = fields.named.iter().map(|field| {
let ident = &field.ident;
let ty = &field.ty;
quote::quote_spanned! {field.span()=>
#ident : crate::utils::extract_arg!(ctx, #ident, #ty)
}
});
TokenStream::from(quote::quote! {
impl Extract for #name {
fn extract(ctx: crate::ApplicationContext) -> Self {
Self {
#(#extracted,)*
}
}
}
})
}
Fields::Unit => TokenStream::from(quote::quote! {
impl Extract for #name {
fn extract(ctx: crate::ApplicationContext) -> Self {
Self {}
}
}
}),
_ => {
panic!("Only named/unit structs can derive Extract");
}
},
_ => {
panic!("Only structs can derive Extract");
}
}
}
-13
View File
@@ -1,13 +0,0 @@
#!/bin/bash
export $(grep -v '^#' /etc/reminder-rs/config.env | xargs -d '\n')
REGEX='mysql://([A-Za-z]+)@(.+)/(.+)'
[[ $DATABASE_URL =~ $REGEX ]]
VAR=$(mysql -u "${BASH_REMATCH[1]}" -h "${BASH_REMATCH[2]}" -N -D "${BASH_REMATCH[3]}" -e "SELECT COUNT(1) FROM reminders WHERE utc_time < NOW() - INTERVAL 10 MINUTE AND enabled = 1 AND status = 'pending'")
if [ "$VAR" -gt 0 ]
then
echo "This is to inform that there is a reminder backlog which must be resolved." | mail -s "Backlog: $VAR" "$REPORT_EMAIL"
fi
@@ -1,19 +0,0 @@
-- Drop existing constraint
ALTER TABLE `reminders` DROP CONSTRAINT `reminders_ibfk_1`;
ALTER TABLE `reminders` MODIFY COLUMN `channel_id` INT UNSIGNED;
ALTER TABLE `reminders` ADD COLUMN `guild_id` INT UNSIGNED;
ALTER TABLE `reminders`
ADD CONSTRAINT `guild_id_fk`
FOREIGN KEY (`guild_id`)
REFERENCES `guilds`(`id`)
ON DELETE CASCADE;
ALTER TABLE `reminders`
ADD CONSTRAINT `channel_id_fk`
FOREIGN KEY (`channel_id`)
REFERENCES `channels`(`id`)
ON DELETE SET NULL;
UPDATE `reminders` SET `guild_id` = (SELECT guilds.`id` FROM `channels` INNER JOIN `guilds` ON channels.guild_id = guilds.id WHERE reminders.channel_id = channels.id);
@@ -1,4 +0,0 @@
ALTER TABLE reminders ADD COLUMN `status_change_time` DATETIME;
-- This is a best-guess as to the status change time.
UPDATE reminders SET `status_change_time` = `utc_time` WHERE `status` != 'pending';
@@ -0,0 +1,3 @@
ALTER TABLE `reminder_template` ADD COLUMN `interval_seconds` INT UNSIGNED;
ALTER TABLE `reminder_template` ADD COLUMN `interval_days` INT UNSIGNED;
ALTER TABLE `reminder_template` ADD COLUMN `interval_months` INT UNSIGNED;
@@ -0,0 +1,50 @@
CREATE TABLE command_macro (
id INT UNSIGNED AUTO_INCREMENT,
guild_id INT UNSIGNED NOT NULL,
name VARCHAR(100) NOT NULL,
description VARCHAR(100),
commands JSON NOT NULL,
FOREIGN KEY (guild_id) REFERENCES guilds(id) ON DELETE CASCADE,
PRIMARY KEY (id)
);
# New JSON structure is {command_name: "Remind", "<option name>": "<option value>", ...}
INSERT INTO command_macro (guild_id, description, name, commands)
SELECT
guild_id,
description,
name,
(
SELECT JSON_ARRAYAGG(
(
SELECT JSON_OBJECTAGG(t2.name, t2.value)
FROM JSON_TABLE(
JSON_ARRAY_APPEND(t1.options, '$', JSON_OBJECT('name', 'command_name', 'value', t1.command_name)),
'$[*]' COLUMNS (
name VARCHAR(64) PATH '$.name' ERROR ON ERROR,
value TEXT PATH '$.value' ERROR ON ERROR
)) AS t2
)
)
FROM macro m2
JOIN JSON_TABLE(
commands,
'$[*]' COLUMNS (
command_name VARCHAR(64) PATH '$.command_name' ERROR ON ERROR,
options JSON PATH '$.options' ERROR ON ERROR
)) AS t1
WHERE m1.id = m2.id
)
FROM macro m1;
# # Check which commands are used in macros
# SELECT DISTINCT command_name
# FROM macro m2
# JOIN JSON_TABLE(
# commands,
# '$[*]' COLUMNS (
# command_name VARCHAR(64) PATH '$.command_name' ERROR ON ERROR,
# options JSON PATH '$.options' ERROR ON ERROR
# )) AS t1
@@ -0,0 +1,5 @@
-- Add migration script here
ALTER TABLE reminders
ADD INDEX `utc_time_index` (`utc_time`);
ALTER TABLE reminders
ADD INDEX `status_index` (`status`);
+53
View File
@@ -0,0 +1,53 @@
server {
server_name www.reminder-bot.com;
return 301 https://reminder-bot.com$request_uri;
}
server {
listen 80;
server_name beta.reminder-bot.com;
return 301 https://reminder-bot.com$request_uri;
}
server {
listen 443 ssl;
server_name beta.reminder-bot.com;
ssl_certificate /etc/letsencrypt/live/beta.reminder-bot.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/beta.reminder-bot.com/privkey.pem;
return 301 https://reminder-bot.com$request_uri;
}
server {
listen 443 ssl;
server_name reminder-bot.com;
ssl_certificate /etc/letsencrypt/live/reminder-bot.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/reminder-bot.com/privkey.pem;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
client_max_body_size 10M;
location / {
proxy_pass http://localhost:18920;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /static {
alias /var/www/reminder-rs/static;
expires 30d;
}
}
-41
View File
@@ -1,41 +0,0 @@
server {
server_name www.reminder-bot.com;
return 301 $scheme://reminder-bot.com$request_uri;
}
server {
listen 80;
server_name reminder-bot.com;
return 301 https://reminder-bot.com$request_uri;
}
server {
listen 443 ssl;
server_name reminder-bot.com;
ssl_certificate /etc/letsencrypt/live/reminder-bot.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/reminder-bot.com/privkey.pem;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
location / {
proxy_pass http://localhost:18920;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /static {
alias /var/www/reminder-rs/static;
expires 30d;
}
}
-16
View File
@@ -1,16 +0,0 @@
[package]
name = "postman"
version = "0.1.0"
edition = "2021"
[dependencies]
tokio = { version = "1", features = ["process", "full"] }
regex = "1.9"
log = "0.4"
chrono = "0.4"
chrono-tz = { version = "0.8", features = ["serde"] }
lazy_static = "1.4"
num-integer = "0.1"
serde = "1.0"
sqlx = { version = "0.7", features = ["runtime-tokio-rustls", "macros", "mysql", "bigdecimal", "chrono", "json"]}
serenity = { version = "0.11", default-features = false, features = ["builder", "cache", "client", "gateway", "http", "model", "utils", "rustls_backend"] }
-800
View File
@@ -1,800 +0,0 @@
use std::env;
use chrono::{DateTime, Days, Duration, Months};
use chrono_tz::Tz;
use lazy_static::lazy_static;
use log::{error, info, warn};
use num_integer::Integer;
use regex::{Captures, Regex};
use serde::Deserialize;
use serenity::{
builder::CreateEmbed,
http::{CacheHttp, Http, HttpError},
model::{
channel::{Channel, Embed as SerenityEmbed},
id::ChannelId,
webhook::Webhook,
},
Error, Result,
};
use sqlx::{
types::{
chrono::{NaiveDateTime, Utc},
Json,
},
Executor,
};
use crate::Database;
lazy_static! {
pub static ref TIMEFROM_REGEX: Regex =
Regex::new(r#"<<timefrom:(?P<time>\d+):(?P<format>.+)?>>"#).unwrap();
pub static ref TIMENOW_REGEX: Regex =
Regex::new(r#"<<timenow:(?P<timezone>(?:\w|/|_)+):(?P<format>.+)?>>"#).unwrap();
pub static ref LOG_TO_DATABASE: bool = env::var("LOG_TO_DATABASE").map_or(true, |v| v == "1");
}
fn fmt_displacement(format: &str, seconds: u64) -> String {
let mut seconds = seconds;
let mut days: u64 = 0;
let mut hours: u64 = 0;
let mut minutes: u64 = 0;
for (rep, time_type, div) in
[("%d", &mut days, 86400), ("%h", &mut hours, 3600), ("%m", &mut minutes, 60)].iter_mut()
{
if format.contains(*rep) {
let (divided, new_seconds) = seconds.div_rem(&div);
**time_type = divided;
seconds = new_seconds;
}
}
format
.replace("%s", &seconds.to_string())
.replace("%m", &minutes.to_string())
.replace("%h", &hours.to_string())
.replace("%d", &days.to_string())
}
pub fn substitute(string: &str) -> String {
let new = TIMEFROM_REGEX.replace(string, |caps: &Captures| {
let final_time = caps.name("time").map(|m| m.as_str().parse::<i64>().ok()).flatten();
let format = caps.name("format").map(|m| m.as_str());
if let (Some(final_time), Some(format)) = (final_time, format) {
match NaiveDateTime::from_timestamp_opt(final_time, 0) {
Some(dt) => {
let now = Utc::now().naive_utc();
let difference = {
if now < dt {
dt - Utc::now().naive_utc()
} else {
Utc::now().naive_utc() - dt
}
};
fmt_displacement(format, difference.num_seconds() as u64)
}
None => String::new(),
}
} else {
String::new()
}
});
TIMENOW_REGEX
.replace(&new, |caps: &Captures| {
let timezone = caps.name("timezone").map(|m| m.as_str().parse::<Tz>().ok()).flatten();
let format = caps.name("format").map(|m| m.as_str());
if let (Some(timezone), Some(format)) = (timezone, format) {
let now = Utc::now().with_timezone(&timezone);
now.format(format).to_string()
} else {
String::new()
}
})
.to_string()
}
struct Embed {
title: String,
description: String,
image_url: Option<String>,
thumbnail_url: Option<String>,
footer: String,
footer_url: Option<String>,
author: String,
author_url: Option<String>,
color: u32,
fields: Json<Vec<EmbedField>>,
}
#[derive(Deserialize)]
struct EmbedField {
title: String,
value: String,
inline: bool,
}
impl Embed {
pub async fn from_id(
pool: impl Executor<'_, Database = Database> + Copy,
id: u32,
) -> Option<Self> {
match sqlx::query_as!(
Self,
r#"
SELECT
`embed_title` AS title,
`embed_description` AS description,
`embed_image_url` AS image_url,
`embed_thumbnail_url` AS thumbnail_url,
`embed_footer` AS footer,
`embed_footer_url` AS footer_url,
`embed_author` AS author,
`embed_author_url` AS author_url,
`embed_color` AS color,
IFNULL(`embed_fields`, '[]') AS "fields:_"
FROM reminders
WHERE `id` = ?"#,
id
)
.fetch_one(pool)
.await
{
Ok(mut embed) => {
embed.title = substitute(&embed.title);
embed.description = substitute(&embed.description);
embed.footer = substitute(&embed.footer);
embed.fields.iter_mut().for_each(|field| {
field.title = substitute(&field.title);
field.value = substitute(&field.value);
});
if embed.has_content() {
Some(embed)
} else {
None
}
}
Err(e) => {
warn!("Error loading embed from reminder: {:?}", e);
None
}
}
}
pub fn has_content(&self) -> bool {
if self.title.is_empty()
&& self.description.is_empty()
&& self.image_url.is_none()
&& self.thumbnail_url.is_none()
&& self.footer.is_empty()
&& self.footer_url.is_none()
&& self.author.is_empty()
&& self.author_url.is_none()
&& self.fields.0.is_empty()
{
false
} else {
true
}
}
}
impl Into<CreateEmbed> for Embed {
fn into(self) -> CreateEmbed {
let mut c = CreateEmbed::default();
c.title(&self.title)
.description(&self.description)
.color(self.color)
.author(|a| {
a.name(&self.author);
if let Some(author_icon) = &self.author_url {
a.icon_url(author_icon);
}
a
})
.footer(|f| {
f.text(&self.footer);
if let Some(footer_icon) = &self.footer_url {
f.icon_url(footer_icon);
}
f
});
for field in &self.fields.0 {
c.field(&field.title, &field.value, field.inline);
}
if let Some(image_url) = &self.image_url {
c.image(image_url);
}
if let Some(thumbnail_url) = &self.thumbnail_url {
c.thumbnail(thumbnail_url);
}
c
}
}
pub struct Reminder {
id: u32,
channel_id: Option<u64>,
webhook_id: Option<u64>,
webhook_token: Option<String>,
channel_paused: Option<bool>,
channel_paused_until: Option<NaiveDateTime>,
enabled: bool,
tts: bool,
pin: bool,
content: String,
attachment: Option<Vec<u8>>,
attachment_name: Option<String>,
utc_time: DateTime<Utc>,
timezone: String,
restartable: bool,
expires: Option<DateTime<Utc>>,
interval_seconds: Option<u32>,
interval_days: Option<u32>,
interval_months: Option<u32>,
avatar: Option<String>,
username: Option<String>,
}
impl Reminder {
pub async fn fetch_reminders(pool: impl Executor<'_, Database = Database> + Copy) -> Vec<Self> {
match sqlx::query_as_unchecked!(
Reminder,
r#"
SELECT
reminders.`id` AS id,
channels.`channel` AS channel_id,
channels.`webhook_id` AS webhook_id,
channels.`webhook_token` AS webhook_token,
channels.`paused` AS 'channel_paused',
channels.`paused_until` AS 'channel_paused_until',
reminders.`enabled` AS 'enabled',
reminders.`tts` AS tts,
reminders.`pin` AS pin,
reminders.`content` AS content,
reminders.`attachment` AS attachment,
reminders.`attachment_name` AS attachment_name,
reminders.`utc_time` AS 'utc_time',
reminders.`timezone` AS timezone,
reminders.`restartable` AS restartable,
reminders.`expires` AS 'expires',
reminders.`interval_seconds` AS 'interval_seconds',
reminders.`interval_days` AS 'interval_days',
reminders.`interval_months` AS 'interval_months',
reminders.`avatar` AS avatar,
reminders.`username` AS username
FROM
reminders
LEFT JOIN
channels
ON
reminders.channel_id = channels.id
WHERE
reminders.`status` = 'pending' AND
reminders.`id` IN (
SELECT
MIN(id)
FROM
reminders
WHERE
reminders.`utc_time` <= NOW() AND
`status` = 'pending' AND
(
reminders.`interval_seconds` IS NOT NULL
OR reminders.`interval_months` IS NOT NULL
OR reminders.`interval_days` IS NOT NULL
OR reminders.enabled
)
GROUP BY channel_id
)
"#,
)
.fetch_all(pool)
.await
{
Ok(reminders) => reminders
.into_iter()
.map(|mut rem| {
rem.content = substitute(&rem.content);
rem
})
.collect::<Vec<Self>>(),
Err(e) => {
warn!("Could not fetch reminders: {:?}", e);
vec![]
}
}
}
async fn reset_webhook(&self, pool: impl Executor<'_, Database = Database> + Copy) {
let _ = sqlx::query!(
"
UPDATE channels SET webhook_id = NULL, webhook_token = NULL
WHERE channel = ?
",
self.channel_id
)
.execute(pool)
.await;
}
async fn refresh(&self, pool: impl Executor<'_, Database = Database> + Copy) {
if self.interval_seconds.is_some()
|| self.interval_months.is_some()
|| self.interval_days.is_some()
{
// If all intervals are zero then dont care
if self.interval_seconds == Some(0)
&& self.interval_days == Some(0)
&& self.interval_months == Some(0)
{
self.set_sent(pool).await;
}
let now = Utc::now();
let mut updated_reminder_time =
self.utc_time.with_timezone(&self.timezone.parse().unwrap_or(Tz::UTC));
let mut fail_count = 0;
while updated_reminder_time < now && fail_count < 4 {
if let Some(interval) = self.interval_months {
if interval != 0 {
updated_reminder_time = updated_reminder_time
.checked_add_months(Months::new(interval))
.unwrap_or_else(|| {
warn!(
"{}: Could not add {} months to a reminder",
interval, self.id
);
fail_count += 1;
updated_reminder_time
});
}
}
if let Some(interval) = self.interval_days {
if interval != 0 {
updated_reminder_time = updated_reminder_time
.checked_add_days(Days::new(interval as u64))
.unwrap_or_else(|| {
warn!("{}: Could not add {} days to a reminder", self.id, interval);
fail_count += 1;
updated_reminder_time
})
}
}
if let Some(interval) = self.interval_seconds {
updated_reminder_time += Duration::seconds(interval as i64);
}
}
if fail_count >= 4 {
self.log_error(
pool,
"Failed to update 4 times and so is being deleted",
None::<&'static str>,
)
.await;
self.set_failed(pool, "Failed to update 4 times and so is being deleted").await;
} else if self.expires.map_or(false, |expires| updated_reminder_time > expires) {
self.set_sent(pool).await;
} else {
sqlx::query!(
"
UPDATE reminders SET `utc_time` = ? WHERE `id` = ?
",
updated_reminder_time.with_timezone(&Utc),
self.id
)
.execute(pool)
.await
.expect(&format!("Could not update time on Reminder {}", self.id));
}
} else {
self.set_sent(pool).await;
}
}
async fn log_error(
&self,
pool: impl Executor<'_, Database = Database> + Copy,
error: &'static str,
debug_info: Option<impl std::fmt::Debug>,
) {
let message = match debug_info {
Some(info) => format!(
"{}
{:?}",
error, info
),
None => error.to_string(),
};
error!("[Reminder {}] {}", self.id, message);
if *LOG_TO_DATABASE {
sqlx::query!(
"
INSERT INTO stat (type, reminder_id, message)
VALUES ('reminder_failed', ?, ?)
",
self.id,
message,
)
.execute(pool)
.await
.expect("Could not log error to database");
}
}
async fn log_success(&self, pool: impl Executor<'_, Database = Database> + Copy) {
if *LOG_TO_DATABASE {
sqlx::query!(
"
INSERT INTO stat (type, reminder_id)
VALUES ('reminder_sent', ?)
",
self.id,
)
.execute(pool)
.await
.expect("Could not log success to database");
}
}
async fn set_sent(&self, pool: impl Executor<'_, Database = Database> + Copy) {
sqlx::query!(
"
UPDATE reminders
SET `status` = 'sent', `status_change_time` = NOW()
WHERE `id` = ?
",
self.id
)
.execute(pool)
.await
.expect(&format!("Could not delete Reminder {}", self.id));
}
async fn set_failed(
&self,
pool: impl Executor<'_, Database = Database> + Copy,
message: &'static str,
) {
sqlx::query!(
"
UPDATE reminders
SET `status` = 'failed', `status_message` = ?, `status_change_time` = NOW()
WHERE `id` = ?
",
message,
self.id
)
.execute(pool)
.await
.expect(&format!("Could not delete Reminder {}", self.id));
}
async fn pin_message<M: Into<u64>>(&self, message_id: M, http: impl AsRef<Http>) {
if let Some(channel_id) = self.channel_id {
let _ = http.as_ref().pin_message(channel_id, message_id.into(), None).await;
}
}
pub async fn send(
&self,
pool: impl Executor<'_, Database = Database> + Copy,
cache_http: impl CacheHttp,
) {
async fn send_to_channel(
cache_http: impl CacheHttp,
channel_id: u64,
reminder: &Reminder,
embed: Option<CreateEmbed>,
) -> Result<()> {
let channel = ChannelId(channel_id).to_channel(&cache_http).await;
match channel {
Ok(Channel::Guild(channel)) => {
match channel
.send_message(&cache_http, |m| {
m.content(&reminder.content).tts(reminder.tts);
if let (Some(attachment), Some(name)) =
(&reminder.attachment, &reminder.attachment_name)
{
m.add_file((attachment as &[u8], name.as_str()));
}
if let Some(embed) = embed {
m.set_embed(embed);
}
m
})
.await
{
Ok(m) => {
if reminder.pin {
reminder.pin_message(m.id, cache_http.http()).await;
}
Ok(())
}
Err(e) => Err(e),
}
}
Ok(Channel::Private(channel)) => {
match channel
.send_message(&cache_http.http(), |m| {
m.content(&reminder.content).tts(reminder.tts);
if let (Some(attachment), Some(name)) =
(&reminder.attachment, &reminder.attachment_name)
{
m.add_file((attachment as &[u8], name.as_str()));
}
if let Some(embed) = embed {
m.set_embed(embed);
}
m
})
.await
{
Ok(m) => {
if reminder.pin {
reminder.pin_message(m.id, cache_http.http()).await;
}
Ok(())
}
Err(e) => Err(e),
}
}
Err(e) => Err(e),
_ => Err(Error::Other("Channel not of valid type")),
}
}
async fn send_to_webhook(
cache_http: impl CacheHttp,
reminder: &Reminder,
webhook: Webhook,
embed: Option<CreateEmbed>,
) -> Result<()> {
match webhook
.execute(&cache_http.http(), reminder.pin || reminder.restartable, |w| {
w.content(&reminder.content).tts(reminder.tts);
if let Some(username) = &reminder.username {
if !username.is_empty() {
w.username(username);
}
}
if let Some(avatar) = &reminder.avatar {
w.avatar_url(avatar);
}
if let (Some(attachment), Some(name)) =
(&reminder.attachment, &reminder.attachment_name)
{
w.add_file((attachment as &[u8], name.as_str()));
}
if let Some(embed) = embed {
w.embeds(vec![SerenityEmbed::fake(|c| {
*c = embed;
c
})]);
}
w
})
.await
{
Ok(m) => {
if reminder.pin {
if let Some(message) = m {
reminder.pin_message(message.id, cache_http.http()).await;
}
}
Ok(())
}
Err(e) => Err(e),
}
}
match self.channel_id {
Some(channel_id) => {
if self.enabled
&& !(self.channel_paused.unwrap_or(false)
&& self
.channel_paused_until
.map_or(true, |inner| inner >= Utc::now().naive_local()))
{
let _ = sqlx::query!(
"
UPDATE `channels`
SET paused = 0, paused_until = NULL
WHERE `channel` = ?
",
self.channel_id
)
.execute(pool)
.await;
let embed = Embed::from_id(pool, self.id).await.map(|e| e.into());
let result = if let (Some(webhook_id), Some(webhook_token)) =
(self.webhook_id, &self.webhook_token)
{
let webhook_res = cache_http
.http()
.get_webhook_with_token(webhook_id, webhook_token)
.await;
if let Ok(webhook) = webhook_res {
send_to_webhook(cache_http, &self, webhook, embed).await
} else {
warn!("Webhook vanished for reminder {}: {:?}", self.id, webhook_res);
self.reset_webhook(pool).await;
send_to_channel(cache_http, channel_id, &self, embed).await
}
} else {
send_to_channel(cache_http, channel_id, &self, embed).await
};
if let Err(e) = result {
if let Error::Http(error) = e {
if let HttpError::UnsuccessfulRequest(http_error) = *error {
match http_error.error.code {
10003 => {
self.log_error(
pool,
"Could not be sent as channel does not exist",
None::<&'static str>,
)
.await;
self.set_failed(
pool,
"Could not be sent as channel does not exist",
)
.await;
}
10004 => {
self.log_error(
pool,
"Could not be sent as guild does not exist",
None::<&'static str>,
)
.await;
self.set_failed(
pool,
"Could not be sent as guild does not exist",
)
.await;
}
50001 => {
self.log_error(
pool,
"Could not be sent as missing access",
None::<&'static str>,
)
.await;
self.set_failed(
pool,
"Could not be sent as missing access",
)
.await;
}
50007 => {
self.log_error(
pool,
"Could not be sent as user has DMs disabled",
None::<&'static str>,
)
.await;
self.set_failed(
pool,
"Could not be sent as user has DMs disabled",
)
.await;
}
50013 => {
self.log_error(
pool,
"Could not be sent as permissions are invalid",
None::<&'static str>,
)
.await;
self.set_failed(
pool,
"Could not be sent as permissions are invalid",
)
.await;
}
_ => {
self.log_error(
pool,
"HTTP error sending reminder",
Some(http_error),
)
.await;
self.refresh(pool).await;
}
}
} else {
self.log_error(pool, "(Likely) a parsing error", Some(error)).await;
self.refresh(pool).await;
}
} else {
self.log_error(pool, "Non-HTTP error", Some(e)).await;
self.refresh(pool).await;
}
} else {
self.log_success(pool).await;
self.refresh(pool).await;
}
} else {
info!("Reminder {} is paused", self.id);
self.refresh(pool).await;
}
}
None => {
info!("Reminder {} is orphaned", self.id);
self.log_error(pool, "Orphaned", Option::<u8>::None).await;
self.set_failed(pool, "Could not be sent as channel was deleted").await;
}
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+11
View File
@@ -0,0 +1,11 @@
[package]
name = "recordable_derive"
version = "0.1.0"
edition = "2021"
[lib]
proc-macro = true
[dependencies]
quote = "1.0.35"
syn = { version = "2.0.49", features = ["full"] }
+42
View File
@@ -0,0 +1,42 @@
use proc_macro::TokenStream;
use syn::{spanned::Spanned, Data};
/// Macro to allow Recordable to be implemented on an enum by dispatching over each variant.
#[proc_macro_derive(Recordable)]
pub fn extract(input: TokenStream) -> TokenStream {
let ast = syn::parse_macro_input!(input);
impl_recordable(&ast)
}
fn impl_recordable(ast: &syn::DeriveInput) -> TokenStream {
let name = &ast.ident;
match &ast.data {
Data::Enum(en) => {
let extracted = en.variants.iter().map(|var| {
let ident = &var.ident;
quote::quote_spanned! {var.span()=>
Self::#ident (opt) => opt.run(ctx).await?
}
});
TokenStream::from(quote::quote! {
impl Recordable for #name {
async fn run(self, ctx: crate::Context<'_>) -> Result<(), crate::Error> {
match self {
#(#extracted,)*
}
Ok(())
}
}
})
}
_ => {
panic!("Only enums can derive Recordable");
}
}
}
+2
View File
@@ -0,0 +1,2 @@
printWidth = 100
tabWidth = 4
+19
View File
@@ -0,0 +1,19 @@
# reminder-dashboard
The re-re-rewrite of the dashboard.
## Why
The existing beta variant of the dashboard is written using vanilla JavaScript. This is fine,
but annoying to update. This would've been okay if I was more dedicated to updating the vanilla
JavaScript too, but I want to experiment with "new" things.
This also allows me to expand my frontend skills, which is relevant to part of my job.
## Developing
1. Run both `npm run dev` and `cargo run`
2. Symlink assets: assuming cloned
into `$HOME`, `ln -s $HOME/reminder-bot/reminder-dashboard/dist/index.html $HOME/reminder-bot/web/static/index.html`
and
`ln -s $HOME/reminder-bot/reminder-dashboard/dist/static/assets $HOME/reminder-bot/web/static/assets`
+34
View File
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="EN">
<head>
<meta name="description" content="The most powerful Discord Reminders Bot">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8">
<meta name="yandex-verification" content="bb77b8681eb64a90"/>
<meta name="google-site-verification" content="7h7UVTeEe0AOzHiH3cFtsqMULYGN-zCZdMT_YCkW1Ho"/>
<!-- <meta http-equiv="Content-Security-Policy" content="default-src 'self'; img-src *; font-src fonts.gstatic.com 'self'"> -->
<!-- favicon -->
<link rel="apple-touch-icon" sizes="180x180"
href="/static/favicon/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32"
href="/static/favicon/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16"
href="/static/favicon/favicon-16x16.png">
<link rel="manifest" href="/static/site.webmanifest">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="theme-color" content="#ffffff">
<title>Reminder Bot | Dashboard</title>
<!-- styles -->
<link rel="stylesheet" href="/static/css/bulma.min.css">
<link rel="stylesheet" href="/static/css/fa.css">
<link rel="stylesheet" href="/static/css/font.css">
<link rel="stylesheet" href="/static/css/style.css">
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/index.tsx"></script>
</body>
</html>
File diff suppressed because it is too large. Load diff
+32
View File
@@ -0,0 +1,32 @@
{
"name": "example",
"private": true,
"type": "module",
"scripts": {
"dev": "vite build --watch --mode development",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"axios": "^1.5.1",
"bulma": "^0.9.4",
"luxon": "^3.4.3",
"preact": "^10.13.1",
"react-colorful": "^5.6.1",
"react-query": "^3.39.3",
"tributejs": "^5.1.3",
"use-debounce": "^10.0.0",
"wouter": "^3.0"
},
"devDependencies": {
"@preact/preset-vite": "^2.5.0",
"@types/luxon": "^3.3.2",
"eslint": "^8.50.0",
"eslint-config-preact": "^1.3.0",
"prettier": "^3.0.3",
"react-datepicker": "^4.21.0",
"sass": "^1.71.1",
"typescript": "^5.2.2",
"vite": "^5.1"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -15,6 +15,10 @@ div.reminderContent.is-collapsed .column.settings {
display: none;
}
div.reminderContent.is-collapsed .reminder-settings {
margin-bottom: 0;
}
div.reminderContent.is-collapsed .button-row {
display: none;
}
@@ -304,11 +308,6 @@ div.dashboard-sidebar {
padding-right: 0;
}
div.dashboard-sidebar:not(.mobile-sidebar) {
display: flex;
flex-direction: column;
}
ul.guildList {
flex-grow: 1;
flex-shrink: 1;
@@ -318,6 +317,9 @@ ul.guildList {
div.dashboard-sidebar:not(.mobile-sidebar) .aside-footer {
flex-shrink: 0;
flex-grow: 0;
position: fixed;
bottom: 0;
width: 226px;
}
div.dashboard-sidebar svg {
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -18,7 +18,6 @@ const $downloader = document.querySelector("a#downloader");
const $uploader = document.querySelector("input#uploader");
let channels = [];
let reminderErrors = [];
let guildNames = {};
let roles = [];
let templates = {};
@@ -34,11 +33,7 @@ let globalPatreon = false;
let guildPatreon = false;
function guildId() {
return document.querySelector("li > a.is-active").parentElement.dataset["guild"];
}
function guildName() {
return guildNames[guildId()];
return document.querySelector(".guildList a.is-active").dataset["guild"];
}
function colorToInt(r, g, b) {
@@ -57,7 +52,7 @@ function switch_pane(selector) {
el.classList.add("is-hidden");
});
document.querySelector(`*[data-name=${selector}]`).classList.remove("is-hidden");
document.getElementById(selector).classList.remove("is-hidden");
}
function update_select(sel) {
@@ -228,11 +223,10 @@ async function fetch_reminders(guild_id) {
}
async function serialize_reminder(node, mode) {
let interval, utc_time, expiration_time;
let utc_time, expiration_time;
let interval = get_interval(node);
if (mode !== "template") {
interval = get_interval(node);
utc_time = luxon.DateTime.fromISO(
node.querySelector('input[name="time"]').value
).setZone("UTC");
@@ -361,9 +355,9 @@ async function serialize_reminder(node, mode) {
embed_title: embed_title,
embed_fields: fields,
expires: expiration_time,
interval_seconds: mode !== "template" ? interval.seconds : null,
interval_days: mode !== "template" ? interval.days : null,
interval_months: mode !== "template" ? interval.months : null,
interval_seconds: interval.seconds,
interval_days: interval.days,
interval_months: interval.months,
name: node.querySelector('input[name="name"]').value,
tts: node.querySelector('input[name="tts"]').checked,
username: node.querySelector('input[name="username"]').value,
@@ -425,9 +419,9 @@ function deserialize_reminder(reminder, frame, mode) {
.insertBefore(embed_field, lastChild);
}
if (mode !== "template") {
if (reminder["interval_seconds"]) update_interval(frame);
if (reminder["interval_seconds"]) update_interval(frame);
if (mode !== "template") {
let $enableBtn = frame.querySelector(".disable-enable");
$enableBtn.dataset["action"] = reminder["enabled"] ? "disable" : "enable";
@@ -454,27 +448,21 @@ document.addEventListener("guildSwitched", async (e) => {
.querySelectorAll(".patreon-only")
.forEach((el) => el.classList.add("is-locked"));
let $li = document.querySelectorAll(`li[data-guild="${e.detail.guild_id}"]`);
let $anchor = document.querySelector(
`.switch-pane[data-guild="${e.detail.guild_id}"]`
);
if ($li.length === 0) {
let hasError = false;
if ($anchor === null) {
switch_pane("user-error");
hasError = true;
return;
}
switch_pane(e.detail.pane);
switch_pane($anchor.dataset["pane"]);
reset_guild_pane();
document
.querySelectorAll(`li[data-guild="${e.detail.guild_id}"] > a`)
.forEach((el) => {
el.classList.add("is-active");
});
document
.querySelectorAll(
`li[data-guild="${e.detail.guild_id}"] *[data-pane="${e.detail.pane}"]`
)
.forEach((el) => {
el.classList.add("is-active");
});
$anchor.classList.add("is-active");
if (globalPatreon || (await fetch_patreon(e.detail.guild_id))) {
document
@@ -482,26 +470,15 @@ document.addEventListener("guildSwitched", async (e) => {
.forEach((el) => el.classList.remove("is-locked"));
}
const event = new CustomEvent("paneLoad", {
detail: {
guild_id: e.detail.guild_id,
pane: e.detail.pane,
},
});
document.dispatchEvent(event);
});
document.addEventListener("paneLoad", async (ev) => {
const hasError = await fetch_channels(ev.detail.guild_id);
hasError = await fetch_channels(e.detail.guild_id);
if (!hasError) {
fetch_roles(ev.detail.guild_id);
fetch_templates(ev.detail.guild_id);
fetch_reminders(ev.detail.guild_id);
fetch_roles(e.detail.guild_id);
fetch_templates(e.detail.guild_id);
fetch_reminders(e.detail.guild_id);
document.querySelectorAll("p.pageTitle").forEach((el) => {
el.textContent = `${guildName()} Reminders`;
el.textContent = `${e.detail.guild_name} Reminders`;
});
document.querySelectorAll("select.channel-selector").forEach((el) => {
el.addEventListener("change", (e) => {
update_select(e.target);
@@ -626,6 +603,16 @@ function show_error(error) {
}, 5000);
}
function show_success(error) {
document.getElementById("success").querySelector("span.success-message").textContent =
error;
document.getElementById("success").classList.add("is-active");
window.setTimeout(() => {
document.getElementById("success").classList.remove("is-active");
}, 5000);
}
$colorPickerInput.value = colorPicker.color.hexString;
$colorPickerInput.addEventListener("input", () => {
@@ -706,56 +693,36 @@ document.addEventListener("DOMContentLoaded", async () => {
"%guildname%",
guild.name
);
$anchor.dataset["guild"] = guild.id;
$anchor.dataset["name"] = guild.name;
$anchor.href = `/dashboard/${guild.id}/reminders`;
$anchor.href = `/dashboard/${guild.id}?name=${guild.name}`;
const $li = $anchor.parentElement;
$li.dataset["guild"] = guild.id;
$li.querySelectorAll("a").forEach((el) => {
el.addEventListener("click", (e) => {
const pane = el.dataset["pane"];
const slug = el.dataset["slug"];
if (pane !== undefined && slug !== undefined) {
e.preventDefault();
switch_pane(pane);
window.history.pushState(
{},
"",
`/dashboard/${guild.id}/${slug}`
);
const event = new CustomEvent("guildSwitched", {
detail: {
guild_id: guild.id,
pane,
},
});
document.dispatchEvent(event);
}
$anchor.addEventListener("click", async (e) => {
e.preventDefault();
window.history.pushState({}, "", `/dashboard/${guild.id}`);
const event = new CustomEvent("guildSwitched", {
detail: {
guild_name: guild.name,
guild_id: guild.id,
},
});
document.dispatchEvent(event);
});
element.append($clone);
});
}
const matches = window.location.href.match(
/dashboard\/(\d+)(\/)?([a-zA-Z\-]+)?/
);
const matches = window.location.href.match(/dashboard\/(\d+)/);
if (matches) {
let id = matches[1];
let kind = matches[3];
let name = guildNames[id];
const event = new CustomEvent("guildSwitched", {
detail: {
guild_name: name,
guild_id: id,
pane: kind,
},
});
@@ -796,12 +763,26 @@ $uploader.addEventListener("change", (ev) => {
fileReader.onload = (e) => resolve(fileReader.result);
fileReader.readAsDataURL($uploader.files[0]);
}).then((dataUrl) => {
$importBtn.setAttribute("disabled", true);
fetch(`/dashboard/api/guild/${guildId()}/export/${urlTail}`, {
method: "PUT",
body: JSON.stringify({ body: dataUrl.split(",")[1] }),
}).then(() => {
delete $uploader.files[0];
});
})
.then((response) => response.json())
.then((data) => {
$importBtn.removeAttribute("disabled");
if (data.error) {
show_error(data.error);
} else {
show_success(data.message);
}
})
.then(() => {
delete $uploader.files[0];
fetch_reminders(guild);
});
});
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loaded 100 of 368 files, more files were not shown because too many files have changed in this diff. Show more