Remove generic bot state
This commit is contained in:
parent
c356c5f2ae
commit
51ee7b9246
9 changed files with 53 additions and 69 deletions
|
|
@ -47,10 +47,9 @@ impl<C> Global<C> {
|
|||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<S, E, C> Command<S, E> for Global<C>
|
||||
impl<E, C> Command<E> for Global<C>
|
||||
where
|
||||
S: Send + Sync,
|
||||
C: Command<S, E> + Sync,
|
||||
C: Command<E> + Sync,
|
||||
{
|
||||
fn info(&self, ctx: &Context) -> Info {
|
||||
self.inner
|
||||
|
|
@ -63,7 +62,7 @@ where
|
|||
arg: &str,
|
||||
msg: &Message,
|
||||
ctx: &Context,
|
||||
bot: &Bot<S, E>,
|
||||
bot: &Bot<E>,
|
||||
) -> Result<Propagate, E> {
|
||||
let Some((name, rest)) = parse_prefix_initiated(arg, &self.prefix) else {
|
||||
return Ok(Propagate::Yes);
|
||||
|
|
@ -99,10 +98,9 @@ impl<C> General<C> {
|
|||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<S, E, C> Command<S, E> for General<C>
|
||||
impl<E, C> Command<E> for General<C>
|
||||
where
|
||||
S: Send + Sync,
|
||||
C: Command<S, E> + Sync,
|
||||
C: Command<E> + Sync,
|
||||
{
|
||||
fn info(&self, ctx: &Context) -> Info {
|
||||
self.inner
|
||||
|
|
@ -115,7 +113,7 @@ where
|
|||
arg: &str,
|
||||
msg: &Message,
|
||||
ctx: &Context,
|
||||
bot: &Bot<S, E>,
|
||||
bot: &Bot<E>,
|
||||
) -> Result<Propagate, E> {
|
||||
let Some((name, rest)) = parse_prefix_initiated(arg, &self.prefix) else {
|
||||
return Ok(Propagate::Yes);
|
||||
|
|
@ -158,10 +156,9 @@ impl<C> Specific<C> {
|
|||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<S, E, C> Command<S, E> for Specific<C>
|
||||
impl<E, C> Command<E> for Specific<C>
|
||||
where
|
||||
S: Send + Sync,
|
||||
C: Command<S, E> + Sync,
|
||||
C: Command<E> + Sync,
|
||||
{
|
||||
fn info(&self, ctx: &Context) -> Info {
|
||||
let nick = nick::mention(&ctx.joined.session.name);
|
||||
|
|
@ -175,7 +172,7 @@ where
|
|||
arg: &str,
|
||||
msg: &Message,
|
||||
ctx: &Context,
|
||||
bot: &Bot<S, E>,
|
||||
bot: &Bot<E>,
|
||||
) -> Result<Propagate, E> {
|
||||
let Some((name, rest)) = parse_prefix_initiated(arg, &self.prefix) else {
|
||||
return Ok(Propagate::Yes);
|
||||
|
|
|
|||
|
|
@ -51,10 +51,9 @@ impl<C> Described<C> {
|
|||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<S, E, C> Command<S, E> for Described<C>
|
||||
impl<E, C> Command<E> for Described<C>
|
||||
where
|
||||
S: Send + Sync,
|
||||
C: Command<S, E> + Sync,
|
||||
C: Command<E> + Sync,
|
||||
{
|
||||
fn info(&self, ctx: &Context) -> Info {
|
||||
let info = self.inner.info(ctx);
|
||||
|
|
@ -69,7 +68,7 @@ where
|
|||
arg: &str,
|
||||
msg: &Message,
|
||||
ctx: &Context,
|
||||
bot: &Bot<S, E>,
|
||||
bot: &Bot<E>,
|
||||
) -> Result<Propagate, E> {
|
||||
self.inner.execute(arg, msg, ctx, bot).await
|
||||
}
|
||||
|
|
@ -90,10 +89,9 @@ impl<C> Prefixed<C> {
|
|||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<S, E, C> Command<S, E> for Prefixed<C>
|
||||
impl<E, C> Command<E> for Prefixed<C>
|
||||
where
|
||||
S: Send + Sync,
|
||||
C: Command<S, E> + Sync,
|
||||
C: Command<E> + Sync,
|
||||
{
|
||||
fn info(&self, ctx: &Context) -> Info {
|
||||
self.inner.info(ctx).with_prepended_trigger(&self.prefix)
|
||||
|
|
@ -104,7 +102,7 @@ where
|
|||
arg: &str,
|
||||
msg: &Message,
|
||||
ctx: &Context,
|
||||
bot: &Bot<S, E>,
|
||||
bot: &Bot<E>,
|
||||
) -> Result<Propagate, E> {
|
||||
if let Some(rest) = arg.trim_start().strip_prefix(&self.prefix) {
|
||||
self.inner.execute(rest, msg, ctx, bot).await
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ impl FullHelp {
|
|||
self
|
||||
}
|
||||
|
||||
fn formulate_reply<S, E>(&self, ctx: &Context, bot: &Bot<S, E>) -> String {
|
||||
fn formulate_reply<E>(&self, ctx: &Context, bot: &Bot<E>) -> String {
|
||||
let mut result = String::new();
|
||||
|
||||
if !self.before.is_empty() {
|
||||
|
|
@ -60,9 +60,8 @@ impl FullHelp {
|
|||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<S, E> Command<S, E> for FullHelp
|
||||
impl<E> Command<E> for FullHelp
|
||||
where
|
||||
S: Send + Sync,
|
||||
E: From<euphoxide::Error>,
|
||||
{
|
||||
async fn execute(
|
||||
|
|
@ -70,7 +69,7 @@ where
|
|||
arg: &str,
|
||||
msg: &Message,
|
||||
ctx: &Context,
|
||||
bot: &Bot<S, E>,
|
||||
bot: &Bot<E>,
|
||||
) -> Result<Propagate, E> {
|
||||
if arg.trim().is_empty() {
|
||||
let reply = self.formulate_reply(ctx, bot);
|
||||
|
|
@ -89,9 +88,8 @@ pub struct FullHelpArgs {}
|
|||
|
||||
#[cfg(feature = "clap")]
|
||||
#[async_trait]
|
||||
impl<S, E> ClapCommand<S, E> for FullHelp
|
||||
impl<E> ClapCommand<E> for FullHelp
|
||||
where
|
||||
S: Send + Sync,
|
||||
E: From<euphoxide::Error>,
|
||||
{
|
||||
type Args = FullHelpArgs;
|
||||
|
|
@ -101,7 +99,7 @@ where
|
|||
_args: Self::Args,
|
||||
msg: &Message,
|
||||
ctx: &Context,
|
||||
bot: &Bot<S, E>,
|
||||
bot: &Bot<E>,
|
||||
) -> Result<Propagate, E> {
|
||||
let reply = self.formulate_reply(ctx, bot);
|
||||
ctx.reply_only(msg.id, reply).await?;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ impl Default for Ping {
|
|||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<S, E> Command<S, E> for Ping
|
||||
impl<E> Command<E> for Ping
|
||||
where
|
||||
E: From<euphoxide::Error>,
|
||||
{
|
||||
|
|
@ -34,7 +34,7 @@ where
|
|||
arg: &str,
|
||||
msg: &Message,
|
||||
ctx: &Context,
|
||||
_bot: &Bot<S, E>,
|
||||
_bot: &Bot<E>,
|
||||
) -> Result<Propagate, E> {
|
||||
if arg.trim().is_empty() {
|
||||
ctx.reply_only(msg.id, &self.0).await?;
|
||||
|
|
@ -52,7 +52,7 @@ pub struct PingArgs {}
|
|||
|
||||
#[cfg(feature = "clap")]
|
||||
#[async_trait]
|
||||
impl<S, E> ClapCommand<S, E> for Ping
|
||||
impl<E> ClapCommand<E> for Ping
|
||||
where
|
||||
E: From<euphoxide::Error>,
|
||||
{
|
||||
|
|
@ -63,7 +63,7 @@ where
|
|||
_args: Self::Args,
|
||||
msg: &Message,
|
||||
ctx: &Context,
|
||||
_bot: &Bot<S, E>,
|
||||
_bot: &Bot<E>,
|
||||
) -> Result<Propagate, E> {
|
||||
ctx.reply_only(msg.id, &self.0).await?;
|
||||
Ok(Propagate::No)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ impl ShortHelp {
|
|||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<S, E> Command<S, E> for ShortHelp
|
||||
impl<E> Command<E> for ShortHelp
|
||||
where
|
||||
E: From<euphoxide::Error>,
|
||||
{
|
||||
|
|
@ -28,7 +28,7 @@ where
|
|||
arg: &str,
|
||||
msg: &Message,
|
||||
ctx: &Context,
|
||||
_bot: &Bot<S, E>,
|
||||
_bot: &Bot<E>,
|
||||
) -> Result<Propagate, E> {
|
||||
if arg.trim().is_empty() {
|
||||
ctx.reply_only(msg.id, &self.0).await?;
|
||||
|
|
@ -46,7 +46,7 @@ pub struct ShortHelpArgs {}
|
|||
|
||||
#[cfg(feature = "clap")]
|
||||
#[async_trait]
|
||||
impl<S, E> ClapCommand<S, E> for ShortHelp
|
||||
impl<E> ClapCommand<E> for ShortHelp
|
||||
where
|
||||
E: From<euphoxide::Error>,
|
||||
{
|
||||
|
|
@ -57,7 +57,7 @@ where
|
|||
_args: Self::Args,
|
||||
msg: &Message,
|
||||
ctx: &Context,
|
||||
_bot: &Bot<S, E>,
|
||||
_bot: &Bot<E>,
|
||||
) -> Result<Propagate, E> {
|
||||
ctx.reply_only(msg.id, &self.0).await?;
|
||||
Ok(Propagate::No)
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ pub trait HasStartTime {
|
|||
}
|
||||
|
||||
impl Uptime {
|
||||
fn formulate_reply<S, E>(&self, ctx: &Context, bot: &Bot<S, E>, connected: bool) -> String {
|
||||
fn formulate_reply<E>(&self, ctx: &Context, bot: &Bot<E>, connected: bool) -> String {
|
||||
let start = bot.start_time;
|
||||
let now = Timestamp::now();
|
||||
|
||||
|
|
@ -86,9 +86,8 @@ impl Uptime {
|
|||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<S, E> Command<S, E> for Uptime
|
||||
impl<E> Command<E> for Uptime
|
||||
where
|
||||
S: Send + Sync,
|
||||
E: From<euphoxide::Error>,
|
||||
{
|
||||
async fn execute(
|
||||
|
|
@ -96,7 +95,7 @@ where
|
|||
arg: &str,
|
||||
msg: &Message,
|
||||
ctx: &Context,
|
||||
bot: &Bot<S, E>,
|
||||
bot: &Bot<E>,
|
||||
) -> Result<Propagate, E> {
|
||||
if arg.trim().is_empty() {
|
||||
let reply = self.formulate_reply(ctx, bot, false);
|
||||
|
|
@ -119,9 +118,8 @@ pub struct UptimeArgs {
|
|||
|
||||
#[cfg(feature = "clap")]
|
||||
#[async_trait]
|
||||
impl<S, E> ClapCommand<S, E> for Uptime
|
||||
impl<E> ClapCommand<E> for Uptime
|
||||
where
|
||||
S: Send + Sync,
|
||||
E: From<euphoxide::Error>,
|
||||
{
|
||||
type Args = UptimeArgs;
|
||||
|
|
@ -131,7 +129,7 @@ where
|
|||
args: Self::Args,
|
||||
msg: &Message,
|
||||
ctx: &Context,
|
||||
bot: &Bot<S, E>,
|
||||
bot: &Bot<E>,
|
||||
) -> Result<Propagate, E> {
|
||||
let reply = self.formulate_reply(ctx, bot, args.connected);
|
||||
ctx.reply_only(msg.id, reply).await?;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use crate::bot::Bot;
|
|||
use super::{Command, Context, Info, Propagate};
|
||||
|
||||
#[async_trait]
|
||||
pub trait ClapCommand<S, E> {
|
||||
pub trait ClapCommand<E> {
|
||||
type Args;
|
||||
|
||||
async fn execute(
|
||||
|
|
@ -17,7 +17,7 @@ pub trait ClapCommand<S, E> {
|
|||
args: Self::Args,
|
||||
msg: &Message,
|
||||
ctx: &Context,
|
||||
bot: &Bot<S, E>,
|
||||
bot: &Bot<E>,
|
||||
) -> Result<Propagate, E>;
|
||||
}
|
||||
|
||||
|
|
@ -101,11 +101,10 @@ fn parse_quoted_args(text: &str) -> Result<Vec<String>, &'static str> {
|
|||
pub struct Clap<C>(pub C);
|
||||
|
||||
#[async_trait]
|
||||
impl<S, E, C> Command<S, E> for Clap<C>
|
||||
impl<E, C> Command<E> for Clap<C>
|
||||
where
|
||||
S: Send + Sync,
|
||||
E: From<euphoxide::Error>,
|
||||
C: ClapCommand<S, E> + Sync,
|
||||
C: ClapCommand<E> + Sync,
|
||||
C::Args: Parser + Send,
|
||||
{
|
||||
fn info(&self, _ctx: &Context) -> Info {
|
||||
|
|
@ -120,7 +119,7 @@ where
|
|||
arg: &str,
|
||||
msg: &Message,
|
||||
ctx: &Context,
|
||||
bot: &Bot<S, E>,
|
||||
bot: &Bot<E>,
|
||||
) -> Result<Propagate, E> {
|
||||
let mut args = match parse_quoted_args(arg) {
|
||||
Ok(args) => args,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue