guilded_rs

Crates.ioguilded_rs
lib.rsguilded_rs
version0.1.0
sourcesrc
created_at2023-05-20 04:09:56.156996
updated_at2023-09-24 11:11:23.536843
descriptionLibary for creating bots in rust for guilded
homepage
repository
max_upload_size
id869211
size56,449
Nils Kristians Ramps-Rampans (SafeShows)

documentation

README

guilded_rs

crates.io Documentation

Easy to use rust library for creating guilded bots using rust.

Features:

The example folder

This folder is used for showing live working example on how the lib should be used. But also use
for testing the library as I'm bad at writing unit test and I kinda hate 'em.

Task Pool

Using Task Pool you have the ability to create tasks that run in the background.

Examples

This will run every second

bot.add_task(Task {
    interval: Duration::from_secs(1),
    handler: |_| {
        println!("Hi from task that runs every second");
    },
});

This task will run every 10 seconds and send a message in a channel.

bot.add_task(Task {
    interval: Duration::from_secs(10),
    handler: |bot| {
        let mut message = ChatMessage::default();
        message.set_content("Content of the message");
        let channel_id = "2b203b41-5409-436e-9ade-a3c1b640b594";
        let is_reply = false;
        match bot.send_chat_message(message, channel_id) {
            Some(msg) => {
                // msg is the message that just got created
            }
            None => {
                // Returns None if the request failed.
                // in this case look at the console for the error message.
                // And if you need help with that don't be
                // shy and send me a message on guilded.
            }
        }
    },
});

Event Handler

Right now the only event the library parses is the ChatMessageCreated event from the WS server

// The bot variable is the http client of the bot.
// While the event is the enum of the event
bot.add_event_handler(|_bot, event| match event {
    Event::ChatMessageCreated(data) => {
        println!("{:?}", data);
    }
    _ => {}
});

Commands

Example of how to declare a command.

struct PingCommand;
impl Command for PingCommand {
    fn name(&self) -> String {
        "ping".to_string()
    }

    fn description(&self) -> String {
        "returns pong".to_string()
    }

    fn handler(&self, ctx: CommandContext, _args: Vec<String>) {
        let mut message = Message::default();
        message.set_content("pong");
        ctx.reply(message);
    }
}

And here's how to add it to the bot

let ping_command: PingCommand = PingCommand {};
bot.add_command(Box::new(ping_command));
Commit count: 0

cargo fmt