pub struct MatrixBot { /* private fields */ }Expand description
Matrix bot builder
Create a bot with command and reaction handlers, then call run() to start.
§Example
ⓘ
use botkit_matrix::{MatrixBot, MatrixConfig};
use botkit_core::{Bot, User};
async fn ping() -> &'static str { "Pong!" }
async fn greet(user: User) -> String { format!("Hello, {}!", user.name) }
let config = MatrixConfig::new("https://matrix.org")
.password_auth("@bot:matrix.org", "password")
.command_prefix("!");
MatrixBot::new(config)
.command("ping", ping)
.command("greet", greet)
.run()
.await
.unwrap();Implementations§
Source§impl MatrixBot
impl MatrixBot
Sourcepub fn new(config: MatrixConfig) -> Self
pub fn new(config: MatrixConfig) -> Self
Create a new Matrix bot with the given configuration
Sourcepub fn command<H, Args>(self, name: impl Into<String>, handler: H) -> Selfwhere
H: IntoHandler<Args>,
pub fn command<H, Args>(self, name: impl Into<String>, handler: H) -> Selfwhere
H: IntoHandler<Args>,
Register a command handler (e.g., !ping, !help)
Commands are parsed from message text using the configured prefix.
Sourcepub fn command_with_description<H, Args>(
self,
name: impl Into<String>,
description: impl Into<String>,
handler: H,
) -> Selfwhere
H: IntoHandler<Args>,
pub fn command_with_description<H, Args>(
self,
name: impl Into<String>,
description: impl Into<String>,
handler: H,
) -> Selfwhere
H: IntoHandler<Args>,
Register a command handler with description
Sourcepub fn reaction<H, Args>(self, emoji: impl AsRef<str>, handler: H) -> Selfwhere
H: IntoHandler<Args>,
pub fn reaction<H, Args>(self, emoji: impl AsRef<str>, handler: H) -> Selfwhere
H: IntoHandler<Args>,
Register a reaction handler
Reactions are routed through the same table as buttons, under the id
reaction:<emoji>, so a single handler can serve a Discord button and a
Matrix reaction.
Sourcepub fn message<H, Args>(self, handler: H) -> Selfwhere
H: IntoHandler<Args>,
pub fn message<H, Args>(self, handler: H) -> Selfwhere
H: IntoHandler<Args>,
Register a message handler (for non-command messages)
Sourcepub fn fallback<H, Args>(self, handler: H) -> Selfwhere
H: IntoHandler<Args>,
pub fn fallback<H, Args>(self, handler: H) -> Selfwhere
H: IntoHandler<Args>,
Register a handler for events nothing else claimed
Unregistered commands and unmatched reactions reach the fallback
rather than being dropped. See BotBuilder::fallback.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for MatrixBot
impl !UnwindSafe for MatrixBot
impl Freeze for MatrixBot
impl Send for MatrixBot
impl Sync for MatrixBot
impl Unpin for MatrixBot
impl UnsafeUnpin for MatrixBot
Blanket Implementations§
impl<T> Any for Twhere
T: Any,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ChatActionSenderBounds for T
Source§impl<T> DropFlavorWrapper<T> for T
impl<T> DropFlavorWrapper<T> for T
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more