New memes
+ clippy + fmt
This commit is contained in:
parent
014402b951
commit
5a65fdf54d
@ -1,5 +1,6 @@
|
|||||||
use config::{Config, File};
|
use config::{Config, File};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use serenity::model::prelude::UserId;
|
||||||
use serenity::prelude::TypeMapKey;
|
use serenity::prelude::TypeMapKey;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
@ -43,10 +44,16 @@ impl BotConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Default)]
|
||||||
|
pub struct BotState {
|
||||||
|
pub accepted_nsfw: Option<UserId>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct GlobalData {
|
pub struct GlobalData {
|
||||||
pub args: Args,
|
pub args: Args,
|
||||||
pub cfg: BotConfig,
|
pub cfg: BotConfig,
|
||||||
|
pub bot_state: BotState,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TypeMapKey for GlobalData {
|
impl TypeMapKey for GlobalData {
|
||||||
|
|||||||
49
src/discord/celeryman.rs
Normal file
49
src/discord/celeryman.rs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
use crate::{command, group, GlobalData};
|
||||||
|
use serenity::client::Context;
|
||||||
|
use serenity::framework::standard::{Args, CommandResult};
|
||||||
|
use serenity::model::channel::Message;
|
||||||
|
|
||||||
|
#[group]
|
||||||
|
#[commands(nudetayne, tayne, celeryman)]
|
||||||
|
pub struct CeleryMan;
|
||||||
|
|
||||||
|
#[command]
|
||||||
|
#[aliases("NUDETAYNE")]
|
||||||
|
#[only_in(guilds)]
|
||||||
|
async fn nudetayne(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
|
||||||
|
if msg.content.starts_with("!nudetayne") {
|
||||||
|
msg.reply(&ctx.http, "Not computing, please repeat.")
|
||||||
|
.await?;
|
||||||
|
} else if msg.content.starts_with("!NUDETAYNE") {
|
||||||
|
let mut data = ctx.data.write().await;
|
||||||
|
let global_data = data.get_mut::<GlobalData>().unwrap();
|
||||||
|
msg.reply(&ctx.http, "This is not suitable for work are you sure?")
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
global_data.bot_state.accepted_nsfw = Some(msg.author.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[command]
|
||||||
|
#[only_in(guilds)]
|
||||||
|
async fn tayne(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
|
||||||
|
msg.reply(
|
||||||
|
&ctx.http,
|
||||||
|
"https://media.tenor.com/115eUl2XUaAAAAAM/flarhgunnstow-paul-rudd.gif",
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[command]
|
||||||
|
#[only_in(guilds)]
|
||||||
|
async fn celeryman(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
|
||||||
|
msg.reply(
|
||||||
|
&ctx.http,
|
||||||
|
"https://media.tenor.com/1iOUXZFLpBgAAAAM/dance-dancing.gif",
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@ -1,17 +1,50 @@
|
|||||||
pub mod album;
|
pub mod album;
|
||||||
|
pub mod celeryman;
|
||||||
pub mod color;
|
pub mod color;
|
||||||
|
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::{help, hook, imgur, GlobalData};
|
use crate::{help, hook, imgur, GlobalData};
|
||||||
use rand::prelude::SliceRandom;
|
use rand::prelude::SliceRandom;
|
||||||
|
use serenity::async_trait;
|
||||||
use serenity::client::Context;
|
use serenity::client::Context;
|
||||||
use serenity::framework::standard::{
|
use serenity::framework::standard::{
|
||||||
help_commands, Args, CommandGroup, CommandResult, HelpOptions,
|
help_commands, Args, CommandGroup, CommandResult, HelpOptions,
|
||||||
};
|
};
|
||||||
use serenity::model::channel::Message;
|
use serenity::model::channel::Message;
|
||||||
use serenity::model::id::UserId;
|
use serenity::model::id::UserId;
|
||||||
|
use serenity::model::prelude::Ready;
|
||||||
|
use serenity::prelude::EventHandler;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
|
pub struct Handler;
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl EventHandler for Handler {
|
||||||
|
async fn message(&self, ctx: Context, new_message: Message) {
|
||||||
|
if new_message.author.bot {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if new_message.content.eq_ignore_ascii_case("yes")
|
||||||
|
|| new_message.content.eq_ignore_ascii_case("mhmm")
|
||||||
|
{
|
||||||
|
let mut data = ctx.data.write().await;
|
||||||
|
let global_data = data.get_mut::<GlobalData>().unwrap();
|
||||||
|
|
||||||
|
if let Some(u) = global_data.bot_state.accepted_nsfw {
|
||||||
|
if new_message.author.id == u {
|
||||||
|
new_message.reply(&ctx.http, "||https://cdn.discordapp.com/attachments/614891432079130625/1041545254362423368/unknown.png||").await.unwrap();
|
||||||
|
global_data.bot_state.accepted_nsfw = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn ready(&self, _: Context, ready: Ready) {
|
||||||
|
println!("Connected as {}", ready.user.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[hook]
|
#[hook]
|
||||||
pub async fn after(
|
pub async fn after(
|
||||||
_ctx: &Context,
|
_ctx: &Context,
|
||||||
|
|||||||
@ -2,6 +2,7 @@ use crate::imgur::ImgurError;
|
|||||||
use std::fmt::{Display, Formatter};
|
use std::fmt::{Display, Formatter};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[allow(clippy::enum_variant_names)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
ConfigError(config::ConfigError),
|
ConfigError(config::ConfigError),
|
||||||
ImgurError(ImgurError),
|
ImgurError(ImgurError),
|
||||||
|
|||||||
10
src/main.rs
10
src/main.rs
@ -3,7 +3,7 @@ mod discord;
|
|||||||
mod error;
|
mod error;
|
||||||
mod imgur;
|
mod imgur;
|
||||||
|
|
||||||
use crate::config::{Args, BotConfig, GlobalData};
|
use crate::config::{Args, BotConfig, BotState, GlobalData};
|
||||||
use crate::discord::unrecognised_command_hook;
|
use crate::discord::unrecognised_command_hook;
|
||||||
use serenity::framework::standard::macros::{command, group, help, hook};
|
use serenity::framework::standard::macros::{command, group, help, hook};
|
||||||
use serenity::framework::standard::StandardFramework;
|
use serenity::framework::standard::StandardFramework;
|
||||||
@ -22,12 +22,17 @@ async fn main() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let global_data = GlobalData { args, cfg };
|
let global_data = GlobalData {
|
||||||
|
args,
|
||||||
|
cfg,
|
||||||
|
bot_state: BotState::default(),
|
||||||
|
};
|
||||||
|
|
||||||
let framework = StandardFramework::new()
|
let framework = StandardFramework::new()
|
||||||
.configure(|c| c.with_whitespace(true).prefix("!").ignore_bots(true))
|
.configure(|c| c.with_whitespace(true).prefix("!").ignore_bots(true))
|
||||||
.group(&discord::color::COLOR_GROUP)
|
.group(&discord::color::COLOR_GROUP)
|
||||||
.group(&discord::album::ALBUM_GROUP)
|
.group(&discord::album::ALBUM_GROUP)
|
||||||
|
.group(&discord::celeryman::CELERYMAN_GROUP)
|
||||||
.unrecognised_command(unrecognised_command_hook)
|
.unrecognised_command(unrecognised_command_hook)
|
||||||
.help(&discord::MY_HELP)
|
.help(&discord::MY_HELP)
|
||||||
.after(discord::after);
|
.after(discord::after);
|
||||||
@ -36,6 +41,7 @@ async fn main() {
|
|||||||
let mut client = Client::builder(&global_data.cfg.bot_token, intents)
|
let mut client = Client::builder(&global_data.cfg.bot_token, intents)
|
||||||
.framework(framework)
|
.framework(framework)
|
||||||
.type_map_insert::<GlobalData>(global_data)
|
.type_map_insert::<GlobalData>(global_data)
|
||||||
|
.event_handler(discord::Handler)
|
||||||
.await
|
.await
|
||||||
.expect("Unable to create client.");
|
.expect("Unable to create client.");
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user