patreon gated repeat argument
This commit is contained in:
parent
a21f518b21
commit
23c6b3869e
@ -11,6 +11,7 @@ use regex_command_attr::command;
|
|||||||
use serenity::{builder::CreateEmbed, client::Context, model::channel::Channel};
|
use serenity::{builder::CreateEmbed, client::Context, model::channel::Channel};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
check_subscription,
|
||||||
component_models::{
|
component_models::{
|
||||||
pager::{DelPager, LookPager, Pager},
|
pager::{DelPager, LookPager, Pager},
|
||||||
ComponentDataModel, DelSelector,
|
ComponentDataModel, DelSelector,
|
||||||
@ -665,6 +666,17 @@ DELETE FROM timers WHERE owner = ? AND name = ?
|
|||||||
)]
|
)]
|
||||||
#[hook(CHECK_GUILD_PERMISSIONS_HOOK)]
|
#[hook(CHECK_GUILD_PERMISSIONS_HOOK)]
|
||||||
async fn remind(ctx: &Context, invoke: &mut CommandInvoke, args: CommandOptions) {
|
async fn remind(ctx: &Context, invoke: &mut CommandInvoke, args: CommandOptions) {
|
||||||
|
if args.get("repeat").is_none() && args.get("expires").is_some() {
|
||||||
|
let _ = invoke
|
||||||
|
.respond(
|
||||||
|
&ctx,
|
||||||
|
CreateGenericResponse::new().content("`expires` can only be used with `repeat`"),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
invoke.defer(&ctx).await;
|
invoke.defer(&ctx).await;
|
||||||
|
|
||||||
let user_data = ctx.user_data(invoke.author_id()).await.unwrap();
|
let user_data = ctx.user_data(invoke.author_id()).await.unwrap();
|
||||||
@ -698,22 +710,33 @@ async fn remind(ctx: &Context, invoke: &mut CommandInvoke, args: CommandOptions)
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// todo gate this on patreon subscription
|
let (interval, expires) = if let Some(repeat) = args.get("repeat") {
|
||||||
let interval = args
|
if check_subscription(&ctx, invoke.author_id()).await {
|
||||||
.get("repeat")
|
(
|
||||||
.map(|arg| {
|
humantime::parse_duration(&repeat.to_string())
|
||||||
humantime::parse_duration(&arg.to_string())
|
.or_else(|_| {
|
||||||
.or_else(|_| humantime::parse_duration(&format!("1 {}", arg.to_string())))
|
humantime::parse_duration(&format!("1 {}", repeat.to_string()))
|
||||||
.map(|duration| duration.as_secs() as i64)
|
|
||||||
.ok()
|
|
||||||
})
|
})
|
||||||
.flatten();
|
.map(|duration| duration.as_secs() as i64)
|
||||||
let expires = {
|
.ok(),
|
||||||
|
{
|
||||||
if let Some(arg) = args.get("expires") {
|
if let Some(arg) = args.get("expires") {
|
||||||
natural_parser(&arg.to_string(), &timezone.to_string()).await
|
natural_parser(&arg.to_string(), &timezone.to_string()).await
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
let _ = invoke
|
||||||
|
.respond(&ctx, CreateGenericResponse::new()
|
||||||
|
.content("`repeat` is only available to Patreon subscribers or self-hosted users")
|
||||||
|
).await;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
(None, None)
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut builder = MultiReminderBuilder::new(ctx, invoke.guild_id())
|
let mut builder = MultiReminderBuilder::new(ctx, invoke.guild_id())
|
||||||
|
Loading…
Reference in New Issue
Block a user