Compare commits
3 commits
6d1d920385
...
d3acda2eeb
Author | SHA1 | Date | |
---|---|---|---|
d3acda2eeb | |||
1887759977 | |||
30f7e3c7f0 |
19 changed files with 141 additions and 20 deletions
|
@ -23,3 +23,4 @@ tenorv2 = { path = "./tenor-v2/tenorv2" }
|
|||
[features]
|
||||
DEBUG = []
|
||||
RELEASE = []
|
||||
GUILD_COMMAND = []
|
|
@ -1,2 +1,11 @@
|
|||
pub mod moove;
|
||||
pub mod say;
|
||||
pub use moover::*;
|
||||
pub use notice::*;
|
||||
pub use other::*;
|
||||
pub use user_interactions::*;
|
||||
|
||||
pub mod moover;
|
||||
pub mod notice;
|
||||
pub mod user_interactions;
|
||||
pub mod other;
|
||||
|
||||
pub mod channel_test;
|
7
src/commands/moover/mod.rs
Normal file
7
src/commands/moover/mod.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
pub use moove::*;
|
||||
pub use say::*;
|
||||
pub use gif::*;
|
||||
|
||||
pub mod moove;
|
||||
pub mod say;
|
||||
pub mod gif;
|
0
src/commands/notice/birthday.rs
Normal file
0
src/commands/notice/birthday.rs
Normal file
0
src/commands/notice/events.rs
Normal file
0
src/commands/notice/events.rs
Normal file
20
src/commands/user_interactions/headpat.rs
Normal file
20
src/commands/user_interactions/headpat.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
use poise;
|
||||
use serenity::all::User;
|
||||
|
||||
use super::interaction::send_with_embed;
|
||||
use crate::types::{Error, Context};
|
||||
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
description_localized("en-US", "Headpat all your friends!")
|
||||
)]
|
||||
pub async fn headpat(ctx: Context<'_>,
|
||||
#[description = "Who is the lucky one?"]
|
||||
user: User
|
||||
) -> Result<(), Error> {
|
||||
let title = "HEADPATS!";
|
||||
let desc = format!("{} headpats {}", ctx.author(), user);
|
||||
send_with_embed(ctx, "headpat", &title, &desc).await?;
|
||||
ctx.reply("Done!").await?;
|
||||
Ok(())
|
||||
}
|
20
src/commands/user_interactions/hug.rs
Normal file
20
src/commands/user_interactions/hug.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
use poise;
|
||||
use serenity::all::User;
|
||||
|
||||
use super::interaction::send_with_embed;
|
||||
use crate::types::{Error, Context};
|
||||
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
description_localized("en-US", "Hug all your friends!")
|
||||
)]
|
||||
pub async fn hug(ctx: Context<'_>,
|
||||
#[description = "Who is the lucky one?"]
|
||||
user: User
|
||||
) -> Result<(), Error> {
|
||||
let title = "HUGS!";
|
||||
let desc = format!("{} hugs {}", ctx.author(), user);
|
||||
send_with_embed(ctx, "hug", &title, &desc).await?;
|
||||
ctx.reply("Done!").await?;
|
||||
Ok(())
|
||||
}
|
38
src/commands/user_interactions/interaction.rs
Normal file
38
src/commands/user_interactions/interaction.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
use anyhow::anyhow;
|
||||
use serenity::all::{Colour, CreateEmbed, CreateMessage};
|
||||
use tenorv2::tenor_builder::Tenor;
|
||||
|
||||
use crate::{types::Context, util::{gifs::get_random_tenor_gif, utilities}};
|
||||
|
||||
pub(super) async fn send_with_embed(ctx: Context<'_>, query: &str, title: &str, desc: &str) -> anyhow::Result<()> {
|
||||
let tenor_response = Tenor::new()?
|
||||
.random(true)
|
||||
.search(query).await?;
|
||||
|
||||
const LIMIT: u8 = 20;
|
||||
let url = get_random_tenor_gif(tenor_response, LIMIT).await?;
|
||||
|
||||
let embed = CreateEmbed::new()
|
||||
.color(Colour::new(rand::random::<u32>() % 0xFFFFFF))
|
||||
.title(title)
|
||||
.description(desc)
|
||||
.image(url.as_str());
|
||||
|
||||
if ctx.guild_id().is_none() {
|
||||
return Err(anyhow!("Guild id not available in context"));
|
||||
}
|
||||
|
||||
utilities::get_system_channel(
|
||||
ctx.guild_id().unwrap(), ctx.http()
|
||||
).await?
|
||||
.send_message(
|
||||
ctx.http(),
|
||||
CreateMessage::new().add_embed(embed)
|
||||
).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) async fn send(ctx: Context<'_>, msg: &str) -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
6
src/commands/user_interactions/mod.rs
Normal file
6
src/commands/user_interactions/mod.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
pub use headpat::*;
|
||||
pub use hug::*;
|
||||
|
||||
pub mod interaction;
|
||||
pub mod headpat;
|
||||
pub mod hug;
|
30
src/main.rs
30
src/main.rs
|
@ -5,13 +5,14 @@ use std::time::Duration;
|
|||
use std::error;
|
||||
use std::env;
|
||||
|
||||
use poise::samples::register_in_guild;
|
||||
use poise::samples::register_globally;
|
||||
|
||||
use poise::samples::register_in_guild;
|
||||
use serenity::async_trait;
|
||||
use serenity::prelude::GatewayIntents;
|
||||
use serenity::client::Context;
|
||||
use serenity::model::gateway::Ready;
|
||||
use serenity::all::{EventHandler, GuildId, Message};
|
||||
use serenity::all::{EventHandler, Message};
|
||||
use serenity::Client;
|
||||
|
||||
use dotenv::dotenv;
|
||||
|
@ -82,7 +83,10 @@ async fn main() -> anyhow::Result<()> {
|
|||
|
||||
// create poise framework for registering commands
|
||||
let options: poise::FrameworkOptions<(), Box<dyn error::Error + Send + Sync>> = poise::FrameworkOptions {
|
||||
commands: vec![],
|
||||
commands: vec![
|
||||
commands::say(),
|
||||
commands::hug()
|
||||
],
|
||||
prefix_options: poise::PrefixFrameworkOptions {
|
||||
prefix: Some("/".into()),
|
||||
edit_tracker: Some(Arc::new(poise::EditTracker::for_timespan(
|
||||
|
@ -99,15 +103,21 @@ async fn main() -> anyhow::Result<()> {
|
|||
..Default::default()
|
||||
};
|
||||
|
||||
let debug_guild_id = env::var("DEBUG_GUILD_ID")
|
||||
.context("DEBUG_GUILD_ID not found in env")?
|
||||
.parse::<u64>().unwrap();
|
||||
|
||||
let framework = poise::Framework::builder()
|
||||
.setup(move |ctx, _ready, framework| {
|
||||
Box::pin(async move {
|
||||
register_in_guild(ctx, &framework.options().commands, GuildId::new(debug_guild_id)).await?;
|
||||
Ok(())
|
||||
.setup(move |ctx, _ready, framework| {
|
||||
Box::pin(async move {
|
||||
#[cfg(feature="GUILD_COMMAND")] {
|
||||
let debug_guild_id = env::var("DEBUG_GUILD_ID")
|
||||
.context("DEBUG_GUILD_ID not found in env")?
|
||||
.parse::<u64>().unwrap();
|
||||
|
||||
register_in_guild(ctx, &framework.options().commands, debug_guild_id).await?;
|
||||
}
|
||||
#[cfg(not(feature="GUILD_COMMAND"))] {
|
||||
register_globally(ctx, &framework.options().commands).await?;
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
})
|
||||
.options(options)
|
||||
|
|
|
@ -8,7 +8,7 @@ use std::sync::Arc;
|
|||
use crate::util::debug::send_error;
|
||||
use crate::util::utilities;
|
||||
|
||||
use crate::commands::moove::{moove, moove_check};
|
||||
use crate::commands::moover::moove::{moove, moove_check};
|
||||
|
||||
pub async fn handle(ctx: Context, msg: Message) {
|
||||
if msg.author.bot {
|
||||
|
|
|
@ -30,7 +30,7 @@ async fn announce_event(guild_id: GuildId, name: &str, special_message: &str, ht
|
|||
.color(Colour::new(rand::random::<u32>() % 0xFFFFFF))
|
||||
.title("Today's event is:");
|
||||
|
||||
let system_channel = utilities::get_system_channel(guild_id, http.clone()).await?;
|
||||
let system_channel = utilities::get_system_channel(guild_id, &http).await?;
|
||||
|
||||
if special_message.contains("http") {
|
||||
event_embed = event_embed.description(name);
|
||||
|
@ -65,7 +65,7 @@ async fn celebrate_birthday(guild_id: GuildId, user_id: UserId, nick: &str, http
|
|||
}
|
||||
};
|
||||
|
||||
let system_channel = utilities::get_system_channel(guild_id, http.clone()).await?;
|
||||
let system_channel = utilities::get_system_channel(guild_id, &http).await?;
|
||||
|
||||
let mut embed = CreateEmbed::new()
|
||||
.color(Colour::new(rand::random::<u32>() % 0xFFFFFF))
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
|
||||
pub type Error = Box<dyn std::error::Error + Send + Sync>;
|
||||
// replace () with Data if you ever need to store some additional data
|
||||
// pub type Context<'a> = poise::Context<'a, (), Error>;
|
||||
pub type Context<'a> = poise::Context<'a, (), Error>;
|
||||
|
|
9
src/util/gifs.rs
Normal file
9
src/util/gifs.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
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;
|
||||
match tenor::get_gif_url(MediaFilter::gif, tenor_response) {
|
||||
Ok(urls) => Ok(urls[index].clone()),
|
||||
Err(e) => Err(e)
|
||||
}
|
||||
}
|
|
@ -1,2 +1,3 @@
|
|||
pub mod debug;
|
||||
pub mod utilities;
|
||||
pub mod gifs;
|
|
@ -4,7 +4,7 @@ use serenity::{all::{ChannelId, CreateMessage, GuildId, Message}, http::Http};
|
|||
|
||||
use anyhow::Context;
|
||||
|
||||
pub async fn get_system_channel(guild_id: GuildId, http: Arc<Http>) -> anyhow::Result<ChannelId> {
|
||||
pub async fn get_system_channel(guild_id: GuildId, http: &Http) -> anyhow::Result<ChannelId> {
|
||||
return http.get_guild(guild_id).await?.system_channel_id
|
||||
.context(format!("System channel of guild: {} not found", guild_id.get()));
|
||||
}
|
||||
|
|
2
tenor-v2
2
tenor-v2
|
@ -1 +1 @@
|
|||
Subproject commit ddf5b39fe854c3593e172fd6e82ffba1994ba5d1
|
||||
Subproject commit fd8c8bde1be41116fe398776c45625a19ec10281
|
Loading…
Reference in a new issue