Created
November 7, 2017 01:49
-
-
Save ThatsNoMoon/bdca229926e2f6102c398654886e8f12 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro_rules! oops { | |
($why:expr) => { | |
error_embed(&msg.channel_id, &format!("Something went wrong! Contact the developer with this error message if this problem continues.\n{}", $why)); | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate serenity; | |
#[macro_use] extern crate diesel; | |
#[macro_use] extern crate diesel_codegen; | |
#[macro_use] extern crate lazy_static; | |
#[macro_use] extern crate log; | |
extern crate env_logger; | |
extern crate dotenv; | |
use serenity::prelude::*; | |
use serenity::model::*; | |
use std::env; | |
use std::error::Error; | |
use dotenv::dotenv; | |
use log::{ LogRecord, LogLevelFilter }; | |
use env_logger::LogBuilder; | |
mod framework; | |
pub mod commands; | |
pub mod db; | |
pub mod util; | |
#[macro_use] | |
pub mod macros; | |
struct Handler; | |
impl Handler { | |
fn new() -> Handler { | |
Handler | |
} | |
} | |
impl EventHandler for Handler { | |
fn ready(&self, ctx: Context, ready: Ready) { | |
info!("{} is connected!", ready.user.name); | |
ctx.set_game_name(&format!("@{} help", ready.user.name)); | |
} | |
} | |
fn main() { | |
if let Err(why) = dotenv() { | |
eprintln!("Dotenv failed to initialize: {:?}", why) | |
} | |
let format = |record: &LogRecord| { | |
format!("{} - {}", record.level(), record.args()) | |
}; | |
let mut builder = LogBuilder::new(); | |
builder.format(format) | |
.filter(Some("serenity"), LogLevelFilter::Warn) | |
.filter(None, LogLevelFilter::Info); | |
if let Ok(var) = env::var("RUST_LOG") { | |
builder.parse(&var); | |
} | |
if let Err(why) = builder.init() { | |
eprintln!("Env logger failed to initialize: {}", why.description()) | |
} | |
let token = env::var("DISCORD_TOKEN") | |
.expect("Expected a token environment variable"); | |
let mut client = Client::new(&token, Handler::new()) | |
.expect("Client failed to initialize"); | |
client.with_framework(framework::framework()); | |
if let Err(why) = client.start() { | |
error!("Client failed to start: {:?}", why); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment