Crates.io | guilded_rs |
lib.rs | guilded_rs |
version | 0.1.0 |
source | src |
created_at | 2023-05-20 04:09:56.156996 |
updated_at | 2023-09-24 11:11:23.536843 |
description | Libary for creating bots in rust for guilded |
homepage | |
repository | |
max_upload_size | |
id | 869211 |
size | 56,449 |
Easy to use rust library for creating guilded bots using rust.
example
folderThis 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.
Using Task Pool you have the ability to create tasks that run in the background.
bot.add_task(Task {
interval: Duration::from_secs(1),
handler: |_| {
println!("Hi from task that runs every second");
},
});
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.
}
}
},
});
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);
}
_ => {}
});
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));