Upgrade poise. Combine remind/multiline into one command
This commit is contained in:
@ -18,7 +18,7 @@ use crate::{
|
||||
Context, Data, Error, GuildId,
|
||||
};
|
||||
|
||||
async fn timezone_autocomplete(ctx: Context<'_>, partial: String) -> Vec<String> {
|
||||
async fn timezone_autocomplete(ctx: Context<'_>, partial: &str) -> Vec<String> {
|
||||
if partial.is_empty() {
|
||||
ctx.data().popular_timezones.iter().map(|t| t.to_string()).collect::<Vec<String>>()
|
||||
} else {
|
||||
@ -206,7 +206,7 @@ Do not share it!
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn macro_name_autocomplete(ctx: Context<'_>, partial: String) -> Vec<String> {
|
||||
async fn macro_name_autocomplete(ctx: Context<'_>, partial: &str) -> Vec<String> {
|
||||
sqlx::query!(
|
||||
"
|
||||
SELECT name
|
||||
|
@ -8,8 +8,9 @@ use chrono::NaiveDateTime;
|
||||
use chrono_tz::Tz;
|
||||
use num_integer::Integer;
|
||||
use poise::{
|
||||
serenity::{builder::CreateEmbed, model::channel::Channel},
|
||||
serenity_prelude::{component::ButtonStyle, ReactionType},
|
||||
serenity_prelude::{
|
||||
builder::CreateEmbed, component::ButtonStyle, model::channel::Channel, ReactionType,
|
||||
},
|
||||
CreateReply, Modal,
|
||||
};
|
||||
|
||||
@ -558,40 +559,16 @@ struct ContentModal {
|
||||
content: String,
|
||||
}
|
||||
|
||||
/// Create a new reminder with multiline content
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
rename = "multiline",
|
||||
identifying_name = "remind_multiline",
|
||||
default_member_permissions = "MANAGE_GUILD"
|
||||
)]
|
||||
pub async fn remind_multiline(
|
||||
ctx: ApplicationContext<'_>,
|
||||
#[description = "A description of the time to set the reminder for"] time: String,
|
||||
#[description = "Channel or user mentions to set the reminder for"] channels: Option<String>,
|
||||
#[description = "(Patreon only) Time to wait before repeating the reminder. Leave blank for one-shot reminder"]
|
||||
interval: Option<String>,
|
||||
#[description = "(Patreon only) For repeating reminders, the time at which the reminder will stop repeating"]
|
||||
expires: Option<String>,
|
||||
#[description = "Set the TTS flag on the reminder message, similar to the /tts command"]
|
||||
tts: Option<bool>,
|
||||
) -> Result<(), Error> {
|
||||
let data = ContentModal::execute(ctx).await?;
|
||||
|
||||
create_reminder(Context::Application(ctx), time, data.content, channels, interval, expires, tts)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Create a new reminder
|
||||
/// Create a reminder. Press "+5 more" for other options. A modal will open if "content" is not provided
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
identifying_name = "remind",
|
||||
default_member_permissions = "MANAGE_GUILD"
|
||||
)]
|
||||
pub async fn remind(
|
||||
ctx: Context<'_>,
|
||||
ctx: ApplicationContext<'_>,
|
||||
#[description = "A description of the time to set the reminder for"] time: String,
|
||||
#[description = "The message content to send"] content: String,
|
||||
#[description = "The message content to send"] content: Option<String>,
|
||||
#[description = "Channel or user mentions to set the reminder for"] channels: Option<String>,
|
||||
#[description = "(Patreon only) Time to wait before repeating the reminder. Leave blank for one-shot reminder"]
|
||||
interval: Option<String>,
|
||||
@ -600,7 +577,35 @@ pub async fn remind(
|
||||
#[description = "Set the TTS flag on the reminder message, similar to the /tts command"]
|
||||
tts: Option<bool>,
|
||||
) -> Result<(), Error> {
|
||||
create_reminder(ctx, time, content, channels, interval, expires, tts).await
|
||||
match content {
|
||||
Some(content) => {
|
||||
create_reminder(
|
||||
Context::Application(ctx),
|
||||
time,
|
||||
content,
|
||||
channels,
|
||||
interval,
|
||||
expires,
|
||||
tts,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
None => {
|
||||
let data = ContentModal::execute(ctx).await?;
|
||||
|
||||
create_reminder(
|
||||
Context::Application(ctx),
|
||||
time,
|
||||
data.content,
|
||||
channels,
|
||||
interval,
|
||||
expires,
|
||||
tts,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn create_reminder(
|
||||
|
@ -5,9 +5,9 @@ use std::io::Cursor;
|
||||
use chrono_tz::Tz;
|
||||
use log::warn;
|
||||
use poise::{
|
||||
serenity::{
|
||||
serenity_prelude as serenity,
|
||||
serenity_prelude::{
|
||||
builder::CreateEmbed,
|
||||
client::Context,
|
||||
model::{
|
||||
application::interaction::{
|
||||
message_component::MessageComponentInteraction, InteractionResponseType,
|
||||
@ -15,8 +15,8 @@ use poise::{
|
||||
},
|
||||
channel::Channel,
|
||||
},
|
||||
Context,
|
||||
},
|
||||
serenity_prelude as serenity,
|
||||
};
|
||||
use rmp_serde::Serializer;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -1,6 +1,8 @@
|
||||
// todo split pager out into a single struct
|
||||
use chrono_tz::Tz;
|
||||
use poise::serenity::{builder::CreateComponents, model::application::component::ButtonStyle};
|
||||
use poise::serenity_prelude::{
|
||||
builder::CreateComponents, model::application::component::ButtonStyle,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_repr::*;
|
||||
|
||||
|
@ -12,7 +12,7 @@ pub const MACRO_MAX_COMMANDS: usize = 5;
|
||||
|
||||
use std::{collections::HashSet, env, iter::FromIterator};
|
||||
|
||||
use poise::serenity::model::prelude::AttachmentType;
|
||||
use poise::serenity_prelude::model::prelude::AttachmentType;
|
||||
use regex::Regex;
|
||||
|
||||
lazy_static! {
|
||||
|
@ -1,8 +1,8 @@
|
||||
use std::{collections::HashMap, env};
|
||||
|
||||
use poise::{
|
||||
serenity::{model::application::interaction::Interaction, utils::shard_id},
|
||||
serenity_prelude as serenity,
|
||||
serenity_prelude::{model::application::interaction::Interaction, utils::shard_id},
|
||||
};
|
||||
|
||||
use crate::{component_models::ComponentDataModel, Data, Error};
|
||||
|
@ -1,4 +1,4 @@
|
||||
use poise::serenity::model::channel::Channel;
|
||||
use poise::serenity_prelude::model::channel::Channel;
|
||||
|
||||
use crate::{consts::MACRO_MAX_COMMANDS, models::command_macro::RecordedCommand, Context, Error};
|
||||
|
||||
|
@ -23,7 +23,7 @@ use std::{
|
||||
use chrono_tz::Tz;
|
||||
use dotenv::dotenv;
|
||||
use log::{error, warn};
|
||||
use poise::serenity::model::{
|
||||
use poise::serenity_prelude::model::{
|
||||
gateway::GatewayIntents,
|
||||
id::{GuildId, UserId},
|
||||
};
|
||||
@ -134,7 +134,6 @@ async fn _main(tx: Sender<()>) -> Result<(), Box<dyn StdError + Send + Sync>> {
|
||||
..reminder_cmds::timer_base()
|
||||
},
|
||||
reminder_cmds::remind(),
|
||||
reminder_cmds::remind_multiline(),
|
||||
poise::Command {
|
||||
subcommands: vec![
|
||||
poise::Command {
|
||||
@ -178,7 +177,7 @@ async fn _main(tx: Sender<()>) -> Result<(), Box<dyn StdError + Send + Sync>> {
|
||||
.map(|t| t.timezone.parse::<Tz>().unwrap())
|
||||
.collect::<Vec<Tz>>();
|
||||
|
||||
poise::Framework::build()
|
||||
poise::Framework::builder()
|
||||
.token(discord_token)
|
||||
.user_data_setup(move |ctx, _bot, framework| {
|
||||
Box::pin(async move {
|
||||
|
@ -1,5 +1,5 @@
|
||||
use chrono::NaiveDateTime;
|
||||
use poise::serenity::model::channel::Channel;
|
||||
use poise::serenity_prelude::model::channel::Channel;
|
||||
use sqlx::MySqlPool;
|
||||
|
||||
pub struct ChannelData {
|
||||
|
@ -1,4 +1,4 @@
|
||||
use poise::serenity::model::{
|
||||
use poise::serenity_prelude::model::{
|
||||
application::interaction::application_command::CommandDataOption, id::GuildId,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -5,7 +5,7 @@ pub mod timer;
|
||||
pub mod user_data;
|
||||
|
||||
use chrono_tz::Tz;
|
||||
use poise::serenity::{async_trait, model::id::UserId};
|
||||
use poise::serenity_prelude::{async_trait, model::id::UserId};
|
||||
|
||||
use crate::{
|
||||
models::{channel_data::ChannelData, user_data::UserData},
|
||||
|
@ -2,7 +2,7 @@ use std::{collections::HashSet, fmt::Display};
|
||||
|
||||
use chrono::{Duration, NaiveDateTime, Utc};
|
||||
use chrono_tz::Tz;
|
||||
use poise::serenity::{
|
||||
use poise::serenity_prelude::{
|
||||
http::CacheHttp,
|
||||
model::{
|
||||
channel::GuildChannel,
|
||||
|
@ -1,4 +1,4 @@
|
||||
use poise::serenity::model::id::ChannelId;
|
||||
use poise::serenity_prelude::model::id::ChannelId;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_repr::*;
|
||||
|
||||
|
@ -8,9 +8,9 @@ use std::hash::{Hash, Hasher};
|
||||
|
||||
use chrono::{NaiveDateTime, TimeZone};
|
||||
use chrono_tz::Tz;
|
||||
use poise::{
|
||||
serenity::model::id::{ChannelId, GuildId, UserId},
|
||||
serenity_prelude::Cache,
|
||||
use poise::serenity_prelude::{
|
||||
model::id::{ChannelId, GuildId, UserId},
|
||||
Cache,
|
||||
};
|
||||
use sqlx::Executor;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use chrono_tz::Tz;
|
||||
use log::error;
|
||||
use poise::serenity::{http::CacheHttp, model::id::UserId};
|
||||
use poise::serenity_prelude::{http::CacheHttp, model::id::UserId};
|
||||
use sqlx::MySqlPool;
|
||||
|
||||
use crate::consts::LOCAL_TIMEZONE;
|
||||
|
12
src/utils.rs
12
src/utils.rs
@ -1,11 +1,11 @@
|
||||
use poise::{
|
||||
serenity::{
|
||||
serenity_prelude as serenity,
|
||||
serenity_prelude::{
|
||||
builder::CreateApplicationCommands,
|
||||
http::CacheHttp,
|
||||
interaction::MessageFlags,
|
||||
model::id::{GuildId, UserId},
|
||||
},
|
||||
serenity_prelude as serenity,
|
||||
serenity_prelude::interaction::MessageFlags,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
@ -14,10 +14,10 @@ use crate::{
|
||||
};
|
||||
|
||||
pub async fn register_application_commands(
|
||||
ctx: &poise::serenity::client::Context,
|
||||
ctx: &serenity::Context,
|
||||
framework: &poise::Framework<Data, Error>,
|
||||
guild_id: Option<GuildId>,
|
||||
) -> Result<(), poise::serenity::Error> {
|
||||
) -> Result<(), serenity::Error> {
|
||||
let mut commands_builder = CreateApplicationCommands::default();
|
||||
let commands = &framework.options().commands;
|
||||
for command in commands {
|
||||
@ -28,7 +28,7 @@ pub async fn register_application_commands(
|
||||
commands_builder.add_application_command(context_menu_command);
|
||||
}
|
||||
}
|
||||
let commands_builder = poise::serenity::json::Value::Array(commands_builder.0);
|
||||
let commands_builder = poise::serenity_prelude::json::Value::Array(commands_builder.0);
|
||||
|
||||
if let Some(guild_id) = guild_id {
|
||||
ctx.http.create_guild_application_commands(guild_id.0, &commands_builder).await?;
|
||||
|
Reference in New Issue
Block a user