Add prefix getter for custom server prefixes and Payphone mentions
This commit is contained in:
+31
-6
@@ -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<State> for ServerPrefixOrPayphoneMention {
|
||||
async fn get(
|
||||
&self,
|
||||
rt: &Runtime<State>,
|
||||
server_id: Option<u64>,
|
||||
_user_id: Option<u64>,
|
||||
) -> Vec<String> {
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user