diff options
author | Till Hoeppner | 2014-11-03 17:57:42 +0100 |
---|---|---|
committer | Till Hoeppner | 2014-11-03 17:57:42 +0100 |
commit | 11b12ada4530dc22a54d64ed97dc41cc293ee492 (patch) | |
tree | a56185b8fb65a4a3eb64a4928ba3cad32a8a08c4 /README.md | |
parent | 668e6ef7031069ad71206fd82342bb7565f7b624 (diff) | |
download | irsc-11b12ada4530dc22a54d64ed97dc41cc293ee492.tar.gz irsc-11b12ada4530dc22a54d64ed97dc41cc293ee492.tar.xz irsc-11b12ada4530dc22a54d64ed97dc41cc293ee492.zip |
Added README
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..711a6fc --- /dev/null +++ b/README.md @@ -0,0 +1,55 @@ +irsc [![Build Status](https://travis-ci.org/hoeppnertill/irsc.svg)](https://travis-ci.org/hoeppnertill/irsc) +========= + +*This repository contains code that has not been properly tested yet, continue +at the risk of doing stupid things while discovering parts of this library +don't work.* + +## Introduction + +Want to build an IRC bot with low resource consumption? You might want to have a look at this library (maybe later, though). + +This library is supposed to be a thin layer over the IRC protocol, doing all the network IO and event parsing for you. Right now, it only works, nothing more. + +## Example + +```rust +#![feature(globs, slicing_syntax)] + +extern crate irsc; + +use irsc::server::Server; +use irsc::color::bold; +use irsc::event; +use irsc::event::{ Event, ParseResult, PrivMsg }; + +static NAME: &'static str = "rusticbot"; +static DESC: &'static str = "A bot, written in Rust."; + +fn callback(arg: (Server, Event)) { + let (mut server, event) = arg; + match event.command[] { + event::PRIVMSG => { + let privmsg: PrivMsg = ParseResult::parse(event).unwrap(); + let response = format!("You wrote: {}", bold(privmsg.content[])); + server.msg(privmsg.from.nickname[], response[]).unwrap(); + }, + _ => () + } +} + +fn main() { + let mut s = Server::new(); + s.connect("irc.freenode.org".into_string(), 6667).unwrap(); + s.nick(NAME).unwrap(); + s.user(NAME, "*", "*", DESC).unwrap(); + s.join("#botzoo").unwrap(); + + s.msg("flan3002", "Hey there! You should probably change the nick in this README!").unwrap(); + + s.events.lock().register(&callback); + + // Dedicate this thread to listening and event processing + s.listen().unwrap(); +} +``` |