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

View file

@ -47,7 +47,7 @@ impl<C> Global<C> {
#[async_trait]
impl<B, E, C> Command<B, E> for Global<C>
where
B: Send,
B: Sync,
C: Command<B, E> + 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<Propagate, E> {
let Some((name, rest)) = parse_prefix_initiated(arg, &self.prefix) else {
return Ok(Propagate::Yes);
@ -99,7 +99,7 @@ impl<C> General<C> {
#[async_trait]
impl<B, E, C> Command<B, E> for General<C>
where
B: Send,
B: Sync,
C: Command<B, E> + 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<Propagate, E> {
let Some((name, rest)) = parse_prefix_initiated(arg, &self.prefix) else {
return Ok(Propagate::Yes);
@ -158,7 +158,7 @@ impl<C> Specific<C> {
#[async_trait]
impl<B, E, C> Command<B, E> for Specific<C>
where
B: Send,
B: Sync,
C: Command<B, E> + 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<Propagate, E> {
let Some((name, rest)) = parse_prefix_initiated(arg, &self.prefix) else {
return Ok(Propagate::Yes);

View file

@ -51,7 +51,7 @@ impl<C> Described<C> {
#[async_trait]
impl<B, E, C> Command<B, E> for Described<C>
where
B: Send,
B: Sync,
C: Command<B, E> + 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<Propagate, E> {
self.inner.execute(arg, msg, ctx, bot).await
}
@ -90,7 +90,7 @@ impl<C> Prefixed<C> {
#[async_trait]
impl<B, E, C> Command<B, E> for Prefixed<C>
where
B: Send,
B: Sync,
C: Command<B, E> + 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<Propagate, E> {
if let Some(rest) = arg.trim_start().strip_prefix(&self.prefix) {
self.inner.execute(rest, msg, ctx, bot).await

View file

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

View file

@ -31,7 +31,7 @@ where
arg: &str,
msg: &Message,
ctx: &Context,
_bot: &mut B,
_bot: &B,
) -> Result<Propagate, E> {
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<Propagate, E> {
ctx.reply_only(msg.id, &self.0).await?;
Ok(Propagate::No)

View file

@ -25,7 +25,7 @@ where
arg: &str,
msg: &Message,
ctx: &Context,
_bot: &mut B,
_bot: &B,
) -> Result<Propagate, E> {
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<Propagate, E> {
ctx.reply_only(msg.id, &self.0).await?;
Ok(Propagate::No)

View file

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

View file

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