Commit 811181a5 authored by fooker's avatar fooker 👽

Formatting and origanizing imports

parent 62fd6698
Pipeline #448 passed with stage
in 11 minutes and 13 seconds
use std::collections::{hash_map::{DefaultHasher, Entry::{Occupied, Vacant}, OccupiedEntry}, HashMap};
use std::convert::TryFrom;
use std::hash::{Hash, Hasher};
use std::ops::Deref;
use std::ops::DerefMut;
use std::convert::TryFrom;
use failure::{Error, format_err};
use chrono::{Local, NaiveDate};
use failure::{Error, format_err};
use serde_derive::{Deserialize, Serialize};
use crate::opinion::*;
......
extern crate chrono;
extern crate clap;
extern crate itertools;
extern crate regex;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
extern crate spacebot;
extern crate time;
use std::collections::HashSet;
use std::convert::TryFrom;
use std::fmt;
use std::iter::FromIterator;
use std::convert::TryFrom;
use clap::{Arg, SubCommand};
use itertools::Itertools;
use serde_derive::Deserialize;
use spacebot::prelude::*;
......
use std::collections::HashMap;
use serde_derive::{Deserialize, Serialize};
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub enum Opinion {
Yes,
......
extern crate chrono;
extern crate clap;
extern crate itertools;
#[macro_use]
extern crate serde_derive;
extern crate spacebot;
extern crate time;
extern crate tokio;
use std::collections::HashMap;
use std::sync::Arc;
use std::time::Duration as StdDuration;
use chrono::{DateTime, Local, Timelike};
use clap::{Arg, SubCommand};
use itertools::Itertools;
use spacebot::prelude::*;
use std::collections::HashMap;
use std::sync::Arc;
use std::time::Duration as StdDuration;
use serde_derive::{Deserialize, Serialize};
use time::Duration;
use tokio::prelude::Stream;
use tokio::timer::Interval;
use spacebot::prelude::*;
const ABOUT: &str = "\
This is a bot helping to organize food orders. People can simply tell the bot \
......@@ -80,9 +72,9 @@ impl PizzaBot {
response.message(&self.channel,
&format!("New order started. Deadline for this order is {:02}:{:02} and {} is in charge place the order",
deadline.hour(),
deadline.minute(),
nick))?;
deadline.hour(),
deadline.minute(),
nick))?;
};
let run = state.as_mut().unwrap();
......@@ -149,13 +141,13 @@ impl PizzaBot {
run.deadline = deadline;
response.message(&self.channel,
&format!("Deadline for this order has been changed {:02}:{:02}",
run.deadline.hour(),
run.deadline.minute()))?;
run.deadline.hour(),
run.deadline.minute()))?;
} else {
// Show current deadline
response.respond_message(&format!("Deadline for this order is {:02}:{:02}",
run.deadline.hour(),
run.deadline.minute()))?;
run.deadline.hour(),
run.deadline.minute()))?;
}
return Ok(());
......@@ -186,8 +178,8 @@ impl PizzaBot {
}
response.respond_message(&format!("-- Deadline for this order is {:02}:{:02}",
run.deadline.hour(),
run.deadline.minute()))?;
run.deadline.hour(),
run.deadline.minute()))?;
return Ok(());
});
......
use clap::{App, Arg};
use serde::Deserialize;
use simple_logger;
use crate::bot::Bot;
use crate::bot::Module;
use crate::config;
use serde::Deserialize;
use simple_logger;
use log;
pub fn bootstrap<M>(name: &str)
where M: Module + 'static,
......@@ -15,14 +15,14 @@ pub fn bootstrap<M>(name: &str)
let config = format!("/etc/spacebot/{}.yaml", name);
let args = App::new(binary)
.arg(Arg::with_name("config")
.short("c")
.long("config")
.value_name("FILE")
.default_value(&config)
.help("Specify the config file to use")
.takes_value(true))
.get_matches();
.arg(Arg::with_name("config")
.short("c")
.long("config")
.value_name("FILE")
.default_value(&config)
.help("Specify the config file to use")
.takes_value(true))
.get_matches();
let config = args.value_of("config").unwrap();
let config = config::load(config).expect(&format!("Failed to load config: {}", config));
......
......@@ -2,7 +2,7 @@ use failure::Error;
use irc::client::Client as ClientX;
use irc::client::PackedIrcClient;
use irc::client::prelude::*;
use log::{debug, info, trace};
use log::{debug, info};
use tokio::prelude::{future, IntoFuture};
use tokio::runtime::current_thread::Runtime;
......@@ -149,7 +149,7 @@ impl<M> Bot<M>
// Handle incoming messages
let messages_future = connection.stream().from_err().for_each(move |message| {
if let Command::PRIVMSG(ref target, ref text) = message.command {
let source = if let Some(source) = message.source_nickname() { source } else { return Ok(()) };
let source = if let Some(source) = message.source_nickname() { source } else { return Ok(()); };
let respondee = if target.is_channel_name() { target } else { source };
let request = Request {
......
pub use clap::{App, AppSettings, Arg, ArgMatches, SubCommand, Values, ErrorKind as AppErrorKind};
use crate::bot::{Initializer, Module, Request, Response};
use crate::config::ModuleConfig;
pub use clap::{App, AppSettings, Arg, ArgMatches, ErrorKind as AppErrorKind, SubCommand, Values};
use failure::Fail;
use shellwords;
use crate::bot::{Initializer, Module, Request, Response};
use crate::config::ModuleConfig;
#[derive(Debug, Fail)]
pub enum Error {
#[fail(display="command error: {}", msg)]
CommandError{msg: String},
#[fail(display = "command error: {}", msg)]
CommandError { msg: String },
#[fail(display="bot error")]
#[fail(display = "bot error")]
BotError(#[fail(cause)] failure::Error),
}
......@@ -51,7 +52,7 @@ impl<M> Module for M
type Config = M::Config;
fn init(config: &Self::Config, initializer: &mut Initializer) -> Result<Self, failure::Error> {
return M::init(config, initializer)
return M::init(config, initializer);
}
fn handle(&mut self, request: Request, response: Response) -> Result<(), failure::Error> {
......@@ -66,13 +67,13 @@ impl<M> Module for M
if let Ok(args) = shellwords::split(message) { // FIXME: Error handling of mismatched quotes
let app = App::new("")
.bin_name("FIXME") // FIXME: Use right name and set width to max line length
.setting(AppSettings::ArgRequiredElseHelp)
.setting(AppSettings::DisableVersion)
.setting(AppSettings::DeriveDisplayOrder)
.setting(AppSettings::InferSubcommands)
.setting(AppSettings::UnifiedHelpMessage)
.setting(AppSettings::NoBinaryName);
.bin_name("FIXME") // FIXME: Use right name and set width to max line length
.setting(AppSettings::ArgRequiredElseHelp)
.setting(AppSettings::DisableVersion)
.setting(AppSettings::DeriveDisplayOrder)
.setting(AppSettings::InferSubcommands)
.setting(AppSettings::UnifiedHelpMessage)
.setting(AppSettings::NoBinaryName);
let app = self.register(app);
......@@ -88,20 +89,19 @@ impl<M> Module for M
}, &response);
match result {
Err(Error::CommandError {msg}) => {
Err(Error::CommandError { msg }) => {
response.respond_message(&format!("Error: {}", &msg))?;
}
Err(Error::BotError(err)) => return Err(err),
Ok(result) => return Ok(result),
}
}
Err(err) => {
match err.kind {
// TODO: Show help only for query - send a one-line answer to channels
AppErrorKind::HelpDisplayed => response.message(
&request.source,
&err.message
&err.message,
)?,
_ => response.respond_message(&format!("Error: {}", &err.message))?,
......
use serde::Deserialize;
use serde_yaml as yaml;
use std::error::Error;
use std::fmt;
use std::fs::File;
use std::io;
use std::path::Path;
use serde::Deserialize;
use serde_derive::Deserialize;
use serde_yaml as yaml;
#[derive(Debug)]
pub enum ConfigError {
......
extern crate chrono;
extern crate clap;
extern crate failure;
extern crate irc;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
extern crate serde_yaml;
extern crate shellwords;
extern crate tokio;
pub mod config;
pub mod bot;
pub mod cmd;
......
pub use crate::bootstrap::bootstrap;
pub use crate::bot::{Bot, Client, Initializer, Request, Response};
pub use crate::cmd::{App, AppSettings, Arg, ArgMatches, Command, CommandModule, SubCommand, Values, Error as CmdError};
pub use crate::cmd::{App, AppSettings, Arg, ArgMatches, Command, CommandModule, Error as CmdError, SubCommand, Values};
pub use crate::config::{ConnectionConfig, ModuleConfig};
pub use crate::store::Store;
use serde::de::DeserializeOwned;
use serde::ser::Serialize;
use serde_json;
use std::ffi::OsStr;
use std::fs::{File, rename};
use std::ops::{Deref, DerefMut};
use std::path::Path;
use std::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard};
use serde::de::DeserializeOwned;
use serde::ser::Serialize;
use serde_json;
pub struct Store<T>
where T: DeserializeOwned + Serialize + Default {
path: String,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment