adding simple bot code
parent
1b51383920
commit
dd409bc238
@ -0,0 +1,8 @@
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
/target/
|
||||
|
||||
# These are backup files generated by rustfmt
|
||||
**/*.rs.bk
|
||||
|
||||
config.toml
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "bones"
|
||||
version = "0.0.1"
|
||||
authors = ["lance <lza_menace@protonmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
irc = "0.13.6"
|
@ -1,2 +1,3 @@
|
||||
# bones
|
||||
Simple IRC bot written in Rust as a learning exercise.
|
||||
|
||||
Simple IRC bot written in Rust as a learning exercise. Uses the [irc](https://docs.rs/irc) crate.
|
||||
|
@ -0,0 +1,7 @@
|
||||
owners = ["yourmain"]
|
||||
nickname = "botname"
|
||||
server = "chat.freenode.net"
|
||||
port = 6697
|
||||
use_ssl = true
|
||||
channels = ["#random"]
|
||||
user_info = "I'm a test bot. Leave me be."
|
@ -0,0 +1,25 @@
|
||||
use irc::client::prelude::{IrcClient, ClientExt, Client, Command};
|
||||
|
||||
fn main() {
|
||||
println!("[DEBUG] Connecting to IRC server...");
|
||||
let client = IrcClient::new("config.toml").unwrap();
|
||||
client.identify().unwrap();
|
||||
client.for_each_incoming(|irc_msg| {
|
||||
|
||||
// Debug
|
||||
// println!("{}", &irc_msg);
|
||||
|
||||
if let Command::NOTICE(channel, message) = &irc_msg.command {
|
||||
println!("[{:?}][{}]: {}", &irc_msg.response_target(), &channel, &message)
|
||||
}
|
||||
|
||||
if let Command::PRIVMSG(channel, message) = &irc_msg.command {
|
||||
// Print all messages
|
||||
println!("[{}][{}]: {}", &irc_msg.response_target().unwrap(), &irc_msg.source_nickname().unwrap(), message);
|
||||
|
||||
if message.contains(&format!("hey {}", client.current_nickname())) {
|
||||
let _ = client.send_privmsg(&channel, format!("hey there {}", &irc_msg.source_nickname().unwrap()));
|
||||
}
|
||||
}
|
||||
}).unwrap();
|
||||
}
|
Loading…
Reference in New Issue