From 38556a16dd1b6eaa2c3dc551f825265f3352432a Mon Sep 17 00:00:00 2001 From: Joscha Date: Fri, 27 Dec 2024 19:11:52 +0100 Subject: [PATCH] Make bot state readonly --- euphoxide-bot/src/command.rs | 8 ++++---- euphoxide-bot/src/command/bang.rs | 12 ++++++------ euphoxide-bot/src/command/basic.rs | 8 ++++---- euphoxide-bot/src/command/botrulez/full_help.rs | 8 ++++---- euphoxide-bot/src/command/botrulez/ping.rs | 4 ++-- euphoxide-bot/src/command/botrulez/short_help.rs | 4 ++-- euphoxide-bot/src/command/botrulez/uptime.rs | 8 ++++---- euphoxide-bot/src/command/clap.rs | 6 +++--- 8 files changed, 29 insertions(+), 29 deletions(-) diff --git a/euphoxide-bot/src/command.rs b/euphoxide-bot/src/command.rs index 4999372..9f490a2 100644 --- a/euphoxide-bot/src/command.rs +++ b/euphoxide-bot/src/command.rs @@ -118,7 +118,7 @@ pub trait Command { arg: &str, msg: &Message, ctx: &Context, - bot: &mut B, + bot: &B, ) -> Result; } @@ -149,7 +149,7 @@ impl Commands { conn: ClientConnHandle, state: State, packet: ParsedPacket, - bot: &mut B, + bot: &B, ) -> Result { let Ok(Data::SendEvent(SendEvent(msg))) = &packet.content else { return Ok(Propagate::Yes); @@ -174,7 +174,7 @@ impl Commands { pub async fn on_instance_event( &self, event: InstanceEvent, - bot: &mut B, + bot: &B, ) -> Result { if let InstanceEvent::Packet { conn, @@ -189,7 +189,7 @@ impl Commands { } } - pub async fn on_bot_event(&self, event: BotEvent, bot: &mut B) -> Result { + pub async fn on_bot_event(&self, event: BotEvent, bot: &B) -> Result { if let BotEvent::Packet { conn, state, diff --git a/euphoxide-bot/src/command/bang.rs b/euphoxide-bot/src/command/bang.rs index da2d213..778b211 100644 --- a/euphoxide-bot/src/command/bang.rs +++ b/euphoxide-bot/src/command/bang.rs @@ -47,7 +47,7 @@ impl Global { #[async_trait] impl Command for Global where - B: Send, + B: Sync, C: Command + Send + Sync, { fn info(&self, ctx: &Context) -> Info { @@ -61,7 +61,7 @@ where arg: &str, msg: &Message, ctx: &Context, - bot: &mut B, + bot: &B, ) -> Result { let Some((name, rest)) = parse_prefix_initiated(arg, &self.prefix) else { return Ok(Propagate::Yes); @@ -99,7 +99,7 @@ impl General { #[async_trait] impl Command for General where - B: Send, + B: Sync, C: Command + Send + Sync, { fn info(&self, ctx: &Context) -> Info { @@ -113,7 +113,7 @@ where arg: &str, msg: &Message, ctx: &Context, - bot: &mut B, + bot: &B, ) -> Result { let Some((name, rest)) = parse_prefix_initiated(arg, &self.prefix) else { return Ok(Propagate::Yes); @@ -158,7 +158,7 @@ impl Specific { #[async_trait] impl Command for Specific where - B: Send, + B: Sync, C: Command + Send + Sync, { fn info(&self, ctx: &Context) -> Info { @@ -173,7 +173,7 @@ where arg: &str, msg: &Message, ctx: &Context, - bot: &mut B, + bot: &B, ) -> Result { let Some((name, rest)) = parse_prefix_initiated(arg, &self.prefix) else { return Ok(Propagate::Yes); diff --git a/euphoxide-bot/src/command/basic.rs b/euphoxide-bot/src/command/basic.rs index 8e5b35c..6d943f4 100644 --- a/euphoxide-bot/src/command/basic.rs +++ b/euphoxide-bot/src/command/basic.rs @@ -51,7 +51,7 @@ impl Described { #[async_trait] impl Command for Described where - B: Send, + B: Sync, C: Command + Send + Sync, { fn info(&self, ctx: &Context) -> Info { @@ -67,7 +67,7 @@ where arg: &str, msg: &Message, ctx: &Context, - bot: &mut B, + bot: &B, ) -> Result { self.inner.execute(arg, msg, ctx, bot).await } @@ -90,7 +90,7 @@ impl Prefixed { #[async_trait] impl Command for Prefixed where - B: Send, + B: Sync, C: Command + Send + Sync, { fn info(&self, ctx: &Context) -> Info { @@ -102,7 +102,7 @@ where arg: &str, msg: &Message, ctx: &Context, - bot: &mut B, + bot: &B, ) -> Result { if let Some(rest) = arg.trim_start().strip_prefix(&self.prefix) { self.inner.execute(rest, msg, ctx, bot).await diff --git a/euphoxide-bot/src/command/botrulez/full_help.rs b/euphoxide-bot/src/command/botrulez/full_help.rs index ea44f45..47e944c 100644 --- a/euphoxide-bot/src/command/botrulez/full_help.rs +++ b/euphoxide-bot/src/command/botrulez/full_help.rs @@ -63,7 +63,7 @@ impl FullHelp { #[async_trait] impl Command for FullHelp where - B: HasCommandInfos + Send, + B: HasCommandInfos + Sync, E: From, { async fn execute( @@ -71,7 +71,7 @@ where arg: &str, msg: &Message, ctx: &Context, - bot: &mut B, + bot: &B, ) -> Result { if arg.trim().is_empty() { let reply = self.formulate_reply(ctx, bot); @@ -92,7 +92,7 @@ pub struct FullHelpArgs {} #[async_trait] impl ClapCommand for FullHelp where - B: HasCommandInfos + Send, + B: HasCommandInfos + Sync, E: From, { type Args = FullHelpArgs; @@ -102,7 +102,7 @@ where _args: Self::Args, msg: &Message, ctx: &Context, - bot: &mut B, + bot: &B, ) -> Result { let reply = self.formulate_reply(ctx, bot); ctx.reply_only(msg.id, reply).await?; diff --git a/euphoxide-bot/src/command/botrulez/ping.rs b/euphoxide-bot/src/command/botrulez/ping.rs index a90c913..7d4da58 100644 --- a/euphoxide-bot/src/command/botrulez/ping.rs +++ b/euphoxide-bot/src/command/botrulez/ping.rs @@ -31,7 +31,7 @@ where arg: &str, msg: &Message, ctx: &Context, - _bot: &mut B, + _bot: &B, ) -> Result { if arg.trim().is_empty() { ctx.reply_only(msg.id, &self.0).await?; @@ -60,7 +60,7 @@ where _args: Self::Args, msg: &Message, ctx: &Context, - _bot: &mut B, + _bot: &B, ) -> Result { ctx.reply_only(msg.id, &self.0).await?; Ok(Propagate::No) diff --git a/euphoxide-bot/src/command/botrulez/short_help.rs b/euphoxide-bot/src/command/botrulez/short_help.rs index badb4eb..249da23 100644 --- a/euphoxide-bot/src/command/botrulez/short_help.rs +++ b/euphoxide-bot/src/command/botrulez/short_help.rs @@ -25,7 +25,7 @@ where arg: &str, msg: &Message, ctx: &Context, - _bot: &mut B, + _bot: &B, ) -> Result { if arg.trim().is_empty() { ctx.reply_only(msg.id, &self.0).await?; @@ -54,7 +54,7 @@ where _args: Self::Args, msg: &Message, ctx: &Context, - _bot: &mut B, + _bot: &B, ) -> Result { ctx.reply_only(msg.id, &self.0).await?; Ok(Propagate::No) diff --git a/euphoxide-bot/src/command/botrulez/uptime.rs b/euphoxide-bot/src/command/botrulez/uptime.rs index 2fa63d4..564d89f 100644 --- a/euphoxide-bot/src/command/botrulez/uptime.rs +++ b/euphoxide-bot/src/command/botrulez/uptime.rs @@ -85,7 +85,7 @@ impl Uptime { #[async_trait] impl Command for Uptime where - B: HasStartTime + Send, + B: HasStartTime + Sync, E: From, { async fn execute( @@ -93,7 +93,7 @@ where arg: &str, msg: &Message, ctx: &Context, - bot: &mut B, + bot: &B, ) -> Result { if arg.trim().is_empty() { let reply = self.formulate_reply(ctx, bot, false); @@ -118,7 +118,7 @@ pub struct UptimeArgs { #[async_trait] impl ClapCommand for Uptime where - B: HasStartTime + Send, + B: HasStartTime + Sync, E: From, { type Args = UptimeArgs; @@ -128,7 +128,7 @@ where args: Self::Args, msg: &Message, ctx: &Context, - bot: &mut B, + bot: &B, ) -> Result { let reply = self.formulate_reply(ctx, bot, args.connected); ctx.reply_only(msg.id, reply).await?; diff --git a/euphoxide-bot/src/command/clap.rs b/euphoxide-bot/src/command/clap.rs index 1a9180a..b20edb6 100644 --- a/euphoxide-bot/src/command/clap.rs +++ b/euphoxide-bot/src/command/clap.rs @@ -15,7 +15,7 @@ pub trait ClapCommand { args: Self::Args, msg: &Message, ctx: &Context, - bot: &mut B, + bot: &B, ) -> Result; } @@ -101,7 +101,7 @@ pub struct Clap(pub C); #[async_trait] impl Command for Clap where - B: Send, + B: Sync, E: From, C: ClapCommand + Send + Sync, C::Args: Parser + Send, @@ -118,7 +118,7 @@ where arg: &str, msg: &Message, ctx: &Context, - bot: &mut B, + bot: &B, ) -> Result { let mut args = match parse_quoted_args(arg) { Ok(args) => args,