removed dead code
This commit is contained in:
@ -2,13 +2,13 @@ use chrono::offset::Utc;
|
||||
use chrono_tz::{Tz, TZ_VARIANTS};
|
||||
use levenshtein::levenshtein;
|
||||
use regex_command_attr::command;
|
||||
use serenity::{
|
||||
client::Context,
|
||||
model::{id::GuildId, misc::Mentionable},
|
||||
};
|
||||
use serenity::{client::Context, model::misc::Mentionable};
|
||||
|
||||
use crate::{
|
||||
component_models::{pager::Pager, ComponentDataModel, Restrict},
|
||||
component_models::{
|
||||
pager::{MacroPager, Pager},
|
||||
ComponentDataModel, Restrict,
|
||||
},
|
||||
consts::{EMBED_DESCRIPTION_MAX_LENGTH, THEME_COLOR},
|
||||
framework::{CommandInvoke, CommandOptions, CreateGenericResponse, OptionValue},
|
||||
hooks::{CHECK_GUILD_PERMISSIONS_HOOK, CHECK_MANAGED_PERMISSIONS_HOOK},
|
||||
@ -16,52 +16,6 @@ use crate::{
|
||||
PopularTimezones, RecordingMacros, RegexFramework, SQLPool,
|
||||
};
|
||||
|
||||
#[command("blacklist")]
|
||||
#[description("Block channels from using bot commands")]
|
||||
#[arg(
|
||||
name = "channel",
|
||||
description = "The channel to blacklist",
|
||||
kind = "Channel",
|
||||
required = false
|
||||
)]
|
||||
#[supports_dm(false)]
|
||||
#[hook(CHECK_GUILD_PERMISSIONS_HOOK)]
|
||||
#[can_blacklist(false)]
|
||||
async fn blacklist(ctx: &Context, invoke: &mut CommandInvoke, args: CommandOptions) {
|
||||
let pool = ctx.data.read().await.get::<SQLPool>().cloned().unwrap();
|
||||
|
||||
let channel = match args.get("channel") {
|
||||
Some(OptionValue::Channel(channel_id)) => *channel_id,
|
||||
|
||||
_ => invoke.channel_id(),
|
||||
}
|
||||
.to_channel_cached(&ctx)
|
||||
.unwrap();
|
||||
|
||||
let mut channel_data = ChannelData::from_channel(&channel, &pool).await.unwrap();
|
||||
|
||||
channel_data.blacklisted = !channel_data.blacklisted;
|
||||
channel_data.commit_changes(&pool).await;
|
||||
|
||||
if channel_data.blacklisted {
|
||||
let _ = invoke
|
||||
.respond(
|
||||
ctx.http.clone(),
|
||||
CreateGenericResponse::new()
|
||||
.content(format!("{} has been blacklisted", channel.mention())),
|
||||
)
|
||||
.await;
|
||||
} else {
|
||||
let _ = invoke
|
||||
.respond(
|
||||
ctx.http.clone(),
|
||||
CreateGenericResponse::new()
|
||||
.content(format!("{} has been removed from the blacklist", channel.mention())),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
|
||||
#[command("timezone")]
|
||||
#[description("Select your timezone")]
|
||||
#[arg(
|
||||
@ -173,44 +127,6 @@ You may want to use one of the popular timezones below, otherwise click [here](h
|
||||
}
|
||||
}
|
||||
|
||||
#[command("prefix")]
|
||||
#[description("Configure a prefix for text-based commands (deprecated)")]
|
||||
#[supports_dm(false)]
|
||||
#[hook(CHECK_GUILD_PERMISSIONS_HOOK)]
|
||||
async fn prefix(ctx: &Context, invoke: &mut CommandInvoke, args: String) {
|
||||
let pool = ctx.data.read().await.get::<SQLPool>().cloned().unwrap();
|
||||
|
||||
let guild_data = ctx.guild_data(invoke.guild_id().unwrap()).await.unwrap();
|
||||
|
||||
if args.len() > 5 {
|
||||
let _ = invoke
|
||||
.respond(
|
||||
ctx.http.clone(),
|
||||
CreateGenericResponse::new().content("Please select a prefix under 5 characters"),
|
||||
)
|
||||
.await;
|
||||
} else if args.is_empty() {
|
||||
let _ = invoke
|
||||
.respond(
|
||||
ctx.http.clone(),
|
||||
CreateGenericResponse::new()
|
||||
.content("Please use this command as `@reminder-bot prefix <prefix>`"),
|
||||
)
|
||||
.await;
|
||||
} else {
|
||||
guild_data.write().await.prefix = args;
|
||||
guild_data.read().await.commit_changes(&pool).await;
|
||||
|
||||
let _ = invoke
|
||||
.respond(
|
||||
ctx.http.clone(),
|
||||
CreateGenericResponse::new()
|
||||
.content(format!("Prefix changed to {}", guild_data.read().await.prefix)),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
|
||||
#[command("restrict")]
|
||||
#[description("Configure which roles can use commands on the bot")]
|
||||
#[arg(
|
||||
@ -402,9 +318,9 @@ Any commands ran as part of recording will be inconsequential")
|
||||
"list" => {
|
||||
let macros = CommandMacro::from_guild(ctx, invoke.guild_id().unwrap()).await;
|
||||
|
||||
let resp = show_macro_page(¯os, 0, invoke.guild_id().unwrap());
|
||||
let resp = show_macro_page(¯os, 0);
|
||||
|
||||
invoke.respond(&ctx, resp).await;
|
||||
invoke.respond(&ctx, resp).await.unwrap();
|
||||
}
|
||||
"run" => {
|
||||
let macro_name = args.get("name").unwrap().to_string();
|
||||
@ -456,7 +372,10 @@ Any commands ran as part of recording will be inconsequential")
|
||||
.await
|
||||
{
|
||||
Ok(row) => {
|
||||
sqlx::query!("DELETE FROM macro WHERE id = ?", row.id).execute(&pool).await;
|
||||
sqlx::query!("DELETE FROM macro WHERE id = ?", row.id)
|
||||
.execute(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let _ = invoke
|
||||
.respond(
|
||||
@ -510,12 +429,8 @@ pub fn max_macro_page(macros: &[CommandMacro]) -> usize {
|
||||
})
|
||||
}
|
||||
|
||||
fn show_macro_page(
|
||||
macros: &[CommandMacro],
|
||||
page: usize,
|
||||
guild_id: GuildId,
|
||||
) -> CreateGenericResponse {
|
||||
let pager = Pager::new(page, guild_id);
|
||||
pub fn show_macro_page(macros: &[CommandMacro], page: usize) -> CreateGenericResponse {
|
||||
let pager = MacroPager::new(page);
|
||||
|
||||
if macros.is_empty() {
|
||||
return CreateGenericResponse::new().embed(|e| {
|
||||
|
@ -16,15 +16,10 @@ use crate::{
|
||||
pager::{DelPager, LookPager, Pager},
|
||||
ComponentDataModel, DelSelector,
|
||||
},
|
||||
consts::{
|
||||
EMBED_DESCRIPTION_MAX_LENGTH, REGEX_CHANNEL_USER, REGEX_NATURAL_COMMAND_1,
|
||||
REGEX_NATURAL_COMMAND_2, SELECT_MAX_ENTRIES, THEME_COLOR,
|
||||
},
|
||||
consts::{EMBED_DESCRIPTION_MAX_LENGTH, REGEX_CHANNEL_USER, SELECT_MAX_ENTRIES, THEME_COLOR},
|
||||
framework::{CommandInvoke, CommandOptions, CreateGenericResponse, OptionValue},
|
||||
hooks::{CHECK_GUILD_PERMISSIONS_HOOK, CHECK_MANAGED_PERMISSIONS_HOOK},
|
||||
models::{
|
||||
channel_data::ChannelData,
|
||||
guild_data::GuildData,
|
||||
reminder::{
|
||||
builder::{MultiReminderBuilder, ReminderScope},
|
||||
content::Content,
|
||||
@ -704,6 +699,7 @@ async fn remind(ctx: &Context, invoke: &mut CommandInvoke, args: CommandOptions)
|
||||
}
|
||||
};
|
||||
|
||||
// todo gate this on patreon subscription
|
||||
let interval = args
|
||||
.get("repeat")
|
||||
.map(|arg| {
|
||||
@ -805,178 +801,3 @@ fn parse_mention_list(mentions: &str) -> Vec<ReminderScope> {
|
||||
})
|
||||
.collect::<Vec<ReminderScope>>()
|
||||
}
|
||||
|
||||
/*
|
||||
#[command("natural")]
|
||||
#[permission_level(Managed)]
|
||||
async fn natural(ctx: &Context, msg: &Message, args: String) {
|
||||
let (pool, lm) = get_ctx_data(&ctx).await;
|
||||
|
||||
let user_data = UserData::from_user(&msg.author, &ctx, &pool).await.unwrap();
|
||||
|
||||
match REGEX_NATURAL_COMMAND_1.captures(&args) {
|
||||
Some(captures) => {
|
||||
let (expires, interval, string_content) =
|
||||
if check_subscription_on_message(&ctx, msg).await {
|
||||
let rest_content = captures.name("msg").unwrap().as_str();
|
||||
|
||||
match REGEX_NATURAL_COMMAND_2.captures(rest_content) {
|
||||
Some(secondary_captures) => {
|
||||
let expires =
|
||||
if let Some(expires_crop) = secondary_captures.name("expires") {
|
||||
natural_parser(expires_crop.as_str(), &user_data.timezone).await
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let interval =
|
||||
if let Some(interval_crop) = secondary_captures.name("interval") {
|
||||
humantime::parse_duration(interval_crop.as_str())
|
||||
.or_else(|_| {
|
||||
humantime::parse_duration(&format!(
|
||||
"1 {}",
|
||||
interval_crop.as_str()
|
||||
))
|
||||
})
|
||||
.map(|duration| duration.as_secs() as i64)
|
||||
.ok()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
(
|
||||
expires,
|
||||
interval,
|
||||
if interval.is_some() {
|
||||
secondary_captures.name("msg").unwrap().as_str()
|
||||
} else {
|
||||
rest_content
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
None => (None, None, rest_content),
|
||||
}
|
||||
} else {
|
||||
(None, None, captures.name("msg").unwrap().as_str())
|
||||
};
|
||||
|
||||
let location_ids = if let Some(mentions) = captures.name("mentions").map(|m| m.as_str())
|
||||
{
|
||||
parse_mention_list(mentions)
|
||||
} else {
|
||||
vec![ReminderScope::Channel(msg.channel_id.into())]
|
||||
};
|
||||
|
||||
if let Some(timestamp) =
|
||||
natural_parser(captures.name("time").unwrap().as_str(), &user_data.timezone).await
|
||||
{
|
||||
let content_res = Content::build(string_content, msg).await;
|
||||
|
||||
match content_res {
|
||||
Ok(mut content) => {
|
||||
if let Some(guild) = msg.guild(&ctx) {
|
||||
content.substitute(guild);
|
||||
}
|
||||
|
||||
let user_data = ctx.user_data(&msg.author).await.unwrap();
|
||||
|
||||
let mut builder = MultiReminderBuilder::new(ctx, msg.guild_id)
|
||||
.author(user_data)
|
||||
.content(content)
|
||||
.interval(interval)
|
||||
.expires(expires)
|
||||
.time(timestamp);
|
||||
|
||||
builder.set_scopes(location_ids);
|
||||
|
||||
let (errors, successes) = builder.build().await;
|
||||
|
||||
let success_part = match successes.len() {
|
||||
0 => "".to_string(),
|
||||
n => format!(
|
||||
"Reminder{s} for {locations} set for <t:{offset}:R>",
|
||||
s = if n > 1 { "s" } else { "" },
|
||||
locations = successes
|
||||
.iter()
|
||||
.map(|l| l.mention())
|
||||
.collect::<Vec<String>>()
|
||||
.join(", "),
|
||||
offset = timestamp
|
||||
),
|
||||
};
|
||||
|
||||
let error_part = match errors.len() {
|
||||
0 => "".to_string(),
|
||||
n => format!(
|
||||
"{n} reminder{s} failed to set:\n{errors}",
|
||||
s = if n > 1 { "s" } else { "" },
|
||||
n = n,
|
||||
errors = errors
|
||||
.iter()
|
||||
.map(|e| e.display(true))
|
||||
.collect::<Vec<String>>()
|
||||
.join("\n")
|
||||
),
|
||||
};
|
||||
|
||||
let _ = msg
|
||||
.channel_id
|
||||
.send_message(&ctx, |m| {
|
||||
m.embed(|e| {
|
||||
e.title(format!(
|
||||
"{n} Reminder{s} Set",
|
||||
n = successes.len(),
|
||||
s = if successes.len() > 1 { "s" } else { "" }
|
||||
))
|
||||
.description(format!("{}\n\n{}", success_part, error_part))
|
||||
.color(*THEME_COLOR)
|
||||
})
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
Err(content_error) => {
|
||||
let _ = msg
|
||||
.channel_id
|
||||
.send_message(ctx, |m| {
|
||||
m.embed(move |e| {
|
||||
e.title("0 Reminders Set")
|
||||
.description(content_error.to_string())
|
||||
.color(*THEME_COLOR)
|
||||
})
|
||||
})
|
||||
.await;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let _ = msg
|
||||
.channel_id
|
||||
.send_message(ctx, |m| {
|
||||
m.embed(move |e| {
|
||||
e.title(
|
||||
lm.get(&user_data.language, "remind/title")
|
||||
.replace("{number}", "0"),
|
||||
)
|
||||
.description(lm.get(&user_data.language, "natural/invalid_time"))
|
||||
.color(*THEME_COLOR)
|
||||
})
|
||||
})
|
||||
.await;
|
||||
}
|
||||
}
|
||||
|
||||
None => {
|
||||
command_help(
|
||||
ctx,
|
||||
msg,
|
||||
lm,
|
||||
&ctx.prefix(msg.guild_id).await,
|
||||
&user_data.language,
|
||||
"natural",
|
||||
)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
Reference in New Issue
Block a user