Browse Source

Initial commit: borrow from egbot

main
Nick Thomas 3 years ago
commit
ca532135b8
Signed by: lupine
GPG Key ID: 1F1A7ECCCFE0B92F
  1. 3
      .gitignore
  2. 1756
      Cargo.lock
  3. 14
      Cargo.toml
  4. 12
      lysenko.yml.example
  5. 57
      src/bin/lysenko.rs

3
.gitignore vendored

@ -0,0 +1,3 @@
/target
/lysenko.yml
**/*.rs.bk

1756
Cargo.lock generated

File diff suppressed because it is too large Load Diff

14
Cargo.toml

@ -0,0 +1,14 @@
[package]
name = "lysenko-rs"
version = "0.1.0"
authors = ["Nick Thomas <me@ur.gs>"]
edition = "2018"
[dependencies]
log = "0.4.0"
env_logger = "0.6.1"
clap = "2.33"
# For local development
# irc-bot = { path = "/home/lupine/dev/code.ur.gs/lupine/irc-bot.rs" }
irc-bot = { git = "https://code.ur.gs/lupine/irc-bot.rs", branch = "for-lysenko" }

12
lysenko.yml.example

@ -0,0 +1,12 @@
---
nickname: lysenko
nick_password: A password here
realname: Comrade Trofim Lysenko
servers:
- host: chat.freenode.net
port: 6697
tls: true
channels: ["#testbot"]
admins:
- nick: lupine
host: unaffiliated/lupine-85/x-7392152

57
src/bin/lysenko.rs

@ -0,0 +1,57 @@
#![forbid(unsafe_code)]
#[macro_use]
extern crate log;
#[macro_use]
extern crate clap;
extern crate env_logger;
use clap::{App, Arg};
use irc_bot::modules;
arg_enum! {
#[derive(Debug)]
enum LogLevel {
Display,
Debug
}
}
fn arg<'a, 'b>(name: &'a str, short: &'b str) -> Arg<'a, 'b> {
return Arg::with_name(name).long(name).short(short);
}
fn main() {
env_logger::init();
let ll_arg = arg("log-level", "l")
.possible_values(&LogLevel::variants())
.default_value("Display")
.case_insensitive(true);
let app = App::new("lysenko")
.arg(arg("config", "C").default_value("lysenko.yml"))
.arg(arg("data-dir", "d").default_value("."))
.arg(ll_arg);
let args = app.get_matches();
let config_file = args.value_of("config").expect("default missing?");
let data_dir = args.value_of("data-dir").expect("default missing?");
let log_level = value_t!(args, "log-level", LogLevel).unwrap_or_else(|err| err.exit());
irc_bot::run(
irc_bot::Config::try_from_path(config_file),
data_dir,
move |err| {
match log_level {
LogLevel::Display => error!("{}", err),
LogLevel::Debug => error!("{:?}", err),
}
irc_bot::ErrorReaction::Proceed
},
&[modules::default, modules::test],
);
}
Loading…
Cancel
Save