Make bot state readonly

This commit is contained in:
Joscha 2024-12-27 19:11:52 +01:00
parent 818b8748a1
commit 38556a16dd
8 changed files with 29 additions and 29 deletions

View file

@ -118,7 +118,7 @@ pub trait Command<B, E> {
arg: &str, arg: &str,
msg: &Message, msg: &Message,
ctx: &Context, ctx: &Context,
bot: &mut B, bot: &B,
) -> Result<Propagate, E>; ) -> Result<Propagate, E>;
} }
@ -149,7 +149,7 @@ impl<B, E> Commands<B, E> {
conn: ClientConnHandle, conn: ClientConnHandle,
state: State, state: State,
packet: ParsedPacket, packet: ParsedPacket,
bot: &mut B, bot: &B,
) -> Result<Propagate, E> { ) -> Result<Propagate, E> {
let Ok(Data::SendEvent(SendEvent(msg))) = &packet.content else { let Ok(Data::SendEvent(SendEvent(msg))) = &packet.content else {
return Ok(Propagate::Yes); return Ok(Propagate::Yes);
@ -174,7 +174,7 @@ impl<B, E> Commands<B, E> {
pub async fn on_instance_event( pub async fn on_instance_event(
&self, &self,
event: InstanceEvent, event: InstanceEvent,
bot: &mut B, bot: &B,
) -> Result<Propagate, E> { ) -> Result<Propagate, E> {
if let InstanceEvent::Packet { if let InstanceEvent::Packet {
conn, conn,
@ -189,7 +189,7 @@ impl<B, E> Commands<B, E> {
} }
} }
pub async fn on_bot_event(&self, event: BotEvent, bot: &mut B) -> Result<Propagate, E> { pub async fn on_bot_event(&self, event: BotEvent, bot: &B) -> Result<Propagate, E> {
if let BotEvent::Packet { if let BotEvent::Packet {
conn, conn,
state, state,

View file

@ -47,7 +47,7 @@ impl<C> Global<C> {
#[async_trait] #[async_trait]
impl<B, E, C> Command<B, E> for Global<C> impl<B, E, C> Command<B, E> for Global<C>
where where
B: Send, B: Sync,
C: Command<B, E> + Send + Sync, C: Command<B, E> + Send + Sync,
{ {
fn info(&self, ctx: &Context) -> Info { fn info(&self, ctx: &Context) -> Info {
@ -61,7 +61,7 @@ where
arg: &str, arg: &str,
msg: &Message, msg: &Message,
ctx: &Context, ctx: &Context,
bot: &mut B, bot: &B,
) -> Result<Propagate, E> { ) -> Result<Propagate, E> {
let Some((name, rest)) = parse_prefix_initiated(arg, &self.prefix) else { let Some((name, rest)) = parse_prefix_initiated(arg, &self.prefix) else {
return Ok(Propagate::Yes); return Ok(Propagate::Yes);
@ -99,7 +99,7 @@ impl<C> General<C> {
#[async_trait] #[async_trait]
impl<B, E, C> Command<B, E> for General<C> impl<B, E, C> Command<B, E> for General<C>
where where
B: Send, B: Sync,
C: Command<B, E> + Send + Sync, C: Command<B, E> + Send + Sync,
{ {
fn info(&self, ctx: &Context) -> Info { fn info(&self, ctx: &Context) -> Info {
@ -113,7 +113,7 @@ where
arg: &str, arg: &str,
msg: &Message, msg: &Message,
ctx: &Context, ctx: &Context,
bot: &mut B, bot: &B,
) -> Result<Propagate, E> { ) -> Result<Propagate, E> {
let Some((name, rest)) = parse_prefix_initiated(arg, &self.prefix) else { let Some((name, rest)) = parse_prefix_initiated(arg, &self.prefix) else {
return Ok(Propagate::Yes); return Ok(Propagate::Yes);
@ -158,7 +158,7 @@ impl<C> Specific<C> {
#[async_trait] #[async_trait]
impl<B, E, C> Command<B, E> for Specific<C> impl<B, E, C> Command<B, E> for Specific<C>
where where
B: Send, B: Sync,
C: Command<B, E> + Send + Sync, C: Command<B, E> + Send + Sync,
{ {
fn info(&self, ctx: &Context) -> Info { fn info(&self, ctx: &Context) -> Info {
@ -173,7 +173,7 @@ where
arg: &str, arg: &str,
msg: &Message, msg: &Message,
ctx: &Context, ctx: &Context,
bot: &mut B, bot: &B,
) -> Result<Propagate, E> { ) -> Result<Propagate, E> {
let Some((name, rest)) = parse_prefix_initiated(arg, &self.prefix) else { let Some((name, rest)) = parse_prefix_initiated(arg, &self.prefix) else {
return Ok(Propagate::Yes); return Ok(Propagate::Yes);

View file

@ -51,7 +51,7 @@ impl<C> Described<C> {
#[async_trait] #[async_trait]
impl<B, E, C> Command<B, E> for Described<C> impl<B, E, C> Command<B, E> for Described<C>
where where
B: Send, B: Sync,
C: Command<B, E> + Send + Sync, C: Command<B, E> + Send + Sync,
{ {
fn info(&self, ctx: &Context) -> Info { fn info(&self, ctx: &Context) -> Info {
@ -67,7 +67,7 @@ where
arg: &str, arg: &str,
msg: &Message, msg: &Message,
ctx: &Context, ctx: &Context,
bot: &mut B, bot: &B,
) -> Result<Propagate, E> { ) -> Result<Propagate, E> {
self.inner.execute(arg, msg, ctx, bot).await self.inner.execute(arg, msg, ctx, bot).await
} }
@ -90,7 +90,7 @@ impl<C> Prefixed<C> {
#[async_trait] #[async_trait]
impl<B, E, C> Command<B, E> for Prefixed<C> impl<B, E, C> Command<B, E> for Prefixed<C>
where where
B: Send, B: Sync,
C: Command<B, E> + Send + Sync, C: Command<B, E> + Send + Sync,
{ {
fn info(&self, ctx: &Context) -> Info { fn info(&self, ctx: &Context) -> Info {
@ -102,7 +102,7 @@ where
arg: &str, arg: &str,
msg: &Message, msg: &Message,
ctx: &Context, ctx: &Context,
bot: &mut B, bot: &B,
) -> Result<Propagate, E> { ) -> Result<Propagate, E> {
if let Some(rest) = arg.trim_start().strip_prefix(&self.prefix) { if let Some(rest) = arg.trim_start().strip_prefix(&self.prefix) {
self.inner.execute(rest, msg, ctx, bot).await self.inner.execute(rest, msg, ctx, bot).await

View file

@ -63,7 +63,7 @@ impl FullHelp {
#[async_trait] #[async_trait]
impl<B, E> Command<B, E> for FullHelp impl<B, E> Command<B, E> for FullHelp
where where
B: HasCommandInfos + Send, B: HasCommandInfos + Sync,
E: From<euphoxide::Error>, E: From<euphoxide::Error>,
{ {
async fn execute( async fn execute(
@ -71,7 +71,7 @@ where
arg: &str, arg: &str,
msg: &Message, msg: &Message,
ctx: &Context, ctx: &Context,
bot: &mut B, bot: &B,
) -> Result<Propagate, E> { ) -> Result<Propagate, E> {
if arg.trim().is_empty() { if arg.trim().is_empty() {
let reply = self.formulate_reply(ctx, bot); let reply = self.formulate_reply(ctx, bot);
@ -92,7 +92,7 @@ pub struct FullHelpArgs {}
#[async_trait] #[async_trait]
impl<B, E> ClapCommand<B, E> for FullHelp impl<B, E> ClapCommand<B, E> for FullHelp
where where
B: HasCommandInfos + Send, B: HasCommandInfos + Sync,
E: From<euphoxide::Error>, E: From<euphoxide::Error>,
{ {
type Args = FullHelpArgs; type Args = FullHelpArgs;
@ -102,7 +102,7 @@ where
_args: Self::Args, _args: Self::Args,
msg: &Message, msg: &Message,
ctx: &Context, ctx: &Context,
bot: &mut B, bot: &B,
) -> Result<Propagate, E> { ) -> Result<Propagate, E> {
let reply = self.formulate_reply(ctx, bot); let reply = self.formulate_reply(ctx, bot);
ctx.reply_only(msg.id, reply).await?; ctx.reply_only(msg.id, reply).await?;

View file

@ -31,7 +31,7 @@ where
arg: &str, arg: &str,
msg: &Message, msg: &Message,
ctx: &Context, ctx: &Context,
_bot: &mut B, _bot: &B,
) -> Result<Propagate, E> { ) -> Result<Propagate, E> {
if arg.trim().is_empty() { if arg.trim().is_empty() {
ctx.reply_only(msg.id, &self.0).await?; ctx.reply_only(msg.id, &self.0).await?;
@ -60,7 +60,7 @@ where
_args: Self::Args, _args: Self::Args,
msg: &Message, msg: &Message,
ctx: &Context, ctx: &Context,
_bot: &mut B, _bot: &B,
) -> Result<Propagate, E> { ) -> Result<Propagate, E> {
ctx.reply_only(msg.id, &self.0).await?; ctx.reply_only(msg.id, &self.0).await?;
Ok(Propagate::No) Ok(Propagate::No)

View file

@ -25,7 +25,7 @@ where
arg: &str, arg: &str,
msg: &Message, msg: &Message,
ctx: &Context, ctx: &Context,
_bot: &mut B, _bot: &B,
) -> Result<Propagate, E> { ) -> Result<Propagate, E> {
if arg.trim().is_empty() { if arg.trim().is_empty() {
ctx.reply_only(msg.id, &self.0).await?; ctx.reply_only(msg.id, &self.0).await?;
@ -54,7 +54,7 @@ where
_args: Self::Args, _args: Self::Args,
msg: &Message, msg: &Message,
ctx: &Context, ctx: &Context,
_bot: &mut B, _bot: &B,
) -> Result<Propagate, E> { ) -> Result<Propagate, E> {
ctx.reply_only(msg.id, &self.0).await?; ctx.reply_only(msg.id, &self.0).await?;
Ok(Propagate::No) Ok(Propagate::No)

View file

@ -85,7 +85,7 @@ impl Uptime {
#[async_trait] #[async_trait]
impl<B, E> Command<B, E> for Uptime impl<B, E> Command<B, E> for Uptime
where where
B: HasStartTime + Send, B: HasStartTime + Sync,
E: From<euphoxide::Error>, E: From<euphoxide::Error>,
{ {
async fn execute( async fn execute(
@ -93,7 +93,7 @@ where
arg: &str, arg: &str,
msg: &Message, msg: &Message,
ctx: &Context, ctx: &Context,
bot: &mut B, bot: &B,
) -> Result<Propagate, E> { ) -> Result<Propagate, E> {
if arg.trim().is_empty() { if arg.trim().is_empty() {
let reply = self.formulate_reply(ctx, bot, false); let reply = self.formulate_reply(ctx, bot, false);
@ -118,7 +118,7 @@ pub struct UptimeArgs {
#[async_trait] #[async_trait]
impl<B, E> ClapCommand<B, E> for Uptime impl<B, E> ClapCommand<B, E> for Uptime
where where
B: HasStartTime + Send, B: HasStartTime + Sync,
E: From<euphoxide::Error>, E: From<euphoxide::Error>,
{ {
type Args = UptimeArgs; type Args = UptimeArgs;
@ -128,7 +128,7 @@ where
args: Self::Args, args: Self::Args,
msg: &Message, msg: &Message,
ctx: &Context, ctx: &Context,
bot: &mut B, bot: &B,
) -> Result<Propagate, E> { ) -> Result<Propagate, E> {
let reply = self.formulate_reply(ctx, bot, args.connected); let reply = self.formulate_reply(ctx, bot, args.connected);
ctx.reply_only(msg.id, reply).await?; ctx.reply_only(msg.id, reply).await?;

View file

@ -15,7 +15,7 @@ pub trait ClapCommand<B, E> {
args: Self::Args, args: Self::Args,
msg: &Message, msg: &Message,
ctx: &Context, ctx: &Context,
bot: &mut B, bot: &B,
) -> Result<Propagate, E>; ) -> Result<Propagate, E>;
} }
@ -101,7 +101,7 @@ pub struct Clap<C>(pub C);
#[async_trait] #[async_trait]
impl<B, E, C> Command<B, E> for Clap<C> impl<B, E, C> Command<B, E> for Clap<C>
where where
B: Send, B: Sync,
E: From<euphoxide::Error>, E: From<euphoxide::Error>,
C: ClapCommand<B, E> + Send + Sync, C: ClapCommand<B, E> + Send + Sync,
C::Args: Parser + Send, C::Args: Parser + Send,
@ -118,7 +118,7 @@ where
arg: &str, arg: &str,
msg: &Message, msg: &Message,
ctx: &Context, ctx: &Context,
bot: &mut B, bot: &B,
) -> Result<Propagate, E> { ) -> Result<Propagate, E> {
let mut args = match parse_quoted_args(arg) { let mut args = match parse_quoted_args(arg) {
Ok(args) => args, Ok(args) => args,