1 unstable release

0.1.0 Sep 24, 2023
0.0.1 May 20, 2023

#1667 in Web programming

45 downloads per month

CC-BY-NC-ND-4.0

57KB
1.5K SLoC

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));

Dependencies

~9–23MB
~353K SLoC