diff --git a/src/main.rs b/src/main.rs index 6ae855c..5cdd0f5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -107,6 +107,7 @@ use std::{ sync::mpsc, }; +use async_trait::async_trait; use axum::{Router, response::Redirect, routing}; use clap::Parser; use notify::{Event, EventKind, Watcher}; @@ -115,9 +116,10 @@ use tower_http::services::ServeDir; use twilight_gateway::Intents; use crate::{ - cli::{Args, Commands}, - framework::bot::Bot, - groups::{ + cli::{Args, Commands}, constants::DEFAULT_PREFIX, database::models::Server, framework::{ + bot::{Bot, PrefixGetter}, + runtime::Runtime, + }, groups::{ about::{commands::HelpCommand, components::HelpGoBackButton}, calls::{ commands::{CallCommand, HangupCommand, SkipCommand}, @@ -125,8 +127,7 @@ use crate::{ }, gateway::events::{ReadyHandler, ReconnectHandler}, servers::events::{ServerCreateHandler, ServerDeleteHandler, ServerUpdateHandler}, - }, - state::State, + }, state::State }; mod cli; @@ -166,6 +167,30 @@ pub async fn main() { } } +struct ServerPrefixOrPayphoneMention; + +#[async_trait] +impl PrefixGetter for ServerPrefixOrPayphoneMention { + async fn get( + &self, + rt: &Runtime, + server_id: Option, + _user_id: Option, + ) -> Vec { + let mention = format!("<@{}>", rt.app.bot.as_ref().unwrap().id); + + let default_prefixes = vec![DEFAULT_PREFIX.to_string(), mention.clone()]; + + if let Some(server_id) = server_id { + if let Ok(Some(server)) = Server::get_by_id(server_id, &rt.state.db).await { + return vec![server.prefix, mention]; + } + } + + default_prefixes + } +} + /// Starts a Payphone shard. /// /// TODO: Support multiple shards. @@ -184,7 +209,7 @@ async fn start(token: String, database_addr: String) { let state = State { db }; - let bot = Bot::new(state, ["p."]) + let bot = Bot::new(state, ServerPrefixOrPayphoneMention) .intent(Intents::GUILDS) .intent(Intents::GUILD_MESSAGES) .intent(Intents::MESSAGE_CONTENT)