made the Option<> changes and some stylistics

This commit is contained in:
Anish Nayak
2025-08-13 15:36:57 +01:00
parent bacdc8ea0f
commit e7d380f391
10 changed files with 29 additions and 21 deletions
+1 -1
View File
@@ -5,6 +5,7 @@ CREATE KEYSPACE IF NOT EXISTS payphone
} AND TABLETS = {
'enabled': false
};
CREATE TYPE IF NOT EXISTS payphone.message (
id BIGINT,
@@ -27,7 +28,6 @@ CREATE TYPE IF NOT EXISTS payphone.message (
is_censored BOOLEAN,
);
CREATE TABLE IF NOT EXISTS payphone.users (
user_id BIGINT PRIMARY KEY,
+13 -12
View File
@@ -195,36 +195,36 @@ impl From<TwilightUser> for User {
pub struct Message {
pub id: i64,
pub author_id: i64,
pub author_name: Option<String>,
pub author_avatar_url: Option<String>,
pub author_name: String,
pub author_avatar_url: String,
pub author_mask: Option<String>,
pub content: Option<String>,
pub content: String,
pub attachments: Option<Vec<String>>,
pub sticker: Option<i64>,
pub propagation_message_id: Option<i64>,
pub propagation_channel_id: Option<i64>,
pub replying_to_id: Option<i64>,
pub is_deleted: Option<bool>,
pub is_edited: Option<bool>,
pub is_censored: Option<bool>,
pub is_deleted: bool,
pub is_edited: bool,
pub is_censored: bool,
}
impl<'a> Object<'a> for Message {
type Row = (
i64,
i64,
String,
String,
Option<String>,
Option<String>,
Option<String>,
Option<String>,
String,
Option<Vec<String>>,
Option<i64>,
Option<i64>,
Option<i64>,
Option<i64>,
Option<bool>,
Option<bool>,
Option<bool>,
bool,
bool,
bool,
);
fn from_row(row: Self::Row) -> Self {
Self {
@@ -398,6 +398,7 @@ impl Report {
)
.await
.map_err(DatabaseError::QueryError)?;
Ok(())
}
}
+2
View File
@@ -108,6 +108,7 @@ impl<T: 'static + Send + Sync + Debug> Bot<T> {
on_server_delete_handlers: Vec::new(),
}
}
pub fn message_command(mut self, command: impl MessageCommand<T> + 'static) -> Self {
self.message_commands.push(Arc::new(command));
self
@@ -200,6 +201,7 @@ impl<T: 'static + Send + Sync + Debug> Bot<T> {
}
let mut bot = self;
bot.on_interaction_handlers.insert(
0,
Arc::new(MessageCommandRunner {
+3 -2
View File
@@ -6,6 +6,7 @@ use twilight_model::{
};
use crate::framework::{
interactions::messages::InteractionResponder,
commands::messages::OriginalMessageUpdater, interactions::InteractionError, runtime::Runtime,
};
@@ -18,8 +19,8 @@ pub struct InteractionContext<T> {
impl<T> InteractionContext<T> {
pub fn send(
self: &Arc<Self>,
) -> crate::framework::interactions::messages::InteractionResponder<T> {
crate::framework::interactions::messages::InteractionResponder::new(self.clone())
) -> InteractionResponder<T> {
InteractionResponder::new(self.clone())
}
pub fn new(event: InteractionCreate, rt: Arc<Runtime<T>>, prefix: String) -> Self {
Self { event, rt, prefix }
@@ -6,9 +6,11 @@ use twilight_model::gateway::payload::incoming::InteractionCreate;
#[async_trait]
pub trait MessageCommand<T>: Send + Sync + Debug {
fn name(&self) -> &'static str;
fn description(&self) -> &'static str {
"A Payphone context menu command."
}
async fn execute(
&self,
ctx: InteractionContext<T>,
@@ -1,3 +1,4 @@
use crate::framework::interactions::InteractionError::InteractionTypeUnsent;
use async_trait::async_trait;
use std::sync::Arc;
use twilight_model::gateway::payload::incoming::InteractionCreate;
@@ -20,10 +21,7 @@ impl<T: Send + Sync + std::fmt::Debug + 'static> OnInteractionHandler<T>
async fn on_interaction(&self, event: &InteractionCreate, rt: Arc<Runtime<T>>) -> EventResult {
if let Err(e) = self.registry.execute(event, rt).await {
// Only log errors that aren't "not a message command"
if !matches!(
e,
crate::framework::interactions::InteractionError::InteractionTypeUnsent
) {
if !matches!(e, InteractionTypeUnsent) {
log::error!("Message command dispatch error: {e:?}");
}
}
+1 -1
View File
@@ -34,7 +34,7 @@ impl<T> InteractionResponder<T> {
},
)
.await
.map_err(|_| InteractionError::DeferringFailed)?;
.map_err(|_| InteractionError::RespondingFailed)?;
Ok(())
}
}
+3
View File
@@ -24,6 +24,9 @@ pub enum InteractionError {
#[error("The original message was attempted to be edited, but it failed")]
OriginalMessageEditingFailed,
#[error("Responding to the interaction failed")]
RespondingFailed,
#[error("No prefixes were returned for the event")]
PrefixesVectorEmpty,
+1
View File
@@ -12,6 +12,7 @@ use crate::{
state::State,
utils::{Bye, get_random_u64},
};
#[derive(Debug, Default)]
pub struct ReportMessageCommand;
+1 -1
View File
@@ -107,9 +107,9 @@ use std::{
sync::mpsc,
};
use crate::groups::calls::commands::ReportMessageCommand;
use crate::{
cli::{Args, Commands},
groups::calls::commands::ReportMessageCommand,
framework::bot::Bot,
groups::{
about::{commands::HelpCommand, components::HelpGoBackButton},