feat(bot): refactor a bit and start working on miiverse mod applications
This commit is contained in:
parent
aebdcbb0e5
commit
151a8285a6
6 changed files with 155 additions and 57 deletions
|
|
@ -30,7 +30,11 @@ features = [
|
|||
|
||||
[dependencies.serenity]
|
||||
version = "0.12.4"
|
||||
features = ["interactions_endpoint"]
|
||||
features = [
|
||||
"interactions_endpoint",
|
||||
"utils",
|
||||
"collector"
|
||||
]
|
||||
|
||||
[build-dependencies]
|
||||
serde = { version = "1.0.217", features = ["derive"] }
|
||||
|
|
|
|||
65
src/ayy.rs
Normal file
65
src/ayy.rs
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use serenity::all::{Context, EventHandler, Message};
|
||||
use serenity::async_trait;
|
||||
|
||||
static AY_REGEX: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new("(^|\\s)[Aa][Yy]+($|\\s)").expect("invalid regex"));
|
||||
pub struct AyyHandler;
|
||||
|
||||
#[async_trait]
|
||||
impl EventHandler for AyyHandler {
|
||||
async fn message(&self, ctx: Context, msg: Message) {
|
||||
if msg.author.bot{
|
||||
return;
|
||||
}
|
||||
|
||||
if AY_REGEX.is_match(&msg.content){
|
||||
let mut output = "".to_owned();
|
||||
let mut lastpos = 0;
|
||||
for ay in AY_REGEX.find_iter(&msg.content){
|
||||
output += &msg.content[lastpos..ay.start()];
|
||||
|
||||
lastpos = ay.end();
|
||||
|
||||
let mut str = ay.as_str();
|
||||
|
||||
if str.starts_with(' '){
|
||||
str = &str[1..];
|
||||
output.push(' ');
|
||||
}
|
||||
|
||||
let mut chars = str.chars();
|
||||
|
||||
let Some(first_char) = chars.next() else{
|
||||
return
|
||||
};
|
||||
|
||||
if first_char.is_lowercase(){
|
||||
output.push_str("lma")
|
||||
} else {
|
||||
output.push_str("LMA")
|
||||
}
|
||||
|
||||
for char in chars{
|
||||
if char == ' '{
|
||||
output.push(' ');
|
||||
break;
|
||||
}
|
||||
|
||||
if char.is_lowercase(){
|
||||
output.push('o');
|
||||
} else {
|
||||
output.push('O');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
output += &msg.content[lastpos..];
|
||||
|
||||
msg.reply(&ctx.http, output).await.ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
22
src/cheeseburger.rs
Normal file
22
src/cheeseburger.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use serenity::all::{Context, CreateCommand, EventHandler, Message};
|
||||
use serenity::async_trait;
|
||||
use crate::error_codes::ErrorCodeHandler;
|
||||
|
||||
static CHEESEBURGER_REGEX: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new("[Cc]heeseburger(s)?").expect("invalid regex"));
|
||||
pub struct CheeseburgerHandler;
|
||||
|
||||
#[async_trait]
|
||||
impl EventHandler for CheeseburgerHandler {
|
||||
async fn message(&self, ctx: Context, msg: Message) {
|
||||
if msg.author.bot{
|
||||
return;
|
||||
}
|
||||
|
||||
if CHEESEBURGER_REGEX.is_match(&msg.content){
|
||||
msg.reply(&ctx.http, "currently scratching the FUCK out of my bum bum idgaf").await.ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -55,11 +55,8 @@ impl Default for ErrorInfo{
|
|||
static ERROR_CODE_REGEX: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new("\\d\\d\\d-\\d\\d\\d\\d").expect("invalid regex"));
|
||||
|
||||
static CHEESEBURGER_REGEX: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new("[Cc]heeseburger(s)?").expect("invalid regex"));
|
||||
|
||||
static AY_REGEX: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new("(^|\\s)[Aa][Yy]+($|\\s)").expect("invalid regex"));
|
||||
|
||||
|
||||
pub struct ErrorCodeHandler;
|
||||
|
||||
|
|
@ -155,58 +152,6 @@ impl EventHandler for ErrorCodeHandler {
|
|||
|
||||
start_timed_explanation_collapse(msg, ctx.http.clone(), str_code);
|
||||
}
|
||||
|
||||
if CHEESEBURGER_REGEX.is_match(&msg.content){
|
||||
msg.reply(&ctx.http, "currently scratching the FUCK out of my bum bum idgaf").await.ok();
|
||||
}
|
||||
|
||||
if AY_REGEX.is_match(&msg.content){
|
||||
let mut output = "".to_owned();
|
||||
let mut lastpos = 0;
|
||||
for ay in AY_REGEX.find_iter(&msg.content){
|
||||
output += &msg.content[lastpos..ay.start()];
|
||||
|
||||
lastpos = ay.end();
|
||||
|
||||
let mut str = ay.as_str();
|
||||
|
||||
if str.starts_with(' '){
|
||||
str = &str[1..];
|
||||
output.push(' ');
|
||||
}
|
||||
|
||||
let mut chars = str.chars();
|
||||
|
||||
let Some(first_char) = chars.next() else{
|
||||
return
|
||||
};
|
||||
|
||||
if first_char.is_lowercase(){
|
||||
output.push_str("lma")
|
||||
} else {
|
||||
output.push_str("LMA")
|
||||
}
|
||||
|
||||
for char in chars{
|
||||
if char == ' '{
|
||||
output.push(' ');
|
||||
break;
|
||||
}
|
||||
|
||||
if char.is_lowercase(){
|
||||
output.push('o');
|
||||
} else {
|
||||
output.push('O');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
output += &msg.content[lastpos..];
|
||||
|
||||
msg.reply(&ctx.http, output).await.ok();
|
||||
}
|
||||
}
|
||||
|
||||
async fn interaction_create(&self, ctx: Context, interaction: Interaction) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
mod error_codes;
|
||||
mod cheeseburger;
|
||||
mod ayy;
|
||||
mod miiverse_mod_application;
|
||||
|
||||
use std::env;
|
||||
use once_cell::sync::Lazy;
|
||||
|
|
@ -21,6 +24,9 @@ async fn main() {
|
|||
|
||||
let mut client = Client::builder(&token, intents)
|
||||
.event_handler(error_codes::ErrorCodeHandler)
|
||||
.event_handler(ayy::AyyHandler)
|
||||
.event_handler(cheeseburger::CheeseburgerHandler)
|
||||
.event_handler(miiverse_mod_application::MiiverseModApplicationHandler::default())
|
||||
.await.expect("unable to create client");
|
||||
|
||||
client.start().await.expect("error running bot");
|
||||
|
|
|
|||
56
src/miiverse_mod_application.rs
Normal file
56
src/miiverse_mod_application.rs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
|
||||
use crate::cheeseburger::CheeseburgerHandler;
|
||||
use serenity::all::{ActivityData, ActivityType, Command, CommandId, Context, CreateCommand, CreateInputText, CreateQuickModal, EventHandler, Guild, GuildId, InputTextStyle, Interaction, Message, Ready};
|
||||
use serenity::async_trait;
|
||||
use tokio::sync::OnceCell;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct MiiverseModApplicationHandler{
|
||||
command_id: OnceCell<CommandId>
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl EventHandler for MiiverseModApplicationHandler {
|
||||
async fn ready(&self, ctx: Context, data_about_bot: Ready) {
|
||||
let command = CreateCommand::new("miivserse-mod-application")
|
||||
.description("Apply for miiverse moderator");
|
||||
|
||||
let cmd = Command::create_global_command(&ctx.http, command).await.expect("unable to register command");
|
||||
|
||||
self.command_id.set(cmd.id).ok();
|
||||
}
|
||||
|
||||
async fn interaction_create(&self, ctx: Context, interaction: Interaction) {
|
||||
let Interaction::Command(cmd) = interaction else {
|
||||
return;
|
||||
};
|
||||
|
||||
let Some(id) = self.command_id.get() else {
|
||||
return;
|
||||
};
|
||||
|
||||
if cmd.data.id != *id{
|
||||
return;
|
||||
}
|
||||
|
||||
let main_field = CreateInputText::new(
|
||||
InputTextStyle::Paragraph,
|
||||
"Text",
|
||||
"MAIN_CONTENT"
|
||||
);
|
||||
|
||||
let modal = CreateQuickModal::new("Miiverse Moderator Application Form")
|
||||
.field(main_field);
|
||||
|
||||
let response = match cmd.quick_modal(&ctx, modal).await{
|
||||
Ok(v) => v,
|
||||
Err(e) => { eprintln!("{}", e); return }
|
||||
};
|
||||
|
||||
let Some(response) = response else {
|
||||
return
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue