fix: change some replies to ephemeral, updated rand, cleanup
This commit is contained in:
parent
276e9f5d75
commit
9e66b56721
11 changed files with 22 additions and 33 deletions
|
@ -2,7 +2,7 @@ use poise;
|
|||
use serenity::all::User;
|
||||
|
||||
use super::interaction::send_with_embed;
|
||||
use crate::types::{Error, Context};
|
||||
use crate::types::{Context, ContextExt, Error};
|
||||
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
|
@ -16,6 +16,6 @@ pub async fn headpat(ctx: Context<'_>,
|
|||
let title = "HEADPATS!";
|
||||
let desc = format!("{} headpats {}", ctx.author(), user);
|
||||
send_with_embed(ctx, "headpat", &title, &desc).await?;
|
||||
ctx.reply("Done!").await?;
|
||||
ctx.reply_ephemeral("Done!").await?;
|
||||
Ok(())
|
||||
}
|
|
@ -2,7 +2,7 @@ use poise;
|
|||
use serenity::all::User;
|
||||
|
||||
use super::interaction::send_with_embed;
|
||||
use crate::types::{Error, Context};
|
||||
use crate::types::{Context, ContextExt, Error};
|
||||
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
|
@ -16,6 +16,6 @@ pub async fn hug(ctx: Context<'_>,
|
|||
let title = "HUGS!";
|
||||
let desc = format!("{} hugs {}", ctx.author(), user);
|
||||
send_with_embed(ctx, "hug", &title, &desc).await?;
|
||||
ctx.reply("Done!").await?;
|
||||
ctx.reply_ephemeral("Done!").await?;
|
||||
Ok(())
|
||||
}
|
|
@ -2,7 +2,7 @@ use anyhow::anyhow;
|
|||
use serenity::all::{Colour, CreateEmbed, CreateMessage};
|
||||
use tenorv2::tenor_builder::Tenor;
|
||||
|
||||
use crate::{types::Context, utils::{gifs::get_random_tenor_gif, utilities}};
|
||||
use crate::{types::Context, utils::gifs::get_random_tenor_gif};
|
||||
|
||||
/// Sends embed with random tenor gif from searched query
|
||||
/// title and desc are used in the embed
|
||||
|
@ -24,9 +24,7 @@ pub(super) async fn send_with_embed(ctx: Context<'_>, query: &str, title: &str,
|
|||
return Err(anyhow!("Guild id not available in context"));
|
||||
}
|
||||
|
||||
utilities::get_system_channel(
|
||||
ctx.guild_id().unwrap(), ctx.http()
|
||||
).await?
|
||||
ctx.channel_id()
|
||||
.send_message(
|
||||
ctx.http(),
|
||||
CreateMessage::new().add_embed(embed)
|
||||
|
|
|
@ -5,8 +5,3 @@ pub mod player_common;
|
|||
pub mod radio;
|
||||
pub mod general_player;
|
||||
pub mod voice_types;
|
||||
|
||||
// ! not working
|
||||
// pub mod yt;
|
||||
// TODO implement
|
||||
// pub mod spotify;
|
||||
|
|
|
@ -37,7 +37,7 @@ pub async fn disconnect(
|
|||
let has_handler = manager.get(guild_id).is_some();
|
||||
|
||||
if ! has_handler {
|
||||
ctx.reply("I am not connected to a channel!").await?;
|
||||
ctx.reply_ephemeral("I am not connected to a channel!").await?;
|
||||
return Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -5,13 +5,13 @@ use radiobrowser::{ApiStation, StationSearchBuilder};
|
|||
use regex::Regex;
|
||||
use serenity::all::{CreateActionRow, CreateButton, CreateEmbed, CreateEmbedFooter, CreateInteractionResponse, CreateInteractionResponseMessage};
|
||||
|
||||
use crate::{commands::voice_types::NumberOfEntries, types::Context};
|
||||
use crate::{commands::voice_types::NumberOfEntries, types::{Context, ContextExt, Error}};
|
||||
|
||||
pub async fn paginate_search_stations(
|
||||
ctx: &Context<'_>,
|
||||
search_builder: &StationSearchBuilder,
|
||||
limit: NumberOfEntries
|
||||
) -> Result<(), serenity::Error> {
|
||||
) -> Result<(), Error> {
|
||||
// Define some unique identifiers for the navigation buttons
|
||||
let ctx_id = ctx.id();
|
||||
let prev_button_id = format!("{}prev", ctx_id);
|
||||
|
@ -20,7 +20,7 @@ pub async fn paginate_search_stations(
|
|||
let search_builder = search_builder;
|
||||
|
||||
let Ok(stations) = search_builder.clone().send().await else {
|
||||
ctx.reply("Something went wrong, try searching again").await?;
|
||||
ctx.reply_ephemeral("Something went wrong, try searching again").await?;
|
||||
return Ok(())
|
||||
};
|
||||
|
||||
|
@ -66,7 +66,7 @@ pub async fn paginate_search_stations(
|
|||
}
|
||||
|
||||
let Ok(mut stations) = search_builder.clone().offset(offset.to_string()).send().await else {
|
||||
ctx.reply("Something went wrong, try searching again").await?;
|
||||
ctx.reply_ephemeral("Something went wrong, try searching again").await?;
|
||||
return Ok(())
|
||||
};
|
||||
|
||||
|
@ -75,7 +75,7 @@ pub async fn paginate_search_stations(
|
|||
page = 0;
|
||||
|
||||
let Ok(new_stations) = search_builder.clone().offset(offset.to_string()).send().await else {
|
||||
ctx.reply("Something went wrong, try searching again").await?;
|
||||
ctx.reply_ephemeral("Something went wrong, try searching again").await?;
|
||||
return Ok(())
|
||||
};
|
||||
stations = new_stations;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use rand::random;
|
||||
use rand::seq::IndexedRandom;
|
||||
use serenity::http::CacheHttp;
|
||||
use serenity::{client::Context, http::Http};
|
||||
use serenity::model::channel::Message;
|
||||
|
@ -80,8 +81,8 @@ async fn response(http: Arc<Http>, msg: Message) -> bool {
|
|||
"Hm?"
|
||||
];
|
||||
|
||||
let num = random::<usize>() % RESPONSES.len();
|
||||
match msg.reply(http.clone(), RESPONSES[num]).await {
|
||||
let response = RESPONSES.choose(&mut rand::rng()).unwrap_or(&"?").to_string();
|
||||
match msg.reply(http.clone(), response).await {
|
||||
Ok(_) => { return true }
|
||||
Err(e) => {
|
||||
let _ = send_error(http, e.to_string()).await;
|
||||
|
@ -93,9 +94,8 @@ async fn response(http: Arc<Http>, msg: Message) -> bool {
|
|||
async fn henlo(http: Arc<Http>, msg: Message) -> bool {
|
||||
const EMOJIS: [&str; 7] = ["🥰", "🐄", "🐮", "❤️", "👋", "🤠", "😊"];
|
||||
|
||||
let num = random::<usize>() % EMOJIS.len();
|
||||
let response = format!("Henlooo {} {}", msg.author.name, EMOJIS[num]);
|
||||
|
||||
let emoji = EMOJIS.choose(&mut rand::rng()).unwrap_or(&"🐮");
|
||||
let response = format!("Henlooo {} {}", msg.author.name, emoji);
|
||||
|
||||
match msg.reply(http.clone(), response).await {
|
||||
Ok(_) => { return true }
|
||||
|
|
|
@ -58,7 +58,7 @@ async fn celebrate_birthday(guild_id: GuildId, user_id: UserId, nick: &str, http
|
|||
.locale("sk".to_string())
|
||||
.search("vsetko najlepsie").await?;
|
||||
|
||||
let index = rand::random::<usize>() % LIMIT as usize;
|
||||
let index = (rand::random::<u8>() % LIMIT) as usize;
|
||||
let gif_url = match tenor::get_gif_url(MediaFilter::gif, tenor_response) {
|
||||
Ok(urls) => Some(urls),
|
||||
Err(e) => {
|
||||
|
|
|
@ -26,6 +26,7 @@ pub async fn hello(http: Arc<Http>) -> anyhow::Result<()> {
|
|||
use serenity::all::ChannelId;
|
||||
use anyhow::Context;
|
||||
use std::env;
|
||||
use rand::seq::IndexedRandom;
|
||||
|
||||
let messages = [
|
||||
"AAAAAAAAAAAAAAAAAAAA",
|
||||
|
@ -38,11 +39,11 @@ pub async fn hello(http: Arc<Http>) -> anyhow::Result<()> {
|
|||
"Whom'st have summoned the ancient one?",
|
||||
];
|
||||
|
||||
let num = rand::random::<usize>() % messages.len();
|
||||
let message = messages.choose(&mut rand::rng()).unwrap_or(&"Chello").to_string();
|
||||
|
||||
let channel_id: String = env::var("DEBUG_CHANNEL_ID").context("DEBUG_CHANNEL_ID not found in env file")?;
|
||||
let channel = ChannelId::new(channel_id.parse::<u64>().unwrap());
|
||||
if let Err(why) = channel.say(http, messages[num]).await {
|
||||
if let Err(why) = channel.say(http, message).await {
|
||||
print!("Error sending message: {:?}", why);
|
||||
};
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use tenorv2::{tenor, tenor_types::{MediaFilter, TenorError}, JsonValue};
|
||||
|
||||
pub async fn get_random_tenor_gif(tenor_response: JsonValue, limit: u8) -> Result<String, TenorError> {
|
||||
let index = rand::random::<usize>() % limit as usize;
|
||||
let index = (rand::random::<u8>() % limit) as usize;
|
||||
match tenor::get_gif_url(MediaFilter::gif, tenor_response) {
|
||||
Ok(urls) => Ok(urls[index].clone()),
|
||||
Err(e) => Err(e)
|
||||
|
|
|
@ -2,11 +2,6 @@ use std::{fs, hash::{DefaultHasher, Hash, Hasher}, io, path::Path, sync::Arc, ve
|
|||
|
||||
use serenity::{all::{ChannelId, ChannelType, CreateMessage, GuildId, GuildRef, Message}, http::Http};
|
||||
|
||||
use poise::CreateReply;
|
||||
use serenity::async_trait;
|
||||
|
||||
use crate::types::Context;
|
||||
|
||||
|
||||
pub async fn get_system_channel(guild_id: GuildId, http: &Http) -> anyhow::Result<ChannelId> {
|
||||
use anyhow::Context;
|
||||
|
|
Loading…
Reference in a new issue