update for new database models

This commit is contained in:
jude 2022-05-13 10:03:45 +01:00
parent b88d046846
commit 88255032de
5 changed files with 627 additions and 456 deletions

1029
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -22,7 +22,7 @@ serde_json = "1.0"
rand = "0.7" rand = "0.7"
Inflector = "0.11" Inflector = "0.11"
levenshtein = "1.0" levenshtein = "1.0"
serenity = { git = "https://github.com/serenity-rs/serenity", branch = "next", features = ["collector", "unstable_discord_api"] } serenity = { git = "https://github.com/serenity-rs/serenity", rev = "c83ba2a1d61bf8e29638da26bab9f94dd0d90c0f", features = ["collector", "unstable_discord_api"] }
sqlx = { version = "0.5", features = ["runtime-tokio-rustls", "macros", "mysql", "bigdecimal", "chrono"]} sqlx = { version = "0.5", features = ["runtime-tokio-rustls", "macros", "mysql", "bigdecimal", "chrono"]}
[dependencies.regex_command_attr] [dependencies.regex_command_attr]

View File

@ -8,9 +8,9 @@ use serenity::{
channel::{Channel, GuildChannel}, channel::{Channel, GuildChannel},
guild::Guild, guild::Guild,
id::{ChannelId, GuildId, UserId}, id::{ChannelId, GuildId, UserId},
misc::Mentionable,
webhook::Webhook, webhook::Webhook,
}, },
prelude::Mentionable,
Result as SerenityResult, Result as SerenityResult,
}; };
@ -770,7 +770,7 @@ INSERT INTO reminders (
`embed_color`, `embed_color`,
`channel_id`, `channel_id`,
`utc_time`, `utc_time`,
`interval`, `interval_seconds`,
`set_by`, `set_by`,
`expires` `expires`
) VALUES ( ) VALUES (
@ -1393,7 +1393,7 @@ INSERT INTO reminders (
channel_id, channel_id,
`utc_time`, `utc_time`,
expires, expires,
`interval`, `interval_seconds`,
set_by set_by
) VALUES ( ) VALUES (
?, ?,

View File

@ -11,13 +11,13 @@ mod time_parser;
use serenity::{ use serenity::{
async_trait, async_trait,
cache::Cache, cache::Cache,
client::{bridge::gateway::GatewayIntents, Client}, client::Client,
futures::TryFutureExt, futures::TryFutureExt,
http::{client::Http, CacheHttp}, http::{client::Http, CacheHttp},
model::{ model::{
channel::GuildChannel, channel::GuildChannel,
channel::Message, channel::Message,
guild::{Guild, GuildUnavailable}, guild::Guild,
id::{GuildId, UserId}, id::{GuildId, UserId},
interactions::Interaction, interactions::Interaction,
}, },
@ -48,9 +48,11 @@ use tokio::sync::RwLock;
use chrono::Utc; use chrono::Utc;
use chrono_tz::Tz; use chrono_tz::Tz;
use serenity::model::guild::UnavailableGuild;
use serenity::model::prelude::{ use serenity::model::prelude::{
InteractionApplicationCommandCallbackDataFlags, InteractionResponseType, InteractionApplicationCommandCallbackDataFlags, InteractionResponseType,
}; };
use serenity::prelude::GatewayIntents;
struct GuildDataCache; struct GuildDataCache;
@ -232,7 +234,7 @@ DELETE FROM channels WHERE channel = ?
async fn guild_delete( async fn guild_delete(
&self, &self,
ctx: Context, ctx: Context,
deleted_guild: GuildUnavailable, deleted_guild: UnavailableGuild,
_guild: Option<Guild>, _guild: Option<Guild>,
) { ) {
let pool = ctx let pool = ctx
@ -301,7 +303,7 @@ DELETE FROM guilds WHERE guild = ?
1, 1,
); );
d.create_embed(|e| e.title(lm.get(&user_data.language, "timezone/set_p_title")) d.embed(|e| e.title(lm.get(&user_data.language, "timezone/set_p_title"))
.color(*THEME_COLOR) .color(*THEME_COLOR)
.description(content) .description(content)
.footer(|f| f.text(footer_text))) .footer(|f| f.text(footer_text)))
@ -325,7 +327,7 @@ DELETE FROM guilds WHERE guild = ?
.create_interaction_response(&ctx, |r| { .create_interaction_response(&ctx, |r| {
r.kind(InteractionResponseType::ChannelMessageWithSource) r.kind(InteractionResponseType::ChannelMessageWithSource)
.interaction_response_data(|d| { .interaction_response_data(|d| {
d.create_embed(|e| { d.embed(|e| {
e.title( e.title(
lm.get(&user_data.language, "lang/set_p_title"), lm.get(&user_data.language, "lang/set_p_title"),
) )
@ -355,7 +357,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let token = env::var("DISCORD_TOKEN").expect("Missing DISCORD_TOKEN from environment"); let token = env::var("DISCORD_TOKEN").expect("Missing DISCORD_TOKEN from environment");
let http = Http::new_with_token(&token); let http = Http::new(&token);
let logged_in_id = http let logged_in_id = http
.get_current_user() .get_current_user()
@ -414,8 +416,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let framework_arc = Arc::new(framework); let framework_arc = Arc::new(framework);
let mut client = Client::builder(&token) let mut client = Client::builder(
.intents(if dm_enabled { &token,
if dm_enabled {
GatewayIntents::GUILD_MESSAGES GatewayIntents::GUILD_MESSAGES
| GatewayIntents::GUILDS | GatewayIntents::GUILDS
| GatewayIntents::GUILD_MESSAGE_REACTIONS | GatewayIntents::GUILD_MESSAGE_REACTIONS
@ -425,12 +428,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
GatewayIntents::GUILD_MESSAGES GatewayIntents::GUILD_MESSAGES
| GatewayIntents::GUILDS | GatewayIntents::GUILDS
| GatewayIntents::GUILD_MESSAGE_REACTIONS | GatewayIntents::GUILD_MESSAGE_REACTIONS
}) },
.application_id(application_id.0) )
.event_handler(Handler) .application_id(application_id.0)
.framework_arc(framework_arc.clone()) .event_handler(Handler)
.await .framework_arc(framework_arc.clone())
.expect("Error occurred creating client"); .await
.expect("Error occurred creating client");
{ {
let guild_data_cache = dashmap::DashMap::new(); let guild_data_cache = dashmap::DashMap::new();

View File

@ -37,7 +37,7 @@ pub struct Reminder {
pub uid: String, pub uid: String,
pub channel: u64, pub channel: u64,
pub utc_time: NaiveDateTime, pub utc_time: NaiveDateTime,
pub interval: Option<u32>, pub interval_seconds: Option<u32>,
pub expires: Option<NaiveDateTime>, pub expires: Option<NaiveDateTime>,
pub enabled: bool, pub enabled: bool,
pub content: String, pub content: String,
@ -57,7 +57,7 @@ SELECT
reminders.uid, reminders.uid,
channels.channel, channels.channel,
reminders.utc_time, reminders.utc_time,
reminders.interval, reminders.interval_seconds,
reminders.expires, reminders.expires,
reminders.enabled, reminders.enabled,
reminders.content, reminders.content,
@ -101,7 +101,7 @@ SELECT
reminders.uid, reminders.uid,
channels.channel, channels.channel,
reminders.utc_time, reminders.utc_time,
reminders.interval, reminders.interval_seconds,
reminders.expires, reminders.expires,
reminders.enabled, reminders.enabled,
reminders.content, reminders.content,
@ -157,7 +157,7 @@ SELECT
reminders.uid, reminders.uid,
channels.channel, channels.channel,
reminders.utc_time, reminders.utc_time,
reminders.interval, reminders.interval_seconds,
reminders.expires, reminders.expires,
reminders.enabled, reminders.enabled,
reminders.content, reminders.content,
@ -189,7 +189,7 @@ SELECT
reminders.uid, reminders.uid,
channels.channel, channels.channel,
reminders.utc_time, reminders.utc_time,
reminders.interval, reminders.interval_seconds,
reminders.expires, reminders.expires,
reminders.enabled, reminders.enabled,
reminders.content, reminders.content,
@ -222,7 +222,7 @@ SELECT
reminders.uid, reminders.uid,
channels.channel, channels.channel,
reminders.utc_time, reminders.utc_time,
reminders.interval, reminders.interval_seconds,
reminders.expires, reminders.expires,
reminders.enabled, reminders.enabled,
reminders.content, reminders.content,
@ -264,7 +264,7 @@ WHERE
TimeDisplayType::Relative => format!("<t:{}:R>", self.utc_time.timestamp()), TimeDisplayType::Relative => format!("<t:{}:R>", self.utc_time.timestamp()),
}; };
if let Some(interval) = self.interval { if let Some(interval) = self.interval_seconds {
format!( format!(
"'{}' *{}* **{}**, repeating every **{}** (set by {})", "'{}' *{}* **{}**, repeating every **{}** (set by {})",
self.display_content(), self.display_content(),