Add support for extras, conditionally displaying commands in the help command, and start working on moderation commands

This commit is contained in:
2025-08-22 18:06:52 -03:00
parent 55ae1c8937
commit 8868b18be3
41 changed files with 1075 additions and 368 deletions
+40 -7
View File
@@ -101,6 +101,7 @@
//! ```
use std::{
error::Error,
net::{IpAddr, Ipv4Addr, SocketAddr},
path::Path,
process::Command,
@@ -115,17 +116,22 @@ use tokio::net::TcpListener;
use tower_http::services::ServeDir;
use twilight_cache_inmemory::ResourceType;
use twilight_gateway::{Intents, ShardId};
use twilight_model::gateway::{
payload::outgoing::update_presence::UpdatePresencePayload,
presence::{Activity, ActivityType, Status},
use twilight_model::{
gateway::{
payload::outgoing::update_presence::UpdatePresencePayload,
presence::{Activity, ActivityType, Status},
},
user::User as TwilightUser,
};
use crate::{
cli::{Args, Commands},
constants::DEFAULT_PREFIX,
database::models::Server,
database::models::{Server, User},
extras::Extras,
framework::{
bot::{Bot, PrefixGetter},
commands::extras::ExtrasGetter,
runtime::Runtime,
},
groups::{
@@ -136,6 +142,7 @@ use crate::{
},
gateway::events::{ReadyHandler, ReconnectHandler},
leveling::{commands::LeaderboardCommand, events::MessageLevelingHandler},
moderation::commands::{IncidentsCommand, ModeratorCommand},
servers::{
commands::PrefixCommand,
events::{ServerCreateHandler, ServerDeleteHandler, ServerUpdateHandler},
@@ -148,6 +155,7 @@ mod cli;
mod constants;
mod database;
mod discord;
mod extras;
mod framework;
mod groups;
mod logging;
@@ -176,6 +184,7 @@ pub async fn main() {
database_password,
shard,
redis_urls,
bot_owner_id,
} => {
start(
token,
@@ -184,6 +193,7 @@ pub async fn main() {
database_password,
shard.into(),
redis_urls,
bot_owner_id
)
.await;
}
@@ -197,10 +207,10 @@ pub async fn main() {
struct ServerPrefixOrPayphoneMention;
#[async_trait]
impl PrefixGetter<State> for ServerPrefixOrPayphoneMention {
impl PrefixGetter<State, Extras> for ServerPrefixOrPayphoneMention {
async fn get(
&self,
rt: &Runtime<State>,
rt: &Runtime<State, Extras>,
server_id: Option<u64>,
_user_id: Option<u64>,
) -> Vec<String> {
@@ -218,6 +228,25 @@ impl PrefixGetter<State> for ServerPrefixOrPayphoneMention {
}
}
struct PayphoneExtrasGetter;
#[async_trait]
impl ExtrasGetter<State> for PayphoneExtrasGetter {
type Extras = Extras;
async fn get_extra(
&self,
user: &TwilightUser,
rt: &Runtime<State, Self::Extras>,
) -> Result<Self::Extras, Box<dyn Error>> {
log::trace!("Getting extras!");
let user = User::get_or_create_and_set_last_seen(user.clone(), &rt.state.db).await?;
Ok(Extras { user })
}
}
/// Starts a Payphone shard.
async fn start(
token: String,
@@ -226,6 +255,7 @@ async fn start(
database_password: Option<String>,
shard: ShardId,
redis_urls: Vec<String>,
bot_owner_id: u64,
) {
log::info!("Welcome to Payphone, Nyeki!");
log::info!(
@@ -246,9 +276,10 @@ async fn start(
let state = State {
db,
redis: redis_pool,
bot_owner_id
};
let bot = Bot::new(state, ServerPrefixOrPayphoneMention)
let bot = Bot::new(state, ServerPrefixOrPayphoneMention, PayphoneExtrasGetter)
.shard(shard)
.intent(Intents::GUILDS)
.intent(Intents::GUILD_MESSAGES)
@@ -260,6 +291,8 @@ async fn start(
.command(FriendRequestCommand)
.command(PrefixCommand)
.command(LeaderboardCommand)
.command(ModeratorCommand)
.command(IncidentsCommand)
.component(HelpGoBackButton)
.cache_resource_type(ResourceType::GUILD)
.cache_resource_type(ResourceType::CHANNEL)