Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use serenity::async_trait;
- use serenity::model::prelude::*;
- use serenity::prelude::*;
- use std::time::{Duration, SystemTime};
- const VOID_CHANNEL_ID: u64 = 952_722_147_099_422_730;
- const OWNER_USER_ID: u64 = 348_275_601_934_778_368;
- pub struct Handler;
- #[async_trait]
- impl EventHandler for Handler {
- async fn message(&self, ctx: Context, new_message: Message) {
- if new_message.channel_id.0 == VOID_CHANNEL_ID {
- if let Err(why) = new_message.delete(&ctx.http).await {
- eprintln!("{:#?}", why);
- }
- }
- }
- async fn reaction_add(&self, ctx: Context, add_reaction: Reaction) {
- if add_reaction.emoji.as_data() == *"🗑️" {
- match add_reaction.message(&ctx.http).await {
- Ok(msg) => {
- if let Err(why) = msg.delete(&ctx.http).await {
- eprintln!("{:#?}", why);
- }
- }
- Err(why) => eprintln!("{:#?}", why),
- }
- }
- }
- async fn ready(&self, ctx: Context, data_about_bot: Ready) {
- let me = ctx.http.get_user(OWNER_USER_ID).await.unwrap();
- match me.direct_message(&ctx.http, |msg| {
- msg.embed(|embed| {
- embed.title(format!("{} is Awake and Ready to Run!", data_about_bot.user.name))
- .thumbnail(data_about_bot.user.face())
- .description(format!("It's <t:{}:f>! What are y'all doing standing around?! We've got work to do! WHERE'S MY COFFEE?", SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs()))
- })
- }).await {
- Ok(message) => {
- tokio::time::sleep(Duration::from_secs(60)).await;
- if let Err(why) = message.delete(&ctx.http).await {
- eprintln!("{:#?}", why);
- }
- },
- Err(why) => eprintln!("{:#?}", why),
- }
- }
- #[allow(clippy::single_match)]
- async fn interaction_create(&self, ctx: Context, interaction: Interaction) {
- match interaction {
- Interaction::ApplicationCommand(command) => {
- if let Err(why) = parse_application_command(ctx, command).await {
- eprintln!("{:#?}", why);
- }
- }
- Interaction::Autocomplete(autocomplete) => {
- use serde_json::Value;
- let options = &autocomplete.data.options;
- let mut prediction_groups = vec![];
- for option in options {
- if let Some(Value::String(value)) = &option.value {
- let results = crate::fuzzy::fuzzy_search(&ctx, value).await;
- match results {
- Ok(results) => prediction_groups.push(results),
- Err(why) => eprintln!("{:#?}", why),
- }
- }
- }
- if let Err(why) = autocomplete
- .create_autocomplete_response(&ctx.http, |response| {
- for prediction_group in prediction_groups {
- for prediction in prediction_group.predictions {
- response.add_string_choice(
- &prediction.description,
- &prediction.description,
- );
- }
- }
- response
- })
- .await
- {
- eprintln!("{:#?}", why);
- }
- }
- _ => {}
- }
- }
- }
- #[allow(clippy::single_match)]
- async fn parse_application_command(
- ctx: Context,
- interaction: application_command::ApplicationCommandInteraction,
- ) -> anyhow::Result<()> {
- use interactions::application_command::ApplicationCommandType;
- match interaction.data.kind {
- ApplicationCommandType::ChatInput => parse_slash_commands(ctx, interaction).await?,
- _ => {}
- }
- Ok(())
- }
- #[allow(clippy::single_match)]
- async fn parse_slash_commands(
- ctx: Context,
- interaction: application_command::ApplicationCommandInteraction,
- ) -> anyhow::Result<()> {
- use crate::commands::directions;
- use crate::commands::user_info;
- match &*interaction.data.name {
- "user-info" => user_info::execute(ctx, interaction).await?,
- "directions" => directions::execute(ctx, interaction).await?,
- _ => {}
- }
- Ok(())
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement