fixed remind command having too many spaces
This commit is contained in:
@ -13,9 +13,7 @@ use crate::{
|
||||
FrameworkCtx, THEME_COLOR,
|
||||
};
|
||||
|
||||
use crate::framework::RegexFramework;
|
||||
use serenity::builder::CreateEmbedFooter;
|
||||
use std::mem;
|
||||
use std::sync::Arc;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
@ -112,17 +110,13 @@ async fn help(ctx: &Context, msg: &Message, args: String) {
|
||||
let prefix = GuildData::prefix_from_id(msg.guild_id, &pool);
|
||||
|
||||
if !args.is_empty() {
|
||||
let framework: Arc<Box<RegexFramework>> = {
|
||||
let framework_trait = ctx
|
||||
.data
|
||||
.read()
|
||||
.await
|
||||
.get::<FrameworkCtx>()
|
||||
.cloned()
|
||||
.expect("Could not get FrameworkCtx from data");
|
||||
|
||||
unsafe { mem::transmute(framework_trait.clone()) }
|
||||
};
|
||||
let framework = ctx
|
||||
.data
|
||||
.read()
|
||||
.await
|
||||
.get::<FrameworkCtx>()
|
||||
.cloned()
|
||||
.expect("Could not get FrameworkCtx from data");
|
||||
|
||||
let matched = framework
|
||||
.commands
|
||||
|
@ -993,9 +993,96 @@ async fn countdown(ctx: &Context, msg: &Message, args: String) {
|
||||
let interval = split_args.get(1).unwrap();
|
||||
let event_name = split_args.get(2).unwrap();
|
||||
|
||||
let time_parser = TimeParser::new(*time, &timezone);
|
||||
let now = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_secs();
|
||||
|
||||
if let Ok(target_ts) = time_parser.timestamp() {}
|
||||
let time_parser = TimeParser::new(*time, timezone);
|
||||
let interval_parser = TimeParser::new(*interval, timezone);
|
||||
|
||||
if let Ok(target_ts) = time_parser.timestamp() {
|
||||
if let Ok(interval) = interval_parser.displacement() {
|
||||
let mut first_time = target_ts;
|
||||
|
||||
while first_time + interval < now as i64 {
|
||||
first_time += interval;
|
||||
}
|
||||
|
||||
let description = format!(
|
||||
"**{}** occurs in **<<timefrom:{}:%d days, %h:%m>>**",
|
||||
event_name, target_ts
|
||||
);
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
INSERT INTO embeds (title, description, color) VALUES (?, ?, ?)
|
||||
",
|
||||
event_name,
|
||||
description,
|
||||
*THEME_COLOR
|
||||
)
|
||||
.execute(&pool)
|
||||
.await;
|
||||
|
||||
let embed_id = sqlx::query!(
|
||||
"
|
||||
SELECT id FROM embeds WHERE title = ? AND description = ?
|
||||
",
|
||||
event_name,
|
||||
description
|
||||
)
|
||||
.fetch_one(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
INSERT INTO messages (embed_id) VALUES (?)
|
||||
",
|
||||
embed_id.id
|
||||
)
|
||||
.execute(&pool)
|
||||
.await;
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
INSERT INTO reminders (
|
||||
`uid`,
|
||||
`name`,
|
||||
`message_id`,
|
||||
`channel_id`,
|
||||
`time`,
|
||||
`interval`,
|
||||
`method`,
|
||||
`set_by`,
|
||||
`expires`
|
||||
) VALUES (
|
||||
?,
|
||||
'Countdown',
|
||||
(SELECT id FROM messages WHERE embed_id = ?),
|
||||
(SELECT id FROM channels WHERE channel = ?),
|
||||
?,
|
||||
?,
|
||||
'countdown',
|
||||
(SELECT id FROM users WHERE user = ?),
|
||||
FROM_UNIXTIME(?)
|
||||
)
|
||||
",
|
||||
generate_uid(),
|
||||
embed_id.id,
|
||||
msg.channel_id.as_u64(),
|
||||
first_time,
|
||||
interval,
|
||||
msg.author.id.as_u64(),
|
||||
target_ts
|
||||
)
|
||||
.execute(&pool)
|
||||
.await;
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
|
@ -25,7 +25,7 @@ lazy_static! {
|
||||
pub static ref REGEX_CHANNEL_USER: Regex = Regex::new(r#"\s*<(#|@)(?:!)?(\d+)>\s*"#).unwrap();
|
||||
|
||||
pub static ref REGEX_REMIND_COMMAND: Regex = RegexBuilder::new(
|
||||
r#"(?P<mentions>(?:<@\d+>\s|<@!\d+>\s|<#\d+>\s)*)(?P<time>(?:(?:\d+)(?:s|m|h|d|:|/|-|))+)(?:\s+(?P<interval>(?:(?:\d+)(?:s|m|h|d|))+))?(?:\s+(?P<expires>(?:(?:\d+)(?:s|m|h|d|:|/|-|))+))?\s+(?P<content>.*)"#
|
||||
r#"(?P<mentions>(?:<@\d+>\s+|<@!\d+>\s+|<#\d+>\s+)*)(?P<time>(?:(?:\d+)(?:s|m|h|d|:|/|-|))+)(?:\s+(?P<interval>(?:(?:\d+)(?:s|m|h|d|))+))?(?:\s+(?P<expires>(?:(?:\d+)(?:s|m|h|d|:|/|-|))+))?\s+(?P<content>.*)"#
|
||||
)
|
||||
.dot_matches_new_line(true)
|
||||
.build()
|
||||
|
@ -12,7 +12,6 @@ use serenity::{
|
||||
async_trait,
|
||||
cache::Cache,
|
||||
client::{bridge::gateway::GatewayIntents, Client},
|
||||
framework::Framework,
|
||||
http::{client::Http, CacheHttp},
|
||||
model::{
|
||||
channel::GuildChannel,
|
||||
@ -60,7 +59,7 @@ impl TypeMapKey for ReqwestClient {
|
||||
struct FrameworkCtx;
|
||||
|
||||
impl TypeMapKey for FrameworkCtx {
|
||||
type Value = Arc<Box<dyn Framework + Send + Sync>>;
|
||||
type Value = Arc<RegexFramework>;
|
||||
}
|
||||
|
||||
struct PopularTimezones;
|
||||
@ -242,7 +241,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
.add_command("a", &moderation_cmds::ALIAS_COMMAND)
|
||||
.build();
|
||||
|
||||
let framework_arc = Arc::new(Box::new(framework) as Box<dyn Framework + Send + Sync>);
|
||||
let framework_arc = Arc::new(framework);
|
||||
|
||||
let mut client = Client::builder(&token)
|
||||
.intents(if dm_enabled {
|
||||
|
Reference in New Issue
Block a user