Compare commits
	
		
			101 Commits
		
	
	
		
			4b42966284
			...
			jude/orpha
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 5f703e8538 | ||
|  | 2993505a47 | ||
|  | b225ad7e45 | ||
|  | ee89cb40c5 | ||
|  | b6b5e6d2b2 | ||
|  | adf29dca5d | ||
|  | ea3fe3f543 | ||
|  | 109cf16dbb | ||
|  | 6726ca0c2d | ||
| 38133be15d | |||
|  | 8587bed703 | ||
|  | 6c9af1ae8e | ||
|  | 7695b7a476 | ||
| 651da7b28e | |||
| eb086146bf | |||
| 4ebd705e5e | |||
| 5a85f1d83a | |||
| 68ba25886a | |||
|  | e25bf6b828 | ||
|  | 5a386daa9d | ||
|  | 0d4a02fb1e | ||
|  | e135a74a9b | ||
|  | 77f17c8dc2 | ||
|  | 6a94f990cf | ||
|  | 3aa5bd37aa | ||
|  | fa83fed1af | ||
|  | 666cb7fa2f | ||
|  | a5678e15dc | ||
|  | 9405cfcee9 | ||
|  | cb25d02cdf | ||
|  | bfe651a125 | ||
|  | dc5e52d9ce | ||
|  | 229ada83e1 | ||
|  | 13171d6744 | ||
|  | 2ad941c94c | ||
|  | 924d31e978 | ||
|  | f9a1b23212 | ||
|  | ae5795a7ea | ||
|  | ee36c38eda | ||
|  | eca7df3d9f | ||
|  | 902b7e1b4a | ||
|  | db1a53a797 | ||
|  | 3605d71b73 | ||
|  | ea2cea573e | ||
|  | d5fa8036e8 | ||
|  | b8707bbc9a | ||
|  | 99eea16f62 | ||
|  | 88737302f3 | ||
|  | 213e3a5100 | ||
|  | 8fa1402ecc | ||
|  | e63996bb61 | ||
|  | 9ede879630 | ||
|  | 88e9826a62 | ||
|  | 5d655c7e6d | ||
|  | 51c9d8a7ae | ||
|  | 90df265114 | ||
|  | e65429aa9c | ||
|  | 8d2232f0da | ||
|  | a58b9866ea | ||
|  | b1f25be5d7 | ||
|  | f0f9787326 | ||
|  | 302f5835e6 | ||
|  | 58c778632e | ||
|  | 5671fd462b | ||
|  | 5ac9733f15 | ||
|  | 01dc0334fd | ||
|  | 4a17aac15c | ||
|  | 8ce4fc9c6d | ||
|  | b4f07cfc1c | ||
|  | 8799089b2d | ||
|  | 88c4830209 | ||
|  | 4dd3df5cc2 | ||
|  | 369a325a46 | ||
|  | 1a1a0fdefb | ||
|  | dda8bd3e10 | ||
|  | edbfc92cb9 | ||
|  | 6de11f09db | ||
|  | 284bfcd9ad | ||
|  | 3d627b5bf0 | ||
|  | c3c0dbbbae | ||
|  | 64dd81e941 | ||
|  | 799298ca34 | ||
|  | fa542bb24f | ||
|  | e025d945cf | ||
|  | bb1c61d0b9 | ||
|  | 1519474f93 | ||
|  | 9d8622f418 | ||
|  | a66db37b33 | ||
|  | c8c1a171d4 | ||
|  | 88cfb829e3 | ||
|  | 16be7a328e | ||
|  | 04babf7930 | ||
|  | 96bc09e8b5 | ||
|  | 976fb91ecc | ||
|  | 1305b6e64e | ||
|  | cdfe44d958 | ||
|  | c824a36832 | ||
|  | c4bd2c1d18 | ||
|  | 561555ab7e | ||
|  | 115fbd44cb | ||
|  | aa931328b0 | 
							
								
								
									
										1431
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										1431
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										21
									
								
								Cargo.toml
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								Cargo.toml
									
									
									
									
									
								
							| @@ -1,13 +1,13 @@ | |||||||
| [package] | [package] | ||||||
| name = "reminder-rs" | name = "reminder-rs" | ||||||
| version = "1.6.10" | version = "1.6.38" | ||||||
| authors = ["Jude Southworth <judesouthworth@pm.me>"] | authors = ["Jude Southworth <judesouthworth@pm.me>"] | ||||||
| edition = "2021" | edition = "2021" | ||||||
| license = "AGPL-3.0 only" | license = "AGPL-3.0 only" | ||||||
| description = "Reminder Bot for Discord, now in Rust" | description = "Reminder Bot for Discord, now in Rust" | ||||||
|  |  | ||||||
| [dependencies] | [dependencies] | ||||||
| poise = "0.4" | poise = "0.5.5" | ||||||
| dotenv = "0.15" | dotenv = "0.15" | ||||||
| tokio = { version = "1", features = ["process", "full"] } | tokio = { version = "1", features = ["process", "full"] } | ||||||
| reqwest = "0.11" | reqwest = "0.11" | ||||||
| @@ -26,7 +26,7 @@ rmp-serde = "1.1" | |||||||
| rand = "0.8" | rand = "0.8" | ||||||
| levenshtein = "1.0" | levenshtein = "1.0" | ||||||
| sqlx = { version = "0.6", features = ["runtime-tokio-rustls", "macros", "mysql", "bigdecimal", "chrono", "migrate"]} | sqlx = { version = "0.6", features = ["runtime-tokio-rustls", "macros", "mysql", "bigdecimal", "chrono", "migrate"]} | ||||||
| base64 = "0.13" | base64 = "0.21.0" | ||||||
|  |  | ||||||
| [dependencies.postman] | [dependencies.postman] | ||||||
| path = "postman" | path = "postman" | ||||||
| @@ -35,16 +35,23 @@ path = "postman" | |||||||
| path = "web" | path = "web" | ||||||
|  |  | ||||||
| [package.metadata.deb] | [package.metadata.deb] | ||||||
| depends = "$auto, python3-dateparser" | depends = "$auto, python3-dateparser (>= 1.0.0)" | ||||||
| suggests = "mysql-server-8.0, nginx" | suggests = "mysql-server-8.0, nginx" | ||||||
| maintainer-scripts = "debian" | maintainer-scripts = "debian" | ||||||
| assets = [ | assets = [ | ||||||
|     ["target/release/reminder-rs", "usr/bin/reminder-rs", "755"], |     ["target/release/reminder-rs", "usr/bin/reminder-rs", "755"], | ||||||
|     ["conf/default.env", "etc/reminder-rs/default.env", "600"], |     ["conf/default.env", "etc/reminder-rs/config.env", "600"], | ||||||
|     ["web/static/**/*", "var/www/reminder-rs/static", "755"], |     ["conf/Rocket.toml", "etc/reminder-rs/Rocket.toml", "600"], | ||||||
|     ["web/templates/**/*", "var/www/reminder-rs/templates", "755"], |     ["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", | ||||||
|  |     "/etc/reminder-rs/Rocket.toml", | ||||||
|  | ] | ||||||
|  |  | ||||||
| [package.metadata.deb.systemd-units] | [package.metadata.deb.systemd-units] | ||||||
| unit-scripts = "systemd" | unit-scripts = "systemd" | ||||||
|   | |||||||
							
								
								
									
										28
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								README.md
									
									
									
									
									
								
							| @@ -7,7 +7,22 @@ reminders are paid on the hosted version of the bot. Keep reading if you want to | |||||||
|  |  | ||||||
| You'll need rustc and cargo for compilation. To run, you'll need Python 3 still (due to no suitable replacement for dateparser in Rust) | You'll need rustc and cargo for compilation. To run, you'll need Python 3 still (due to no suitable replacement for dateparser in Rust) | ||||||
|  |  | ||||||
| ### Compiling for local target | ### Build APT package | ||||||
|  |  | ||||||
|  | Recommended method. | ||||||
|  |  | ||||||
|  | By default, this builds targeting Ubuntu 20.04. Modify the Containerfile if you wish to target a different platform. These instructions are written using `podman`, but `docker` should work too. | ||||||
|  |  | ||||||
|  | 1. Install container software: `sudo apt install podman`. | ||||||
|  | 2. Install database server: `sudo apt install mysql-server-8.0`. Create a database called `reminders` | ||||||
|  | 3. Install SQLx CLI: `cargo install sqlx-cli` | ||||||
|  | 4. From the source code directory, execute `sqlx migrate run` | ||||||
|  | 5. Build container image: `podman build -t reminder-rs .` | ||||||
|  | 6. Build with podman: `podman run --rm --network=host -v "$PWD":/mnt -w /mnt -e "DATABASE_URL=mysql://user@localhost/reminders" reminder-rs cargo deb`  | ||||||
|  |  | ||||||
|  |  | ||||||
|  | ### Compiling for other target | ||||||
|  |  | ||||||
| 1. Install requirements:  | 1. Install requirements:  | ||||||
| `sudo apt install gcc gcc-multilib cmake libssl-dev build-essential python3-dateparser` | `sudo apt install gcc gcc-multilib cmake libssl-dev build-essential python3-dateparser` | ||||||
| 2. Install rustup from https://rustup.rs | 2. Install rustup from https://rustup.rs | ||||||
| @@ -19,18 +34,9 @@ You'll need rustc and cargo for compilation. To run, you'll need Python 3 still | |||||||
|    * `DATABASE_URL` - the URL of your MySQL database (`mysql://user[:password]@domain/database`) |    * `DATABASE_URL` - the URL of your MySQL database (`mysql://user[:password]@domain/database`) | ||||||
| 8. Build: `cargo build --release` | 8. Build: `cargo build --release` | ||||||
|  |  | ||||||
| ### Compiling for other target |  | ||||||
| By default, this builds targeting Ubuntu 20.04. Modify the Containerfile if you wish to target a different platform. These instructions are written using `podman`, but `docker` should work too. |  | ||||||
|  |  | ||||||
| 1. Install container software: `sudo apt install podman`. |  | ||||||
| 2. Install database server: `sudo apt install mysql-server-8.0`. Create a database called `reminders` |  | ||||||
| 3. Install SQLx CLI: `cargo install sqlx-cli` |  | ||||||
| 4. From the source code directory, execute `sqlx migrate run` |  | ||||||
| 5. Build container image: `podman build -t reminder-rs .` |  | ||||||
| 6. Build with podman: `podman run --rm --network=host -v "$PWD":/mnt -w /mnt -e "DATABASE_URL=mysql://user@localhost/reminders" reminder-rs cargo deb`  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| ### Configuring | ### Configuring | ||||||
|  |  | ||||||
| Reminder Bot reads a number of environment variables. Some are essential, and others have hardcoded fallbacks. Environment variables can be loaded from a .env file in the working directory. | Reminder Bot reads a number of environment variables. Some are essential, and others have hardcoded fallbacks. Environment variables can be loaded from a .env file in the working directory. | ||||||
|  |  | ||||||
| __Required Variables__ | __Required Variables__ | ||||||
|   | |||||||
							
								
								
									
										8
									
								
								conf/Rocket.toml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								conf/Rocket.toml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | |||||||
|  | [default] | ||||||
|  | address = "127.0.0.1" | ||||||
|  | port = 18920 | ||||||
|  | template_dir = "/lib/reminder-rs/templates" | ||||||
|  | limits = { json = "10MiB" } | ||||||
|  |  | ||||||
|  | [release] | ||||||
|  | # secret_key = "" | ||||||
| @@ -7,10 +7,13 @@ PATREON_ROLE_ID= | |||||||
| LOCAL_TIMEZONE= | LOCAL_TIMEZONE= | ||||||
| MIN_INTERVAL= | MIN_INTERVAL= | ||||||
| PYTHON_LOCATION=/usr/bin/python3 | PYTHON_LOCATION=/usr/bin/python3 | ||||||
| DONTRUN=web | DONTRUN= | ||||||
| SECRET_KEY= | SECRET_KEY= | ||||||
|  |  | ||||||
| REMIND_INTERVAL= | REMIND_INTERVAL= | ||||||
| OAUTH2_DISCORD_CALLBACK= | OAUTH2_DISCORD_CALLBACK= | ||||||
| OAUTH2_CLIENT_ID= | OAUTH2_CLIENT_ID= | ||||||
| OAUTH2_CLIENT_SECRET= | OAUTH2_CLIENT_SECRET= | ||||||
|  |  | ||||||
|  | REPORT_EMAIL= | ||||||
|  | LOG_TO_DATABASE=1 | ||||||
|   | |||||||
							
								
								
									
										1
									
								
								cron.d/reminder_health
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								cron.d/reminder_health
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | |||||||
|  | */10 * * * * reminder /lib/reminder-rs/healthcheck | ||||||
							
								
								
									
										6
									
								
								debian/postinst
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								debian/postinst
									
									
									
									
										vendored
									
									
								
							| @@ -4,10 +4,6 @@ set -e | |||||||
|  |  | ||||||
| id -u reminder &>/dev/null || useradd -r -M reminder | id -u reminder &>/dev/null || useradd -r -M reminder | ||||||
|  |  | ||||||
| if [ ! -f /etc/reminder-rs/config.env ]; then | chown -R reminder /etc/reminder-rs | ||||||
|   cp /etc/reminder-rs/default.env /etc/reminder-rs/config.env |  | ||||||
| fi |  | ||||||
|  |  | ||||||
| chown reminder /etc/reminder-rs/config.env |  | ||||||
|  |  | ||||||
| #DEBHELPER# | #DEBHELPER# | ||||||
|   | |||||||
							
								
								
									
										4
									
								
								debian/postrm
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								debian/postrm
									
									
									
									
										vendored
									
									
								
							| @@ -4,8 +4,4 @@ set -e | |||||||
|  |  | ||||||
| id -u reminder &>/dev/null || userdel reminder | id -u reminder &>/dev/null || userdel reminder | ||||||
|  |  | ||||||
| if [ -f /etc/reminder-rs/config.env ]; then |  | ||||||
|   rm /etc/reminder-rs/config.env |  | ||||||
| fi |  | ||||||
|  |  | ||||||
| #DEBHELPER# | #DEBHELPER# | ||||||
|   | |||||||
							
								
								
									
										13
									
								
								healthcheck
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										13
									
								
								healthcheck
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,13 @@ | |||||||
|  | #!/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,2 +1 @@ | |||||||
| -- Add migration script here |  | ||||||
| ALTER TABLE reminders ADD COLUMN `thread_id` BIGINT DEFAULT NULL; | ALTER TABLE reminders ADD COLUMN `thread_id` BIGINT DEFAULT NULL; | ||||||
|   | |||||||
							
								
								
									
										1
									
								
								migrations/20230511180231_ephemeral_confirmations.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								migrations/20230511180231_ephemeral_confirmations.sql
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | |||||||
|  | ALTER TABLE guilds ADD COLUMN ephemeral_confirmations BOOL NOT NULL DEFAULT 0; | ||||||
							
								
								
									
										2
									
								
								migrations/20230722130906_increase_reminder_name.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								migrations/20230722130906_increase_reminder_name.sql
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | |||||||
|  | ALTER TABLE reminders MODIFY `name` VARCHAR(100) NOT NULL DEFAULT 'Reminder'; | ||||||
|  | ALTER TABLE reminder_template MODIFY `name` VARCHAR(100) NOT NULL DEFAULT 'Reminder'; | ||||||
							
								
								
									
										9
									
								
								migrations/20230730134827_stats.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								migrations/20230730134827_stats.sql
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | |||||||
|  | CREATE TABLE stat ( | ||||||
|  |     `id` BIGINT NOT NULL AUTO_INCREMENT, | ||||||
|  |     `utc_time` DATETIME NOT NULL DEFAULT NOW(), | ||||||
|  |     `type` ENUM('reminder_sent', 'reminder_failed'), | ||||||
|  |     `reminder_id` INT UNSIGNED, | ||||||
|  |     `message` TEXT, | ||||||
|  |  | ||||||
|  |     PRIMARY KEY (`id`) | ||||||
|  | ); | ||||||
							
								
								
									
										2
									
								
								migrations/20230731170452_reminder_archive.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								migrations/20230731170452_reminder_archive.sql
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | |||||||
|  | ALTER TABLE reminders ADD COLUMN `status` ENUM ('pending', 'sent', 'failed', 'deleted') NOT NULL DEFAULT 'pending'; | ||||||
|  | ALTER TABLE reminders ADD COLUMN `status_message` TEXT; | ||||||
							
								
								
									
										19
									
								
								migrations/20230812111348_orphan_reminders.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								migrations/20230812111348_orphan_reminders.sql
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | |||||||
|  | -- 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); | ||||||
							
								
								
									
										4
									
								
								migrations/20230903131153_reminder_status_timing.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								migrations/20230903131153_reminder_status_timing.sql
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | |||||||
|  | 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`; | ||||||
| @@ -1,3 +1,5 @@ | |||||||
|  | use std::env; | ||||||
|  |  | ||||||
| use chrono::{DateTime, Days, Duration, Months}; | use chrono::{DateTime, Days, Duration, Months}; | ||||||
| use chrono_tz::Tz; | use chrono_tz::Tz; | ||||||
| use lazy_static::lazy_static; | use lazy_static::lazy_static; | ||||||
| @@ -7,7 +9,7 @@ use regex::{Captures, Regex}; | |||||||
| use serde::Deserialize; | use serde::Deserialize; | ||||||
| use serenity::{ | use serenity::{ | ||||||
|     builder::CreateEmbed, |     builder::CreateEmbed, | ||||||
|     http::{CacheHttp, Http, HttpError, StatusCode}, |     http::{CacheHttp, Http, HttpError}, | ||||||
|     model::{ |     model::{ | ||||||
|         channel::{Channel, Embed as SerenityEmbed}, |         channel::{Channel, Embed as SerenityEmbed}, | ||||||
|         id::ChannelId, |         id::ChannelId, | ||||||
| @@ -30,6 +32,7 @@ lazy_static! { | |||||||
|         Regex::new(r#"<<timefrom:(?P<time>\d+):(?P<format>.+)?>>"#).unwrap(); |         Regex::new(r#"<<timefrom:(?P<time>\d+):(?P<format>.+)?>>"#).unwrap(); | ||||||
|     pub static ref TIMENOW_REGEX: Regex = |     pub static ref TIMENOW_REGEX: Regex = | ||||||
|         Regex::new(r#"<<timenow:(?P<timezone>(?:\w|/|_)+):(?P<format>.+)?>>"#).unwrap(); |         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 { | fn fmt_displacement(format: &str, seconds: u64) -> String { | ||||||
| @@ -151,7 +154,7 @@ impl Embed { | |||||||
|                 embed.description = substitute(&embed.description); |                 embed.description = substitute(&embed.description); | ||||||
|                 embed.footer = substitute(&embed.footer); |                 embed.footer = substitute(&embed.footer); | ||||||
|  |  | ||||||
|                 embed.fields.iter_mut().for_each(|mut field| { |                 embed.fields.iter_mut().for_each(|field| { | ||||||
|                     field.title = substitute(&field.title); |                     field.title = substitute(&field.title); | ||||||
|                     field.value = substitute(&field.value); |                     field.value = substitute(&field.value); | ||||||
|                 }); |                 }); | ||||||
| @@ -299,16 +302,20 @@ INNER JOIN | |||||||
| ON | ON | ||||||
|     reminders.channel_id = channels.id |     reminders.channel_id = channels.id | ||||||
| WHERE | WHERE | ||||||
|  |     reminders.`status` = 'pending' AND | ||||||
|     reminders.`id` IN ( |     reminders.`id` IN ( | ||||||
|         SELECT |         SELECT | ||||||
|             MIN(id) |             MIN(id) | ||||||
|         FROM |         FROM | ||||||
|             reminders |             reminders | ||||||
|         WHERE |         WHERE | ||||||
|             reminders.`utc_time` <= NOW() |             reminders.`utc_time` <= NOW() AND | ||||||
|             AND ( |             reminders.`channel_id` IS NOT NULL AND | ||||||
|  |             `status` = 'pending' AND | ||||||
|  |             ( | ||||||
|                 reminders.`interval_seconds` IS NOT NULL |                 reminders.`interval_seconds` IS NOT NULL | ||||||
|                 OR reminders.`interval_months` IS NOT NULL |                 OR reminders.`interval_months` IS NOT NULL | ||||||
|  |                 OR reminders.`interval_days` IS NOT NULL | ||||||
|                 OR reminders.enabled |                 OR reminders.enabled | ||||||
|             ) |             ) | ||||||
|         GROUP BY channel_id |         GROUP BY channel_id | ||||||
| @@ -345,40 +352,68 @@ WHERE | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     async fn refresh(&self, pool: impl Executor<'_, Database = Database> + Copy) { |     async fn refresh(&self, pool: impl Executor<'_, Database = Database> + Copy) { | ||||||
|         if self.interval_seconds.is_some() || self.interval_months.is_some() { |         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 now = Utc::now(); | ||||||
|             let mut updated_reminder_time = |             let mut updated_reminder_time = | ||||||
|                 self.utc_time.with_timezone(&self.timezone.parse().unwrap_or(Tz::UTC)); |                 self.utc_time.with_timezone(&self.timezone.parse().unwrap_or(Tz::UTC)); | ||||||
|  |             let mut fail_count = 0; | ||||||
|  |  | ||||||
|             while updated_reminder_time < now { |             while updated_reminder_time < now && fail_count < 4 { | ||||||
|                 if let Some(interval) = self.interval_months { |                 if let Some(interval) = self.interval_months { | ||||||
|  |                     if interval != 0 { | ||||||
|                         updated_reminder_time = updated_reminder_time |                         updated_reminder_time = updated_reminder_time | ||||||
|                             .checked_add_months(Months::new(interval)) |                             .checked_add_months(Months::new(interval)) | ||||||
|                             .unwrap_or_else(|| { |                             .unwrap_or_else(|| { | ||||||
|                             warn!("Could not add months to a reminder"); |                                 warn!( | ||||||
|  |                                     "{}: Could not add {} months to a reminder", | ||||||
|  |                                     interval, self.id | ||||||
|  |                                 ); | ||||||
|  |                                 fail_count += 1; | ||||||
|  |  | ||||||
|                                 updated_reminder_time |                                 updated_reminder_time | ||||||
|                             }); |                             }); | ||||||
|                     } |                     } | ||||||
|  |                 } | ||||||
|  |  | ||||||
|                 if let Some(interval) = self.interval_days { |                 if let Some(interval) = self.interval_days { | ||||||
|  |                     if interval != 0 { | ||||||
|                         updated_reminder_time = updated_reminder_time |                         updated_reminder_time = updated_reminder_time | ||||||
|                             .checked_add_days(Days::new(interval as u64)) |                             .checked_add_days(Days::new(interval as u64)) | ||||||
|                             .unwrap_or_else(|| { |                             .unwrap_or_else(|| { | ||||||
|                             warn!("Could not add days to a reminder"); |                                 warn!("{}: Could not add {} days to a reminder", self.id, interval); | ||||||
|  |                                 fail_count += 1; | ||||||
|  |  | ||||||
|                                 updated_reminder_time |                                 updated_reminder_time | ||||||
|                         }); |                             }) | ||||||
|  |                     } | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 if let Some(interval) = self.interval_seconds { |                 if let Some(interval) = self.interval_seconds { | ||||||
|                     updated_reminder_time = |                     updated_reminder_time += Duration::seconds(interval as i64); | ||||||
|                         updated_reminder_time + Duration::seconds(interval as i64); |  | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             if self.expires.map_or(false, |expires| updated_reminder_time > expires) { |             if fail_count >= 4 { | ||||||
|                 self.force_delete(pool).await; |                 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 { |             } else { | ||||||
|                 sqlx::query!( |                 sqlx::query!( | ||||||
|                     "UPDATE reminders SET `utc_time` = ? WHERE `id` = ?", |                     "UPDATE reminders SET `utc_time` = ? WHERE `id` = ?", | ||||||
| @@ -390,12 +425,76 @@ WHERE | |||||||
|                 .expect(&format!("Could not update time on Reminder {}", self.id)); |                 .expect(&format!("Could not update time on Reminder {}", self.id)); | ||||||
|             } |             } | ||||||
|         } else { |         } else { | ||||||
|             self.force_delete(pool).await; |             self.set_sent(pool).await; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     async fn force_delete(&self, pool: impl Executor<'_, Database = Database> + Copy) { |     async fn log_error( | ||||||
|         sqlx::query!("DELETE FROM reminders WHERE `id` = ?", self.id) |         &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` = ? WHERE `id` = ?", | ||||||
|  |             message, | ||||||
|  |             self.id | ||||||
|  |         ) | ||||||
|         .execute(pool) |         .execute(pool) | ||||||
|         .await |         .await | ||||||
|         .expect(&format!("Could not delete Reminder {}", self.id)); |         .expect(&format!("Could not delete Reminder {}", self.id)); | ||||||
| @@ -555,7 +654,7 @@ WHERE | |||||||
|                 if let Ok(webhook) = webhook_res { |                 if let Ok(webhook) = webhook_res { | ||||||
|                     send_to_webhook(cache_http, &self, webhook, embed).await |                     send_to_webhook(cache_http, &self, webhook, embed).await | ||||||
|                 } else { |                 } else { | ||||||
|                     warn!("Webhook vanished: {:?}", webhook_res); |                     warn!("Webhook vanished for reminder {}: {:?}", self.id, webhook_res); | ||||||
|  |  | ||||||
|                     self.reset_webhook(pool).await; |                     self.reset_webhook(pool).await; | ||||||
|                     send_to_channel(cache_http, &self, embed).await |                     send_to_channel(cache_http, &self, embed).await | ||||||
| @@ -565,24 +664,84 @@ WHERE | |||||||
|             }; |             }; | ||||||
|  |  | ||||||
|             if let Err(e) = result { |             if let Err(e) = result { | ||||||
|                 error!("Error sending reminder {}: {:?}", self.id, e); |  | ||||||
|  |  | ||||||
|                 if let Error::Http(error) = e { |                 if let Error::Http(error) = e { | ||||||
|                     if error.status_code() == Some(StatusCode::NOT_FOUND) { |                     if let HttpError::UnsuccessfulRequest(http_error) = *error { | ||||||
|                         warn!("Seeing channel is deleted. Removing reminder"); |                         match http_error.error.code { | ||||||
|                         self.force_delete(pool).await; |                             10003 => { | ||||||
|                     } else if let HttpError::UnsuccessfulRequest(error) = *error { |                                 self.log_error( | ||||||
|                         if error.error.code == 50007 { |                                     pool, | ||||||
|                             warn!("User cannot receive DMs"); |                                     "Could not be sent as channel does not exist", | ||||||
|                             self.force_delete(pool).await; |                                     None::<&'static str>, | ||||||
|                         } else { |                                 ) | ||||||
|  |                                 .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; |                                 self.refresh(pool).await; | ||||||
|                             } |                             } | ||||||
|                         } |                         } | ||||||
|                     } else { |                     } else { | ||||||
|  |                         self.log_error(pool, "(Likely) a parsing error", Some(error)).await; | ||||||
|                         self.refresh(pool).await; |                         self.refresh(pool).await; | ||||||
|                     } |                     } | ||||||
|                 } else { |                 } 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; |                 self.refresh(pool).await; | ||||||
|             } |             } | ||||||
|         } else { |         } else { | ||||||
|   | |||||||
| @@ -55,7 +55,7 @@ pub async fn time_hint_autocomplete( | |||||||
|                     if diff < 0 { |                     if diff < 0 { | ||||||
|                         vec![AutocompleteChoice { |                         vec![AutocompleteChoice { | ||||||
|                             name: "Time is in the past".to_string(), |                             name: "Time is in the past".to_string(), | ||||||
|                             value: "now".to_string(), |                             value: "1 year ago".to_string(), | ||||||
|                         }] |                         }] | ||||||
|                     } else { |                     } else { | ||||||
|                         if diff > 86400 { |                         if diff > 86400 { | ||||||
|   | |||||||
| @@ -6,8 +6,8 @@ use crate::{models::CtxData, Context, Error, THEME_COLOR}; | |||||||
| fn footer( | fn footer( | ||||||
|     ctx: Context<'_>, |     ctx: Context<'_>, | ||||||
| ) -> impl FnOnce(&mut serenity::CreateEmbedFooter) -> &mut serenity::CreateEmbedFooter { | ) -> impl FnOnce(&mut serenity::CreateEmbedFooter) -> &mut serenity::CreateEmbedFooter { | ||||||
|     let shard_count = ctx.discord().cache.shard_count(); |     let shard_count = ctx.serenity_context().cache.shard_count(); | ||||||
|     let shard = ctx.discord().shard_id; |     let shard = ctx.serenity_context().shard_id; | ||||||
|  |  | ||||||
|     move |f| { |     move |f| { | ||||||
|         f.text(format!( |         f.text(format!( | ||||||
|   | |||||||
| @@ -102,6 +102,78 @@ You may want to use one of the popular timezones below, otherwise click [here](h | |||||||
|     Ok(()) |     Ok(()) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | /// Configure server settings | ||||||
|  | #[poise::command( | ||||||
|  |     slash_command, | ||||||
|  |     rename = "settings", | ||||||
|  |     identifying_name = "settings", | ||||||
|  |     guild_only = true | ||||||
|  | )] | ||||||
|  | pub async fn settings(_ctx: Context<'_>) -> Result<(), Error> { | ||||||
|  |     Ok(()) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /// Configure ephemeral setup | ||||||
|  | #[poise::command( | ||||||
|  |     slash_command, | ||||||
|  |     rename = "ephemeral", | ||||||
|  |     identifying_name = "ephemeral_confirmations", | ||||||
|  |     guild_only = true | ||||||
|  | )] | ||||||
|  | pub async fn ephemeral_confirmations(_ctx: Context<'_>) -> Result<(), Error> { | ||||||
|  |     Ok(()) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /// Set reminder confirmations to be sent "ephemerally" (private and cleared automatically) | ||||||
|  | #[poise::command( | ||||||
|  |     slash_command, | ||||||
|  |     rename = "on", | ||||||
|  |     identifying_name = "set_ephemeral_confirmations", | ||||||
|  |     guild_only = true | ||||||
|  | )] | ||||||
|  | pub async fn set_ephemeral_confirmations(ctx: Context<'_>) -> Result<(), Error> { | ||||||
|  |     let mut guild_data = ctx.guild_data().await.unwrap()?; | ||||||
|  |     guild_data.ephemeral_confirmations = true; | ||||||
|  |     guild_data.commit_changes(&ctx.data().database).await; | ||||||
|  |  | ||||||
|  |     ctx.send(|r| { | ||||||
|  |         r.ephemeral(true).embed(|e| { | ||||||
|  |             e.title("Confirmations ephemeral") | ||||||
|  |                 .description("Reminder confirmations will be sent privately, and removed when your client restarts.") | ||||||
|  |                 .color(*THEME_COLOR) | ||||||
|  |         }) | ||||||
|  |     }) | ||||||
|  |     .await?; | ||||||
|  |  | ||||||
|  |     Ok(()) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /// Set reminder confirmations to persist indefinitely | ||||||
|  | #[poise::command( | ||||||
|  |     slash_command, | ||||||
|  |     rename = "off", | ||||||
|  |     identifying_name = "unset_ephemeral_confirmations", | ||||||
|  |     guild_only = true | ||||||
|  | )] | ||||||
|  | pub async fn unset_ephemeral_confirmations(ctx: Context<'_>) -> Result<(), Error> { | ||||||
|  |     let mut guild_data = ctx.guild_data().await.unwrap()?; | ||||||
|  |     guild_data.ephemeral_confirmations = false; | ||||||
|  |     guild_data.commit_changes(&ctx.data().database).await; | ||||||
|  |  | ||||||
|  |     ctx.send(|r| { | ||||||
|  |         r.ephemeral(true).embed(|e| { | ||||||
|  |             e.title("Confirmations public") | ||||||
|  |                 .description( | ||||||
|  |                     "Reminder confirmations will be sent as regular messages, and won't be removed automatically.", | ||||||
|  |                 ) | ||||||
|  |                 .color(*THEME_COLOR) | ||||||
|  |         }) | ||||||
|  |     }) | ||||||
|  |     .await?; | ||||||
|  |  | ||||||
|  |     Ok(()) | ||||||
|  | } | ||||||
|  |  | ||||||
| /// Configure whether other users can set reminders to your direct messages | /// Configure whether other users can set reminders to your direct messages | ||||||
| #[poise::command(slash_command, rename = "dm", identifying_name = "allowed_dm")] | #[poise::command(slash_command, rename = "dm", identifying_name = "allowed_dm")] | ||||||
| pub async fn allowed_dm(_ctx: Context<'_>) -> Result<(), Error> { | pub async fn allowed_dm(_ctx: Context<'_>) -> Result<(), Error> { | ||||||
| @@ -109,7 +181,7 @@ pub async fn allowed_dm(_ctx: Context<'_>) -> Result<(), Error> { | |||||||
| } | } | ||||||
|  |  | ||||||
| /// Allow other users to set reminders in your direct messages | /// Allow other users to set reminders in your direct messages | ||||||
| #[poise::command(slash_command, rename = "allow", identifying_name = "allowed_dm")] | #[poise::command(slash_command, rename = "allow", identifying_name = "set_allowed_dm")] | ||||||
| pub async fn set_allowed_dm(ctx: Context<'_>) -> Result<(), Error> { | pub async fn set_allowed_dm(ctx: Context<'_>) -> Result<(), Error> { | ||||||
|     let mut user_data = ctx.author_data().await?; |     let mut user_data = ctx.author_data().await?; | ||||||
|     user_data.allowed_dm = true; |     user_data.allowed_dm = true; | ||||||
| @@ -128,7 +200,7 @@ pub async fn set_allowed_dm(ctx: Context<'_>) -> Result<(), Error> { | |||||||
| } | } | ||||||
|  |  | ||||||
| /// Block other users from setting reminders in your direct messages | /// Block other users from setting reminders in your direct messages | ||||||
| #[poise::command(slash_command, rename = "block", identifying_name = "allowed_dm")] | #[poise::command(slash_command, rename = "block", identifying_name = "unset_allowed_dm")] | ||||||
| pub async fn unset_allowed_dm(ctx: Context<'_>) -> Result<(), Error> { | pub async fn unset_allowed_dm(ctx: Context<'_>) -> Result<(), Error> { | ||||||
|     let mut user_data = ctx.author_data().await?; |     let mut user_data = ctx.author_data().await?; | ||||||
|     user_data.allowed_dm = false; |     user_data.allowed_dm = false; | ||||||
|   | |||||||
| @@ -2,6 +2,7 @@ use std::{collections::HashSet, string::ToString}; | |||||||
|  |  | ||||||
| use chrono::{DateTime, NaiveDateTime, Utc}; | use chrono::{DateTime, NaiveDateTime, Utc}; | ||||||
| use chrono_tz::Tz; | use chrono_tz::Tz; | ||||||
|  | use log::warn; | ||||||
| use num_integer::Integer; | use num_integer::Integer; | ||||||
| use poise::{ | use poise::{ | ||||||
|     serenity_prelude::{ |     serenity_prelude::{ | ||||||
| @@ -215,7 +216,7 @@ pub async fn look( | |||||||
|         }), |         }), | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     let channel_opt = ctx.channel_id().to_channel_cached(&ctx.discord()); |     let channel_opt = ctx.channel_id().to_channel_cached(&ctx); | ||||||
|  |  | ||||||
|     let channel_id = if let Some(Channel::Guild(channel)) = channel_opt { |     let channel_id = if let Some(Channel::Guild(channel)) = channel_opt { | ||||||
|         if Some(channel.guild_id) == ctx.guild_id() { |         if Some(channel.guild_id) == ctx.guild_id() { | ||||||
| @@ -227,8 +228,7 @@ pub async fn look( | |||||||
|         ctx.channel_id() |         ctx.channel_id() | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     let channel_name = |     let channel_name = if let Some(Channel::Guild(channel)) = channel_id.to_channel_cached(&ctx) { | ||||||
|         if let Some(Channel::Guild(channel)) = channel_id.to_channel_cached(&ctx.discord()) { |  | ||||||
|         Some(channel.name) |         Some(channel.name) | ||||||
|     } else { |     } else { | ||||||
|         None |         None | ||||||
| @@ -294,8 +294,7 @@ pub async fn delete(ctx: Context<'_>) -> Result<(), Error> { | |||||||
|     let timezone = ctx.timezone().await; |     let timezone = ctx.timezone().await; | ||||||
|  |  | ||||||
|     let reminders = |     let reminders = | ||||||
|         Reminder::from_guild(&ctx.discord(), &ctx.data().database, ctx.guild_id(), ctx.author().id) |         Reminder::from_guild(&ctx, &ctx.data().database, ctx.guild_id(), ctx.author().id).await; | ||||||
|             .await; |  | ||||||
|  |  | ||||||
|     let resp = show_delete_page(&reminders, 0, timezone); |     let resp = show_delete_page(&reminders, 0, timezone); | ||||||
|  |  | ||||||
| @@ -585,8 +584,10 @@ pub async fn multiline( | |||||||
|     timezone: Option<String>, |     timezone: Option<String>, | ||||||
| ) -> Result<(), Error> { | ) -> Result<(), Error> { | ||||||
|     let tz = timezone.map(|t| t.parse::<Tz>().ok()).flatten(); |     let tz = timezone.map(|t| t.parse::<Tz>().ok()).flatten(); | ||||||
|     let data = ContentModal::execute(ctx).await?; |     let data_opt = ContentModal::execute(ctx).await?; | ||||||
|  |  | ||||||
|  |     match data_opt { | ||||||
|  |         Some(data) => { | ||||||
|             create_reminder( |             create_reminder( | ||||||
|                 Context::Application(ctx), |                 Context::Application(ctx), | ||||||
|                 time, |                 time, | ||||||
| @@ -598,6 +599,16 @@ pub async fn multiline( | |||||||
|                 tz, |                 tz, | ||||||
|             ) |             ) | ||||||
|             .await |             .await | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         None => { | ||||||
|  |             warn!("Unexpected None encountered in /multiline"); | ||||||
|  |             Ok(Context::Application(ctx) | ||||||
|  |                 .send(|m| m.content("Unexpected error.").ephemeral(true)) | ||||||
|  |                 .await | ||||||
|  |                 .map(|_| ())?) | ||||||
|  |         } | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| /// Create a reminder. Press "+4 more" for other options. Use "/multiline" for multiline content. | /// Create a reminder. Press "+4 more" for other options. Use "/multiline" for multiline content. | ||||||
| @@ -645,7 +656,13 @@ async fn create_reminder( | |||||||
|         return Ok(()); |         return Ok(()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     let ephemeral = | ||||||
|  |         ctx.guild_data().await.map_or(false, |gr| gr.map_or(false, |g| g.ephemeral_confirmations)); | ||||||
|  |     if ephemeral { | ||||||
|  |         ctx.defer_ephemeral().await?; | ||||||
|  |     } else { | ||||||
|         ctx.defer().await?; |         ctx.defer().await?; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     let user_data = ctx.author_data().await.unwrap(); |     let user_data = ctx.author_data().await.unwrap(); | ||||||
|     let timezone = timezone.unwrap_or(ctx.timezone().await); |     let timezone = timezone.unwrap_or(ctx.timezone().await); | ||||||
| @@ -675,9 +692,9 @@ async fn create_reminder( | |||||||
|             }; |             }; | ||||||
|  |  | ||||||
|             let (processed_interval, processed_expires) = if let Some(repeat) = &interval { |             let (processed_interval, processed_expires) = if let Some(repeat) = &interval { | ||||||
|                 if check_subscription(&ctx.discord(), ctx.author().id).await |                 if check_subscription(&ctx, ctx.author().id).await | ||||||
|                     || (ctx.guild_id().is_some() |                     || (ctx.guild_id().is_some() | ||||||
|                         && check_guild_subscription(&ctx.discord(), ctx.guild_id().unwrap()).await) |                         && check_guild_subscription(&ctx, ctx.guild_id().unwrap()).await) | ||||||
|                 { |                 { | ||||||
|                     ( |                     ( | ||||||
|                         parse_duration(repeat) |                         parse_duration(repeat) | ||||||
| @@ -692,9 +709,10 @@ async fn create_reminder( | |||||||
|                         }, |                         }, | ||||||
|                     ) |                     ) | ||||||
|                 } else { |                 } else { | ||||||
|                     ctx.say( |                     ctx.send(|b| { | ||||||
|                         "`repeat` is only available to Patreon subscribers or self-hosted users", |                         b.content( | ||||||
|                     ) |                         "`repeat` is only available to Patreon subscribers or self-hosted users") | ||||||
|  |                     }) | ||||||
|                     .await?; |                     .await?; | ||||||
|  |  | ||||||
|                     return Ok(()); |                     return Ok(()); | ||||||
| @@ -704,12 +722,17 @@ async fn create_reminder( | |||||||
|             }; |             }; | ||||||
|  |  | ||||||
|             if processed_interval.is_none() && interval.is_some() { |             if processed_interval.is_none() && interval.is_some() { | ||||||
|                 ctx.say( |                 ctx.send(|b| { | ||||||
|                     "Repeat interval could not be processed. Try similar to `1 hour` or `4 days`", |                     b.content( | ||||||
|                 ) |                     "Repeat interval could not be processed. Try similar to `1 hour` or `4 days`") | ||||||
|  |                 }) | ||||||
|                 .await?; |                 .await?; | ||||||
|             } else if processed_expires.is_none() && expires.is_some() { |             } else if processed_expires.is_none() && expires.is_some() { | ||||||
|                 ctx.say("Expiry time failed to process. Please make it as clear as possible") |                 ctx.send(|b| { | ||||||
|  |                     b.ephemeral(true).content( | ||||||
|  |                         "Expiry time failed to process. Please make it as clear as possible", | ||||||
|  |                     ) | ||||||
|  |                 }) | ||||||
|                 .await?; |                 .await?; | ||||||
|             } else { |             } else { | ||||||
|                 let mut builder = MultiReminderBuilder::new(&ctx, ctx.guild_id()) |                 let mut builder = MultiReminderBuilder::new(&ctx, ctx.guild_id()) | ||||||
|   | |||||||
| @@ -2,6 +2,7 @@ pub(crate) mod pager; | |||||||
|  |  | ||||||
| use std::io::Cursor; | use std::io::Cursor; | ||||||
|  |  | ||||||
|  | use base64::{engine::general_purpose, Engine}; | ||||||
| use chrono_tz::Tz; | use chrono_tz::Tz; | ||||||
| use log::warn; | use log::warn; | ||||||
| use poise::{ | use poise::{ | ||||||
| @@ -51,11 +52,12 @@ impl ComponentDataModel { | |||||||
|     pub fn to_custom_id(&self) -> String { |     pub fn to_custom_id(&self) -> String { | ||||||
|         let mut buf = Vec::new(); |         let mut buf = Vec::new(); | ||||||
|         self.serialize(&mut Serializer::new(&mut buf)).unwrap(); |         self.serialize(&mut Serializer::new(&mut buf)).unwrap(); | ||||||
|         base64::encode(buf) |         general_purpose::STANDARD.encode(buf) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     pub fn from_custom_id(data: &String) -> Self { |     pub fn from_custom_id(data: &String) -> Self { | ||||||
|         let buf = base64::decode(data) |         let buf = general_purpose::STANDARD | ||||||
|  |             .decode(data) | ||||||
|             .map_err(|e| format!("Could not decode `custom_id' {}: {:?}", data, e)) |             .map_err(|e| format!("Could not decode `custom_id' {}: {:?}", data, e)) | ||||||
|             .unwrap(); |             .unwrap(); | ||||||
|         let cur = Cursor::new(buf); |         let cur = Cursor::new(buf); | ||||||
| @@ -164,12 +166,21 @@ impl ComponentDataModel { | |||||||
|                     .await; |                     .await; | ||||||
|             } |             } | ||||||
|             ComponentDataModel::DelSelector(selector) => { |             ComponentDataModel::DelSelector(selector) => { | ||||||
|                 let selected_id = component.data.values.join(","); |                 for id in &component.data.values { | ||||||
|  |                     match id.parse::<u32>() { | ||||||
|  |                         Ok(id) => { | ||||||
|  |                             if let Some(reminder) = Reminder::from_id(&data.database, id).await { | ||||||
|  |                                 reminder.delete(&data.database).await.unwrap(); | ||||||
|  |                             } else { | ||||||
|  |                                 warn!("Attempt to delete non-existent reminder"); | ||||||
|  |                             } | ||||||
|  |                         } | ||||||
|  |  | ||||||
|                 sqlx::query!("DELETE FROM reminders WHERE FIND_IN_SET(id, ?)", selected_id) |                         Err(e) => { | ||||||
|                     .execute(&data.database) |                             warn!("Error casting ID to integer: {:?}.", e); | ||||||
|                     .await |                         } | ||||||
|                     .unwrap(); |                     } | ||||||
|  |                 } | ||||||
|  |  | ||||||
|                 let reminders = Reminder::from_guild( |                 let reminders = Reminder::from_guild( | ||||||
|                     &ctx, |                     &ctx, | ||||||
|   | |||||||
							
								
								
									
										12
									
								
								src/hooks.rs
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								src/hooks.rs
									
									
									
									
									
								
							| @@ -47,21 +47,19 @@ async fn macro_check(ctx: Context<'_>) -> bool { | |||||||
|  |  | ||||||
| async fn check_self_permissions(ctx: Context<'_>) -> bool { | async fn check_self_permissions(ctx: Context<'_>) -> bool { | ||||||
|     if let Some(guild) = ctx.guild() { |     if let Some(guild) = ctx.guild() { | ||||||
|         let user_id = ctx.discord().cache.current_user_id(); |         let user_id = ctx.serenity_context().cache.current_user_id(); | ||||||
|  |  | ||||||
|         let manage_webhooks = guild |         let manage_webhooks = | ||||||
|             .member_permissions(&ctx.discord(), user_id) |             guild.member_permissions(&ctx, user_id).await.map_or(false, |p| p.manage_webhooks()); | ||||||
|             .await |  | ||||||
|             .map_or(false, |p| p.manage_webhooks()); |  | ||||||
|  |  | ||||||
|         let (view_channel, send_messages, embed_links) = ctx |         let (view_channel, send_messages, embed_links) = ctx | ||||||
|             .channel_id() |             .channel_id() | ||||||
|             .to_channel(&ctx.discord()) |             .to_channel(&ctx) | ||||||
|             .await |             .await | ||||||
|             .ok() |             .ok() | ||||||
|             .and_then(|c| { |             .and_then(|c| { | ||||||
|                 if let Channel::Guild(channel) = c { |                 if let Channel::Guild(channel) = c { | ||||||
|                     let perms = channel.permissions_for_user(&ctx.discord(), user_id).ok()?; |                     let perms = channel.permissions_for_user(&ctx, user_id).ok()?; | ||||||
|  |  | ||||||
|                     Some((perms.view_channel(), perms.send_messages(), perms.embed_links())) |                     Some((perms.view_channel(), perms.send_messages(), perms.embed_links())) | ||||||
|                 } else { |                 } else { | ||||||
|   | |||||||
							
								
								
									
										30
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								src/main.rs
									
									
									
									
									
								
							| @@ -91,7 +91,7 @@ async fn _main(tx: Sender<()>) -> Result<(), Box<dyn StdError + Send + Sync>> { | |||||||
|     if Path::new("/etc/reminder-rs/config.env").exists() { |     if Path::new("/etc/reminder-rs/config.env").exists() { | ||||||
|         dotenv::from_path("/etc/reminder-rs/config.env")?; |         dotenv::from_path("/etc/reminder-rs/config.env")?; | ||||||
|     } else { |     } else { | ||||||
|         dotenv::from_path(".env")?; |         let _ = dotenv::dotenv(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     let discord_token = env::var("DISCORD_TOKEN").expect("Missing DISCORD_TOKEN from environment"); |     let discord_token = env::var("DISCORD_TOKEN").expect("Missing DISCORD_TOKEN from environment"); | ||||||
| @@ -112,6 +112,16 @@ async fn _main(tx: Sender<()>) -> Result<(), Box<dyn StdError + Send + Sync>> { | |||||||
|                 ], |                 ], | ||||||
|                 ..moderation_cmds::allowed_dm() |                 ..moderation_cmds::allowed_dm() | ||||||
|             }, |             }, | ||||||
|  |             poise::Command { | ||||||
|  |                 subcommands: vec![poise::Command { | ||||||
|  |                     subcommands: vec![ | ||||||
|  |                         moderation_cmds::set_ephemeral_confirmations(), | ||||||
|  |                         moderation_cmds::unset_ephemeral_confirmations(), | ||||||
|  |                     ], | ||||||
|  |                     ..moderation_cmds::ephemeral_confirmations() | ||||||
|  |                 }], | ||||||
|  |                 ..moderation_cmds::settings() | ||||||
|  |             }, | ||||||
|             moderation_cmds::webhook(), |             moderation_cmds::webhook(), | ||||||
|             poise::Command { |             poise::Command { | ||||||
|                 subcommands: vec![ |                 subcommands: vec![ | ||||||
| @@ -165,7 +175,21 @@ async fn _main(tx: Sender<()>) -> Result<(), Box<dyn StdError + Send + Sync>> { | |||||||
|         ], |         ], | ||||||
|         allowed_mentions: None, |         allowed_mentions: None, | ||||||
|         command_check: Some(|ctx| Box::pin(all_checks(ctx))), |         command_check: Some(|ctx| Box::pin(all_checks(ctx))), | ||||||
|         listener: |ctx, event, _framework, data| Box::pin(listener(ctx, event, data)), |         event_handler: |ctx, event, _framework, data| Box::pin(listener(ctx, event, data)), | ||||||
|  |         on_error: |error| { | ||||||
|  |             Box::pin(async move { | ||||||
|  |                 match error { | ||||||
|  |                     poise::FrameworkError::CommandCheckFailed { .. } => { | ||||||
|  |                         // suppress error | ||||||
|  |                     } | ||||||
|  |                     error => { | ||||||
|  |                         if let Err(e) = poise::builtins::on_error(error).await { | ||||||
|  |                             log::error!("Error while handling error: {}", e); | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             }) | ||||||
|  |         }, | ||||||
|         ..Default::default() |         ..Default::default() | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
| @@ -191,7 +215,7 @@ async fn _main(tx: Sender<()>) -> Result<(), Box<dyn StdError + Send + Sync>> { | |||||||
|  |  | ||||||
|     poise::Framework::builder() |     poise::Framework::builder() | ||||||
|         .token(discord_token) |         .token(discord_token) | ||||||
|         .user_data_setup(move |ctx, _bot, framework| { |         .setup(move |ctx, _bot, framework| { | ||||||
|             Box::pin(async move { |             Box::pin(async move { | ||||||
|                 register_application_commands(ctx, framework, None).await.unwrap(); |                 register_application_commands(ctx, framework, None).await.unwrap(); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -10,6 +10,7 @@ pub struct ChannelData { | |||||||
|     pub webhook_id: Option<u64>, |     pub webhook_id: Option<u64>, | ||||||
|     pub webhook_token: Option<String>, |     pub webhook_token: Option<String>, | ||||||
|     pub paused: bool, |     pub paused: bool, | ||||||
|  |     pub db_guild_id: Option<u32>, | ||||||
|     pub paused_until: Option<NaiveDateTime>, |     pub paused_until: Option<NaiveDateTime>, | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -23,7 +24,9 @@ impl ChannelData { | |||||||
|         if let Ok(c) = sqlx::query_as_unchecked!( |         if let Ok(c) = sqlx::query_as_unchecked!( | ||||||
|             Self, |             Self, | ||||||
|             " |             " | ||||||
| SELECT id, name, nudge, blacklisted, webhook_id, webhook_token, paused, paused_until FROM channels WHERE channel = ? |             SELECT id, name, nudge, blacklisted, webhook_id, webhook_token, paused, paused_until, | ||||||
|  |                 guild_id AS db_guild_id | ||||||
|  |             FROM channels WHERE channel = ? | ||||||
|             ", |             ", | ||||||
|             channel_id |             channel_id | ||||||
|         ) |         ) | ||||||
| @@ -32,13 +35,17 @@ SELECT id, name, nudge, blacklisted, webhook_id, webhook_token, paused, paused_u | |||||||
|         { |         { | ||||||
|             Ok(c) |             Ok(c) | ||||||
|         } else { |         } else { | ||||||
|             let props = channel.to_owned().guild().map(|g| (g.guild_id.as_u64().to_owned(), g.name)); |             let props = | ||||||
|  |                 channel.to_owned().guild().map(|g| (g.guild_id.as_u64().to_owned(), g.name)); | ||||||
|  |  | ||||||
|             let (guild_id, channel_name) = if let Some((a, b)) = props { (Some(a), Some(b)) } else { (None, None) }; |             let (guild_id, channel_name) = | ||||||
|  |                 if let Some((a, b)) = props { (Some(a), Some(b)) } else { (None, None) }; | ||||||
|  |  | ||||||
|             sqlx::query!( |             sqlx::query!( | ||||||
|                 " |                 " | ||||||
| INSERT IGNORE INTO channels (channel, name, guild_id) VALUES (?, ?, (SELECT id FROM guilds WHERE guild = ?)) |                 INSERT IGNORE INTO channels | ||||||
|  |                 (channel, name, guild_id) | ||||||
|  |                 VALUES (?, ?, (SELECT id FROM guilds WHERE guild = ?)) | ||||||
|                 ", |                 ", | ||||||
|                 channel_id, |                 channel_id, | ||||||
|                 channel_name, |                 channel_name, | ||||||
| @@ -50,7 +57,10 @@ INSERT IGNORE INTO channels (channel, name, guild_id) VALUES (?, ?, (SELECT id F | |||||||
|             Ok(sqlx::query_as_unchecked!( |             Ok(sqlx::query_as_unchecked!( | ||||||
|                 Self, |                 Self, | ||||||
|                 " |                 " | ||||||
| SELECT id, name, nudge, blacklisted, webhook_id, webhook_token, paused, paused_until FROM channels WHERE channel = ? |                 SELECT id, name, nudge, blacklisted, webhook_id, webhook_token, paused, | ||||||
|  |                     paused_until, guild_id AS db_guild_id | ||||||
|  |                 FROM channels | ||||||
|  |                 WHERE channel = ? | ||||||
|                 ", |                 ", | ||||||
|                 channel_id |                 channel_id | ||||||
|             ) |             ) | ||||||
| @@ -62,9 +72,10 @@ SELECT id, name, nudge, blacklisted, webhook_id, webhook_token, paused, paused_u | |||||||
|     pub async fn commit_changes(&self, pool: &MySqlPool) { |     pub async fn commit_changes(&self, pool: &MySqlPool) { | ||||||
|         sqlx::query!( |         sqlx::query!( | ||||||
|             " |             " | ||||||
| UPDATE channels SET name = ?, nudge = ?, blacklisted = ?, webhook_id = ?, webhook_token = ?, paused = ?, paused_until \ |             UPDATE channels | ||||||
|              = ? WHERE id = ? |             SET name = ?, nudge = ?, blacklisted = ?, webhook_id = ?, webhook_token = ?, | ||||||
|             ", |                 paused = ?, paused_until = ? | ||||||
|  |             WHERE id = ?", | ||||||
|             self.name, |             self.name, | ||||||
|             self.nudge, |             self.nudge, | ||||||
|             self.blacklisted, |             self.blacklisted, | ||||||
|   | |||||||
							
								
								
									
										48
									
								
								src/models/guild_data.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								src/models/guild_data.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,48 @@ | |||||||
|  | use poise::serenity_prelude::GuildId; | ||||||
|  | use sqlx::MySqlPool; | ||||||
|  |  | ||||||
|  | pub struct GuildData { | ||||||
|  |     pub ephemeral_confirmations: bool, | ||||||
|  |     pub id: u32, | ||||||
|  | } | ||||||
|  |  | ||||||
|  | impl GuildData { | ||||||
|  |     pub async fn from_guild( | ||||||
|  |         guild_id: GuildId, | ||||||
|  |         pool: &MySqlPool, | ||||||
|  |     ) -> Result<Self, Box<dyn std::error::Error + Sync + Send>> { | ||||||
|  |         if let Ok(c) = sqlx::query_as_unchecked!( | ||||||
|  |             Self, | ||||||
|  |             "SELECT id, ephemeral_confirmations FROM guilds WHERE guild = ?", | ||||||
|  |             guild_id.0 | ||||||
|  |         ) | ||||||
|  |         .fetch_one(pool) | ||||||
|  |         .await | ||||||
|  |         { | ||||||
|  |             Ok(c) | ||||||
|  |         } else { | ||||||
|  |             sqlx::query!("INSERT IGNORE INTO guilds (guild) VALUES (?)", guild_id.0) | ||||||
|  |                 .execute(&pool.clone()) | ||||||
|  |                 .await?; | ||||||
|  |  | ||||||
|  |             Ok(sqlx::query_as_unchecked!( | ||||||
|  |                 Self, | ||||||
|  |                 "SELECT id, ephemeral_confirmations FROM guilds WHERE guild = ?", | ||||||
|  |                 guild_id.0 | ||||||
|  |             ) | ||||||
|  |             .fetch_one(pool) | ||||||
|  |             .await?) | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     pub async fn commit_changes(&self, pool: &MySqlPool) { | ||||||
|  |         sqlx::query!( | ||||||
|  |             "UPDATE guilds SET ephemeral_confirmations = ? WHERE id = ?", | ||||||
|  |             self.ephemeral_confirmations, | ||||||
|  |             self.id | ||||||
|  |         ) | ||||||
|  |         .execute(pool) | ||||||
|  |         .await | ||||||
|  |         .unwrap(); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -1,5 +1,6 @@ | |||||||
| pub mod channel_data; | pub mod channel_data; | ||||||
| pub mod command_macro; | pub mod command_macro; | ||||||
|  | pub mod guild_data; | ||||||
| pub mod reminder; | pub mod reminder; | ||||||
| pub mod timer; | pub mod timer; | ||||||
| pub mod user_data; | pub mod user_data; | ||||||
| @@ -8,7 +9,7 @@ use chrono_tz::Tz; | |||||||
| use poise::serenity_prelude::{async_trait, model::id::UserId, ChannelType}; | use poise::serenity_prelude::{async_trait, model::id::UserId, ChannelType}; | ||||||
|  |  | ||||||
| use crate::{ | use crate::{ | ||||||
|     models::{channel_data::ChannelData, user_data::UserData}, |     models::{channel_data::ChannelData, guild_data::GuildData, user_data::UserData}, | ||||||
|     CommandMacro, Context, Data, Error, GuildId, |     CommandMacro, Context, Data, Error, GuildId, | ||||||
| }; | }; | ||||||
|  |  | ||||||
| @@ -18,6 +19,8 @@ pub trait CtxData { | |||||||
|  |  | ||||||
|     async fn author_data(&self) -> Result<UserData, Error>; |     async fn author_data(&self) -> Result<UserData, Error>; | ||||||
|  |  | ||||||
|  |     async fn guild_data(&self) -> Option<Result<GuildData, Error>>; | ||||||
|  |  | ||||||
|     async fn timezone(&self) -> Tz; |     async fn timezone(&self) -> Tz; | ||||||
|  |  | ||||||
|     async fn channel_data(&self) -> Result<ChannelData, Error>; |     async fn channel_data(&self) -> Result<ChannelData, Error>; | ||||||
| @@ -27,15 +30,21 @@ pub trait CtxData { | |||||||
|  |  | ||||||
| #[async_trait] | #[async_trait] | ||||||
| impl CtxData for Context<'_> { | impl CtxData for Context<'_> { | ||||||
|     async fn user_data<U: Into<UserId> + Send>( |     async fn user_data<U: Into<UserId> + Send>(&self, user_id: U) -> Result<UserData, Error> { | ||||||
|         &self, |         UserData::from_user(user_id, &self.serenity_context(), &self.data().database).await | ||||||
|         user_id: U, |  | ||||||
|     ) -> Result<UserData, Box<dyn std::error::Error + Sync + Send>> { |  | ||||||
|         UserData::from_user(user_id, &self.discord(), &self.data().database).await |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     async fn author_data(&self) -> Result<UserData, Box<dyn std::error::Error + Sync + Send>> { |     async fn author_data(&self) -> Result<UserData, Error> { | ||||||
|         UserData::from_user(&self.author().id, &self.discord(), &self.data().database).await |         UserData::from_user(&self.author().id, &self.serenity_context(), &self.data().database) | ||||||
|  |             .await | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     async fn guild_data(&self) -> Option<Result<GuildData, Error>> { | ||||||
|  |         if let Some(guild_id) = self.guild_id() { | ||||||
|  |             Some(GuildData::from_guild(guild_id, &self.data().database).await) | ||||||
|  |         } else { | ||||||
|  |             None | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     async fn timezone(&self) -> Tz { |     async fn timezone(&self) -> Tz { | ||||||
| @@ -44,18 +53,18 @@ impl CtxData for Context<'_> { | |||||||
|  |  | ||||||
|     async fn channel_data(&self) -> Result<ChannelData, Box<dyn std::error::Error + Sync + Send>> { |     async fn channel_data(&self) -> Result<ChannelData, Box<dyn std::error::Error + Sync + Send>> { | ||||||
|         // If we're in a thread, get the parent channel. |         // If we're in a thread, get the parent channel. | ||||||
|         let recv_channel = self.channel_id().to_channel(&self.discord()).await?; |         let recv_channel = self.channel_id().to_channel(&self).await?; | ||||||
|  |  | ||||||
|         let channel = match recv_channel.guild() { |         let channel = match recv_channel.guild() { | ||||||
|             Some(guild_channel) => { |             Some(guild_channel) => { | ||||||
|                 if guild_channel.kind == ChannelType::PublicThread { |                 if guild_channel.kind == ChannelType::PublicThread { | ||||||
|                     guild_channel.parent_id.unwrap().to_channel_cached(&self.discord()).unwrap() |                     guild_channel.parent_id.unwrap().to_channel_cached(&self).unwrap() | ||||||
|                 } else { |                 } else { | ||||||
|                     self.channel_id().to_channel_cached(&self.discord()).unwrap() |                     self.channel_id().to_channel_cached(&self).unwrap() | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             None => self.channel_id().to_channel_cached(&self.discord()).unwrap(), |             None => self.channel_id().to_channel_cached(&self).unwrap(), | ||||||
|         }; |         }; | ||||||
|  |  | ||||||
|         ChannelData::from_channel(&channel, &self.data().database).await |         ChannelData::from_channel(&channel, &self.data().database).await | ||||||
|   | |||||||
| @@ -51,6 +51,7 @@ pub struct ReminderBuilder { | |||||||
|     pool: MySqlPool, |     pool: MySqlPool, | ||||||
|     uid: String, |     uid: String, | ||||||
|     channel: u32, |     channel: u32, | ||||||
|  |     guild: Option<u32>, | ||||||
|     thread_id: Option<u64>, |     thread_id: Option<u64>, | ||||||
|     utc_time: NaiveDateTime, |     utc_time: NaiveDateTime, | ||||||
|     timezone: String, |     timezone: String, | ||||||
| @@ -86,6 +87,7 @@ impl ReminderBuilder { | |||||||
| INSERT INTO reminders ( | INSERT INTO reminders ( | ||||||
|     `uid`, |     `uid`, | ||||||
|     `channel_id`, |     `channel_id`, | ||||||
|  |     `guild_id`, | ||||||
|     `utc_time`, |     `utc_time`, | ||||||
|     `timezone`, |     `timezone`, | ||||||
|     `interval_seconds`, |     `interval_seconds`, | ||||||
| @@ -110,11 +112,13 @@ INSERT INTO reminders ( | |||||||
|     ?, |     ?, | ||||||
|     ?, |     ?, | ||||||
|     ?, |     ?, | ||||||
|  |     ?, | ||||||
|     ? |     ? | ||||||
| ) | ) | ||||||
|             ", |             ", | ||||||
|                         self.uid, |                         self.uid, | ||||||
|                         self.channel, |                         self.channel, | ||||||
|  |                         self.guild, | ||||||
|                         utc_time, |                         utc_time, | ||||||
|                         self.timezone, |                         self.timezone, | ||||||
|                         self.interval_seconds, |                         self.interval_seconds, | ||||||
| @@ -230,35 +234,34 @@ impl<'a> MultiReminderBuilder<'a> { | |||||||
|                 let thread_id = None; |                 let thread_id = None; | ||||||
|                 let db_channel_id = match scope { |                 let db_channel_id = match scope { | ||||||
|                     ReminderScope::User(user_id) => { |                     ReminderScope::User(user_id) => { | ||||||
|                         if let Ok(user) = UserId(user_id).to_user(&self.ctx.discord()).await { |                         if let Ok(user) = UserId(user_id).to_user(&self.ctx).await { | ||||||
|                             let user_data = UserData::from_user( |                             let user_data = UserData::from_user( | ||||||
|                                 &user, |                                 &user, | ||||||
|                                 &self.ctx.discord(), |                                 &self.ctx.serenity_context(), | ||||||
|                                 &self.ctx.data().database, |                                 &self.ctx.data().database, | ||||||
|                             ) |                             ) | ||||||
|                             .await |                             .await | ||||||
|                             .unwrap(); |                             .unwrap(); | ||||||
|  |  | ||||||
|                             if let Some(guild_id) = self.guild_id { |                             if let Some(guild_id) = self.guild_id { | ||||||
|                                 if guild_id.member(&self.ctx.discord(), user).await.is_err() { |                                 if guild_id.member(&self.ctx, user).await.is_err() { | ||||||
|                                     Err(ReminderError::InvalidTag) |                                     Err(ReminderError::InvalidTag) | ||||||
|                                 } else if self.set_by.map_or(true, |i| i != user_data.id) |                                 } else if self.set_by.map_or(true, |i| i != user_data.id) | ||||||
|                                     && !user_data.allowed_dm |                                     && !user_data.allowed_dm | ||||||
|                                 { |                                 { | ||||||
|                                     Err(ReminderError::UserBlockedDm) |                                     Err(ReminderError::UserBlockedDm) | ||||||
|                                 } else { |                                 } else { | ||||||
|                                     Ok(user_data.dm_channel) |                                     Ok((user_data.dm_channel, None)) | ||||||
|                                 } |                                 } | ||||||
|                             } else { |                             } else { | ||||||
|                                 Ok(user_data.dm_channel) |                                 Ok((user_data.dm_channel, None)) | ||||||
|                             } |                             } | ||||||
|                         } else { |                         } else { | ||||||
|                             Err(ReminderError::InvalidTag) |                             Err(ReminderError::InvalidTag) | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                     ReminderScope::Channel(channel_id) => { |                     ReminderScope::Channel(channel_id) => { | ||||||
|                         let channel = |                         let channel = ChannelId(channel_id).to_channel(&self.ctx).await.unwrap(); | ||||||
|                             ChannelId(channel_id).to_channel(&self.ctx.discord()).await.unwrap(); |  | ||||||
|  |  | ||||||
|                         if let Some(mut guild_channel) = channel.clone().guild() { |                         if let Some(mut guild_channel) = channel.clone().guild() { | ||||||
|                             if Some(guild_channel.guild_id) != self.guild_id { |                             if Some(guild_channel.guild_id) != self.guild_id { | ||||||
| @@ -271,7 +274,7 @@ impl<'a> MultiReminderBuilder<'a> { | |||||||
|                                     let parent = guild_channel |                                     let parent = guild_channel | ||||||
|                                         .parent_id |                                         .parent_id | ||||||
|                                         .unwrap() |                                         .unwrap() | ||||||
|                                         .to_channel(&self.ctx.discord()) |                                         .to_channel(&self.ctx) | ||||||
|                                         .await |                                         .await | ||||||
|                                         .unwrap(); |                                         .unwrap(); | ||||||
|                                     guild_channel = parent.clone().guild().unwrap(); |                                     guild_channel = parent.clone().guild().unwrap(); | ||||||
| @@ -287,12 +290,7 @@ impl<'a> MultiReminderBuilder<'a> { | |||||||
|                                 if channel_data.webhook_id.is_none() |                                 if channel_data.webhook_id.is_none() | ||||||
|                                     || channel_data.webhook_token.is_none() |                                     || channel_data.webhook_token.is_none() | ||||||
|                                 { |                                 { | ||||||
|                                     match create_webhook( |                                     match create_webhook(&self.ctx, guild_channel, "Reminder").await | ||||||
|                                         &self.ctx.discord(), |  | ||||||
|                                         guild_channel, |  | ||||||
|                                         "Reminder", |  | ||||||
|                                     ) |  | ||||||
|                                     .await |  | ||||||
|                                     { |                                     { | ||||||
|                                         Ok(webhook) => { |                                         Ok(webhook) => { | ||||||
|                                             channel_data.webhook_id = |                                             channel_data.webhook_id = | ||||||
| @@ -303,13 +301,13 @@ impl<'a> MultiReminderBuilder<'a> { | |||||||
|                                                 .commit_changes(&self.ctx.data().database) |                                                 .commit_changes(&self.ctx.data().database) | ||||||
|                                                 .await; |                                                 .await; | ||||||
|  |  | ||||||
|                                             Ok(channel_data.id) |                                             Ok((channel_data.id, channel_data.db_guild_id)) | ||||||
|                                         } |                                         } | ||||||
|  |  | ||||||
|                                         Err(e) => Err(ReminderError::DiscordError(e.to_string())), |                                         Err(e) => Err(ReminderError::DiscordError(e.to_string())), | ||||||
|                                     } |                                     } | ||||||
|                                 } else { |                                 } else { | ||||||
|                                     Ok(channel_data.id) |                                     Ok((channel_data.id, channel_data.db_guild_id)) | ||||||
|                                 } |                                 } | ||||||
|                             } |                             } | ||||||
|                         } else { |                         } else { | ||||||
| @@ -323,7 +321,8 @@ impl<'a> MultiReminderBuilder<'a> { | |||||||
|                         let builder = ReminderBuilder { |                         let builder = ReminderBuilder { | ||||||
|                             pool: self.ctx.data().database.clone(), |                             pool: self.ctx.data().database.clone(), | ||||||
|                             uid: generate_uid(), |                             uid: generate_uid(), | ||||||
|                             channel: c, |                             channel: c.0, | ||||||
|  |                             guild: c.1, | ||||||
|                             thread_id, |                             thread_id, | ||||||
|                             utc_time: self.utc_time, |                             utc_time: self.utc_time, | ||||||
|                             timezone: self.timezone.to_string(), |                             timezone: self.timezone.to_string(), | ||||||
|   | |||||||
| @@ -159,6 +159,7 @@ LEFT JOIN | |||||||
| ON | ON | ||||||
|     reminders.set_by = users.id |     reminders.set_by = users.id | ||||||
| WHERE | WHERE | ||||||
|  |     `status` = 'pending' AND | ||||||
|     channels.channel = ? AND |     channels.channel = ? AND | ||||||
|     FIND_IN_SET(reminders.enabled, ?) |     FIND_IN_SET(reminders.enabled, ?) | ||||||
| ORDER BY | ORDER BY | ||||||
| @@ -217,6 +218,7 @@ LEFT JOIN | |||||||
| ON | ON | ||||||
|     reminders.set_by = users.id |     reminders.set_by = users.id | ||||||
| WHERE | WHERE | ||||||
|  |     `status` = 'pending' AND | ||||||
|     FIND_IN_SET(channels.channel, ?) |     FIND_IN_SET(channels.channel, ?) | ||||||
|                 ", |                 ", | ||||||
|                     channels |                     channels | ||||||
| @@ -251,6 +253,7 @@ LEFT JOIN | |||||||
| ON | ON | ||||||
|     reminders.set_by = users.id |     reminders.set_by = users.id | ||||||
| WHERE | WHERE | ||||||
|  |     `status` = 'pending' AND | ||||||
|     channels.guild_id = (SELECT id FROM guilds WHERE guild = ?) |     channels.guild_id = (SELECT id FROM guilds WHERE guild = ?) | ||||||
|                 ", |                 ", | ||||||
|                     guild_id.as_u64() |                     guild_id.as_u64() | ||||||
| @@ -286,6 +289,7 @@ LEFT JOIN | |||||||
| ON | ON | ||||||
|     reminders.set_by = users.id |     reminders.set_by = users.id | ||||||
| WHERE | WHERE | ||||||
|  |     `status` = 'pending' AND | ||||||
|     channels.id = (SELECT dm_channel FROM users WHERE user = ?) |     channels.id = (SELECT dm_channel FROM users WHERE user = ?) | ||||||
|             ", |             ", | ||||||
|                 user.as_u64() |                 user.as_u64() | ||||||
| @@ -300,7 +304,13 @@ WHERE | |||||||
|         &self, |         &self, | ||||||
|         db: impl Executor<'_, Database = Database>, |         db: impl Executor<'_, Database = Database>, | ||||||
|     ) -> Result<(), sqlx::Error> { |     ) -> Result<(), sqlx::Error> { | ||||||
|         sqlx::query!("DELETE FROM reminders WHERE uid = ?", self.uid).execute(db).await.map(|_| ()) |         sqlx::query!( | ||||||
|  |             "UPDATE reminders SET `status` = 'deleted', `status_change_time` = NOW() WHERE uid = ?", | ||||||
|  |             self.uid | ||||||
|  |         ) | ||||||
|  |         .execute(db) | ||||||
|  |         .await | ||||||
|  |         .map(|_| ()) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     pub fn display_content(&self) -> &str { |     pub fn display_content(&self) -> &str { | ||||||
|   | |||||||
| @@ -83,7 +83,7 @@ pub fn send_as_initial_response( | |||||||
|         components, |         components, | ||||||
|         ephemeral, |         ephemeral, | ||||||
|         allowed_mentions, |         allowed_mentions, | ||||||
|         reference_message: _, // can't reply to a message in interactions |         reply: _, | ||||||
|     } = data; |     } = data; | ||||||
|  |  | ||||||
|     if let Some(content) = content { |     if let Some(content) = content { | ||||||
|   | |||||||
| @@ -5,9 +5,10 @@ Description=Reminder Bot | |||||||
| User=reminder | User=reminder | ||||||
| Type=simple | Type=simple | ||||||
| ExecStart=/usr/bin/reminder-rs | ExecStart=/usr/bin/reminder-rs | ||||||
|  | WorkingDirectory=/etc/reminder-rs | ||||||
| Restart=always | Restart=always | ||||||
| RestartSec=4 | RestartSec=4 | ||||||
| # Environment="RUST_LOG=warn,reminder_rs=info,postman=info" | Environment="reminder_rs=warn,postman=warn" | ||||||
|  |  | ||||||
| [Install] | [Install] | ||||||
| WantedBy=multi-user.target | WantedBy=multi-user.target | ||||||
|   | |||||||
| @@ -2,6 +2,7 @@ pub const DISCORD_OAUTH_TOKEN: &'static str = "https://discord.com/api/oauth2/to | |||||||
| pub const DISCORD_OAUTH_AUTHORIZE: &'static str = "https://discord.com/api/oauth2/authorize"; | pub const DISCORD_OAUTH_AUTHORIZE: &'static str = "https://discord.com/api/oauth2/authorize"; | ||||||
| pub const DISCORD_API: &'static str = "https://discord.com/api"; | pub const DISCORD_API: &'static str = "https://discord.com/api"; | ||||||
|  |  | ||||||
|  | pub const MAX_NAME_LENGTH: usize = 100; | ||||||
| pub const MAX_CONTENT_LENGTH: usize = 2000; | pub const MAX_CONTENT_LENGTH: usize = 2000; | ||||||
| pub const MAX_EMBED_DESCRIPTION_LENGTH: usize = 4096; | pub const MAX_EMBED_DESCRIPTION_LENGTH: usize = 4096; | ||||||
| pub const MAX_EMBED_TITLE_LENGTH: usize = 256; | pub const MAX_EMBED_TITLE_LENGTH: usize = 256; | ||||||
|   | |||||||
| @@ -6,7 +6,7 @@ mod consts; | |||||||
| mod macros; | mod macros; | ||||||
| mod routes; | mod routes; | ||||||
|  |  | ||||||
| use std::{collections::HashMap, env}; | use std::{collections::HashMap, env, path::Path}; | ||||||
|  |  | ||||||
| use oauth2::{basic::BasicClient, AuthUrl, ClientId, ClientSecret, RedirectUrl, TokenUrl}; | use oauth2::{basic::BasicClient, AuthUrl, ClientId, ClientSecret, RedirectUrl, TokenUrl}; | ||||||
| use rocket::{ | use rocket::{ | ||||||
| @@ -72,10 +72,14 @@ pub async fn initialize( | |||||||
|     db_pool: Pool<Database>, |     db_pool: Pool<Database>, | ||||||
| ) -> Result<(), Box<dyn std::error::Error>> { | ) -> Result<(), Box<dyn std::error::Error>> { | ||||||
|     info!("Checking environment variables..."); |     info!("Checking environment variables..."); | ||||||
|  |  | ||||||
|  |     if env::var("OFFLINE").map_or(true, |v| v != "1") { | ||||||
|         env::var("OAUTH2_CLIENT_ID").expect("`OAUTH2_CLIENT_ID' not supplied"); |         env::var("OAUTH2_CLIENT_ID").expect("`OAUTH2_CLIENT_ID' not supplied"); | ||||||
|         env::var("OAUTH2_CLIENT_SECRET").expect("`OAUTH2_CLIENT_SECRET' not supplied"); |         env::var("OAUTH2_CLIENT_SECRET").expect("`OAUTH2_CLIENT_SECRET' not supplied"); | ||||||
|         env::var("OAUTH2_DISCORD_CALLBACK").expect("`OAUTH2_DISCORD_CALLBACK' not supplied"); |         env::var("OAUTH2_DISCORD_CALLBACK").expect("`OAUTH2_DISCORD_CALLBACK' not supplied"); | ||||||
|         env::var("PATREON_GUILD_ID").expect("`PATREON_GUILD_ID' not supplied"); |         env::var("PATREON_GUILD_ID").expect("`PATREON_GUILD_ID' not supplied"); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     info!("Done!"); |     info!("Done!"); | ||||||
|  |  | ||||||
|     let oauth2_client = BasicClient::new( |     let oauth2_client = BasicClient::new( | ||||||
| @@ -88,6 +92,9 @@ pub async fn initialize( | |||||||
|  |  | ||||||
|     let reqwest_client = reqwest::Client::new(); |     let reqwest_client = reqwest::Client::new(); | ||||||
|  |  | ||||||
|  |     let static_path = | ||||||
|  |         if Path::new("web/static").exists() { "web/static" } else { "/lib/reminder-rs/static" }; | ||||||
|  |  | ||||||
|     rocket::build() |     rocket::build() | ||||||
|         .attach(Template::fairing()) |         .attach(Template::fairing()) | ||||||
|         .register( |         .register( | ||||||
| @@ -105,7 +112,7 @@ pub async fn initialize( | |||||||
|         .manage(reqwest_client) |         .manage(reqwest_client) | ||||||
|         .manage(serenity_context) |         .manage(serenity_context) | ||||||
|         .manage(db_pool) |         .manage(db_pool) | ||||||
|         .mount("/static", FileServer::from(concat!(env!("CARGO_MANIFEST_DIR"), "/static"))) |         .mount("/static", FileServer::from(static_path)) | ||||||
|         .mount( |         .mount( | ||||||
|             "/", |             "/", | ||||||
|             routes![ |             routes![ | ||||||
| @@ -113,7 +120,8 @@ pub async fn initialize( | |||||||
|                 routes::cookies, |                 routes::cookies, | ||||||
|                 routes::privacy, |                 routes::privacy, | ||||||
|                 routes::terms, |                 routes::terms, | ||||||
|                 routes::return_to_same_site |                 routes::return_to_same_site, | ||||||
|  |                 routes::report::report_error, | ||||||
|             ], |             ], | ||||||
|         ) |         ) | ||||||
|         .mount( |         .mount( | ||||||
| @@ -131,11 +139,19 @@ pub async fn initialize( | |||||||
|                 routes::help_iemanager, |                 routes::help_iemanager, | ||||||
|             ], |             ], | ||||||
|         ) |         ) | ||||||
|         .mount("/login", routes![routes::login::discord_login, routes::login::discord_callback]) |         .mount( | ||||||
|  |             "/login", | ||||||
|  |             routes![ | ||||||
|  |                 routes::login::discord_login, | ||||||
|  |                 routes::login::discord_logout, | ||||||
|  |                 routes::login::discord_callback | ||||||
|  |             ], | ||||||
|  |         ) | ||||||
|         .mount( |         .mount( | ||||||
|             "/dashboard", |             "/dashboard", | ||||||
|             routes![ |             routes![ | ||||||
|                 routes::dashboard::dashboard, |                 routes::dashboard::dashboard_1, | ||||||
|  |                 routes::dashboard::dashboard_2, | ||||||
|                 routes::dashboard::dashboard_home, |                 routes::dashboard::dashboard_home, | ||||||
|                 routes::dashboard::user::get_user_info, |                 routes::dashboard::user::get_user_info, | ||||||
|                 routes::dashboard::user::update_user_info, |                 routes::dashboard::user::update_user_info, | ||||||
| @@ -157,6 +173,7 @@ pub async fn initialize( | |||||||
|                 routes::dashboard::export::import_todos, |                 routes::dashboard::export::import_todos, | ||||||
|             ], |             ], | ||||||
|         ) |         ) | ||||||
|  |         .mount("/admin", routes![routes::admin::admin_dashboard_home, routes::admin::bot_data]) | ||||||
|         .launch() |         .launch() | ||||||
|         .await?; |         .await?; | ||||||
|  |  | ||||||
| @@ -173,6 +190,8 @@ pub async fn initialize( | |||||||
| } | } | ||||||
|  |  | ||||||
| pub async fn check_subscription(cache_http: impl CacheHttp, user_id: impl Into<UserId>) -> bool { | pub async fn check_subscription(cache_http: impl CacheHttp, user_id: impl Into<UserId>) -> bool { | ||||||
|  |     offline!(true); | ||||||
|  |  | ||||||
|     if let Some(subscription_guild) = *CNC_GUILD { |     if let Some(subscription_guild) = *CNC_GUILD { | ||||||
|         let guild_member = GuildId(subscription_guild).member(cache_http, user_id).await; |         let guild_member = GuildId(subscription_guild).member(cache_http, user_id).await; | ||||||
|  |  | ||||||
| @@ -194,6 +213,8 @@ pub async fn check_guild_subscription( | |||||||
|     cache_http: impl CacheHttp, |     cache_http: impl CacheHttp, | ||||||
|     guild_id: impl Into<GuildId>, |     guild_id: impl Into<GuildId>, | ||||||
| ) -> bool { | ) -> bool { | ||||||
|  |     offline!(true); | ||||||
|  |  | ||||||
|     if let Some(guild) = cache_http.cache().unwrap().guild(guild_id) { |     if let Some(guild) = cache_http.cache().unwrap().guild(guild_id) { | ||||||
|         let owner = guild.owner_id; |         let owner = guild.owner_id; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,3 +1,11 @@ | |||||||
|  | macro_rules! offline { | ||||||
|  |     ($field:expr) => { | ||||||
|  |         if std::env::var("OFFLINE").map_or(false, |v| v == "1") { | ||||||
|  |             return $field; | ||||||
|  |         } | ||||||
|  |     }; | ||||||
|  | } | ||||||
|  |  | ||||||
| macro_rules! check_length { | macro_rules! check_length { | ||||||
|     ($max:ident, $field:expr) => { |     ($max:ident, $field:expr) => { | ||||||
|         if $field.len() > $max { |         if $field.len() > $max { | ||||||
| @@ -52,18 +60,33 @@ macro_rules! check_authorization { | |||||||
|  |  | ||||||
|         let user_id = $cookies.get_private("userid").map(|c| c.value().parse::<u64>().ok()).flatten(); |         let user_id = $cookies.get_private("userid").map(|c| c.value().parse::<u64>().ok()).flatten(); | ||||||
|  |  | ||||||
|  |         if std::env::var("OFFLINE").map_or(true, |v| v != "1") { | ||||||
|             match user_id { |             match user_id { | ||||||
|                 Some(user_id) => { |                 Some(user_id) => { | ||||||
|                     match GuildId($guild).to_guild_cached($ctx) { |                     match GuildId($guild).to_guild_cached($ctx) { | ||||||
|                         Some(guild) => { |                         Some(guild) => { | ||||||
|                         let member = guild.member($ctx, UserId(user_id)).await; |                             let member_res = guild.member($ctx, UserId(user_id)).await; | ||||||
|  |  | ||||||
|                         match member { |                             match member_res { | ||||||
|                                 Err(_) => { |                                 Err(_) => { | ||||||
|                                     return Err(json!({"error": "User not in guild"})); |                                     return Err(json!({"error": "User not in guild"})); | ||||||
|                                 } |                                 } | ||||||
|  |  | ||||||
|                             Ok(_) => {} |                                 Ok(member) => { | ||||||
|  |                                     let permissions_res = member.permissions($ctx); | ||||||
|  |  | ||||||
|  |                                     match permissions_res { | ||||||
|  |                                         Err(_) => { | ||||||
|  |                                             return Err(json!({"error": "Couldn't fetch permissions"})); | ||||||
|  |                                         } | ||||||
|  |  | ||||||
|  |                                         Ok(permissions) => { | ||||||
|  |                                             if !(permissions.manage_messages() || permissions.manage_guild() || permissions.administrator()) { | ||||||
|  |                                                 return Err(json!({"error": "Incorrect permissions"})); | ||||||
|  |                                             } | ||||||
|  |                                         } | ||||||
|  |                                     } | ||||||
|  |                                 } | ||||||
|                             } |                             } | ||||||
|                         } |                         } | ||||||
|  |  | ||||||
| @@ -78,6 +101,7 @@ macro_rules! check_authorization { | |||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| macro_rules! update_field { | macro_rules! update_field { | ||||||
|   | |||||||
							
								
								
									
										218
									
								
								web/src/routes/admin.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										218
									
								
								web/src/routes/admin.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,218 @@ | |||||||
|  | use std::{collections::HashMap, env}; | ||||||
|  |  | ||||||
|  | use chrono::{DateTime, Utc}; | ||||||
|  | use rocket::{ | ||||||
|  |     http::{CookieJar, Status}, | ||||||
|  |     serde::json::json, | ||||||
|  |     State, | ||||||
|  | }; | ||||||
|  | use rocket_dyn_templates::Template; | ||||||
|  | use serde::Serialize; | ||||||
|  | use sqlx::{MySql, Pool}; | ||||||
|  |  | ||||||
|  | use crate::routes::JsonResult; | ||||||
|  |  | ||||||
|  | fn is_admin(cookies: &CookieJar<'_>) -> bool { | ||||||
|  |     cookies | ||||||
|  |         .get_private("userid") | ||||||
|  |         .map_or(false, |cookie| Some(cookie.value().to_string()) == env::var("ADMIN_ID").ok()) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #[get("/")] | ||||||
|  | pub async fn admin_dashboard_home(cookies: &CookieJar<'_>) -> Result<Template, Status> { | ||||||
|  |     if let Some(cookie) = cookies.get_private("userid") { | ||||||
|  |         let map: HashMap<&str, String> = HashMap::new(); | ||||||
|  |         if Some(cookie.value().to_string()) == env::var("ADMIN_ID").ok() { | ||||||
|  |             Ok(Template::render("admin_dashboard", &map)) | ||||||
|  |         } else { | ||||||
|  |             Err(Status::Forbidden) | ||||||
|  |         } | ||||||
|  |     } else { | ||||||
|  |         Err(Status::Unauthorized) | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #[derive(Serialize)] | ||||||
|  | struct TimeFrame { | ||||||
|  |     time_key: DateTime<Utc>, | ||||||
|  |     count: i64, | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #[get("/data")] | ||||||
|  | pub async fn bot_data(cookies: &CookieJar<'_>, pool: &State<Pool<MySql>>) -> JsonResult { | ||||||
|  |     if !is_admin(cookies) { | ||||||
|  |         return json_err!("Not authorized"); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     let backlog = sqlx::query!( | ||||||
|  |         "SELECT COUNT(1) AS backlog FROM reminders WHERE `utc_time` < NOW() AND enabled = 1 AND `status` = 'pending'" | ||||||
|  |     ) | ||||||
|  |     .fetch_one(pool.inner()) | ||||||
|  |     .await | ||||||
|  |     .unwrap(); | ||||||
|  |  | ||||||
|  |     let schedule_once = sqlx::query_as_unchecked!( | ||||||
|  |         TimeFrame, | ||||||
|  |         "SELECT | ||||||
|  |             FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(`utc_time`) / 300) * 300) AS `time_key`, | ||||||
|  |             COUNT(1) AS `count` | ||||||
|  |         FROM reminders | ||||||
|  |         WHERE | ||||||
|  |             `utc_time` < DATE_ADD(NOW(), INTERVAL 1 DAY) AND | ||||||
|  |             `utc_time` >= NOW() AND | ||||||
|  |             `enabled` = 1 AND | ||||||
|  |             `status` = 'pending' AND | ||||||
|  |             `interval_seconds` IS NULL AND | ||||||
|  |             `interval_months` IS NULL AND | ||||||
|  |             `interval_days` IS NULL | ||||||
|  |         GROUP BY `time_key` | ||||||
|  |         ORDER BY `time_key`" | ||||||
|  |     ) | ||||||
|  |     .fetch_all(pool.inner()) | ||||||
|  |     .await | ||||||
|  |     .unwrap(); | ||||||
|  |  | ||||||
|  |     let schedule_interval = sqlx::query_as_unchecked!( | ||||||
|  |         TimeFrame, | ||||||
|  |         "SELECT | ||||||
|  |             FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(`utc_time`) / 300) * 300) AS `time_key`, | ||||||
|  |             COUNT(1) AS `count` | ||||||
|  |         FROM reminders | ||||||
|  |         WHERE | ||||||
|  |             `utc_time` < DATE_ADD(NOW(), INTERVAL 1 DAY) AND | ||||||
|  |             `utc_time` >= NOW() AND | ||||||
|  |             `status` = 'pending' AND | ||||||
|  |             `enabled` = 1 AND ( | ||||||
|  |                 `interval_seconds` IS NOT NULL OR | ||||||
|  |                 `interval_months` IS NOT NULL OR | ||||||
|  |                 `interval_days` IS NOT NULL | ||||||
|  |             ) | ||||||
|  |         GROUP BY `time_key` | ||||||
|  |         ORDER BY `time_key`" | ||||||
|  |     ) | ||||||
|  |     .fetch_all(pool.inner()) | ||||||
|  |     .await | ||||||
|  |     .unwrap(); | ||||||
|  |  | ||||||
|  |     let schedule_once_long = sqlx::query_as_unchecked!( | ||||||
|  |         TimeFrame, | ||||||
|  |         "SELECT | ||||||
|  |             FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(`utc_time`) / 86400) * 86400) AS `time_key`, | ||||||
|  |             COUNT(1) AS `count` | ||||||
|  |         FROM reminders | ||||||
|  |         WHERE | ||||||
|  |             `utc_time` < DATE_ADD(NOW(), INTERVAL 31 DAY) AND | ||||||
|  |             `utc_time` >= NOW() AND | ||||||
|  |             `enabled` = 1 AND | ||||||
|  |             `status` = 'pending' AND | ||||||
|  |             `interval_seconds` IS NULL AND | ||||||
|  |             `interval_months` IS NULL AND | ||||||
|  |             `interval_days` IS NULL | ||||||
|  |         GROUP BY `time_key` | ||||||
|  |         ORDER BY `time_key`" | ||||||
|  |     ) | ||||||
|  |     .fetch_all(pool.inner()) | ||||||
|  |     .await | ||||||
|  |     .unwrap(); | ||||||
|  |  | ||||||
|  |     let schedule_interval_long = sqlx::query_as_unchecked!( | ||||||
|  |         TimeFrame, | ||||||
|  |         "SELECT | ||||||
|  |             FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(`utc_time`) / 86400) * 86400) AS `time_key`, | ||||||
|  |             COUNT(1) AS `count` | ||||||
|  |         FROM reminders | ||||||
|  |         WHERE | ||||||
|  |             `utc_time` < DATE_ADD(NOW(), INTERVAL 31 DAY) AND | ||||||
|  |             `utc_time` >= NOW() AND | ||||||
|  |             `status` = 'pending' AND | ||||||
|  |             `enabled` = 1 AND ( | ||||||
|  |                 `interval_seconds` IS NOT NULL OR | ||||||
|  |                 `interval_months` IS NOT NULL OR | ||||||
|  |                 `interval_days` IS NOT NULL | ||||||
|  |             ) | ||||||
|  |         GROUP BY `time_key` | ||||||
|  |         ORDER BY `time_key`" | ||||||
|  |     ) | ||||||
|  |     .fetch_all(pool.inner()) | ||||||
|  |     .await | ||||||
|  |     .unwrap(); | ||||||
|  |  | ||||||
|  |     let history = sqlx::query_as_unchecked!( | ||||||
|  |         TimeFrame, | ||||||
|  |         "SELECT | ||||||
|  |             FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(`utc_time`) / 86400) * 86400) AS `time_key`, | ||||||
|  |             COUNT(1) AS `count` | ||||||
|  |         FROM stat | ||||||
|  |         WHERE | ||||||
|  |             `utc_time` > DATE_SUB(NOW(), INTERVAL 31 DAY) AND | ||||||
|  |             `type` = 'reminder_sent' | ||||||
|  |         GROUP BY `time_key` | ||||||
|  |         ORDER BY `time_key`" | ||||||
|  |     ) | ||||||
|  |     .fetch_all(pool.inner()) | ||||||
|  |     .await | ||||||
|  |     .unwrap(); | ||||||
|  |  | ||||||
|  |     let history_failed = sqlx::query_as_unchecked!( | ||||||
|  |         TimeFrame, | ||||||
|  |         "SELECT | ||||||
|  |             FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(`utc_time`) / 86400) * 86400) AS `time_key`, | ||||||
|  |             COUNT(1) AS `count` | ||||||
|  |         FROM stat | ||||||
|  |         WHERE | ||||||
|  |             `utc_time` > DATE_SUB(NOW(), INTERVAL 31 DAY) AND | ||||||
|  |             `type` = 'reminder_failed' | ||||||
|  |         GROUP BY `time_key` | ||||||
|  |         ORDER BY `time_key`" | ||||||
|  |     ) | ||||||
|  |     .fetch_all(pool.inner()) | ||||||
|  |     .await | ||||||
|  |     .unwrap(); | ||||||
|  |  | ||||||
|  |     let interval_count = sqlx::query!( | ||||||
|  |         "SELECT COUNT(1) AS count | ||||||
|  |         FROM reminders | ||||||
|  |         WHERE | ||||||
|  |             `status` = 'pending' AND ( | ||||||
|  |                 `interval_seconds` IS NOT NULL OR | ||||||
|  |                 `interval_months` IS NOT NULL OR | ||||||
|  |                 `interval_days` IS NOT NULL | ||||||
|  |             )" | ||||||
|  |     ) | ||||||
|  |     .fetch_one(pool.inner()) | ||||||
|  |     .await | ||||||
|  |     .unwrap(); | ||||||
|  |  | ||||||
|  |     let reminder_count = sqlx::query!( | ||||||
|  |         "SELECT COUNT(1) AS count | ||||||
|  |         FROM reminders | ||||||
|  |         WHERE | ||||||
|  |             `status` = 'pending' AND | ||||||
|  |             `interval_seconds` IS NULL AND | ||||||
|  |             `interval_months` IS NULL AND | ||||||
|  |             `interval_days` IS NULL" | ||||||
|  |     ) | ||||||
|  |     .fetch_one(pool.inner()) | ||||||
|  |     .await | ||||||
|  |     .unwrap(); | ||||||
|  |  | ||||||
|  |     Ok(json!({ | ||||||
|  |         "backlog": backlog.backlog, | ||||||
|  |         "scheduleShort": { | ||||||
|  |             "once": schedule_once, | ||||||
|  |             "interval": schedule_interval | ||||||
|  |         }, | ||||||
|  |         "scheduleLong": { | ||||||
|  |             "once": schedule_once_long, | ||||||
|  |             "interval": schedule_interval_long, | ||||||
|  |         }, | ||||||
|  |         "historyLong": { | ||||||
|  |             "sent": history, | ||||||
|  |             "failed": history_failed, | ||||||
|  |         }, | ||||||
|  |         "count": { | ||||||
|  |             "reminders": reminder_count.count, | ||||||
|  |             "intervals": interval_count.count, | ||||||
|  |         } | ||||||
|  |     })) | ||||||
|  | } | ||||||
| @@ -10,9 +10,12 @@ use serenity::{ | |||||||
| }; | }; | ||||||
| use sqlx::{MySql, Pool}; | use sqlx::{MySql, Pool}; | ||||||
|  |  | ||||||
| use crate::routes::dashboard::{ | use crate::routes::{ | ||||||
|     create_reminder, generate_uid, ImportBody, JsonResult, Reminder, ReminderCsv, |     dashboard::{ | ||||||
|     ReminderTemplateCsv, TodoCsv, |         create_reminder, generate_uid, ImportBody, Reminder, ReminderCsv, ReminderTemplateCsv, | ||||||
|  |         TodoCsv, | ||||||
|  |     }, | ||||||
|  |     JsonResult, | ||||||
| }; | }; | ||||||
|  |  | ||||||
| #[get("/api/guild/<id>/export/reminders")] | #[get("/api/guild/<id>/export/reminders")] | ||||||
| @@ -142,7 +145,7 @@ pub async fn import_reminders( | |||||||
|                                     attachment: record.attachment, |                                     attachment: record.attachment, | ||||||
|                                     attachment_name: record.attachment_name, |                                     attachment_name: record.attachment_name, | ||||||
|                                     avatar: record.avatar, |                                     avatar: record.avatar, | ||||||
|                                     channel: channel_id, |                                     channel: Some(channel_id), | ||||||
|                                     content: record.content, |                                     content: record.content, | ||||||
|                                     embed_author: record.embed_author, |                                     embed_author: record.embed_author, | ||||||
|                                     embed_author_url: record.embed_author_url, |                                     embed_author_url: record.embed_author_url, | ||||||
| @@ -168,6 +171,8 @@ pub async fn import_reminders( | |||||||
|                                     uid: generate_uid(), |                                     uid: generate_uid(), | ||||||
|                                     username: record.username, |                                     username: record.username, | ||||||
|                                     utc_time: record.utc_time, |                                     utc_time: record.utc_time, | ||||||
|  |                                     status: "pending".to_string(), | ||||||
|  |                                     status_change_time: None, | ||||||
|                                 }; |                                 }; | ||||||
|  |  | ||||||
|                                 create_reminder( |                                 create_reminder( | ||||||
|   | |||||||
| @@ -23,9 +23,12 @@ use crate::{ | |||||||
|         MAX_EMBED_FOOTER_LENGTH, MAX_EMBED_TITLE_LENGTH, MAX_URL_LENGTH, MAX_USERNAME_LENGTH, |         MAX_EMBED_FOOTER_LENGTH, MAX_EMBED_TITLE_LENGTH, MAX_URL_LENGTH, MAX_USERNAME_LENGTH, | ||||||
|         MIN_INTERVAL, |         MIN_INTERVAL, | ||||||
|     }, |     }, | ||||||
|     routes::dashboard::{ |     routes::{ | ||||||
|  |         dashboard::{ | ||||||
|             create_database_channel, create_reminder, template_name_default, DeleteReminder, |             create_database_channel, create_reminder, template_name_default, DeleteReminder, | ||||||
|         DeleteReminderTemplate, JsonResult, PatchReminder, Reminder, ReminderTemplate, |             DeleteReminderTemplate, PatchReminder, Reminder, ReminderTemplate, | ||||||
|  |         }, | ||||||
|  |         JsonResult, | ||||||
|     }, |     }, | ||||||
| }; | }; | ||||||
|  |  | ||||||
| @@ -43,6 +46,7 @@ pub async fn get_guild_patreon( | |||||||
|     cookies: &CookieJar<'_>, |     cookies: &CookieJar<'_>, | ||||||
|     ctx: &State<Context>, |     ctx: &State<Context>, | ||||||
| ) -> JsonResult { | ) -> JsonResult { | ||||||
|  |     offline!(Ok(json!({ "patreon": true }))); | ||||||
|     check_authorization!(cookies, ctx.inner(), id); |     check_authorization!(cookies, ctx.inner(), id); | ||||||
|  |  | ||||||
|     match GuildId(id).to_guild_cached(ctx.inner()) { |     match GuildId(id).to_guild_cached(ctx.inner()) { | ||||||
| @@ -70,6 +74,12 @@ pub async fn get_guild_channels( | |||||||
|     cookies: &CookieJar<'_>, |     cookies: &CookieJar<'_>, | ||||||
|     ctx: &State<Context>, |     ctx: &State<Context>, | ||||||
| ) -> JsonResult { | ) -> JsonResult { | ||||||
|  |     offline!(Ok(json!(vec![ChannelInfo { | ||||||
|  |         name: "general".to_string(), | ||||||
|  |         id: "1".to_string(), | ||||||
|  |         webhook_avatar: None, | ||||||
|  |         webhook_name: None, | ||||||
|  |     }]))); | ||||||
|     check_authorization!(cookies, ctx.inner(), id); |     check_authorization!(cookies, ctx.inner(), id); | ||||||
|  |  | ||||||
|     match GuildId(id).to_guild_cached(ctx.inner()) { |     match GuildId(id).to_guild_cached(ctx.inner()) { | ||||||
| @@ -108,6 +118,7 @@ struct RoleInfo { | |||||||
|  |  | ||||||
| #[get("/api/guild/<id>/roles")] | #[get("/api/guild/<id>/roles")] | ||||||
| pub async fn get_guild_roles(id: u64, cookies: &CookieJar<'_>, ctx: &State<Context>) -> JsonResult { | pub async fn get_guild_roles(id: u64, cookies: &CookieJar<'_>, ctx: &State<Context>) -> JsonResult { | ||||||
|  |     offline!(Ok(json!(vec![RoleInfo { name: "@everyone".to_string(), id: "1".to_string() }]))); | ||||||
|     check_authorization!(cookies, ctx.inner(), id); |     check_authorization!(cookies, ctx.inner(), id); | ||||||
|  |  | ||||||
|     let roles_res = ctx.cache.guild_roles(id); |     let roles_res = ctx.cache.guild_roles(id); | ||||||
| @@ -307,22 +318,22 @@ pub async fn create_guild_reminder( | |||||||
|     .await |     .await | ||||||
| } | } | ||||||
|  |  | ||||||
| #[get("/api/guild/<id>/reminders")] | #[get("/api/guild/<id>/reminders?<status>")] | ||||||
| pub async fn get_reminders(id: u64, ctx: &State<Context>, pool: &State<Pool<MySql>>) -> JsonResult { | pub async fn get_reminders( | ||||||
|     let channels_res = GuildId(id).channels(&ctx.inner()).await; |     id: u64, | ||||||
|  |     cookies: &CookieJar<'_>, | ||||||
|  |     serenity_context: &State<Context>, | ||||||
|  |     pool: &State<Pool<MySql>>, | ||||||
|  |     status: Option<String>, | ||||||
|  | ) -> JsonResult { | ||||||
|  |     check_authorization!(cookies, serenity_context.inner(), id); | ||||||
|  |  | ||||||
|     match channels_res { |     let status = status.unwrap_or("pending".to_string()); | ||||||
|         Ok(channels) => { |  | ||||||
|             let channels = channels |  | ||||||
|                 .keys() |  | ||||||
|                 .into_iter() |  | ||||||
|                 .map(|k| k.as_u64().to_string()) |  | ||||||
|                 .collect::<Vec<String>>() |  | ||||||
|                 .join(","); |  | ||||||
|  |  | ||||||
|     sqlx::query_as_unchecked!( |     sqlx::query_as_unchecked!( | ||||||
|         Reminder, |         Reminder, | ||||||
|                 "SELECT |         " | ||||||
|  |         SELECT | ||||||
|          reminders.attachment, |          reminders.attachment, | ||||||
|          reminders.attachment_name, |          reminders.attachment_name, | ||||||
|          reminders.avatar, |          reminders.avatar, | ||||||
| @@ -337,7 +348,7 @@ pub async fn get_reminders(id: u64, ctx: &State<Context>, pool: &State<Pool<MySq | |||||||
|          reminders.embed_image_url, |          reminders.embed_image_url, | ||||||
|          reminders.embed_thumbnail_url, |          reminders.embed_thumbnail_url, | ||||||
|          reminders.embed_title, |          reminders.embed_title, | ||||||
|                  reminders.embed_fields, |          IFNULL(reminders.embed_fields, '[]') AS embed_fields, | ||||||
|          reminders.enabled, |          reminders.enabled, | ||||||
|          reminders.expires, |          reminders.expires, | ||||||
|          reminders.interval_seconds, |          reminders.interval_seconds, | ||||||
| @@ -348,11 +359,14 @@ pub async fn get_reminders(id: u64, ctx: &State<Context>, pool: &State<Pool<MySq | |||||||
|          reminders.tts, |          reminders.tts, | ||||||
|          reminders.uid, |          reminders.uid, | ||||||
|          reminders.username, |          reminders.username, | ||||||
|                  reminders.utc_time |          reminders.utc_time, | ||||||
|  |          reminders.status, | ||||||
|  |          reminders.status_change_time | ||||||
|         FROM reminders |         FROM reminders | ||||||
|         LEFT JOIN channels ON channels.id = reminders.channel_id |         LEFT JOIN channels ON channels.id = reminders.channel_id | ||||||
|                 WHERE FIND_IN_SET(channels.channel, ?)", |         WHERE FIND_IN_SET(`status`, ?) AND reminders.guild_id = (SELECT id FROM guilds WHERE guild = ?)", | ||||||
|                 channels |         status, | ||||||
|  |         id | ||||||
|     ) |     ) | ||||||
|     .fetch_all(pool.inner()) |     .fetch_all(pool.inner()) | ||||||
|     .await |     .await | ||||||
| @@ -362,13 +376,6 @@ pub async fn get_reminders(id: u64, ctx: &State<Context>, pool: &State<Pool<MySq | |||||||
|  |  | ||||||
|         json_err!("Could not load reminders") |         json_err!("Could not load reminders") | ||||||
|     }) |     }) | ||||||
|         } |  | ||||||
|         Err(e) => { |  | ||||||
|             warn!("Could not fetch channels from {}: {:?}", id, e); |  | ||||||
|  |  | ||||||
|             Ok(json!([])) |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|  |  | ||||||
| #[patch("/api/guild/<id>/reminders", data = "<reminder>")] | #[patch("/api/guild/<id>/reminders", data = "<reminder>")] | ||||||
| @@ -438,7 +445,7 @@ pub async fn edit_reminder( | |||||||
|                 })? |                 })? | ||||||
|                 .days |                 .days | ||||||
|                 .unwrap_or(0), |                 .unwrap_or(0), | ||||||
|             } + match reminder.interval_months { |             } * 86400 + match reminder.interval_months { | ||||||
|                 Some(interval) => interval.unwrap_or(0), |                 Some(interval) => interval.unwrap_or(0), | ||||||
|                 None => sqlx::query!( |                 None => sqlx::query!( | ||||||
|                     "SELECT interval_months AS months FROM reminders WHERE uid = ?", |                     "SELECT interval_months AS months FROM reminders WHERE uid = ?", | ||||||
| @@ -452,7 +459,7 @@ pub async fn edit_reminder( | |||||||
|                 })? |                 })? | ||||||
|                 .months |                 .months | ||||||
|                 .unwrap_or(0), |                 .unwrap_or(0), | ||||||
|             } + match reminder.interval_seconds { |             } * 2592000 + match reminder.interval_seconds { | ||||||
|                 Some(interval) => interval.unwrap_or(0), |                 Some(interval) => interval.unwrap_or(0), | ||||||
|                 None => sqlx::query!( |                 None => sqlx::query!( | ||||||
|                     "SELECT interval_seconds AS seconds FROM reminders WHERE uid = ?", |                     "SELECT interval_seconds AS seconds FROM reminders WHERE uid = ?", | ||||||
| @@ -567,7 +574,9 @@ pub async fn edit_reminder( | |||||||
|          reminders.tts, |          reminders.tts, | ||||||
|          reminders.uid, |          reminders.uid, | ||||||
|          reminders.username, |          reminders.username, | ||||||
|          reminders.utc_time |          reminders.utc_time, | ||||||
|  |          reminders.status, | ||||||
|  |          reminders.status_change_time | ||||||
|         FROM reminders |         FROM reminders | ||||||
|         LEFT JOIN channels ON channels.id = reminders.channel_id |         LEFT JOIN channels ON channels.id = reminders.channel_id | ||||||
|         WHERE uid = ?", |         WHERE uid = ?", | ||||||
| @@ -591,7 +600,10 @@ pub async fn delete_reminder( | |||||||
|     reminder: Json<DeleteReminder>, |     reminder: Json<DeleteReminder>, | ||||||
|     pool: &State<Pool<MySql>>, |     pool: &State<Pool<MySql>>, | ||||||
| ) -> JsonResult { | ) -> JsonResult { | ||||||
|     match sqlx::query!("DELETE FROM reminders WHERE uid = ?", reminder.uid) |     match sqlx::query!( | ||||||
|  |         "UPDATE reminders SET `status` = 'deleted', `status_change_time` = NOW() WHERE uid = ?", | ||||||
|  |         reminder.uid | ||||||
|  |     ) | ||||||
|     .execute(pool.inner()) |     .execute(pool.inner()) | ||||||
|     .await |     .await | ||||||
|     { |     { | ||||||
|   | |||||||
| @@ -2,11 +2,7 @@ use std::collections::HashMap; | |||||||
|  |  | ||||||
| use chrono::{naive::NaiveDateTime, Utc}; | use chrono::{naive::NaiveDateTime, Utc}; | ||||||
| use rand::{rngs::OsRng, seq::IteratorRandom}; | use rand::{rngs::OsRng, seq::IteratorRandom}; | ||||||
| use rocket::{ | use rocket::{http::CookieJar, response::Redirect, serde::json::json}; | ||||||
|     http::CookieJar, |  | ||||||
|     response::Redirect, |  | ||||||
|     serde::json::{json, Value as JsonValue}, |  | ||||||
| }; |  | ||||||
| use rocket_dyn_templates::Template; | use rocket_dyn_templates::Template; | ||||||
| use serde::{Deserialize, Deserializer, Serialize}; | use serde::{Deserialize, Deserializer, Serialize}; | ||||||
| use serenity::{ | use serenity::{ | ||||||
| @@ -22,8 +18,9 @@ use crate::{ | |||||||
|         CHARACTERS, DAY, DEFAULT_AVATAR, MAX_CONTENT_LENGTH, MAX_EMBED_AUTHOR_LENGTH, |         CHARACTERS, DAY, DEFAULT_AVATAR, MAX_CONTENT_LENGTH, MAX_EMBED_AUTHOR_LENGTH, | ||||||
|         MAX_EMBED_DESCRIPTION_LENGTH, MAX_EMBED_FIELDS, MAX_EMBED_FIELD_TITLE_LENGTH, |         MAX_EMBED_DESCRIPTION_LENGTH, MAX_EMBED_FIELDS, MAX_EMBED_FIELD_TITLE_LENGTH, | ||||||
|         MAX_EMBED_FIELD_VALUE_LENGTH, MAX_EMBED_FOOTER_LENGTH, MAX_EMBED_TITLE_LENGTH, |         MAX_EMBED_FIELD_VALUE_LENGTH, MAX_EMBED_FOOTER_LENGTH, MAX_EMBED_TITLE_LENGTH, | ||||||
|         MAX_URL_LENGTH, MAX_USERNAME_LENGTH, MIN_INTERVAL, |         MAX_NAME_LENGTH, MAX_URL_LENGTH, MAX_USERNAME_LENGTH, MIN_INTERVAL, | ||||||
|     }, |     }, | ||||||
|  |     routes::JsonResult, | ||||||
|     Database, Error, |     Database, Error, | ||||||
| }; | }; | ||||||
|  |  | ||||||
| @@ -31,7 +28,6 @@ pub mod export; | |||||||
| pub mod guild; | pub mod guild; | ||||||
| pub mod user; | pub mod user; | ||||||
|  |  | ||||||
| pub type JsonResult = Result<JsonValue, JsonValue>; |  | ||||||
| type Unset<T> = Option<T>; | type Unset<T> = Option<T>; | ||||||
|  |  | ||||||
| fn name_default() -> String { | fn name_default() -> String { | ||||||
| @@ -128,8 +124,8 @@ pub struct Reminder { | |||||||
|     attachment: Option<Vec<u8>>, |     attachment: Option<Vec<u8>>, | ||||||
|     attachment_name: Option<String>, |     attachment_name: Option<String>, | ||||||
|     avatar: Option<String>, |     avatar: Option<String>, | ||||||
|     #[serde(with = "string")] |     #[serde(with = "string_opt")] | ||||||
|     channel: u64, |     channel: Option<u64>, | ||||||
|     content: String, |     content: String, | ||||||
|     embed_author: String, |     embed_author: String, | ||||||
|     embed_author_url: Option<String>, |     embed_author_url: Option<String>, | ||||||
| @@ -154,6 +150,8 @@ pub struct Reminder { | |||||||
|     uid: String, |     uid: String, | ||||||
|     username: Option<String>, |     username: Option<String>, | ||||||
|     utc_time: NaiveDateTime, |     utc_time: NaiveDateTime, | ||||||
|  |     status: String, | ||||||
|  |     status_change_time: Option<NaiveDateTime>, | ||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Serialize, Deserialize)] | #[derive(Serialize, Deserialize)] | ||||||
| @@ -312,6 +310,34 @@ mod string { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | mod string_opt { | ||||||
|  |     use std::{fmt::Display, str::FromStr}; | ||||||
|  |  | ||||||
|  |     use serde::{de, Deserialize, Deserializer, Serializer}; | ||||||
|  |  | ||||||
|  |     pub fn serialize<T, S>(value: &Option<T>, serializer: S) -> Result<S::Ok, S::Error> | ||||||
|  |     where | ||||||
|  |         T: Display, | ||||||
|  |         S: Serializer, | ||||||
|  |     { | ||||||
|  |         match value { | ||||||
|  |             Some(value) => serializer.collect_str(value), | ||||||
|  |             None => serializer.serialize_none(), | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     pub fn deserialize<'de, T, D>(deserializer: D) -> Result<Option<T>, D::Error> | ||||||
|  |     where | ||||||
|  |         T: FromStr, | ||||||
|  |         T::Err: Display, | ||||||
|  |         D: Deserializer<'de>, | ||||||
|  |     { | ||||||
|  |         Option::deserialize(deserializer)? | ||||||
|  |             .map(|d: String| d.parse().map_err(de::Error::custom)) | ||||||
|  |             .transpose() | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
| mod base64s { | mod base64s { | ||||||
|     use serde::{de, Deserialize, Deserializer, Serializer}; |     use serde::{de, Deserialize, Deserializer, Serializer}; | ||||||
|  |  | ||||||
| @@ -376,7 +402,7 @@ pub async fn create_reminder( | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     // validate channel |     // validate channel | ||||||
|     let channel = ChannelId(reminder.channel).to_channel_cached(&ctx); |     let channel = reminder.channel.map(|c| ChannelId(c).to_channel_cached(&ctx)).flatten(); | ||||||
|     let channel_exists = channel.is_some(); |     let channel_exists = channel.is_some(); | ||||||
|  |  | ||||||
|     let channel_matches_guild = |     let channel_matches_guild = | ||||||
| @@ -384,14 +410,14 @@ pub async fn create_reminder( | |||||||
|  |  | ||||||
|     if !channel_matches_guild || !channel_exists { |     if !channel_matches_guild || !channel_exists { | ||||||
|         warn!( |         warn!( | ||||||
|             "Error in `create_reminder`: channel {} not found for guild {} (channel exists: {})", |             "Error in `create_reminder`: channel {:?} not found for guild {} (channel exists: {})", | ||||||
|             reminder.channel, guild_id, channel_exists |             reminder.channel, guild_id, channel_exists | ||||||
|         ); |         ); | ||||||
|  |  | ||||||
|         return Err(json!({"error": "Channel not found"})); |         return Err(json!({"error": "Channel not found"})); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     let channel = create_database_channel(&ctx, ChannelId(reminder.channel), pool).await; |     let channel = create_database_channel(&ctx, ChannelId(reminder.channel.unwrap()), pool).await; | ||||||
|  |  | ||||||
|     if let Err(e) = channel { |     if let Err(e) = channel { | ||||||
|         warn!("`create_database_channel` returned an error code: {:?}", e); |         warn!("`create_database_channel` returned an error code: {:?}", e); | ||||||
| @@ -404,6 +430,7 @@ pub async fn create_reminder( | |||||||
|     let channel = channel.unwrap(); |     let channel = channel.unwrap(); | ||||||
|  |  | ||||||
|     // validate lengths |     // validate lengths | ||||||
|  |     check_length!(MAX_NAME_LENGTH, reminder.name); | ||||||
|     check_length!(MAX_CONTENT_LENGTH, reminder.content); |     check_length!(MAX_CONTENT_LENGTH, reminder.content); | ||||||
|     check_length!(MAX_EMBED_DESCRIPTION_LENGTH, reminder.embed_description); |     check_length!(MAX_EMBED_DESCRIPTION_LENGTH, reminder.embed_description); | ||||||
|     check_length!(MAX_EMBED_TITLE_LENGTH, reminder.embed_title); |     check_length!(MAX_EMBED_TITLE_LENGTH, reminder.embed_title); | ||||||
| @@ -482,6 +509,7 @@ pub async fn create_reminder( | |||||||
|          attachment, |          attachment, | ||||||
|          attachment_name, |          attachment_name, | ||||||
|          channel_id, |          channel_id, | ||||||
|  |          guild_id, | ||||||
|          avatar, |          avatar, | ||||||
|          content, |          content, | ||||||
|          embed_author, |          embed_author, | ||||||
| @@ -504,11 +532,12 @@ pub async fn create_reminder( | |||||||
|          tts, |          tts, | ||||||
|          username, |          username, | ||||||
|          `utc_time` |          `utc_time` | ||||||
|         ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", |         ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", | ||||||
|         new_uid, |         new_uid, | ||||||
|         attachment_data, |         attachment_data, | ||||||
|         reminder.attachment_name, |         reminder.attachment_name, | ||||||
|         channel, |         channel, | ||||||
|  |         guild_id.0, | ||||||
|         reminder.avatar, |         reminder.avatar, | ||||||
|         reminder.content, |         reminder.content, | ||||||
|         reminder.embed_author, |         reminder.embed_author, | ||||||
| @@ -563,7 +592,9 @@ pub async fn create_reminder( | |||||||
|              reminders.tts, |              reminders.tts, | ||||||
|              reminders.uid, |              reminders.uid, | ||||||
|              reminders.username, |              reminders.username, | ||||||
|              reminders.utc_time |              reminders.utc_time, | ||||||
|  |              reminders.status, | ||||||
|  |              reminders.status_change_time | ||||||
|             FROM reminders |             FROM reminders | ||||||
|             LEFT JOIN channels ON channels.id = reminders.channel_id |             LEFT JOIN channels ON channels.id = reminders.channel_id | ||||||
|             WHERE uid = ?", |             WHERE uid = ?", | ||||||
| @@ -665,7 +696,17 @@ pub async fn dashboard_home(cookies: &CookieJar<'_>) -> Result<Template, Redirec | |||||||
| } | } | ||||||
|  |  | ||||||
| #[get("/<_>")] | #[get("/<_>")] | ||||||
| pub async fn dashboard(cookies: &CookieJar<'_>) -> Result<Template, Redirect> { | pub async fn dashboard_1(cookies: &CookieJar<'_>) -> Result<Template, Redirect> { | ||||||
|  |     if cookies.get_private("userid").is_some() { | ||||||
|  |         let map: HashMap<&str, String> = HashMap::new(); | ||||||
|  |         Ok(Template::render("dashboard", &map)) | ||||||
|  |     } else { | ||||||
|  |         Err(Redirect::to("/login/discord")) | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #[get("/<_>/<_>")] | ||||||
|  | pub async fn dashboard_2(cookies: &CookieJar<'_>) -> Result<Template, Redirect> { | ||||||
|     if cookies.get_private("userid").is_some() { |     if cookies.get_private("userid").is_some() { | ||||||
|         let map: HashMap<&str, String> = HashMap::new(); |         let map: HashMap<&str, String> = HashMap::new(); | ||||||
|         Ok(Template::render("dashboard", &map)) |         Ok(Template::render("dashboard", &map)) | ||||||
|   | |||||||
| @@ -54,6 +54,8 @@ pub async fn get_user_info( | |||||||
|     ctx: &State<Context>, |     ctx: &State<Context>, | ||||||
|     pool: &State<Pool<MySql>>, |     pool: &State<Pool<MySql>>, | ||||||
| ) -> JsonValue { | ) -> JsonValue { | ||||||
|  |     offline!(json!(UserInfo { name: "Discord".to_string(), patreon: true, timezone: None })); | ||||||
|  |  | ||||||
|     if let Some(user_id) = |     if let Some(user_id) = | ||||||
|         cookies.get_private("userid").map(|u| u.value().parse::<u64>().ok()).flatten() |         cookies.get_private("userid").map(|u| u.value().parse::<u64>().ok()).flatten() | ||||||
|     { |     { | ||||||
| @@ -116,6 +118,8 @@ pub async fn update_user_info( | |||||||
|  |  | ||||||
| #[get("/api/user/guilds")] | #[get("/api/user/guilds")] | ||||||
| pub async fn get_user_guilds(cookies: &CookieJar<'_>, reqwest_client: &State<Client>) -> JsonValue { | pub async fn get_user_guilds(cookies: &CookieJar<'_>, reqwest_client: &State<Client>) -> JsonValue { | ||||||
|  |     offline!(json!(vec![GuildInfo { id: "1".to_string(), name: "Guild".to_string() }])); | ||||||
|  |  | ||||||
|     if let Some(access_token) = cookies.get_private("access_token") { |     if let Some(access_token) = cookies.get_private("access_token") { | ||||||
|         let request_res = reqwest_client |         let request_res = reqwest_client | ||||||
|             .get(format!("{}/users/@me/guilds", DISCORD_API)) |             .get(format!("{}/users/@me/guilds", DISCORD_API)) | ||||||
|   | |||||||
| @@ -11,7 +11,7 @@ use rocket::{ | |||||||
| }; | }; | ||||||
| use serenity::model::user::User; | use serenity::model::user::User; | ||||||
|  |  | ||||||
| use crate::consts::DISCORD_API; | use crate::{consts::DISCORD_API, routes}; | ||||||
|  |  | ||||||
| #[get("/discord")] | #[get("/discord")] | ||||||
| pub async fn discord_login( | pub async fn discord_login( | ||||||
| @@ -52,6 +52,15 @@ pub async fn discord_login( | |||||||
|     Redirect::to(auth_url.to_string()) |     Redirect::to(auth_url.to_string()) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | #[get("/discord/logout")] | ||||||
|  | pub async fn discord_logout(cookies: &CookieJar<'_>) -> Redirect { | ||||||
|  |     cookies.remove_private(Cookie::named("username")); | ||||||
|  |     cookies.remove_private(Cookie::named("userid")); | ||||||
|  |     cookies.remove_private(Cookie::named("access_token")); | ||||||
|  |  | ||||||
|  |     Redirect::to(uri!(routes::index)) | ||||||
|  | } | ||||||
|  |  | ||||||
| #[get("/discord/authorized?<code>&<state>")] | #[get("/discord/authorized?<code>&<state>")] | ||||||
| pub async fn discord_callback( | pub async fn discord_callback( | ||||||
|     code: &str, |     code: &str, | ||||||
|   | |||||||
| @@ -1,11 +1,15 @@ | |||||||
|  | pub mod admin; | ||||||
| pub mod dashboard; | pub mod dashboard; | ||||||
| pub mod login; | pub mod login; | ||||||
|  | pub mod report; | ||||||
|  |  | ||||||
| use std::collections::HashMap; | use std::collections::HashMap; | ||||||
|  |  | ||||||
| use rocket::request::FlashMessage; | use rocket::{request::FlashMessage, serde::json::Value as JsonValue}; | ||||||
| use rocket_dyn_templates::Template; | use rocket_dyn_templates::Template; | ||||||
|  |  | ||||||
|  | pub type JsonResult = Result<JsonValue, JsonValue>; | ||||||
|  |  | ||||||
| #[get("/")] | #[get("/")] | ||||||
| pub async fn index(flash: Option<FlashMessage<'_>>) -> Template { | pub async fn index(flash: Option<FlashMessage<'_>>) -> Template { | ||||||
|     let mut map: HashMap<&str, String> = HashMap::new(); |     let mut map: HashMap<&str, String> = HashMap::new(); | ||||||
|   | |||||||
							
								
								
									
										48
									
								
								web/src/routes/report.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								web/src/routes/report.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,48 @@ | |||||||
|  | use rocket::{ | ||||||
|  |     http::CookieJar, | ||||||
|  |     serde::{ | ||||||
|  |         json::{json, Json}, | ||||||
|  |         Deserialize, | ||||||
|  |     }, | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | use crate::routes::JsonResult; | ||||||
|  |  | ||||||
|  | #[derive(Deserialize)] | ||||||
|  | pub struct ClientError { | ||||||
|  |     #[serde(rename = "reporterId")] | ||||||
|  |     reporter_id: String, | ||||||
|  |     url: String, | ||||||
|  |     #[serde(rename = "relativeTimestamp")] | ||||||
|  |     relative_timestamp: i64, | ||||||
|  |     #[serde(rename = "errorMessage")] | ||||||
|  |     error_message: String, | ||||||
|  |     #[serde(rename = "errorLine")] | ||||||
|  |     error_line: u64, | ||||||
|  |     #[serde(rename = "errorFile")] | ||||||
|  |     error_file: String, | ||||||
|  |     #[serde(rename = "errorType")] | ||||||
|  |     error_type: String, | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #[post("/report", data = "<client_error>")] | ||||||
|  | pub async fn report_error(cookies: &CookieJar<'_>, client_error: Json<ClientError>) -> JsonResult { | ||||||
|  |     if let Some(user_id) = cookies.get_private("userid") { | ||||||
|  |         error!( | ||||||
|  |             "User {} reports a client-side error. | ||||||
|  | {}, {}:{} at {}ms | ||||||
|  | {}: {} | ||||||
|  | Chain: {}", | ||||||
|  |             user_id, | ||||||
|  |             client_error.url, | ||||||
|  |             client_error.error_file, | ||||||
|  |             client_error.error_line, | ||||||
|  |             client_error.relative_timestamp, | ||||||
|  |             client_error.error_type, | ||||||
|  |             client_error.error_message, | ||||||
|  |             client_error.reporter_id | ||||||
|  |         ); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     Ok(json!({})) | ||||||
|  | } | ||||||
| @@ -11,7 +11,7 @@ div.reminderContent.is-collapsed .column.discord-frame { | |||||||
|     display: none; |     display: none; | ||||||
| } | } | ||||||
|  |  | ||||||
| div.reminderContent.is-collapsed .collapses { | div.reminderContent.is-collapsed .column.settings { | ||||||
|     display: none; |     display: none; | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -23,42 +23,42 @@ div.reminderContent .invert-collapses { | |||||||
|     display: none; |     display: none; | ||||||
| } | } | ||||||
|  |  | ||||||
| div.reminderContent.is-collapsed .settings { |  | ||||||
|     display: flex; |  | ||||||
|     flex-direction: row; |  | ||||||
|     padding-bottom: 0; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| div.reminderContent.is-collapsed .channel-field { |  | ||||||
|     display: inline-flex; |  | ||||||
|     order: 1; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| div.reminderContent.is-collapsed .reminder-topbar { |  | ||||||
|     display: inline-flex; |  | ||||||
|     margin-bottom: 0px; |  | ||||||
|     flex-grow: 1; |  | ||||||
|     order: 2; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| div.reminderContent.is-collapsed input[name="name"] { | div.reminderContent.is-collapsed input[name="name"] { | ||||||
|     display: inline-flex; |     display: inline-flex; | ||||||
|     flex-grow: 1; |     flex-grow: 1; | ||||||
|     border: none; |     border: none; | ||||||
|     font-weight: 700; |  | ||||||
|     background: none; |     background: none; | ||||||
|  |     box-shadow: none; | ||||||
|  |     opacity: 1; | ||||||
| } | } | ||||||
|  |  | ||||||
| div.reminderContent.is-collapsed button.hide-box { | div.reminderContent.is-collapsed .hide-box { | ||||||
|     display: inline-flex; |     display: inline-flex; | ||||||
| } | } | ||||||
|  |  | ||||||
| div.reminderContent.is-collapsed button.hide-box i { | div.reminderContent.is-collapsed .hide-box i { | ||||||
|     transform: rotate(90deg); |     transform: rotate(90deg); | ||||||
| } | } | ||||||
| /* END */ | /* END */ | ||||||
|  |  | ||||||
| /* dashboard styles */ | /* dashboard styles */ | ||||||
|  | .hide-box { | ||||||
|  |     border: none; | ||||||
|  |     background: none; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .hide-box:focus { | ||||||
|  |     outline: none; | ||||||
|  |     box-shadow: none !important; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .channel-bar { | ||||||
|  |     display: flex; | ||||||
|  |     justify-content: center; | ||||||
|  |     flex-direction: column; | ||||||
|  |     font-weight: bold; | ||||||
|  | } | ||||||
|  |  | ||||||
| button.inline-btn { | button.inline-btn { | ||||||
|     height: 100%; |     height: 100%; | ||||||
|     padding: 5px; |     padding: 5px; | ||||||
| @@ -85,18 +85,80 @@ div.discord-embed { | |||||||
|     position: relative; |     position: relative; | ||||||
| } | } | ||||||
|  |  | ||||||
| div.reminderContent { | div.split-controls { | ||||||
|     padding: 2px; |     display: flex; | ||||||
|     background-color: #f5f5f5; |     flex-direction: column; | ||||||
|     border-radius: 8px; |     justify-content: space-between; | ||||||
|     margin: 8px; |     flex-grow: 2; | ||||||
| } | } | ||||||
|  |  | ||||||
| div.interval-group > button { | .reminder-topbar > div { | ||||||
|     margin-left: auto; |     padding-left: 6px; | ||||||
|  |     padding-right: 6px; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .settings { | ||||||
|  |     display: flex; | ||||||
|  |     flex-direction: column; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .name-bar { | ||||||
|  |     flex-grow: 1; | ||||||
|  |     flex-shrink: 1; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .hide-button-bar { | ||||||
|  |     flex-grow: 0; | ||||||
|  |     flex-shrink: 0; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .patreon-only { | ||||||
|  |     padding-bottom: 16px; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .tts-row { | ||||||
|  |     padding-bottom: 10px; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .reminder-topbar { | ||||||
|  |     display: flex; | ||||||
|  |     margin-bottom: 0 !important; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .reminder-settings { | ||||||
|  |     margin-top: 0 !important; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | div.reminderContent { | ||||||
|  |     margin-top: 10px; | ||||||
|  |     margin-bottom: 10px; | ||||||
|  |     padding: 14px; | ||||||
|  |     background-color: #f5f5f5; | ||||||
|  |     border-radius: 8px; | ||||||
| } | } | ||||||
|  |  | ||||||
| /* Interval inputs */ | /* Interval inputs */ | ||||||
|  | div.interval-group { | ||||||
|  |     height: unset !important; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | div.interval-group .clear:focus { | ||||||
|  |     outline: none; | ||||||
|  |     box-shadow: none !important; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | div.interval-group .no-break { | ||||||
|  |     text-wrap: avoid; | ||||||
|  |     white-space: nowrap; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | div.interval-group .clear { | ||||||
|  |     border: none; | ||||||
|  |     background: none; | ||||||
|  |     padding: 1px; | ||||||
|  |     margin-right: -3px; | ||||||
|  | } | ||||||
|  |  | ||||||
| div.interval-group > .interval-group-left input { | div.interval-group > .interval-group-left input { | ||||||
|     -webkit-appearance: none; |     -webkit-appearance: none; | ||||||
|     border-style: none; |     border-style: none; | ||||||
| @@ -110,12 +172,13 @@ div.interval-group > .interval-group-left input.w2 { | |||||||
| } | } | ||||||
|  |  | ||||||
| div.interval-group > .interval-group-left input.w3 { | div.interval-group > .interval-group-left input.w3 { | ||||||
|     width: 6ch; |     width: 3ch; | ||||||
| } | } | ||||||
|  |  | ||||||
| div.interval-group { | div.interval-group { | ||||||
|     display: flex; |     display: flex; | ||||||
|     flex-direction: row; |     flex-direction: row; | ||||||
|  |     justify-content: space-between; | ||||||
| } | } | ||||||
| /* !Interval inputs */ | /* !Interval inputs */ | ||||||
|  |  | ||||||
| @@ -180,6 +243,23 @@ div#pageNavbar a { | |||||||
|     text-align: center; |     text-align: center; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | .navbar-burger { | ||||||
|  |     flex-shrink: 0; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .navbar-item.pageTitle { | ||||||
|  |     flex-shrink: 1; | ||||||
|  |     white-space: nowrap; | ||||||
|  |     overflow: hidden; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .dashboard-burger, .dashboard-burger:active, .dashboard-burger.is-active { | ||||||
|  |     background-color: #adc99c !important; | ||||||
|  |     border-radius: 14px; | ||||||
|  |     padding: 6px; | ||||||
|  |     background-clip: content-box; | ||||||
|  | } | ||||||
|  |  | ||||||
| div#pageNavbar a:hover { | div#pageNavbar a:hover { | ||||||
|     background-color: #4a4a4a; |     background-color: #4a4a4a; | ||||||
| } | } | ||||||
| @@ -211,10 +291,19 @@ div.dashboard-sidebar:not(.mobile-sidebar) { | |||||||
|     flex-direction: column; |     flex-direction: column; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | ul.guildList { | ||||||
|  |     flex-grow: 1; | ||||||
|  |     flex-shrink: 1; | ||||||
|  |     overflow: scroll; | ||||||
|  | } | ||||||
|  |  | ||||||
| div.dashboard-sidebar:not(.mobile-sidebar) .aside-footer { | div.dashboard-sidebar:not(.mobile-sidebar) .aside-footer { | ||||||
|     position: fixed; |     flex-shrink: 0; | ||||||
|     bottom: 0; |     flex-grow: 0; | ||||||
|     width: 226px; | } | ||||||
|  |  | ||||||
|  | div.dashboard-sidebar svg { | ||||||
|  |     flex-shrink: 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| div.mobile-sidebar { | div.mobile-sidebar { | ||||||
| @@ -293,10 +382,7 @@ input.default-width { | |||||||
| } | } | ||||||
|  |  | ||||||
| .message-input:placeholder-shown { | .message-input:placeholder-shown { | ||||||
|     border-top: none; |     font-style: italic; | ||||||
|     border-left: none; |  | ||||||
|     border-right: none; |  | ||||||
|     border-bottom-style: dashed; |  | ||||||
|     background-color: #40444b; |     background-color: #40444b; | ||||||
|     color: #fff; |     color: #fff; | ||||||
| } | } | ||||||
| @@ -462,6 +548,7 @@ input.default-width { | |||||||
|     flex-grow: 1; |     flex-grow: 1; | ||||||
|     flex-shrink: 1; |     flex-shrink: 1; | ||||||
|     flex-basis: auto; |     flex-basis: auto; | ||||||
|  |     margin-right: 4px; | ||||||
| } | } | ||||||
|  |  | ||||||
| .embed-body input, .embed-body textarea { | .embed-body input, .embed-body textarea { | ||||||
| @@ -511,6 +598,69 @@ input.default-width { | |||||||
|     border-bottom: 1px solid #fff; |     border-bottom: 1px solid #fff; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | li.highlight { | ||||||
|  |     margin-bottom: 0 !important; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .button-row { | ||||||
|  |     display: flex; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .button-row .button-row-reminder { | ||||||
|  |     flex-grow: 0; | ||||||
|  |     padding: 2px; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .button-row-template { | ||||||
|  |     display: flex; | ||||||
|  |     flex-grow: 1; | ||||||
|  |     justify-content: space-between; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .button-row .button-row-template > div { | ||||||
|  |     padding: 2px; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @media only screen and (max-width: 1408px) { | ||||||
|  |     .button-row { | ||||||
|  |         display: flex; | ||||||
|  |         flex-direction: column; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     .button-row .button-row-reminder { | ||||||
|  |         width: 100%; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     .button-row .button-row-template > div { | ||||||
|  |         flex-basis: 0; | ||||||
|  |         flex-grow: 1; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     .button-row button { | ||||||
|  |         width: 100%; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @media only screen and (max-width: 768px) { | ||||||
|  |     .button-row-edit { | ||||||
|  |         display: flex; | ||||||
|  |         flex-direction: column; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     .button-row-edit > button { | ||||||
|  |         width: 100%; | ||||||
|  |         margin: 4px; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     p.title.pageTitle { | ||||||
|  |         display: none; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     .dashboard-frame { | ||||||
|  |         margin-top: 4rem !important; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
| @media only screen and (max-width: 768px) { | @media only screen and (max-width: 768px) { | ||||||
|     .customizable.thumbnail img { |     .customizable.thumbnail img { | ||||||
|         width: 60px; |         width: 60px; | ||||||
| @@ -526,6 +676,7 @@ input.default-width { | |||||||
| /* loader */ | /* loader */ | ||||||
| #loader { | #loader { | ||||||
|     position: fixed; |     position: fixed; | ||||||
|  |     top: 0; | ||||||
|     background-color: rgba(255, 255, 255, 0.8); |     background-color: rgba(255, 255, 255, 0.8); | ||||||
|     width: 100vw; |     width: 100vw; | ||||||
|     z-index: 999; |     z-index: 999; | ||||||
| @@ -537,6 +688,76 @@ input.default-width { | |||||||
|  |  | ||||||
| /* END */ | /* END */ | ||||||
|  |  | ||||||
|  | div.reminderError { | ||||||
|  |     margin: 10px; | ||||||
|  |     padding: 14px; | ||||||
|  |     background-color: #f5f5f5; | ||||||
|  |     border-radius: 8px; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | div.reminderError .errorHead { | ||||||
|  |     display: flex; | ||||||
|  |     flex-direction: row; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | div.reminderError .errorIcon { | ||||||
|  |     padding: 8px; | ||||||
|  |     border-radius: 4px; | ||||||
|  |     margin-right: 12px; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | div.reminderError .errorIcon .fas { | ||||||
|  |     display: none | ||||||
|  | } | ||||||
|  |  | ||||||
|  | div.reminderError[data-case="deleted"] .errorIcon { | ||||||
|  |     background-color: #e7e5e4; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | div.reminderError[data-case="failed"] .errorIcon { | ||||||
|  |     background-color: #fecaca; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | div.reminderError[data-case="sent"] .errorIcon { | ||||||
|  |     background-color: #d9f99d; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | div.reminderError[data-case="deleted"] .errorIcon .fas.fa-trash { | ||||||
|  |     display: block; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | div.reminderError[data-case="failed"] .errorIcon .fas.fa-exclamation-triangle { | ||||||
|  |     display: block; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | div.reminderError[data-case="sent"] .errorIcon .fas.fa-check { | ||||||
|  |     display: block; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | div.reminderError .errorHead .reminderName { | ||||||
|  |     font-size: 1rem; | ||||||
|  |     display: flex; | ||||||
|  |     flex-direction: column; | ||||||
|  |     justify-content: center; | ||||||
|  |     color: rgb(54, 54, 54); | ||||||
|  |     flex-grow: 1; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | div.reminderError .errorHead .reminderTime { | ||||||
|  |     font-size: 1rem; | ||||||
|  |     display: flex; | ||||||
|  |     flex-direction: column; | ||||||
|  |     flex-shrink: 1; | ||||||
|  |     justify-content: center; | ||||||
|  |     color: rgb(54, 54, 54); | ||||||
|  |     background-color: #ffffff; | ||||||
|  |     padding: 8px; | ||||||
|  |     border-radius: 4px; | ||||||
|  |     border-color: #e5e5e5; | ||||||
|  |     border-width: 1px; | ||||||
|  |     border-style: solid; | ||||||
|  | } | ||||||
|  |  | ||||||
| /* other stuff */ | /* other stuff */ | ||||||
|  |  | ||||||
| .half-rem { | .half-rem { | ||||||
| @@ -568,11 +789,44 @@ input.default-width { | |||||||
|     background-color: white; |     background-color: white; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | a.switch-pane { | ||||||
|  |     white-space: nowrap; | ||||||
|  |     overflow: hidden; | ||||||
|  |     text-overflow: ellipsis; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .guild-submenu { | ||||||
|  |     display: none; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .guild-submenu li { | ||||||
|  |     font-size: 0.8rem; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | a.switch-pane.is-active ~ .guild-submenu { | ||||||
|  |     display: block; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .feedback { | ||||||
|  |     background-color: #5865F2; | ||||||
|  | } | ||||||
|  |  | ||||||
| .is-locked { | .is-locked { | ||||||
|     pointer-events: none; |     pointer-events: none; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .is-locked > :not(.patreon-invert) { | ||||||
|     opacity: 0.4; |     opacity: 0.4; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | .is-locked .patreon-invert { | ||||||
|  |     display: block; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .patreon-invert { | ||||||
|  |     display: none; | ||||||
|  | } | ||||||
|  |  | ||||||
| .is-locked .foreground { | .is-locked .foreground { | ||||||
|     pointer-events: auto; |     pointer-events: auto; | ||||||
| } | } | ||||||
| @@ -580,3 +834,27 @@ input.default-width { | |||||||
| .is-locked .field:last-of-type { | .is-locked .field:last-of-type { | ||||||
|     display: none; |     display: none; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | .stat-row { | ||||||
|  |     display: flex; | ||||||
|  |     flex-direction: row; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .stat-box { | ||||||
|  |     flex-grow: 1; | ||||||
|  |     border-radius: 6px; | ||||||
|  |     background-color: #fcfcfc; | ||||||
|  |     border-color: #efefef; | ||||||
|  |     border-style: solid; | ||||||
|  |     border-width: 1px; | ||||||
|  |     margin: 4px; | ||||||
|  |     padding: 4px; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .figure { | ||||||
|  |     text-align: center; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .figure-num { | ||||||
|  |     font-size: 2rem; | ||||||
|  | } | ||||||
|   | |||||||
							
								
								
									
										
											BIN
										
									
								
								web/static/img/logo_nobg.webp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								web/static/img/logo_nobg.webp
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 81 KiB | 
							
								
								
									
										131
									
								
								web/static/js/admin.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										131
									
								
								web/static/js/admin.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,131 @@ | |||||||
|  | document.addEventListener("DOMContentLoaded", () => { | ||||||
|  |     fetch("/admin/data") | ||||||
|  |         .then((resp) => resp.json()) | ||||||
|  |         .then((data) => { | ||||||
|  |             document.querySelector("#backlog").textContent = data.backlog; | ||||||
|  |             document.querySelector("#reminders").textContent = data.count.reminders; | ||||||
|  |             document.querySelector("#intervals").textContent = data.count.intervals; | ||||||
|  |  | ||||||
|  |             let historySent = data.historyLong.sent.reduce( | ||||||
|  |                 (iv, frame) => iv + frame.count, | ||||||
|  |                 0 | ||||||
|  |             ); | ||||||
|  |             let historyFailed = data.historyLong.failed.reduce( | ||||||
|  |                 (iv, frame) => iv + frame.count, | ||||||
|  |                 0 | ||||||
|  |             ); | ||||||
|  |             let rate = historyFailed / (historySent + historyFailed); | ||||||
|  |             let formatted = Math.round(rate * 10000) / 100; | ||||||
|  |  | ||||||
|  |             document.querySelector("#historySent").textContent = historySent; | ||||||
|  |             document.querySelector("#historyFailed").textContent = historyFailed; | ||||||
|  |             document.querySelector("#failRate").textContent = `${formatted}%`; | ||||||
|  |  | ||||||
|  |             new Chart(document.getElementById("schedule"), { | ||||||
|  |                 type: "bar", | ||||||
|  |                 data: { | ||||||
|  |                     labels: [ | ||||||
|  |                         ...data.scheduleShort.once, | ||||||
|  |                         ...data.scheduleShort.interval, | ||||||
|  |                     ].map((row) => luxon.DateTime.fromISO(row.time_key)), | ||||||
|  |                     datasets: [ | ||||||
|  |                         { | ||||||
|  |                             label: "Reminders", | ||||||
|  |                             data: data.scheduleShort.once.map((row) => row.count), | ||||||
|  |                         }, | ||||||
|  |                         { | ||||||
|  |                             label: "Intervals", | ||||||
|  |                             data: data.scheduleShort.interval.map((row) => row.count), | ||||||
|  |                         }, | ||||||
|  |                     ], | ||||||
|  |                 }, | ||||||
|  |                 options: { | ||||||
|  |                     responsive: true, | ||||||
|  |                     maintainAspectRatio: false, | ||||||
|  |                     scales: { | ||||||
|  |                         x: { | ||||||
|  |                             stacked: true, | ||||||
|  |                             type: "time", | ||||||
|  |                             time: { | ||||||
|  |                                 unit: "minute", | ||||||
|  |                             }, | ||||||
|  |                         }, | ||||||
|  |                         y: { | ||||||
|  |                             stacked: true, | ||||||
|  |                         }, | ||||||
|  |                     }, | ||||||
|  |                 }, | ||||||
|  |             }); | ||||||
|  |  | ||||||
|  |             new Chart(document.getElementById("scheduleLong"), { | ||||||
|  |                 type: "bar", | ||||||
|  |                 data: { | ||||||
|  |                     labels: [ | ||||||
|  |                         ...data.scheduleLong.once, | ||||||
|  |                         ...data.scheduleLong.interval, | ||||||
|  |                     ].map((row) => luxon.DateTime.fromISO(row.time_key)), | ||||||
|  |                     datasets: [ | ||||||
|  |                         { | ||||||
|  |                             label: "Reminders", | ||||||
|  |                             data: data.scheduleLong.once.map((row) => row.count), | ||||||
|  |                         }, | ||||||
|  |                         { | ||||||
|  |                             label: "Intervals", | ||||||
|  |                             data: data.scheduleLong.interval.map((row) => row.count), | ||||||
|  |                         }, | ||||||
|  |                     ], | ||||||
|  |                 }, | ||||||
|  |                 options: { | ||||||
|  |                     responsive: true, | ||||||
|  |                     maintainAspectRatio: false, | ||||||
|  |                     scales: { | ||||||
|  |                         x: { | ||||||
|  |                             stacked: true, | ||||||
|  |                             type: "time", | ||||||
|  |                             time: { | ||||||
|  |                                 unit: "day", | ||||||
|  |                             }, | ||||||
|  |                         }, | ||||||
|  |                         y: { | ||||||
|  |                             stacked: true, | ||||||
|  |                         }, | ||||||
|  |                     }, | ||||||
|  |                 }, | ||||||
|  |             }); | ||||||
|  |  | ||||||
|  |             new Chart(document.getElementById("historyLong"), { | ||||||
|  |                 type: "bar", | ||||||
|  |                 data: { | ||||||
|  |                     labels: [...data.historyLong.sent, ...data.historyLong.failed].map( | ||||||
|  |                         (row) => luxon.DateTime.fromISO(row.time_key) | ||||||
|  |                     ), | ||||||
|  |                     datasets: [ | ||||||
|  |                         { | ||||||
|  |                             label: "Success", | ||||||
|  |                             data: data.historyLong.sent.map((row) => row.count), | ||||||
|  |                         }, | ||||||
|  |                         { | ||||||
|  |                             label: "Fail", | ||||||
|  |                             data: data.historyLong.failed.map((row) => row.count), | ||||||
|  |                         }, | ||||||
|  |                     ], | ||||||
|  |                 }, | ||||||
|  |                 options: { | ||||||
|  |                     responsive: true, | ||||||
|  |                     maintainAspectRatio: false, | ||||||
|  |                     scales: { | ||||||
|  |                         x: { | ||||||
|  |                             stacked: true, | ||||||
|  |                             type: "time", | ||||||
|  |                             time: { | ||||||
|  |                                 unit: "day", | ||||||
|  |                             }, | ||||||
|  |                         }, | ||||||
|  |                         y: { | ||||||
|  |                             stacked: true, | ||||||
|  |                         }, | ||||||
|  |                     }, | ||||||
|  |                 }, | ||||||
|  |             }); | ||||||
|  |         }); | ||||||
|  | }); | ||||||
							
								
								
									
										20
									
								
								web/static/js/chart.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								web/static/js/chart.js
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										7
									
								
								web/static/js/chartjs-adapter-luxon.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								web/static/js/chartjs-adapter-luxon.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | |||||||
|  | /*! | ||||||
|  |  * chartjs-adapter-luxon v1.3.1 | ||||||
|  |  * https://www.chartjs.org | ||||||
|  |  * (c) 2023 chartjs-adapter-luxon Contributors | ||||||
|  |  * Released under the MIT license | ||||||
|  |  */ | ||||||
|  | !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(require("chart.js"),require("luxon")):"function"==typeof define&&define.amd?define(["chart.js","luxon"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Chart,e.luxon)}(this,(function(e,t){"use strict";const n={datetime:t.DateTime.DATETIME_MED_WITH_SECONDS,millisecond:"h:mm:ss.SSS a",second:t.DateTime.TIME_WITH_SECONDS,minute:t.DateTime.TIME_SIMPLE,hour:{hour:"numeric"},day:{day:"numeric",month:"short"},week:"DD",month:{month:"short",year:"numeric"},quarter:"'Q'q - yyyy",year:{year:"numeric"}};e._adapters._date.override({_id:"luxon",_create:function(e){return t.DateTime.fromMillis(e,this.options)},init(e){this.options.locale||(this.options.locale=e.locale)},formats:function(){return n},parse:function(e,n){const i=this.options,r=typeof e;return null===e||"undefined"===r?null:("number"===r?e=this._create(e):"string"===r?e="string"==typeof n?t.DateTime.fromFormat(e,n,i):t.DateTime.fromISO(e,i):e instanceof Date?e=t.DateTime.fromJSDate(e,i):"object"!==r||e instanceof t.DateTime||(e=t.DateTime.fromObject(e,i)),e.isValid?e.valueOf():null)},format:function(e,t){const n=this._create(e);return"string"==typeof t?n.toFormat(t):n.toLocaleString(t)},add:function(e,t,n){const i={};return i[n]=t,this._create(e).plus(i).valueOf()},diff:function(e,t,n){return this._create(e).diff(this._create(t)).as(n).valueOf()},startOf:function(e,t,n){if("isoWeek"===t){n=Math.trunc(Math.min(Math.max(0,n),6));const t=this._create(e);return t.minus({days:(t.weekday-n+7)%7}).startOf("day").valueOf()}return t?this._create(e).startOf(t).valueOf():e},endOf:function(e,t){return this._create(e).endOf(t).valueOf()}})})); | ||||||
| @@ -18,6 +18,7 @@ const $downloader = document.querySelector("a#downloader"); | |||||||
| const $uploader = document.querySelector("input#uploader"); | const $uploader = document.querySelector("input#uploader"); | ||||||
|  |  | ||||||
| let channels = []; | let channels = []; | ||||||
|  | let reminderErrors = []; | ||||||
| let guildNames = {}; | let guildNames = {}; | ||||||
| let roles = []; | let roles = []; | ||||||
| let templates = {}; | let templates = {}; | ||||||
| @@ -33,7 +34,11 @@ let globalPatreon = false; | |||||||
| let guildPatreon = false; | let guildPatreon = false; | ||||||
|  |  | ||||||
| function guildId() { | function guildId() { | ||||||
|     return document.querySelector(".guildList a.is-active").dataset["guild"]; |     return document.querySelector("li > a.is-active").parentElement.dataset["guild"]; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function guildName() { | ||||||
|  |     return guildNames[guildId()]; | ||||||
| } | } | ||||||
|  |  | ||||||
| function colorToInt(r, g, b) { | function colorToInt(r, g, b) { | ||||||
| @@ -52,23 +57,40 @@ function switch_pane(selector) { | |||||||
|         el.classList.add("is-hidden"); |         el.classList.add("is-hidden"); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     document.getElementById(selector).classList.remove("is-hidden"); |     document.querySelector(`*[data-name=${selector}]`).classList.remove("is-hidden"); | ||||||
| } | } | ||||||
|  |  | ||||||
| function update_select(sel) { | function update_select(sel) { | ||||||
|     if (sel.selectedOptions[0].dataset["webhookAvatar"]) { |     let channelDisplay = sel.closest("div.reminderContent").querySelector(".channel-bar"); | ||||||
|         sel.closest("div.reminderContent").querySelector("img.discord-avatar").src = |  | ||||||
|             sel.selectedOptions[0].dataset["webhookAvatar"]; |     if (channelDisplay !== null) { | ||||||
|     } else { |         channelDisplay.textContent = `#${sel.selectedOptions[0].textContent}`; | ||||||
|         sel.closest("div.reminderContent").querySelector("img.discord-avatar").src = |  | ||||||
|             "/static/img/icon.png"; |  | ||||||
|     } |     } | ||||||
|     if (sel.selectedOptions[0].dataset["webhookName"]) { |  | ||||||
|         sel.closest("div.reminderContent").querySelector("input.discord-username").value = |     if (sel.selectedOptions[0] === undefined) { | ||||||
|             sel.selectedOptions[0].dataset["webhookName"]; |         return; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     const avatarInput = sel.closest("div.reminderContent").querySelector("img.avatar"); | ||||||
|  |  | ||||||
|  |     if (!avatarInput.dataset["set"]) { | ||||||
|  |         if (sel.selectedOptions[0].dataset["webhookAvatar"]) { | ||||||
|  |             avatarInput.src = sel.selectedOptions[0].dataset["webhookAvatar"]; | ||||||
|         } else { |         } else { | ||||||
|         sel.closest("div.reminderContent").querySelector("input.discord-username").value = |             avatarInput.src = "/static/img/icon.png"; | ||||||
|             "Reminder"; |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     const usernameInput = sel | ||||||
|  |         .closest("div.reminderContent") | ||||||
|  |         .querySelector("input.discord-username"); | ||||||
|  |  | ||||||
|  |     if (usernameInput.value.length === 0) { | ||||||
|  |         if (sel.selectedOptions[0].dataset["webhookName"]) { | ||||||
|  |             usernameInput.value = sel.selectedOptions[0].dataset["webhookName"]; | ||||||
|  |         } else { | ||||||
|  |             usernameInput.value = "Reminder"; | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -139,12 +161,18 @@ async function fetch_channels(guild_id) { | |||||||
|     const event = new Event("channelsLoading"); |     const event = new Event("channelsLoading"); | ||||||
|     document.dispatchEvent(event); |     document.dispatchEvent(event); | ||||||
|  |  | ||||||
|  |     let hasError = false; | ||||||
|  |  | ||||||
|     await fetch(`/dashboard/api/guild/${guild_id}/channels`) |     await fetch(`/dashboard/api/guild/${guild_id}/channels`) | ||||||
|         .then((response) => response.json()) |         .then((response) => response.json()) | ||||||
|         .then((data) => { |         .then((data) => { | ||||||
|             if (data.error) { |             if (data.error) { | ||||||
|                 if (data.error === "Bot not in guild") { |                 if (data.error === "Bot not in guild") { | ||||||
|                     switch_pane("guild-error"); |                     switch_pane("guild-error"); | ||||||
|  |                     hasError = true; | ||||||
|  |                 } else if (data.error === "Incorrect permissions") { | ||||||
|  |                     switch_pane("user-error"); | ||||||
|  |                     hasError = true; | ||||||
|                 } else { |                 } else { | ||||||
|                     show_error(data.error); |                     show_error(data.error); | ||||||
|                 } |                 } | ||||||
| @@ -156,6 +184,8 @@ async function fetch_channels(guild_id) { | |||||||
|             const event = new Event("channelsLoaded"); |             const event = new Event("channelsLoaded"); | ||||||
|             document.dispatchEvent(event); |             document.dispatchEvent(event); | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|  |     return hasError; | ||||||
| } | } | ||||||
|  |  | ||||||
| async function fetch_reminders(guild_id) { | async function fetch_reminders(guild_id) { | ||||||
| @@ -206,14 +236,18 @@ async function serialize_reminder(node, mode) { | |||||||
|         utc_time = luxon.DateTime.fromISO( |         utc_time = luxon.DateTime.fromISO( | ||||||
|             node.querySelector('input[name="time"]').value |             node.querySelector('input[name="time"]').value | ||||||
|         ).setZone("UTC"); |         ).setZone("UTC"); | ||||||
|  |  | ||||||
|         if (utc_time.invalid) { |         if (utc_time.invalid) { | ||||||
|             return { error: "Time provided invalid." }; |             return { error: "Time provided invalid." }; | ||||||
|         } else { |         } else { | ||||||
|             utc_time = utc_time.toFormat("yyyy-LL-dd'T'HH:mm:ss"); |             utc_time = utc_time.toFormat("yyyy-LL-dd'T'HH:mm:ss"); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         let expiration = node.querySelector('input[name="expiration"]').value; | ||||||
|  |  | ||||||
|  |         if (expiration) { | ||||||
|             expiration_time = luxon.DateTime.fromISO( |             expiration_time = luxon.DateTime.fromISO( | ||||||
|             node.querySelector('input[name="time"]').value |                 node.querySelector('input[name="expiration"]').value | ||||||
|             ).setZone("UTC"); |             ).setZone("UTC"); | ||||||
|             if (expiration_time.invalid) { |             if (expiration_time.invalid) { | ||||||
|                 return { error: "Expiration provided invalid." }; |                 return { error: "Expiration provided invalid." }; | ||||||
| @@ -221,6 +255,12 @@ async function serialize_reminder(node, mode) { | |||||||
|                 expiration_time = expiration_time.toFormat("yyyy-LL-dd'T'HH:mm:ss"); |                 expiration_time = expiration_time.toFormat("yyyy-LL-dd'T'HH:mm:ss"); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     let name = node.querySelector('input[name="name"]').value; | ||||||
|  |     if (name.length > 100) { | ||||||
|  |         return { error: "Name exceeds maximum length (100)." }; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     let rgb_color = window.getComputedStyle( |     let rgb_color = window.getComputedStyle( | ||||||
|         node.querySelector("div.discord-embed") |         node.querySelector("div.discord-embed") | ||||||
| @@ -284,15 +324,17 @@ async function serialize_reminder(node, mode) { | |||||||
|     const embed_title = node.querySelector('textarea[name="embed_title"]').value; |     const embed_title = node.querySelector('textarea[name="embed_title"]').value; | ||||||
|  |  | ||||||
|     if ( |     if ( | ||||||
|         attachment === null && |         content.length === 0 && | ||||||
|         content.length == 0 && |         embed_author.length === 0 && | ||||||
|  |         embed_title.length === 0 && | ||||||
|  |         embed_description.length === 0 && | ||||||
|  |         embed_footer.length === 0 && | ||||||
|         embed_author_url === null && |         embed_author_url === null && | ||||||
|         embed_author.length == 0 && |  | ||||||
|         embed_description.length == 0 && |  | ||||||
|         embed_footer.length == 0 && |  | ||||||
|         embed_footer_url === null && |         embed_footer_url === null && | ||||||
|         embed_image_url === null && |         embed_image_url === null && | ||||||
|         embed_thumbnail_url === null |         embed_thumbnail_url === null && | ||||||
|  |         fields.length === 0 && | ||||||
|  |         attachment === null | ||||||
|     ) { |     ) { | ||||||
|         return { error: "Reminder needs content." }; |         return { error: "Reminder needs content." }; | ||||||
|     } |     } | ||||||
| @@ -305,7 +347,7 @@ async function serialize_reminder(node, mode) { | |||||||
|         restartable: false, |         restartable: false, | ||||||
|         attachment: attachment, |         attachment: attachment, | ||||||
|         attachment_name: attachment_name, |         attachment_name: attachment_name, | ||||||
|         avatar: has_source(node.querySelector("img.discord-avatar").src), |         avatar: has_source(node.querySelector("img.avatar").src), | ||||||
|         channel: node.querySelector("select.channel-selector").value, |         channel: node.querySelector("select.channel-selector").value, | ||||||
|         content: content, |         content: content, | ||||||
|         embed_author_url: embed_author_url, |         embed_author_url: embed_author_url, | ||||||
| @@ -350,17 +392,27 @@ function deserialize_reminder(reminder, frame, mode) { | |||||||
|                 if ($input !== null) { |                 if ($input !== null) { | ||||||
|                     $input.value = reminder[prop]; |                     $input.value = reminder[prop]; | ||||||
|                 } else if ($image !== null) { |                 } else if ($image !== null) { | ||||||
|  |                     console.log(`loading img ${prop}`); | ||||||
|                     $image.src = reminder[prop]; |                     $image.src = reminder[prop]; | ||||||
|  |                     $image.dataset["set"] = "1"; | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     update_interval(frame); |     update_interval(frame); | ||||||
|  |     update_select(frame.querySelector(".channel-selector")); | ||||||
|  |  | ||||||
|     const lastChild = frame.querySelector("div.embed-multifield-box .embed-field-box"); |     const lastChild = frame.querySelector( | ||||||
|  |         "div.embed-multifield-box .embed-field-box:last-child" | ||||||
|  |     ); | ||||||
|  |  | ||||||
|     for (let field of reminder["embed_fields"]) { |     // Drop existing fields | ||||||
|  |     frame | ||||||
|  |         .querySelectorAll(".embed-field-box:not(:last-child)") | ||||||
|  |         .forEach((el) => el.remove()); | ||||||
|  |  | ||||||
|  |     for (let field of reminder["embed_fields"] || []) { | ||||||
|         let embed_field = $embedFieldTemplate.content.cloneNode(true); |         let embed_field = $embedFieldTemplate.content.cloneNode(true); | ||||||
|         embed_field.querySelector("textarea.discord-field-title").value = field["title"]; |         embed_field.querySelector("textarea.discord-field-title").value = field["title"]; | ||||||
|         embed_field.querySelector("textarea.discord-field-value").value = field["value"]; |         embed_field.querySelector("textarea.discord-field-value").value = field["value"]; | ||||||
| @@ -386,7 +438,7 @@ function deserialize_reminder(reminder, frame, mode) { | |||||||
|         timeInput.value = localTime.toFormat("yyyy-LL-dd'T'HH:mm:ss"); |         timeInput.value = localTime.toFormat("yyyy-LL-dd'T'HH:mm:ss"); | ||||||
|  |  | ||||||
|         if (reminder["expires"]) { |         if (reminder["expires"]) { | ||||||
|             let expiresInput = frame.querySelector('input[name="time"]'); |             let expiresInput = frame.querySelector('input[name="expiration"]'); | ||||||
|             let expiresTime = luxon.DateTime.fromISO(reminder["expires"], { |             let expiresTime = luxon.DateTime.fromISO(reminder["expires"], { | ||||||
|                 zone: "UTC", |                 zone: "UTC", | ||||||
|             }).setZone(timezone); |             }).setZone(timezone); | ||||||
| @@ -402,13 +454,19 @@ document.addEventListener("guildSwitched", async (e) => { | |||||||
|         .querySelectorAll(".patreon-only") |         .querySelectorAll(".patreon-only") | ||||||
|         .forEach((el) => el.classList.add("is-locked")); |         .forEach((el) => el.classList.add("is-locked")); | ||||||
|  |  | ||||||
|     let $anchor = document.querySelector( |     let $li = document.querySelector(`li[data-guild="${e.detail.guild_id}"]`); | ||||||
|         `.switch-pane[data-guild="${e.detail.guild_id}"]` |  | ||||||
|     ); |  | ||||||
|  |  | ||||||
|     switch_pane($anchor.dataset["pane"]); |     if ($li === null) { | ||||||
|  |         switch_pane("user-error"); | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     switch_pane(e.detail.pane); | ||||||
|     reset_guild_pane(); |     reset_guild_pane(); | ||||||
|     $anchor.classList.add("is-active"); |     $li.querySelector("li > a").classList.add("is-active"); | ||||||
|  |     $li.querySelectorAll(`*[data-pane="${e.detail.pane}"]`).forEach((el) => { | ||||||
|  |         el.classList.add("is-active"); | ||||||
|  |     }); | ||||||
|  |  | ||||||
|     if (globalPatreon || (await fetch_patreon(e.detail.guild_id))) { |     if (globalPatreon || (await fetch_patreon(e.detail.guild_id))) { | ||||||
|         document |         document | ||||||
| @@ -416,19 +474,32 @@ document.addEventListener("guildSwitched", async (e) => { | |||||||
|             .forEach((el) => el.classList.remove("is-locked")); |             .forEach((el) => el.classList.remove("is-locked")); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     fetch_roles(e.detail.guild_id); |     const event = new CustomEvent("paneLoad", { | ||||||
|     fetch_templates(e.detail.guild_id); |         detail: { | ||||||
|     await fetch_channels(e.detail.guild_id); |             guild_id: e.detail.guild_id, | ||||||
|     fetch_reminders(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); | ||||||
|  |     if (!hasError) { | ||||||
|  |         fetch_roles(ev.detail.guild_id); | ||||||
|  |         fetch_templates(ev.detail.guild_id); | ||||||
|  |         fetch_reminders(ev.detail.guild_id); | ||||||
|  |  | ||||||
|         document.querySelectorAll("p.pageTitle").forEach((el) => { |         document.querySelectorAll("p.pageTitle").forEach((el) => { | ||||||
|         el.textContent = `${e.detail.guild_name} Reminders`; |             el.textContent = `${guildName()} Reminders`; | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|         document.querySelectorAll("select.channel-selector").forEach((el) => { |         document.querySelectorAll("select.channel-selector").forEach((el) => { | ||||||
|             el.addEventListener("change", (e) => { |             el.addEventListener("change", (e) => { | ||||||
|                 update_select(e.target); |                 update_select(e.target); | ||||||
|             }); |             }); | ||||||
|         }); |         }); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     $loader.classList.add("is-hidden"); |     $loader.classList.add("is-hidden"); | ||||||
| }); | }); | ||||||
| @@ -440,6 +511,12 @@ document.addEventListener("channelsLoaded", () => { | |||||||
| document.addEventListener("remindersLoaded", (event) => { | document.addEventListener("remindersLoaded", (event) => { | ||||||
|     const guild = guildId(); |     const guild = guildId(); | ||||||
|  |  | ||||||
|  |     document.querySelectorAll("select.channel-selector").forEach((el) => { | ||||||
|  |         el.addEventListener("change", (e) => { | ||||||
|  |             update_select(e.target); | ||||||
|  |         }); | ||||||
|  |     }); | ||||||
|  |  | ||||||
|     for (let reminder of event.detail) { |     for (let reminder of event.detail) { | ||||||
|         let node = reminder.node; |         let node = reminder.node; | ||||||
|  |  | ||||||
| @@ -467,9 +544,9 @@ document.addEventListener("remindersLoaded", (event) => { | |||||||
|                     if (data.error) { |                     if (data.error) { | ||||||
|                         show_error(data.error); |                         show_error(data.error); | ||||||
|                     } else { |                     } else { | ||||||
|                         enableBtn.dataset["action"] = data["enabled"] |                         enableBtn.dataset["action"] = data.reminder["enabled"] | ||||||
|                             ? "enable" |                             ? "disable" | ||||||
|                             : "disable"; |                             : "enable"; | ||||||
|                     } |                     } | ||||||
|                 }); |                 }); | ||||||
|         }); |         }); | ||||||
| @@ -566,7 +643,7 @@ document.querySelectorAll(".show-modal").forEach((element) => { | |||||||
|     }); |     }); | ||||||
| }); | }); | ||||||
|  |  | ||||||
| document.addEventListener("DOMContentLoaded", () => { | document.addEventListener("DOMContentLoaded", async () => { | ||||||
|     $loader.classList.remove("is-hidden"); |     $loader.classList.remove("is-hidden"); | ||||||
|  |  | ||||||
|     mentions.attach(document.querySelectorAll("textarea")); |     mentions.attach(document.querySelectorAll("textarea")); | ||||||
| @@ -586,7 +663,7 @@ document.addEventListener("DOMContentLoaded", () => { | |||||||
|         hideBox.closest(".reminderContent").classList.toggle("is-collapsed"); |         hideBox.closest(".reminderContent").classList.toggle("is-collapsed"); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     fetch("/dashboard/api/user") |     await fetch("/dashboard/api/user") | ||||||
|         .then((response) => response.json()) |         .then((response) => response.json()) | ||||||
|         .then((data) => { |         .then((data) => { | ||||||
|             if (data.error) { |             if (data.error) { | ||||||
| @@ -600,7 +677,7 @@ document.addEventListener("DOMContentLoaded", () => { | |||||||
|             } |             } | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|     fetch("/dashboard/api/user/guilds") |     await fetch("/dashboard/api/user/guilds") | ||||||
|         .then((response) => response.json()) |         .then((response) => response.json()) | ||||||
|         .then((data) => { |         .then((data) => { | ||||||
|             if (data.error) { |             if (data.error) { | ||||||
| @@ -621,36 +698,56 @@ document.addEventListener("DOMContentLoaded", () => { | |||||||
|                             "%guildname%", |                             "%guildname%", | ||||||
|                             guild.name |                             guild.name | ||||||
|                         ); |                         ); | ||||||
|                         $anchor.dataset["guild"] = guild.id; |  | ||||||
|                         $anchor.dataset["name"] = guild.name; |                         $anchor.dataset["name"] = guild.name; | ||||||
|                         $anchor.href = `/dashboard/${guild.id}?name=${guild.name}`; |                         $anchor.href = `/dashboard/${guild.id}/reminders`; | ||||||
|  |  | ||||||
|                         $anchor.addEventListener("click", async (e) => { |                         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(); |                                     e.preventDefault(); | ||||||
|                             window.history.pushState({}, "", `/dashboard/${guild.id}`); |  | ||||||
|  |                                     switch_pane(pane); | ||||||
|  |  | ||||||
|  |                                     window.history.pushState( | ||||||
|  |                                         {}, | ||||||
|  |                                         "", | ||||||
|  |                                         `/dashboard/${guild.id}/${slug}` | ||||||
|  |                                     ); | ||||||
|                                     const event = new CustomEvent("guildSwitched", { |                                     const event = new CustomEvent("guildSwitched", { | ||||||
|                                         detail: { |                                         detail: { | ||||||
|                                     guild_name: guild.name, |  | ||||||
|                                             guild_id: guild.id, |                                             guild_id: guild.id, | ||||||
|  |                                             pane, | ||||||
|                                         }, |                                         }, | ||||||
|                                     }); |                                     }); | ||||||
|  |  | ||||||
|                                     document.dispatchEvent(event); |                                     document.dispatchEvent(event); | ||||||
|  |                                 } | ||||||
|  |                             }); | ||||||
|                         }); |                         }); | ||||||
|  |  | ||||||
|                         element.append($clone); |                         element.append($clone); | ||||||
|                     }); |                     }); | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 const matches = window.location.href.match(/dashboard\/(\d+)/); |                 const matches = window.location.href.match( | ||||||
|  |                     /dashboard\/(\d+)(\/)?([a-zA-Z\-]+)?/ | ||||||
|  |                 ); | ||||||
|                 if (matches) { |                 if (matches) { | ||||||
|                     let id = matches[1]; |                     let id = matches[1]; | ||||||
|  |                     let kind = matches[3]; | ||||||
|                     let name = guildNames[id]; |                     let name = guildNames[id]; | ||||||
|  |  | ||||||
|                     const event = new CustomEvent("guildSwitched", { |                     const event = new CustomEvent("guildSwitched", { | ||||||
|                         detail: { |                         detail: { | ||||||
|                             guild_name: name, |                             guild_name: name, | ||||||
|                             guild_id: id, |                             guild_id: id, | ||||||
|  |                             pane: kind, | ||||||
|                         }, |                         }, | ||||||
|                     }); |                     }); | ||||||
|  |  | ||||||
| @@ -782,6 +879,14 @@ $createTemplateBtn.addEventListener("click", async () => { | |||||||
|     ]; |     ]; | ||||||
|  |  | ||||||
|     let reminder = await serialize_reminder($createReminder, "template"); |     let reminder = await serialize_reminder($createReminder, "template"); | ||||||
|  |     if (reminder.error) { | ||||||
|  |         show_error(reminder.error); | ||||||
|  |         $createTemplateBtn.querySelector("span.icon > i").classList = [ | ||||||
|  |             "fas fa-file-spreadsheet", | ||||||
|  |         ]; | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     let guild = guildId(); |     let guild = guildId(); | ||||||
|  |  | ||||||
|     fetch(`/dashboard/api/guild/${guild}/templates`, { |     fetch(`/dashboard/api/guild/${guild}/templates`, { | ||||||
| @@ -823,6 +928,7 @@ $loadTemplateBtn.addEventListener("click", (ev) => { | |||||||
| }); | }); | ||||||
|  |  | ||||||
| $deleteTemplateBtn.addEventListener("click", (ev) => { | $deleteTemplateBtn.addEventListener("click", (ev) => { | ||||||
|  |     if (parseInt($templateSelect.value) !== null) { | ||||||
|         fetch(`/dashboard/api/guild/${guildId()}/templates`, { |         fetch(`/dashboard/api/guild/${guildId()}/templates`, { | ||||||
|             method: "DELETE", |             method: "DELETE", | ||||||
|             headers: { |             headers: { | ||||||
| @@ -840,6 +946,7 @@ $deleteTemplateBtn.addEventListener("click", (ev) => { | |||||||
|                         .remove(); |                         .remove(); | ||||||
|                 } |                 } | ||||||
|             }); |             }); | ||||||
|  |     } | ||||||
| }); | }); | ||||||
|  |  | ||||||
| let $img; | let $img; | ||||||
| @@ -979,6 +1086,13 @@ document.addEventListener("click", (ev) => { | |||||||
|     if (ev.target.closest("button.inline-btn") !== null) { |     if (ev.target.closest("button.inline-btn") !== null) { | ||||||
|         let inlined = ev.target.closest(".embed-field-box").dataset["inlined"]; |         let inlined = ev.target.closest(".embed-field-box").dataset["inlined"]; | ||||||
|         ev.target.closest(".embed-field-box").dataset["inlined"] = |         ev.target.closest(".embed-field-box").dataset["inlined"] = | ||||||
|             inlined == "1" ? "0" : "1"; |             inlined === "1" ? "0" : "1"; | ||||||
|     } |     } | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  | document.addEventListener("DOMContentLoaded", () => { | ||||||
|  |     let now = luxon.DateTime.now().setZone(timezone); | ||||||
|  |     document.querySelectorAll(".prefill-now").forEach((el) => { | ||||||
|  |         el.value = now.toFormat("yyyy-LL-dd'T'HH:mm:ss"); | ||||||
|  |     }); | ||||||
|  | }); | ||||||
|   | |||||||
							
								
								
									
										43
									
								
								web/static/js/reminder_errors.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								web/static/js/reminder_errors.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,43 @@ | |||||||
|  | function loadErrors() { | ||||||
|  |     return fetch( | ||||||
|  |         `/dashboard/api/guild/${guildId()}/reminders?status=deleted,sent,failed` | ||||||
|  |     ).then((response) => response.json()); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | document.addEventListener("paneLoad", (ev) => { | ||||||
|  |     if (ev.detail.pane !== "errors") { | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     document.querySelectorAll(".reminderError").forEach((el) => el.remove()); | ||||||
|  |  | ||||||
|  |     const template = document.getElementById("reminderError"); | ||||||
|  |     const container = document.getElementById("reminderLog"); | ||||||
|  |  | ||||||
|  |     loadErrors() | ||||||
|  |         .then((res) => { | ||||||
|  |             res = res | ||||||
|  |                 .filter((r) => r.status_change_time !== null) | ||||||
|  |                 .sort((a, b) => a.status_change_time < b.status_change_time); | ||||||
|  |  | ||||||
|  |             for (const reminder of res) { | ||||||
|  |                 const newRow = template.content.cloneNode(true); | ||||||
|  |  | ||||||
|  |                 newRow.querySelector(".reminderError").dataset["case"] = reminder.status; | ||||||
|  |  | ||||||
|  |                 const statusTime = new luxon.DateTime.fromISO( | ||||||
|  |                     reminder.status_change_time, | ||||||
|  |                     { zone: "UTC" } | ||||||
|  |                 ); | ||||||
|  |                 newRow.querySelector(".reminderName").textContent = reminder.name; | ||||||
|  |                 newRow.querySelector(".reminderTime").textContent = statusTime | ||||||
|  |                     .toLocal() | ||||||
|  |                     .toLocaleString(luxon.DateTime.DATETIME_MED); | ||||||
|  |  | ||||||
|  |                 container.appendChild(newRow); | ||||||
|  |             } | ||||||
|  |         }) | ||||||
|  |         .finally(() => { | ||||||
|  |             $loader.classList.add("is-hidden"); | ||||||
|  |         }); | ||||||
|  | }); | ||||||
							
								
								
									
										16
									
								
								web/static/js/reporter.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								web/static/js/reporter.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | |||||||
|  | const REPORTER_ID = crypto.randomUUID(); | ||||||
|  |  | ||||||
|  | window.addEventListener("error", async (ev) => { | ||||||
|  |     await fetch("/report", { | ||||||
|  |         method: "POST", | ||||||
|  |         body: JSON.stringify({ | ||||||
|  |             reporterId: REPORTER_ID, | ||||||
|  |             url: window.location.href, | ||||||
|  |             relativeTimestamp: ev.timeStamp, | ||||||
|  |             errorMessage: ev.message, | ||||||
|  |             errorLine: ev.lineno, | ||||||
|  |             errorFile: ev.filename, | ||||||
|  |             errorType: ev.type, | ||||||
|  |         }), | ||||||
|  |     }); | ||||||
|  | }); | ||||||
| @@ -1,14 +1,15 @@ | |||||||
| { | { | ||||||
|     "name": "", |     "name": "Reminder Bot Dashboard", | ||||||
|     "short_name": "", |     "short_name": "Reminders", | ||||||
|  |     "start_url": "/dashboard", | ||||||
|     "icons": [ |     "icons": [ | ||||||
|         { |         { | ||||||
|             "src": "/android-chrome-192x192.png", |             "src": "/static/favicon/android-chrome-192x192.png", | ||||||
|             "sizes": "192x192", |             "sizes": "192x192", | ||||||
|             "type": "image/png" |             "type": "image/png" | ||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
|             "src": "/android-chrome-512x512.png", |             "src": "/static/favicon/android-chrome-512x512.png", | ||||||
|             "sizes": "512x512", |             "sizes": "512x512", | ||||||
|             "type": "image/png" |             "type": "image/png" | ||||||
|         } |         } | ||||||
							
								
								
									
										89
									
								
								web/templates/admin_dashboard.html.tera
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										89
									
								
								web/templates/admin_dashboard.html.tera
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,89 @@ | |||||||
|  | <!DOCTYPE html> | ||||||
|  | <html lang="EN"> | ||||||
|  | <head> | ||||||
|  |     <script src="/static/js/reporter.js" type="application/javascript"></script> | ||||||
|  |  | ||||||
|  |     <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/favicon/site.webmanifest"> | ||||||
|  |     <meta name="msapplication-TileColor" content="#da532c"> | ||||||
|  |     <meta name="theme-color" content="#ffffff"> | ||||||
|  |  | ||||||
|  |     <title>Reminder Bot | Admin</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"> | ||||||
|  |     <link rel="stylesheet" href="/static/css/dtsel.css"> | ||||||
|  |  | ||||||
|  |     <script src="/static/js/luxon.min.js"></script> | ||||||
|  | </head> | ||||||
|  | <body style="width: 100%;"> | ||||||
|  |  | ||||||
|  | <p class="title pageTitle">Admin dashboard</p> | ||||||
|  | <section id="main"> | ||||||
|  |     <div class="stat-row"> | ||||||
|  |         <div class="stat-box" style="height: 400px;"> | ||||||
|  |             <canvas id="schedule"></canvas> | ||||||
|  |         </div> | ||||||
|  |     </div> | ||||||
|  |     <div class="stat-row"> | ||||||
|  |         <div class="stat-box figure"> | ||||||
|  |             <p>Backlog</p> | ||||||
|  |             <p class="figure-num" id="backlog">?</p> | ||||||
|  |         </div> | ||||||
|  |         <div class="stat-box figure"> | ||||||
|  |             <p>Reminders</p> | ||||||
|  |             <p class="figure-num" id="reminders">?</p> | ||||||
|  |         </div> | ||||||
|  |         <div class="stat-box figure"> | ||||||
|  |             <p>Intervals</p> | ||||||
|  |             <p class="figure-num" id="intervals">?</p> | ||||||
|  |         </div> | ||||||
|  |     </div> | ||||||
|  |     <div class="stat-row"> | ||||||
|  |         <div class="stat-box" style="height: 400px;"> | ||||||
|  |             <canvas id="scheduleLong"></canvas> | ||||||
|  |         </div> | ||||||
|  |     </div> | ||||||
|  |     <div class="stat-row"> | ||||||
|  |         <div class="stat-box figure"> | ||||||
|  |             <p>Last 31 days (success)</p> | ||||||
|  |             <p class="figure-num" id="historySent">?</p> | ||||||
|  |         </div> | ||||||
|  |         <div class="stat-box figure"> | ||||||
|  |             <p>Last 31 days (failed)</p> | ||||||
|  |             <p class="figure-num" id="historyFailed">?</p> | ||||||
|  |         </div> | ||||||
|  |         <div class="stat-box figure"> | ||||||
|  |             <p>Last 31 days (failure rate)</p> | ||||||
|  |             <p class="figure-num" id="failRate">?</p> | ||||||
|  |         </div> | ||||||
|  |     </div> | ||||||
|  |     <div class="stat-row"> | ||||||
|  |         <div class="stat-box" style="height: 400px;"> | ||||||
|  |             <canvas id="historyLong"></canvas> | ||||||
|  |         </div> | ||||||
|  |     </div> | ||||||
|  | </section> | ||||||
|  |  | ||||||
|  | <script src="/static/js/chart.js" defer></script> | ||||||
|  | <script src="/static/js/chartjs-adapter-luxon.js" defer></script> | ||||||
|  | <script src="/static/js/admin.js" defer></script> | ||||||
|  |  | ||||||
|  | </body> | ||||||
|  | </html> | ||||||
| @@ -13,7 +13,7 @@ | |||||||
|     <link rel="apple-touch-icon" sizes="180x180" href="/static/favicon/apple-touch-icon.png"> |     <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="32x32" href="/static/favicon/favicon-32x32.png"> | ||||||
|     <link rel="icon" type="image/png" sizes="16x16" href="/static/favicon/favicon-16x16.png"> |     <link rel="icon" type="image/png" sizes="16x16" href="/static/favicon/favicon-16x16.png"> | ||||||
|     <link rel="manifest" href="/static/favicon/site.webmanifest"> |     <link rel="manifest" href="/static/site.webmanifest"> | ||||||
|     <meta name="msapplication-TileColor" content="#da532c"> |     <meta name="msapplication-TileColor" content="#da532c"> | ||||||
|     <meta name="theme-color" content="#ffffff"> |     <meta name="theme-color" content="#ffffff"> | ||||||
|  |  | ||||||
| @@ -51,8 +51,8 @@ | |||||||
|                 <a class="navbar-item" href="https://invite.reminder-bot.com"> |                 <a class="navbar-item" href="https://invite.reminder-bot.com"> | ||||||
|                     <i class="fas fa-plus"></i> |                     <i class="fas fa-plus"></i> | ||||||
|                 </a> |                 </a> | ||||||
|                 <a class="navbar-item" href="https://github.com/jellywx"> |                 <a class="navbar-item" href="https://gitea.jellypro.xyz/jude"> | ||||||
|                     <i class="fab fa-github"></i> |                     <i class="fab fa-git-square"></i> | ||||||
|                 </a> |                 </a> | ||||||
|                 <a class="navbar-item" href="https://discord.jellywx.com"> |                 <a class="navbar-item" href="https://discord.jellywx.com"> | ||||||
|                     <i class="fab fa-discord"></i> |                     <i class="fab fa-discord"></i> | ||||||
| @@ -128,7 +128,7 @@ | |||||||
|                 </div> |                 </div> | ||||||
|             {% elif show_login %} |             {% elif show_login %} | ||||||
|                 <div class="hero-foot has-text-centered"> |                 <div class="hero-foot has-text-centered"> | ||||||
|                     <a class="button is-size-4 is-rounded is-light" href="/oauth/login"> |                     <a class="button is-size-4 is-rounded is-light" href="/login/discord"> | ||||||
|                         <p class="is-size-4"> |                         <p class="is-size-4"> | ||||||
|                             <span>Login with Discord</span> <span class="icon"><i class="fas fa-chevron-right"></i></span> |                             <span>Login with Discord</span> <span class="icon"><i class="fas fa-chevron-right"></i></span> | ||||||
|                         </p> |                         </p> | ||||||
| @@ -155,7 +155,7 @@ | |||||||
|                 <br> |                 <br> | ||||||
|                 <a href="/cookies">Cookies</a> | <a href="/privacy">Privacy Policy</a> | <a href="/terms">Terms of Service</a> |                 <a href="/cookies">Cookies</a> | <a href="/privacy">Privacy Policy</a> | <a href="/terms">Terms of Service</a> | ||||||
|                 <br> |                 <br> | ||||||
|                 <a href="https://patreon.com/jellywx"><strong>Patreon</strong></a> | <a href="https://discord.jellywx.com"><strong>Discord</strong></a> | <a href="https://github.com/JellyWX"><strong>GitHub</strong></a> |                 <a href="https://patreon.com/jellywx"><strong>Patreon</strong></a> | <a href="https://discord.jellywx.com"><strong>Discord</strong></a> | <a href="https://gitea.jellypro.xyz/jude"><strong>Gitea</strong></a> | ||||||
|                 <br> |                 <br> | ||||||
|                 or, <a href="mailto:jude@jellywx.com">Email me</a> |                 or, <a href="mailto:jude@jellywx.com">Email me</a> | ||||||
|             </p> |             </p> | ||||||
|   | |||||||
| @@ -1,6 +1,8 @@ | |||||||
| <!DOCTYPE html> | <!DOCTYPE html> | ||||||
| <html lang="EN"> | <html lang="EN"> | ||||||
| <head> | <head> | ||||||
|  |     <script src="/static/js/reporter.js" type="application/javascript"></script> | ||||||
|  |  | ||||||
|     <meta name="description" content="The most powerful Discord Reminders Bot"> |     <meta name="description" content="The most powerful Discord Reminders Bot"> | ||||||
|     <meta name="viewport" content="width=device-width, initial-scale=1.0"> |     <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||||||
|     <meta charset="UTF-8"> |     <meta charset="UTF-8"> | ||||||
| @@ -38,14 +40,14 @@ | |||||||
|     <div class="navbar-brand"> |     <div class="navbar-brand"> | ||||||
|         <a class="navbar-item" href="/"> |         <a class="navbar-item" href="/"> | ||||||
|             <figure class="image"> |             <figure class="image"> | ||||||
|                 <img src="/static/img/logo_flat.webp" alt="Reminder Bot Logo"> |                 <img src="/static/img/logo_nobg.webp" alt="Reminder Bot Logo"> | ||||||
|             </figure> |             </figure> | ||||||
|         </a> |         </a> | ||||||
|  |  | ||||||
|         <p class="navbar-item pageTitle"> |         <p class="navbar-item pageTitle"> | ||||||
|         </p> |         </p> | ||||||
|  |  | ||||||
|         <a role="button" class="navbar-burger is-right" aria-label="menu" aria-expanded="false" |         <a role="button" class="dashboard-burger navbar-burger is-right" aria-label="menu" aria-expanded="false" | ||||||
|            data-target="mobileSidebar"> |            data-target="mobileSidebar"> | ||||||
|             <span aria-hidden="true"></span> |             <span aria-hidden="true"></span> | ||||||
|             <span aria-hidden="true"></span> |             <span aria-hidden="true"></span> | ||||||
| @@ -231,7 +233,7 @@ | |||||||
|     <div class="column is-2 is-sidebar-menu dashboard-sidebar is-hidden-touch"> |     <div class="column is-2 is-sidebar-menu dashboard-sidebar is-hidden-touch"> | ||||||
|         <a href="/"> |         <a href="/"> | ||||||
|             <div class="brand"> |             <div class="brand"> | ||||||
|                 <img src="/static/img/logo_flat.webp" alt="Reminder bot logo" |                 <img src="/static/img/logo_nobg.webp" alt="Reminder bot logo" | ||||||
|                      class="dashboard-brand"> |                      class="dashboard-brand"> | ||||||
|             </div> |             </div> | ||||||
|         </a> |         </a> | ||||||
| @@ -250,16 +252,24 @@ | |||||||
|             </ul> |             </ul> | ||||||
|             <div class="aside-footer"> |             <div class="aside-footer"> | ||||||
|                 <p class="menu-label"> |                 <p class="menu-label"> | ||||||
|                     Settings |                     Options | ||||||
|                 </p> |                 </p> | ||||||
|                 <ul class="menu-list"> |                 <ul class="menu-list"> | ||||||
|                     <li> |                     <li> | ||||||
|  |                         {# | ||||||
|                         <a class="show-modal" data-modal="dataManagerModal"> |                         <a class="show-modal" data-modal="dataManagerModal"> | ||||||
|                             <span class="icon"><i class="fas fa-exchange"></i></span> Import/Export |                             <span class="icon"><i class="fas fa-exchange"></i></span> Import/Export | ||||||
|                         </a> |                         </a> | ||||||
|  |                         #} | ||||||
|                         <a class="show-modal" data-modal="chooseTimezoneModal"> |                         <a class="show-modal" data-modal="chooseTimezoneModal"> | ||||||
|                             <span class="icon"><i class="fas fa-map-marked"></i></span> Timezone |                             <span class="icon"><i class="fas fa-map-marked"></i></span> Timezone | ||||||
|                         </a> |                         </a> | ||||||
|  |                         <a href="/login/discord/logout"> | ||||||
|  |                             <span class="icon"><i class="fas fa-sign-out"></i></span> Log out | ||||||
|  |                         </a> | ||||||
|  |                         <a href="https://discord.jellywx.com" class="feedback"> | ||||||
|  |                             <span class="icon"><i class="fab fa-discord"></i></span> Give feedback | ||||||
|  |                         </a> | ||||||
|                     </li> |                     </li> | ||||||
|                 </ul> |                 </ul> | ||||||
|             </div> |             </div> | ||||||
| @@ -269,7 +279,7 @@ | |||||||
|     <div class="dashboard-sidebar mobile-sidebar is-hidden-desktop" id="mobileSidebar"> |     <div class="dashboard-sidebar mobile-sidebar is-hidden-desktop" id="mobileSidebar"> | ||||||
|         <a href="/"> |         <a href="/"> | ||||||
|             <div class="brand"> |             <div class="brand"> | ||||||
|                 <img src="/static/img/logo_flat.webp" alt="Reminder bot logo" |                 <img src="/static/img/logo_nobg.webp" alt="Reminder bot logo" | ||||||
|                      class="dashboard-brand"> |                      class="dashboard-brand"> | ||||||
|             </div> |             </div> | ||||||
|         </a> |         </a> | ||||||
| @@ -292,12 +302,20 @@ | |||||||
|                 </p> |                 </p> | ||||||
|                 <ul class="menu-list"> |                 <ul class="menu-list"> | ||||||
|                     <li> |                     <li> | ||||||
|  |                         {# | ||||||
|                         <a class="show-modal" data-modal="dataManagerModal"> |                         <a class="show-modal" data-modal="dataManagerModal"> | ||||||
|                             <span class="icon"><i class="fas fa-exchange"></i></span> Import/Export |                             <span class="icon"><i class="fas fa-exchange"></i></span> Import/Export | ||||||
|                         </a> |                         </a> | ||||||
|  |                         #} | ||||||
|                         <a class="show-modal" data-modal="chooseTimezoneModal"> |                         <a class="show-modal" data-modal="chooseTimezoneModal"> | ||||||
|                             <span class="icon"><i class="fas fa-map-marked"></i></span> Timezone |                             <span class="icon"><i class="fas fa-map-marked"></i></span> Timezone | ||||||
|                         </a> |                         </a> | ||||||
|  |                         <a href="/login/discord/logout"> | ||||||
|  |                             <span class="icon"><i class="fas fa-sign-out"></i></span> Log out | ||||||
|  |                         </a> | ||||||
|  |                         <a href="https://discord.jellywx.com/" class="feedback"> | ||||||
|  |                             <span class="icon"><i class="fab fa-discord"></i></span> Give feedback | ||||||
|  |                         </a> | ||||||
|                     </li> |                     </li> | ||||||
|                 </ul> |                 </ul> | ||||||
|             </div> |             </div> | ||||||
| @@ -314,25 +332,17 @@ | |||||||
|                 <p class="subtitle is-hidden-desktop">Press the <span class="icon"><i class="fal fa-bars"></i></span> to get started</p> |                 <p class="subtitle is-hidden-desktop">Press the <span class="icon"><i class="fal fa-bars"></i></span> to get started</p> | ||||||
|             </div> |             </div> | ||||||
|         </section> |         </section> | ||||||
|         <section id="guild" class="is-hidden"> |         <section data-name="reminders" class="is-hidden"> | ||||||
|             {% include "reminder_dashboard/reminder_dashboard" %} |             {% include "reminder_dashboard/reminder_dashboard" %} | ||||||
|         </section> |         </section> | ||||||
|         <section id="guild-error" class="is-hidden hero is-fullheight"> |         <section data-name="errors" class="is-hidden"> | ||||||
|             <div class="hero-body"> |             {% include "reminder_dashboard/reminder_errors" %} | ||||||
|                 <div class="container has-text-centered"> |         </section> | ||||||
|                     <p class="title"> |         <section data-name="guild-error" class="is-hidden"> | ||||||
|                         We couldn't get this server's data |             {% include "reminder_dashboard/guild_error" %} | ||||||
|                     </p> |         </section> | ||||||
|                     <p class="subtitle"> |         <section data-name="user-error" class="is-hidden"> | ||||||
|                         Please check Reminder Bot is in the server, and has correct permissions. |             {% include "reminder_dashboard/user_error" %} | ||||||
|                     </p> |  | ||||||
|                     <a class="button is-size-4 is-rounded is-success" href="https://invite.reminder-bot.com"> |  | ||||||
|                         <p class="is-size-4"> |  | ||||||
|                             <span>Add to Server</span> <span class="icon"><i class="fas fa-chevron-right"></i></span> |  | ||||||
|                         </p> |  | ||||||
|                     </a> |  | ||||||
|                 </div> |  | ||||||
|             </div> |  | ||||||
|         </section> |         </section> | ||||||
|     </div> |     </div> | ||||||
|     <!-- /main content --> |     <!-- /main content --> | ||||||
| @@ -365,14 +375,28 @@ | |||||||
|  |  | ||||||
| <template id="guildListEntry"> | <template id="guildListEntry"> | ||||||
|     <li> |     <li> | ||||||
|         <a class="switch-pane" data-pane="guild"> |         <a class="switch-pane" data-pane="reminders" data-slug="reminders"> | ||||||
|             <span class="icon"><i class="fas fa-map-pin"></i></span> <span class="guild-name">%guildname%</span> |             <span class="icon"><i class="fas fa-map-pin"></i></span> <span class="guild-name">%guildname%</span> | ||||||
|         </a> |         </a> | ||||||
|  |         <ul class="guild-submenu"> | ||||||
|  |             <li> | ||||||
|  |                 <a class="switch-pane" data-pane="reminders" data-slug="reminders"> | ||||||
|  |                     <span class="icon"><i class="fas fa-calendar-alt"></i></span> Reminders | ||||||
|  |                 </a> | ||||||
|  |                 <a class="switch-pane" data-pane="errors" data-slug="errors"> | ||||||
|  |                     <span class="icon"><i class="fas fa-file-alt"></i></span> Logs | ||||||
|  |                 </a> | ||||||
|  |             </li> | ||||||
|  |         </ul> | ||||||
|     </li> |     </li> | ||||||
| </template> | </template> | ||||||
|  |  | ||||||
| <template id="guildReminder"> | <template id="guildReminder"> | ||||||
|     {% include "reminder_dashboard/guild_reminder" %} |     {% include "reminder_dashboard/templates/guild_reminder" %} | ||||||
|  | </template> | ||||||
|  |  | ||||||
|  | <template id="reminderError"> | ||||||
|  |     {% include "reminder_dashboard/templates/reminder_error" %} | ||||||
| </template> | </template> | ||||||
|  |  | ||||||
| <script src="/static/js/iro.js"></script> | <script src="/static/js/iro.js"></script> | ||||||
|   | |||||||
| @@ -108,8 +108,9 @@ | |||||||
|                 </article> |                 </article> | ||||||
|             </div> |             </div> | ||||||
|             <div class="tile is-parent is-vertical"> |             <div class="tile is-parent is-vertical"> | ||||||
|  |                 {# | ||||||
|                 <article class="tile is-child notification"> |                 <article class="tile is-child notification"> | ||||||
|                     <p class="title">Import/Export</p> |                     <p class="title">Import/export</p> | ||||||
|                     <p class="subtitle">Learn how to import and export data from the dashboard</p> |                     <p class="subtitle">Learn how to import and export data from the dashboard</p> | ||||||
|                     <div class="content has-text-centered"> |                     <div class="content has-text-centered"> | ||||||
|                         <a class="button is-size-4 is-rounded is-light" href="/help/iemanager"> |                         <a class="button is-size-4 is-rounded is-light" href="/help/iemanager"> | ||||||
| @@ -119,19 +120,22 @@ | |||||||
|                         </a> |                         </a> | ||||||
|                     </div> |                     </div> | ||||||
|                 </article> |                 </article> | ||||||
|  |                 #} | ||||||
|             </div> |             </div> | ||||||
|             <div class="tile is-parent"> |             <div class="tile is-parent"> | ||||||
| <!--                <article class="tile is-child notification">--> |                 {# | ||||||
| <!--                    <p class="title">Dashboard</p>--> |                 <article class="tile is-child notification"> | ||||||
| <!--                    <p class="subtitle">Learn to use the interactive web dashboard</p>--> |                     <p class="title">Dashboard</p> | ||||||
| <!--                    <div class="content has-text-centered">--> |                     <p class="subtitle">Learn to use the interactive web dashboard</p> | ||||||
| <!--                        <a class="button is-size-4 is-rounded is-light" href="/help/dashboard">--> |                     <div class="content has-text-centered"> | ||||||
| <!--                            <p class="is-size-4">--> |                         <a class="button is-size-4 is-rounded is-light" href="/help/dashboard"> | ||||||
| <!--                                Read <span class="icon"><i class="fas fa-chevron-right"></i></span>--> |                             <p class="is-size-4"> | ||||||
| <!--                            </p>--> |                                 Read <span class="icon"><i class="fas fa-chevron-right"></i></span> | ||||||
| <!--                        </a>--> |                             </p> | ||||||
| <!--                    </div>--> |                         </a> | ||||||
| <!--                </article>--> |                     </div> | ||||||
|  |                 </article> | ||||||
|  |                 #} | ||||||
|             </div> |             </div> | ||||||
|         </div> |         </div> | ||||||
|     </div> |     </div> | ||||||
| @@ -141,14 +145,14 @@ | |||||||
|             <div class="container has-text-centered"> |             <div class="container has-text-centered"> | ||||||
|                 <p class="title">Need more help?</p> |                 <p class="title">Need more help?</p> | ||||||
|                 <p class="content"> |                 <p class="content"> | ||||||
|                     Feel free to come and ask us! |                     Please come and ask us! | ||||||
|                 </p> |                 </p> | ||||||
|             </div> |             </div> | ||||||
|         </div> |         </div> | ||||||
|         <div class="hero-foot has-text-centered"> |         <div class="hero-foot has-text-centered"> | ||||||
|             <a class="button is-size-6 is-rounded is-primary" href="https://discord.jellywx.com"> |             <a class="button is-size-6 is-rounded is-primary" href="https://discord.jellywx.com"> | ||||||
|                 <p class="is-size-6"> |                 <p class="is-size-6"> | ||||||
|                     Join Discord <span class="icon"><i class="fas fa-chevron-right"></i></span> |                     <span>Join Discord</span> <span class="icon"><i class="fas fa-chevron-right"></i></span> | ||||||
|                 </p> |                 </p> | ||||||
|             </a> |             </a> | ||||||
|         </div> |         </div> | ||||||
|   | |||||||
| @@ -16,7 +16,7 @@ | |||||||
|             <div class="tile is-parent"> |             <div class="tile is-parent"> | ||||||
|                 <article class="tile is-child notification"> |                 <article class="tile is-child notification"> | ||||||
|                     <p class="title">Slash-command Ready <svg aria-hidden="false" width="28" height="28" viewBox="0 0 24 24"><path fill="#777" fill-rule="evenodd" clip-rule="evenodd" d="M5 3C3.89543 3 3 3.89543 3 5V19C3 20.1046 3.89543 21 5 21H19C20.1046 21 21 20.1046 21 19V5C21 3.89543 20.1046 3 19 3H5ZM16.8995 8.41419L15.4853 6.99998L7 15.4853L8.41421 16.8995L16.8995 8.41419Z"></path></svg></p> |                     <p class="title">Slash-command Ready <svg aria-hidden="false" width="28" height="28" viewBox="0 0 24 24"><path fill="#777" fill-rule="evenodd" clip-rule="evenodd" d="M5 3C3.89543 3 3 3.89543 3 5V19C3 20.1046 3.89543 21 5 21H19C20.1046 21 21 20.1046 21 19V5C21 3.89543 20.1046 3 19 3H5ZM16.8995 8.41419L15.4853 6.99998L7 15.4853L8.41421 16.8995L16.8995 8.41419Z"></path></svg></p> | ||||||
|                     <p class="subtitle">Set reminders easily and quickly from anywhere</p> |                     <p class="subtitle">Set reminders easily and quickly from anywhere.</p> | ||||||
|                     <figure class="image"> |                     <figure class="image"> | ||||||
|                         <img class="rounded-corners" src="/static/img/slash-commands.png" alt="Discord slash commands demonstration"> |                         <img class="rounded-corners" src="/static/img/slash-commands.png" alt="Discord slash commands demonstration"> | ||||||
|                     </figure> |                     </figure> | ||||||
| @@ -25,7 +25,7 @@ | |||||||
|             <div class="tile is-parent"> |             <div class="tile is-parent"> | ||||||
|                 <article class="tile is-child notification"> |                 <article class="tile is-child notification"> | ||||||
|                     <p class="title">Advanced Options <span class="icon"><i class="fad fa-palette"></i></span></p> |                     <p class="title">Advanced Options <span class="icon"><i class="fad fa-palette"></i></span></p> | ||||||
|                     <p class="subtitle">Decorate your announcements with our web dashboard</p> |                     <p class="subtitle">Decorate your announcements with our web dashboard.</p> | ||||||
|                     <figure class="image"> |                     <figure class="image"> | ||||||
|                         <img class="rounded-corners" src="/static/img/tournament-demo.png" alt="Advanced options demonstration"> |                         <img class="rounded-corners" src="/static/img/tournament-demo.png" alt="Advanced options demonstration"> | ||||||
|                     </figure> |                     </figure> | ||||||
| @@ -34,32 +34,62 @@ | |||||||
|             <div class="tile is-parent is-vertical"> |             <div class="tile is-parent is-vertical"> | ||||||
|                 <article class="tile is-child notification"> |                 <article class="tile is-child notification"> | ||||||
|                     <p class="title">Unlimited Reminders <span class="icon"><i class="far fa-infinity"></i></span></p> |                     <p class="title">Unlimited Reminders <span class="icon"><i class="far fa-infinity"></i></span></p> | ||||||
|                     <p class="subtitle">Never forget a thing</p> |                     <p class="subtitle">Never forget a thing.</p> | ||||||
|                 </article> |                 </article> | ||||||
|                 <article class="tile is-child notification"> |                 <article class="tile is-child notification"> | ||||||
|                     <p class="title">Repeating Reminders <span class="icon"><i class="fas fa-repeat"></i></span></p> |                     <p class="title">Repeating Reminders <span class="icon"><i class="fas fa-repeat"></i></span></p> | ||||||
|                     <p class="subtitle">Available to <a href="https://patreon.com/jellywx"><span class="patreon-color">Patreon <span class="icon"><i class="fab fa-patreon"></i></span></span></a> subscribers at <strong>$2/month</strong></p> |                     <p class="subtitle">Available to <a href="https://patreon.com/jellywx"><span class="patreon-color">Patreon <span class="icon"><i class="fab fa-patreon"></i></span></span></a> subscribers at <strong>$2/month</strong>.</p> | ||||||
|                 </article> |                 </article> | ||||||
|             </div> |             </div> | ||||||
|         </div> |         </div> | ||||||
|     </div> |     </div> | ||||||
|  |  | ||||||
|     <section class="hero is-small"> |     <section class="hero is-medium"> | ||||||
|         <div class="hero-body"> |         <div class="hero-body"> | ||||||
|  |             <div class="columns"> | ||||||
|  |                 <div class="column"> | ||||||
|  |                     <div class="container has-text-centered"> | ||||||
|  |                         <p class="title">Technically-minded?</p> | ||||||
|  |                         <p class="content"> | ||||||
|  |                             Install the bot on your own computer | ||||||
|  |                         </p> | ||||||
|  |                         <a class="button is-size-6 is-rounded is-link" href="https://gitea.jellypro.xyz/jude/reminder-bot"> | ||||||
|  |                             <p class="is-size-6"> | ||||||
|  |                                 <span>Install</span> <span class="icon"><i class="fas fa-chevron-right"></i></span> | ||||||
|  |                             </p> | ||||||
|  |                         </a> | ||||||
|  |                     </div> | ||||||
|  |                 </div> | ||||||
|  |  | ||||||
|  |                 <div class="column"> | ||||||
|                     <div class="container has-text-centered"> |                     <div class="container has-text-centered"> | ||||||
|                         <p class="title">Ready to go?</p> |                         <p class="title">Ready to go?</p> | ||||||
|                         <p class="content"> |                         <p class="content"> | ||||||
|                     Add the bot to get started! |                             Add the bot to get started | ||||||
|                         </p> |                         </p> | ||||||
|             </div> |  | ||||||
|         </div> |  | ||||||
|         <div class="hero-foot has-text-centered"> |  | ||||||
|                         <a class="button is-size-6 is-rounded is-success" href="https://invite.reminder-bot.com"> |                         <a class="button is-size-6 is-rounded is-success" href="https://invite.reminder-bot.com"> | ||||||
|                             <p class="is-size-6"> |                             <p class="is-size-6"> | ||||||
|                     Add Now <span class="icon"><i class="fas fa-chevron-right"></i></span> |                                 <span>Add Now</span> <span class="icon"><i class="fas fa-chevron-right"></i></span> | ||||||
|                             </p> |                             </p> | ||||||
|                         </a> |                         </a> | ||||||
|                     </div> |                     </div> | ||||||
|  |                 </div> | ||||||
|  |  | ||||||
|  |                 <div class="column"> | ||||||
|  |                     <div class="container has-text-centered"> | ||||||
|  |                         <p class="title">Need support?</p> | ||||||
|  |                         <p class="content"> | ||||||
|  |                             Check out our guides, or join our Discord | ||||||
|  |                         </p> | ||||||
|  |                         <a class="button is-size-6 is-rounded is-primary" href="/help"> | ||||||
|  |                             <p class="is-size-6"> | ||||||
|  |                                 <span>Guides</span> <span class="icon"><i class="fas fa-chevron-right"></i></span> | ||||||
|  |                             </p> | ||||||
|  |                         </a> | ||||||
|  |                     </div> | ||||||
|  |                 </div> | ||||||
|  |             </div> | ||||||
|  |         </div> | ||||||
|     </section> |     </section> | ||||||
|  |  | ||||||
| {% endblock %} | {% endblock %} | ||||||
|   | |||||||
| @@ -13,7 +13,7 @@ | |||||||
|     <section class="section"> |     <section class="section"> | ||||||
|         <div class="container"> |         <div class="container"> | ||||||
|             <h2 class="title">Who we are</h2> |             <h2 class="title">Who we are</h2> | ||||||
|             <p class="is-size-5 pl-6"> |             <p> | ||||||
|                 Reminder Bot is operated solely by Jude Southworth. You can contact me by email at |                 Reminder Bot is operated solely by Jude Southworth. You can contact me by email at | ||||||
|                 <a href="mailto:jude@jellywx.com">jude@jellywx.com</a>, or via private/public message on Discord at |                 <a href="mailto:jude@jellywx.com">jude@jellywx.com</a>, or via private/public message on Discord at | ||||||
|                 <a href="https://discord.jellywx.com">https://discord.jellywx.com</a>. |                 <a href="https://discord.jellywx.com">https://discord.jellywx.com</a>. | ||||||
| @@ -24,12 +24,16 @@ | |||||||
|     <section class="section"> |     <section class="section"> | ||||||
|         <div class="container"> |         <div class="container"> | ||||||
|             <h2 class="title">What data we collect</h2> |             <h2 class="title">What data we collect</h2> | ||||||
|             <p class="is-size-5 pl-6"> |             <p> | ||||||
|                 Reminder Bot stores limited data necessary for the function of the bot. This data |                 Reminder Bot stores limited data necessary for the function of the bot. This data | ||||||
|                 is your <strong>unique user ID</strong>, <strong>timezone</strong>, and <strong>direct message channel</strong>. |                 is your <strong>unique user ID</strong>, <strong>timezone</strong>, and <strong>direct message channel</strong>. | ||||||
|                 <br> |                 <br> | ||||||
|                 <br> |                 <br> | ||||||
|                 Timezones are provided by the user or the user's browser. |                 Timezones are provided by the user or the user's browser. | ||||||
|  |                 <br><br> | ||||||
|  |                 Some  additional information is collected by the dashboard for the purpose of debugging.   This is your | ||||||
|  |                 <strong>time spent on the website</strong>, <strong>current URL</strong>, <strong>unique user ID</strong>, | ||||||
|  |                 <strong>unique session token</strong>, <strong>contents of any client errors</strong>. | ||||||
|             </p> |             </p> | ||||||
|         </div> |         </div> | ||||||
|     </section> |     </section> | ||||||
| @@ -37,10 +41,12 @@ | |||||||
|     <section class="section"> |     <section class="section"> | ||||||
|         <div class="container"> |         <div class="container"> | ||||||
|             <h2 class="title">Why we collect this data</h2> |             <h2 class="title">Why we collect this data</h2> | ||||||
|             <p class="is-size-5 pl-6"> |             <p> | ||||||
|                 Unique user IDs are stored to <strong>keep track of who sets reminders</strong>. User timezones are |                 Unique user IDs are stored to <strong>keep track of who sets reminders</strong>. User timezones are | ||||||
|                 stored to allow users to set reminders in their local timezone. Direct message channels are stored to |                 stored to allow users to set reminders in their local timezone. Direct message channels are stored to | ||||||
|                 allow the setting of reminders for your direct message channel. |                 allow the setting of reminders for your direct message channel. | ||||||
|  |                 <br> | ||||||
|  |                 Information collected  by the dashboard is for resolving bugs. | ||||||
|             </p> |             </p> | ||||||
|         </div> |         </div> | ||||||
|     </section> |     </section> | ||||||
| @@ -48,7 +54,7 @@ | |||||||
|     <section class="section"> |     <section class="section"> | ||||||
|         <div class="container"> |         <div class="container"> | ||||||
|             <h2 class="title">Who your data is shared with</h2> |             <h2 class="title">Who your data is shared with</h2> | ||||||
|             <p class="is-size-5 pl-6"> |             <p> | ||||||
|                 Your data is also guarded by the privacy policies of <strong>MEGA</strong>, our backup provider, and |                 Your data is also guarded by the privacy policies of <strong>MEGA</strong>, our backup provider, and | ||||||
|                 <strong>Hetzner</strong>, our hosting provider. |                 <strong>Hetzner</strong>, our hosting provider. | ||||||
|             </p> |             </p> | ||||||
| @@ -58,17 +64,13 @@ | |||||||
|     <section class="section"> |     <section class="section"> | ||||||
|         <div class="container"> |         <div class="container"> | ||||||
|             <h2 class="title">Accessing or removing your data</h2> |             <h2 class="title">Accessing or removing your data</h2> | ||||||
|             <p class="is-size-5 pl-6"> |             <p> | ||||||
|                 Your timezone can be removed with the command <strong>/timezone UTC</strong>. Other data can be removed |                 Your timezone can be removed with the command <strong>/timezone UTC</strong>. Other data can be removed | ||||||
|                 on request. Please contact me. |                 on request. Please contact me. | ||||||
|                 <br> |                 <br> | ||||||
|                 <br> |                 <br> | ||||||
|                 Reminders created in a guild/channel will be removed automatically when the bot is removed from the |                 Reminders created in a guild/channel will be removed automatically when the bot is removed from the | ||||||
|                 guild, the guild is deleted, or channel is deleted. Data is otherwise not removed automatically. |                 guild, the guild is deleted, or channel is deleted. Data is otherwise not removed automatically. | ||||||
|                 <br> |  | ||||||
|                 <br> |  | ||||||
|                 Reminders deleted with <strong>/del</strong> or via the dashboard are removed from the live database |  | ||||||
|                 instantly, but may persist in backups for up to a year. |  | ||||||
|             </p> |             </p> | ||||||
|         </div> |         </div> | ||||||
|     </section> |     </section> | ||||||
|   | |||||||
							
								
								
									
										17
									
								
								web/templates/reminder_dashboard/guild_error.html.tera
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								web/templates/reminder_dashboard/guild_error.html.tera
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | |||||||
|  | <div class="hero is-fullheight"> | ||||||
|  |     <div class="hero-body"> | ||||||
|  |         <div class="container has-text-centered"> | ||||||
|  |             <p class="title"> | ||||||
|  |                 We couldn't get this server's data | ||||||
|  |             </p> | ||||||
|  |             <p class="subtitle"> | ||||||
|  |                 Please check Reminder Bot is in the server, and has correct permissions. | ||||||
|  |             </p> | ||||||
|  |             <a class="button is-size-4 is-rounded is-success" href="https://invite.reminder-bot.com"> | ||||||
|  |                 <p class="is-size-4"> | ||||||
|  |                     <span>Add to Server</span> <span class="icon"><i class="fas fa-chevron-right"></i></span> | ||||||
|  |                 </p> | ||||||
|  |             </a> | ||||||
|  |         </div> | ||||||
|  |     </div> | ||||||
|  | </div> | ||||||
| @@ -1,251 +0,0 @@ | |||||||
| <div class="columns reminderContent {% if creating %}creator{% endif %}"> |  | ||||||
|     <div class="column discord-frame"> |  | ||||||
|         <article class="media"> |  | ||||||
|             <figure class="media-left"> |  | ||||||
|                 <p class="image is-32x32 customizable"> |  | ||||||
|                     <a> |  | ||||||
|                         <img class="is-rounded discord-avatar" src="/static/img/bg.webp" alt="Image for discord avatar"> |  | ||||||
|                     </a> |  | ||||||
|                 </p> |  | ||||||
|             </figure> |  | ||||||
|             <div class="media-content"> |  | ||||||
|                 <div class="content"> |  | ||||||
|                     <div class="discord-message-header"> |  | ||||||
|                         <label class="is-sr-only">Username Override</label> |  | ||||||
|                         <input class="discord-username message-input" placeholder="Username Override" |  | ||||||
|                                maxlength="32" name="username"> |  | ||||||
|                     </div> |  | ||||||
|                     <label class="is-sr-only">Message</label> |  | ||||||
|                     <textarea class="message-input autoresize discord-content" |  | ||||||
|                               placeholder="Message Content..." |  | ||||||
|                               maxlength="2000" name="content" rows="1"></textarea> |  | ||||||
|  |  | ||||||
|                     <div class="discord-embed"> |  | ||||||
|                         <div class="embed-body"> |  | ||||||
|                             <button class="change-color button is-rounded is-small"> |  | ||||||
|                                 <span class="is-sr-only">Choose embed color</span><i class="fas fa-eye-dropper"></i> |  | ||||||
|                             </button> |  | ||||||
|                             <div class="a"> |  | ||||||
|                                 <div class="embed-author-box"> |  | ||||||
|                                     <div class="a"> |  | ||||||
|                                         <p class="image is-24x24 customizable"> |  | ||||||
|                                             <a> |  | ||||||
|                                                 <img class="is-rounded embed_author_url" src="/static/img/bg.webp" alt="Image for embed author"> |  | ||||||
|                                             </a> |  | ||||||
|                                         </p> |  | ||||||
|                                     </div> |  | ||||||
|  |  | ||||||
|                                     <div class="b"> |  | ||||||
|                                         <label class="is-sr-only" for="embedAuthor">Embed Author</label> |  | ||||||
|                                         <textarea |  | ||||||
|                                                 class="discord-embed-author message-input autoresize" |  | ||||||
|                                                 placeholder="Embed Author..." rows="1" maxlength="256" |  | ||||||
|                                                 name="embed_author"></textarea> |  | ||||||
|                                     </div> |  | ||||||
|                                 </div> |  | ||||||
|  |  | ||||||
|                                 <label class="is-sr-only" for="embedTitle">Embed Title</label> |  | ||||||
|                                 <textarea class="discord-title message-input  autoresize" |  | ||||||
|                                           placeholder="Embed Title..." |  | ||||||
|                                           maxlength="256" rows="1" |  | ||||||
|                                           name="embed_title"></textarea> |  | ||||||
|                                 <br> |  | ||||||
|                                 <label class="is-sr-only" for="embedDescription">Embed Description</label> |  | ||||||
|                                 <textarea class="discord-description message-input autoresize " |  | ||||||
|                                           placeholder="Embed Description..." |  | ||||||
|                                           maxlength="4096" name="embed_description" |  | ||||||
|                                           rows="1"></textarea> |  | ||||||
|                                 <br> |  | ||||||
|  |  | ||||||
|                                 <div class="embed-multifield-box"> |  | ||||||
|                                     <div data-inlined="1" class="embed-field-box"> |  | ||||||
|                                         <label class="is-sr-only" for="embedFieldTitle">Field Title</label> |  | ||||||
|                                         <div class="is-flex"> |  | ||||||
|                                             <textarea class="discord-field-title field-input message-input autoresize" |  | ||||||
|                                                       placeholder="Field Title..." rows="1" |  | ||||||
|                                                       maxlength="256" name="embed_field_title[]"></textarea> |  | ||||||
|                                             <button class="button is-small inline-btn"> |  | ||||||
|                                                 <span class="is-sr-only">Toggle field inline</span><i class="fas fa-arrows-h"></i> |  | ||||||
|                                             </button> |  | ||||||
|                                         </div> |  | ||||||
|  |  | ||||||
|                                         <label class="is-sr-only" for="embedFieldValue">Field Value</label> |  | ||||||
|                                         <textarea |  | ||||||
|                                                 class="discord-field-value field-input message-input autoresize " |  | ||||||
|                                                 placeholder="Field Value..." |  | ||||||
|                                                 maxlength="1024" name="embed_field_value[]" |  | ||||||
|                                                 rows="1"></textarea> |  | ||||||
|                                     </div> |  | ||||||
|                                 </div> |  | ||||||
|                             </div> |  | ||||||
|  |  | ||||||
|                             <div class="b"> |  | ||||||
|                                 <p class="image thumbnail customizable"> |  | ||||||
|                                     <a> |  | ||||||
|                                         <img class="embed_thumbnail_url" src="/static/img/bg.webp" alt="Square thumbnail embedded image"> |  | ||||||
|                                     </a> |  | ||||||
|                                 </p> |  | ||||||
|                             </div> |  | ||||||
|                         </div> |  | ||||||
|  |  | ||||||
|                         <p class="image is-400x300 customizable"> |  | ||||||
|                             <a> |  | ||||||
|                                 <img class="embed_image_url" src="/static/img/bg.webp" alt="Large embedded image"> |  | ||||||
|                             </a> |  | ||||||
|                         </p> |  | ||||||
|  |  | ||||||
|                         <div class="embed-footer-box"> |  | ||||||
|                             <p class="image is-20x20 customizable"> |  | ||||||
|                                 <a> |  | ||||||
|                                     <img class="is-rounded embed_footer_url" src="/static/img/bg.webp" 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" name="embed_footer" rows="1"></textarea> |  | ||||||
|                         </div> |  | ||||||
|                     </div> |  | ||||||
|                 </div> |  | ||||||
|             </div> |  | ||||||
|         </article> |  | ||||||
|     </div> |  | ||||||
|     <div class="column settings"> |  | ||||||
|         <div class="columns is-mobile reminder-topbar"> |  | ||||||
|             <div class="column"> |  | ||||||
|                 <div class="field"> |  | ||||||
|                     <div class="control"> |  | ||||||
|                         <label class="label sr-only">Reminder Name</label> |  | ||||||
|                         <input class="input" type="text" name="name" placeholder="Reminder Name"> |  | ||||||
|                     </div> |  | ||||||
|                 </div> |  | ||||||
|             </div> |  | ||||||
|             <div class="column is-narrow"> |  | ||||||
|                 <button class="button is-rounded hide-box"> |  | ||||||
|                     <span class="is-sr-only">Hide reminder</span><i class="fas fa-chevron-down"></i> |  | ||||||
|                 </button> |  | ||||||
|             </div> |  | ||||||
|         </div> |  | ||||||
|  |  | ||||||
|         <div class="columns"> |  | ||||||
|             <div class="column"> |  | ||||||
|                 <div class="field channel-field"> |  | ||||||
|                     <div class="collapses"> |  | ||||||
|                         <label class="label" for="channelOption">Channel*</label> |  | ||||||
|                     </div> |  | ||||||
|                     <div class="control has-icons-left"> |  | ||||||
|                         <div class="select"> |  | ||||||
|                             <select name="channel" class="channel-selector"> |  | ||||||
|                             </select> |  | ||||||
|                         </div> |  | ||||||
|                         <div class="icon is-small is-left"> |  | ||||||
|                             <i class="fas fa-hashtag"></i> |  | ||||||
|                         </div> |  | ||||||
|                     </div> |  | ||||||
|                 </div> |  | ||||||
|             </div> |  | ||||||
|             <div class="column"> |  | ||||||
|                 <div class="field"> |  | ||||||
|                     <div class="control"> |  | ||||||
|                         <label class="label collapses"> |  | ||||||
|                             Time* |  | ||||||
|                             <input class="input" type="datetime-local" step="1" name="time"> |  | ||||||
|                         </label> |  | ||||||
|                     </div> |  | ||||||
|                 </div> |  | ||||||
|             </div> |  | ||||||
|         </div> |  | ||||||
|  |  | ||||||
|         <div class="collapses"> |  | ||||||
|             <div class="patreon-only"> |  | ||||||
|                 <div class="field"> |  | ||||||
|                     <label class="label">Interval <a class="foreground" href="/help/intervals"><i class="fas fa-question-circle"></i></a></label> |  | ||||||
|                     <div class="control intervalSelector" style="min-width: 400px;" > |  | ||||||
|                         <div class="input interval-group"> |  | ||||||
|                             <div class="interval-group-left"> |  | ||||||
|                                 <label> |  | ||||||
|                                     <span class="is-sr-only">Interval months</span> |  | ||||||
|                                     <input class="w2" type="text" pattern="\d*" name="interval_months" maxlength="2" placeholder=""> <span class="half-rem"></span> months, <span class="half-rem"></span> |  | ||||||
|                                 </label> |  | ||||||
|                                 <label> |  | ||||||
|                                     <span class="is-sr-only">Interval days</span> |  | ||||||
|                                     <input class="w3" type="text" pattern="\d*" name="interval_days" maxlength="4" placeholder=""> <span class="half-rem"></span> days, <span class="half-rem"></span> |  | ||||||
|                                 </label> |  | ||||||
|                                 <label> |  | ||||||
|                                     <span class="is-sr-only">Interval hours</span> |  | ||||||
|                                     <input class="w2" type="text" pattern="\d*" name="interval_hours" maxlength="2" placeholder="HH">: |  | ||||||
|                                 </label> |  | ||||||
|                                 <label> |  | ||||||
|                                     <span class="is-sr-only">Interval minutes</span> |  | ||||||
|                                     <input class="w2" type="text" pattern="\d*" name="interval_minutes" maxlength="2" placeholder="MM">: |  | ||||||
|                                 </label> |  | ||||||
|                                 <label> |  | ||||||
|                                     <span class="is-sr-only">Interval seconds</span> |  | ||||||
|                                     <input class="w2" type="text" pattern="\d*" name="interval_seconds" maxlength="2" placeholder="SS"> |  | ||||||
|                                 </label> |  | ||||||
|                             </div> |  | ||||||
|                             <button class="clear"><span class="is-sr-only">Clear interval</span><span class="icon"><i class="fas fa-trash"></i></span></button> |  | ||||||
|                         </div> |  | ||||||
|                     </div> |  | ||||||
|                 </div> |  | ||||||
|  |  | ||||||
|                 <div class="field"> |  | ||||||
|                     <div class="control"> |  | ||||||
|                         <label class="label"> |  | ||||||
|                             Expiration |  | ||||||
|                             <input class="input" type="datetime-local" step="1" name="expiration"> |  | ||||||
|                         </label> |  | ||||||
|                     </div> |  | ||||||
|                 </div> |  | ||||||
|             </div> |  | ||||||
|  |  | ||||||
|             <div class="columns"> |  | ||||||
|                 <div class="column has-text-centered"> |  | ||||||
|                     <div class="is-boxed"> |  | ||||||
|                         <label class="label">Enable TTS <input type="checkbox" name="tts"></label> |  | ||||||
|                     </div> |  | ||||||
|                 </div> |  | ||||||
|                 <div class="column has-text-centered"> |  | ||||||
|                     <div class="file is-small is-boxed"> |  | ||||||
|                         <label class="file-label"> |  | ||||||
|                             <input class="file-input" type="file" name="attachment"> |  | ||||||
|                             <span class="file-cta"> |  | ||||||
|                                 <span class="file-label"> |  | ||||||
|                                     Add Attachment |  | ||||||
|                                 </span> |  | ||||||
|                                 <span class="file-icon"> |  | ||||||
|                                     <i class="fas fa-upload"></i> |  | ||||||
|                                 </span> |  | ||||||
|                             </span> |  | ||||||
|                         </label> |  | ||||||
|                     </div> |  | ||||||
|                 </div> |  | ||||||
|             </div> |  | ||||||
|  |  | ||||||
|             <div> |  | ||||||
|                 <span class="pad-left"></span> |  | ||||||
|                 {% if creating %} |  | ||||||
|                     <button class="button is-success" id="createReminder"> |  | ||||||
|                         <span>Create Reminder</span> <span class="icon"><i class="fas fa-sparkles"></i></span> |  | ||||||
|                     </button> |  | ||||||
|                     <button class="button is-success is-outlined" id="createTemplate"> |  | ||||||
|                         <span>Create Template</span> <span class="icon"><i class="fas fa-file-spreadsheet"></i></span> |  | ||||||
|                     </button> |  | ||||||
|                     <button class="button is-outlined show-modal is-pulled-right" data-modal="chooseTemplateModal"> |  | ||||||
|                         Load Template |  | ||||||
|                     </button> |  | ||||||
|                 {% else %} |  | ||||||
|                     <button class="button is-success save-btn"> |  | ||||||
|                         <span>Save</span> <span class="icon"><i class="fas fa-save"></i></span> |  | ||||||
|                     </button> |  | ||||||
|                     <button class="button is-warning disable-enable"> |  | ||||||
|                     </button> |  | ||||||
|                     <button class="button is-danger delete-reminder"> |  | ||||||
|                         Delete |  | ||||||
|                     </button> |  | ||||||
|                 {% endif %} |  | ||||||
|             </div> |  | ||||||
|         </div> |  | ||||||
|     </div> |  | ||||||
| </div> |  | ||||||
| @@ -2,7 +2,7 @@ | |||||||
|     <strong>Create Reminder</strong> |     <strong>Create Reminder</strong> | ||||||
|     <div id="reminderCreator"> |     <div id="reminderCreator"> | ||||||
|         {% set creating = true %} |         {% set creating = true %} | ||||||
|         {% include "reminder_dashboard/guild_reminder" %} |         {% include "reminder_dashboard/templates/guild_reminder" %} | ||||||
|         {% set creating = false %} |         {% set creating = false %} | ||||||
|     </div> |     </div> | ||||||
|     <br> |     <br> | ||||||
| @@ -46,6 +46,10 @@ | |||||||
|     <div id="guildReminders"> |     <div id="guildReminders"> | ||||||
|  |  | ||||||
|     </div> |     </div> | ||||||
|  |  | ||||||
|  |     <div id="guildErrors"> | ||||||
|  |  | ||||||
|  |     </div> | ||||||
| </div> | </div> | ||||||
|  |  | ||||||
| <script src="/static/js/sort.js"></script> | <script src="/static/js/sort.js"></script> | ||||||
|   | |||||||
| @@ -0,0 +1,5 @@ | |||||||
|  | <div id="reminderLog"> | ||||||
|  |  | ||||||
|  | </div> | ||||||
|  |  | ||||||
|  | <script src="/static/js/reminder_errors.js"></script> | ||||||
| @@ -0,0 +1,275 @@ | |||||||
|  | <div class="reminderContent {% if creating %}creator{% endif %}"> | ||||||
|  |     <div class="columns is-mobile column reminder-topbar"> | ||||||
|  |         {% if not creating %} | ||||||
|  |         <div class="invert-collapses channel-bar"> | ||||||
|  |             #channel | ||||||
|  |         </div> | ||||||
|  |         {% endif %} | ||||||
|  |         <div class="name-bar"> | ||||||
|  |             <div class="field"> | ||||||
|  |                 <div class="control"> | ||||||
|  |                     <label class="label sr-only">Reminder Name</label> | ||||||
|  |                     <input class="input" type="text" name="name" placeholder="Reminder Name" maxlength="100"> | ||||||
|  |                 </div> | ||||||
|  |             </div> | ||||||
|  |         </div> | ||||||
|  |         <div class="hide-button-bar"> | ||||||
|  |             <button class="button hide-box"> | ||||||
|  |                 <span class="is-sr-only">Hide reminder</span><i class="fas fa-chevron-down"></i> | ||||||
|  |             </button> | ||||||
|  |         </div> | ||||||
|  |     </div> | ||||||
|  |     <div class="columns reminder-settings"> | ||||||
|  |         <div class="column discord-frame"> | ||||||
|  |             <article class="media"> | ||||||
|  |                 <figure class="media-left"> | ||||||
|  |                     <p class="image is-32x32 customizable"> | ||||||
|  |                         <a> | ||||||
|  |                             <img class="is-rounded avatar" src="/static/img/bg.webp" alt="Image for discord avatar"> | ||||||
|  |                         </a> | ||||||
|  |                     </p> | ||||||
|  |                 </figure> | ||||||
|  |                 <div class="media-content"> | ||||||
|  |                     <div class="content"> | ||||||
|  |                         <div class="discord-message-header"> | ||||||
|  |                             <label class="is-sr-only">Username Override</label> | ||||||
|  |                             <input class="discord-username message-input" placeholder="Username Override" | ||||||
|  |                                    maxlength="32" name="username"> | ||||||
|  |                         </div> | ||||||
|  |                         <label class="is-sr-only">Message</label> | ||||||
|  |                         <textarea class="message-input autoresize discord-content" | ||||||
|  |                                   placeholder="Message Content..." | ||||||
|  |                                   maxlength="2000" name="content" rows="1"></textarea> | ||||||
|  |  | ||||||
|  |                         <div class="discord-embed"> | ||||||
|  |                             <div class="embed-body"> | ||||||
|  |                                 <button class="change-color button is-rounded is-small"> | ||||||
|  |                                     <span class="is-sr-only">Choose embed color</span><i class="fas fa-eye-dropper"></i> | ||||||
|  |                                 </button> | ||||||
|  |                                 <div class="a"> | ||||||
|  |                                     <div class="embed-author-box"> | ||||||
|  |                                         <div class="a"> | ||||||
|  |                                             <p class="image is-24x24 customizable"> | ||||||
|  |                                                 <a> | ||||||
|  |                                                     <img class="is-rounded embed_author_url" src="/static/img/bg.webp" alt="Image for embed author"> | ||||||
|  |                                                 </a> | ||||||
|  |                                             </p> | ||||||
|  |                                         </div> | ||||||
|  |  | ||||||
|  |                                         <div class="b"> | ||||||
|  |                                             <label class="is-sr-only" for="embedAuthor">Embed Author</label> | ||||||
|  |                                             <textarea | ||||||
|  |                                                     class="discord-embed-author message-input autoresize" | ||||||
|  |                                                     placeholder="Embed Author..." rows="1" maxlength="256" | ||||||
|  |                                                     name="embed_author"></textarea> | ||||||
|  |                                         </div> | ||||||
|  |                                     </div> | ||||||
|  |  | ||||||
|  |                                     <label class="is-sr-only" for="embedTitle">Embed Title</label> | ||||||
|  |                                     <textarea class="discord-title message-input  autoresize" | ||||||
|  |                                               placeholder="Embed Title..." | ||||||
|  |                                               maxlength="256" rows="1" | ||||||
|  |                                               name="embed_title"></textarea> | ||||||
|  |                                     <br> | ||||||
|  |                                     <label class="is-sr-only" for="embedDescription">Embed Description</label> | ||||||
|  |                                     <textarea class="discord-description message-input autoresize " | ||||||
|  |                                               placeholder="Embed Description..." | ||||||
|  |                                               maxlength="4096" name="embed_description" | ||||||
|  |                                               rows="1"></textarea> | ||||||
|  |                                     <br> | ||||||
|  |  | ||||||
|  |                                     <div class="embed-multifield-box"> | ||||||
|  |                                         <div data-inlined="1" class="embed-field-box"> | ||||||
|  |                                             <label class="is-sr-only" for="embedFieldTitle">Field Title</label> | ||||||
|  |                                             <div class="is-flex"> | ||||||
|  |                                                 <textarea class="discord-field-title field-input message-input autoresize" | ||||||
|  |                                                           placeholder="Field Title..." rows="1" | ||||||
|  |                                                           maxlength="256" name="embed_field_title[]"></textarea> | ||||||
|  |                                                 <button class="button is-small inline-btn"> | ||||||
|  |                                                     <span class="is-sr-only">Toggle field inline</span><i class="fas fa-arrows-h"></i> | ||||||
|  |                                                 </button> | ||||||
|  |                                             </div> | ||||||
|  |  | ||||||
|  |                                             <label class="is-sr-only" for="embedFieldValue">Field Value</label> | ||||||
|  |                                             <textarea | ||||||
|  |                                                     class="discord-field-value field-input message-input autoresize " | ||||||
|  |                                                     placeholder="Field Value..." | ||||||
|  |                                                     maxlength="1024" name="embed_field_value[]" | ||||||
|  |                                                     rows="1"></textarea> | ||||||
|  |                                         </div> | ||||||
|  |                                     </div> | ||||||
|  |                                 </div> | ||||||
|  |  | ||||||
|  |                                 <div class="b"> | ||||||
|  |                                     <p class="image thumbnail customizable"> | ||||||
|  |                                         <a> | ||||||
|  |                                             <img class="embed_thumbnail_url" src="/static/img/bg.webp" alt="Square thumbnail embedded image"> | ||||||
|  |                                         </a> | ||||||
|  |                                     </p> | ||||||
|  |                                 </div> | ||||||
|  |                             </div> | ||||||
|  |  | ||||||
|  |                             <p class="image is-400x300 customizable"> | ||||||
|  |                                 <a> | ||||||
|  |                                     <img class="embed_image_url" src="/static/img/bg.webp" alt="Large embedded image"> | ||||||
|  |                                 </a> | ||||||
|  |                             </p> | ||||||
|  |  | ||||||
|  |                             <div class="embed-footer-box"> | ||||||
|  |                                 <p class="image is-20x20 customizable"> | ||||||
|  |                                     <a> | ||||||
|  |                                         <img class="is-rounded embed_footer_url" src="/static/img/bg.webp" 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" name="embed_footer" rows="1"></textarea> | ||||||
|  |                             </div> | ||||||
|  |                         </div> | ||||||
|  |                     </div> | ||||||
|  |                 </div> | ||||||
|  |             </article> | ||||||
|  |         </div> | ||||||
|  |         <div class="column settings"> | ||||||
|  |             <div class="columns"> | ||||||
|  |                 <div class="column"> | ||||||
|  |                     <div class="field channel-field"> | ||||||
|  |                         <div class="collapses"> | ||||||
|  |                             <label class="label" for="channelOption">Channel*</label> | ||||||
|  |                         </div> | ||||||
|  |                         <div class="control has-icons-left"> | ||||||
|  |                             <div class="select"> | ||||||
|  |                                 <select name="channel" class="channel-selector"> | ||||||
|  |                                 </select> | ||||||
|  |                             </div> | ||||||
|  |                             <div class="icon is-small is-left"> | ||||||
|  |                                 <i class="fas fa-hashtag"></i> | ||||||
|  |                             </div> | ||||||
|  |                         </div> | ||||||
|  |                     </div> | ||||||
|  |                 </div> | ||||||
|  |                 <div class="column"> | ||||||
|  |                     <div class="field"> | ||||||
|  |                         <div class="control"> | ||||||
|  |                             <label class="label collapses"> | ||||||
|  |                                 Time* | ||||||
|  |                                 <input class="input prefill-now" type="datetime-local" step="1" name="time"> | ||||||
|  |                             </label> | ||||||
|  |                         </div> | ||||||
|  |                     </div> | ||||||
|  |                 </div> | ||||||
|  |             </div> | ||||||
|  |  | ||||||
|  |             <div class="collapses split-controls"> | ||||||
|  |                 <div> | ||||||
|  |                     <div class="patreon-only"> | ||||||
|  |                         <div class="patreon-invert foreground"> | ||||||
|  |                             Intervals available on <a href="https://patreon.com/jellywx">Patreon</a> or <a href="https://gitea.jellypro.xyz/jude/reminder-bot">self-hosting</a> | ||||||
|  |                         </div> | ||||||
|  |                         <div class="field"> | ||||||
|  |                             <label class="label">Interval <a class="foreground" href="/help/intervals"><i class="fas fa-question-circle"></i></a></label> | ||||||
|  |                             <div class="control intervalSelector"> | ||||||
|  |                                 <div class="input interval-group"> | ||||||
|  |                                     <div class="interval-group-left"> | ||||||
|  |                                         <span class="no-break"> | ||||||
|  |                                             <label> | ||||||
|  |                                                 <span class="is-sr-only">Interval months</span> | ||||||
|  |                                                 <input class="w2" type="text" pattern="\d*" name="interval_months" maxlength="2" placeholder=""> <span class="half-rem"></span> months, <span class="half-rem"></span> | ||||||
|  |                                             </label> | ||||||
|  |                                             <label> | ||||||
|  |                                                 <span class="is-sr-only">Interval days</span> | ||||||
|  |                                                 <input class="w3" type="text" pattern="\d*" name="interval_days" maxlength="4" placeholder=""> <span class="half-rem"></span> days, <span class="half-rem"></span> | ||||||
|  |                                             </label> | ||||||
|  |                                         </span> | ||||||
|  |                                         <span class="no-break"> | ||||||
|  |                                             <label> | ||||||
|  |                                                 <span class="is-sr-only">Interval hours</span> | ||||||
|  |                                                 <input class="w2" type="text" pattern="\d*" name="interval_hours" maxlength="2" placeholder="HH">: | ||||||
|  |                                             </label> | ||||||
|  |                                             <label> | ||||||
|  |                                                 <span class="is-sr-only">Interval minutes</span> | ||||||
|  |                                                 <input class="w2" type="text" pattern="\d*" name="interval_minutes" maxlength="2" placeholder="MM">: | ||||||
|  |                                             </label> | ||||||
|  |                                             <label> | ||||||
|  |                                                 <span class="is-sr-only">Interval seconds</span> | ||||||
|  |                                                 <input class="w2" type="text" pattern="\d*" name="interval_seconds" maxlength="2" placeholder="SS"> | ||||||
|  |                                             </label> | ||||||
|  |                                         </span> | ||||||
|  |                                     </div> | ||||||
|  |                                     <button class="clear"><span class="is-sr-only">Clear interval</span><span class="icon"><i class="fas fa-trash"></i></span></button> | ||||||
|  |                                 </div> | ||||||
|  |                             </div> | ||||||
|  |                         </div> | ||||||
|  |  | ||||||
|  |                         <div class="field"> | ||||||
|  |                             <div class="control"> | ||||||
|  |                                 <label class="label"> | ||||||
|  |                                     Expiration | ||||||
|  |                                     <input class="input" type="datetime-local" step="1" name="expiration"> | ||||||
|  |                                 </label> | ||||||
|  |                             </div> | ||||||
|  |                         </div> | ||||||
|  |                     </div> | ||||||
|  |  | ||||||
|  |                     <div class="columns is-mobile tts-row"> | ||||||
|  |                         <div class="column has-text-centered"> | ||||||
|  |                             <div class="is-boxed"> | ||||||
|  |                                 <label class="label">Enable TTS <input type="checkbox" name="tts"></label> | ||||||
|  |                             </div> | ||||||
|  |                         </div> | ||||||
|  |                         <div class="column has-text-centered"> | ||||||
|  |                             <div class="file is-small is-boxed"> | ||||||
|  |                                 <label class="file-label"> | ||||||
|  |                                     <input class="file-input" type="file" name="attachment"> | ||||||
|  |                                     <span class="file-cta"> | ||||||
|  |                                         <span class="file-label"> | ||||||
|  |                                             Add Attachment | ||||||
|  |                                         </span> | ||||||
|  |                                         <span class="file-icon"> | ||||||
|  |                                             <i class="fas fa-upload"></i> | ||||||
|  |                                         </span> | ||||||
|  |                                     </span> | ||||||
|  |                                 </label> | ||||||
|  |                             </div> | ||||||
|  |                         </div> | ||||||
|  |                     </div> | ||||||
|  |                 </div> | ||||||
|  |  | ||||||
|  |                 {% if creating %} | ||||||
|  |                     <div class="button-row"> | ||||||
|  |                         <div class="button-row-reminder"> | ||||||
|  |                             <button class="button is-success" id="createReminder"> | ||||||
|  |                                 <span>Create Reminder</span> <span class="icon"><i class="fas fa-sparkles"></i></span> | ||||||
|  |                             </button> | ||||||
|  |                         </div> | ||||||
|  |                         <div class="button-row-template"> | ||||||
|  |                             <div> | ||||||
|  |                                 <button class="button is-success is-outlined" id="createTemplate"> | ||||||
|  |                                     <span>Create Template</span> <span class="icon"><i class="fas fa-file-spreadsheet"></i></span> | ||||||
|  |                                 </button> | ||||||
|  |                             </div> | ||||||
|  |                             <div> | ||||||
|  |                                 <button class="button is-outlined show-modal is-pulled-right" data-modal="chooseTemplateModal"> | ||||||
|  |                                     Load Template | ||||||
|  |                                 </button> | ||||||
|  |                             </div> | ||||||
|  |                         </div> | ||||||
|  |                     </div> | ||||||
|  |                 {% else %} | ||||||
|  |                     <div class="button-row-edit"> | ||||||
|  |                         <button class="button is-success save-btn"> | ||||||
|  |                             <span>Save</span> <span class="icon"><i class="fas fa-save"></i></span> | ||||||
|  |                         </button> | ||||||
|  |                         <button class="button is-warning disable-enable"> | ||||||
|  |                         </button> | ||||||
|  |                         <button class="button is-danger delete-reminder"> | ||||||
|  |                             Delete | ||||||
|  |                         </button> | ||||||
|  |                     </div> | ||||||
|  |                 {% endif %} | ||||||
|  |             </div> | ||||||
|  |         </div> | ||||||
|  |     </div> | ||||||
|  | </div> | ||||||
| @@ -0,0 +1,17 @@ | |||||||
|  | <div class="reminderError" data-case="success"> | ||||||
|  |     <div class="errorHead"> | ||||||
|  |         <div class="errorIcon"> | ||||||
|  |             <span class="icon"> | ||||||
|  |                 <i class="fas fa-trash"></i> | ||||||
|  |                 <i class="fas fa-check"></i> | ||||||
|  |                 <i class="fas fa-exclamation-triangle"></i> | ||||||
|  |             </span> | ||||||
|  |         </div> | ||||||
|  |         <div class="reminderName"> | ||||||
|  |             Reminder | ||||||
|  |         </div> | ||||||
|  |         <div class="reminderTime"> | ||||||
|  |  | ||||||
|  |         </div> | ||||||
|  |     </div> | ||||||
|  | </div> | ||||||
							
								
								
									
										12
									
								
								web/templates/reminder_dashboard/user_error.html.tera
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								web/templates/reminder_dashboard/user_error.html.tera
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | |||||||
|  | <div class="hero is-fullheight"> | ||||||
|  |     <div class="hero-body"> | ||||||
|  |         <div class="container has-text-centered"> | ||||||
|  |             <p class="title"> | ||||||
|  |                 You do not have permissions for this server | ||||||
|  |             </p> | ||||||
|  |             <p class="subtitle"> | ||||||
|  |                 Ask an admin to grant you the "Manage Messages" permission. | ||||||
|  |             </p> | ||||||
|  |         </div> | ||||||
|  |     </div> | ||||||
|  | </div> | ||||||
| @@ -13,8 +13,8 @@ | |||||||
|     <section class="section"> |     <section class="section"> | ||||||
|         <div class="container"> |         <div class="container"> | ||||||
|             <h2 class="title">Outline</h2> |             <h2 class="title">Outline</h2> | ||||||
|             <p class="is-size-5 pl-6"> |             <p class=""> | ||||||
|                 The Terms of Service apply whenever you use <strong>Reminder Bot</strong> and the |                 The Terms of Service apply whenever you use the hosted edition of <strong>Reminder Bot</strong> and the | ||||||
|                 <strong>JellyWX's Home</strong> Discord server. |                 <strong>JellyWX's Home</strong> Discord server. | ||||||
|                 <br> |                 <br> | ||||||
|                 <br> |                 <br> | ||||||
| @@ -25,7 +25,7 @@ | |||||||
|                 <br> |                 <br> | ||||||
|                 <br> |                 <br> | ||||||
|                 The Terms of Service may be updated. Notice will be provided via the Discord server. You |                 The Terms of Service may be updated. Notice will be provided via the Discord server. You | ||||||
|                 should consider the Terms of Service to be a strong for appropriate behaviour. |                 should consider the Terms of Service to be a guide for appropriate behaviour. | ||||||
|             </p> |             </p> | ||||||
|         </div> |         </div> | ||||||
|     </section> |     </section> | ||||||
| @@ -33,32 +33,43 @@ | |||||||
|     <section class="section"> |     <section class="section"> | ||||||
|         <div class="container"> |         <div class="container"> | ||||||
|             <h2 class="title">Reminder Bot</h2> |             <h2 class="title">Reminder Bot</h2> | ||||||
|             <ul class="is-size-5 pl-6"> |             <p> | ||||||
|                 <li>Reasonably disclose potential exploits or bugs to me by email or by Discord private message</li> |                 The Terms of Service <strong>do not</strong> apply to self-hosting users who are using the source code | ||||||
|                 <li>Do not use the bot to harass other Discord users</li> |                 or pre-packaged Debian files to run their own instance of Reminder Bot. | ||||||
|                 <li>Do not use the bot to transmit malware or other illegal content</li> |             </p> | ||||||
|                 <li>Do not use the bot to send more than 15 messages during a 60 second period</li> |             <br> | ||||||
|  |             <h3 class="subtitle">Your access to Reminder Bot may be restricted if you:</h3> | ||||||
|  |             <ul class="pl-6" style="list-style: disc"> | ||||||
|  |                 <li>Abuse exploits or bugs in Reminder Bot.</li> | ||||||
|  |                 <li>Use the bot to harass other Discord users.</li> | ||||||
|  |                 <li>Use the bot to transmit malware or other illegal content.</li> | ||||||
|  |                 <li>Use the bot to send more than 15 messages during a 60 second period.</li> | ||||||
|                 <li> |                 <li> | ||||||
|                     Do not attempt to circumvent restrictions imposed by the bot or website, including trying to access |                     Attempt to circumvent restrictions imposed by the bot or website, including trying to access | ||||||
|                     data of other users, circumvent Patreon restrictions, or uploading files and creating reminders that |                     data of other users, circumvent Patreon restrictions, or uploading files and creating reminders that | ||||||
|                     are too large for the bot to send or process. Some or all of these actions may be illegal in your |                     are too large for the bot to send or process. | ||||||
|                     country |  | ||||||
|                 </li> |                 </li> | ||||||
|             </ul> |             </ul> | ||||||
|  |             <br> | ||||||
|  |             <p> | ||||||
|  |                 Some or all of these actions may be illegal in your country. | ||||||
|  |             </p> | ||||||
|         </div> |         </div> | ||||||
|     </section> |     </section> | ||||||
|  |  | ||||||
|     <section class="section"> |     <section class="section"> | ||||||
|         <div class="container"> |         <div class="container"> | ||||||
|             <h2 class="title">JellyWX's Home</h2> |             <h2 class="title">JellyWX's Home</h2> | ||||||
|             <ul class="is-size-5 pl-6"> |             <h3 class="subtitle">Your access to the JellyWX's Home Discord server may be restricted if you:</h3> | ||||||
|                 <li>Do not discuss politics, harass other users, or use language intended to upset other users</li> |             <ul class="pl-6" style="list-style: disc"> | ||||||
|                 <li>Do not share personal information about yourself or any other user. This includes but is not |                 <li>Discuss politics, harass other users, or use language intended to upset other users.</li> | ||||||
|  |                 <li>Abuse any exploits.</li> | ||||||
|  |                 <li>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, |                     limited to real names<sup>1</sup>, addresses, phone numbers, country of origin<sup>2</sup>, religion, email address, | ||||||
|                     IP address.</li> |                     IP address.</li> | ||||||
|                 <li>Do not send malicious links or attachments</li> |                 <li>Send malicious links or attachments.</li> | ||||||
|                 <li>Do not advertise</li> |                 <li>Advertise without permission.</li> | ||||||
|                 <li>Do not send unwarranted direct messages</li> |                 <li>Send unwarranted direct messages.</li> | ||||||
|             </ul> |             </ul> | ||||||
|             <p class="small"> |             <p class="small"> | ||||||
|                 <sup>1</sup> Some users may use their real name on their account. In this case, do not assert that |                 <sup>1</sup> Some users may use their real name on their account. In this case, do not assert that | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user