73 lines
2.1 KiB
Rust
73 lines
2.1 KiB
Rust
#![feature(in_band_lifetimes)]
|
|
#![feature(async_closure)]
|
|
use serenity::client::Client;
|
|
use serenity::framework::standard::StandardFramework;
|
|
use serenity::futures::lock::Mutex;
|
|
use serenity::http::Http;
|
|
|
|
use std::collections::{HashMap, HashSet};
|
|
use std::env;
|
|
use std::sync::atomic::AtomicBool;
|
|
use std::sync::Arc;
|
|
|
|
mod commands;
|
|
mod handler;
|
|
mod track;
|
|
|
|
use commands::*;
|
|
use handler::*;
|
|
use track::{err_strs, Active, InfoSent, Sent, SourceChannel, TargetChannel, Weave};
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
let token = env::var("MPSC_BOT_TOKEN").expect("token");
|
|
|
|
let http = Http::new_with_token(&token);
|
|
|
|
let (owners, _) = match http.get_current_application_info().await {
|
|
Ok(info) => {
|
|
let mut owners = HashSet::new();
|
|
if let Some(team) = info.team {
|
|
owners.insert(team.owner_user_id);
|
|
} else {
|
|
owners.insert(info.owner.id);
|
|
}
|
|
match http.get_current_user().await {
|
|
Ok(bot_id) => (owners, bot_id.id),
|
|
Err(why) => panic!("Could not access the bot id: {:?}", why),
|
|
}
|
|
}
|
|
Err(why) => panic!("Could not access application info: {:?}", why),
|
|
};
|
|
|
|
let framework = StandardFramework::new()
|
|
.configure(|c| {
|
|
c.with_whitespace(true)
|
|
.prefix("~")
|
|
.owners(owners)
|
|
.ignore_bots(true)
|
|
})
|
|
.group(&GENERAL_GROUP);
|
|
|
|
let mut client = Client::builder(token)
|
|
.event_handler(Handler::default())
|
|
.framework(framework)
|
|
.await
|
|
.expect("Error creating client");
|
|
|
|
{
|
|
let mut data = client.data.write().await;
|
|
data.insert::<Active>(Arc::new(AtomicBool::new(false)));
|
|
data.insert::<InfoSent>(Arc::new(Mutex::new(Vec::new())));
|
|
data.insert::<Sent>(Arc::new(Mutex::new(HashMap::new())));
|
|
data.insert::<SourceChannel>(Arc::new(Mutex::new(None)));
|
|
data.insert::<TargetChannel>(Arc::new(Mutex::new(None)));
|
|
data.insert::<Weave>(Arc::new(AtomicBool::new(true)));
|
|
}
|
|
|
|
// start listening for events by starting a single shard
|
|
if let Err(why) = client.start().await {
|
|
println!("An error occurred while running the client: {:?}", why);
|
|
}
|
|
}
|