mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-04-18 16:28:55 +00:00
Split youmubot-core
This commit is contained in:
parent
aec9cd130d
commit
84150cd82e
14 changed files with 56 additions and 38 deletions
15
Cargo.lock
generated
15
Cargo.lock
generated
|
@ -1677,15 +1677,24 @@ dependencies = [
|
||||||
name = "youmubot"
|
name = "youmubot"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"dotenv 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"dotenv 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"serenity 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"youmubot-core 0.1.0",
|
||||||
|
"youmubot-db 0.1.0",
|
||||||
|
"youmubot-osu 0.1.0",
|
||||||
|
"youmubot-prelude 0.1.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "youmubot-core"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"reqwest 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serenity 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serenity 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"static_assertions 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"static_assertions 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"youmubot-db 0.1.0",
|
"youmubot-db 0.1.0",
|
||||||
"youmubot-osu 0.1.0",
|
|
||||||
"youmubot-prelude 0.1.0",
|
"youmubot-prelude 0.1.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
members = [
|
members = [
|
||||||
"youmubot-prelude",
|
"youmubot-prelude",
|
||||||
"youmubot-db",
|
"youmubot-db",
|
||||||
|
"youmubot-core",
|
||||||
"youmubot-osu",
|
"youmubot-osu",
|
||||||
"youmubot",
|
"youmubot",
|
||||||
]
|
]
|
||||||
|
|
17
youmubot-core/Cargo.toml
Normal file
17
youmubot-core/Cargo.toml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
[package]
|
||||||
|
name = "youmubot-core"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Natsu Kagami <natsukagami@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
serenity = "0.8"
|
||||||
|
rand = "0.7"
|
||||||
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
chrono = "0.4"
|
||||||
|
static_assertions = "1.1"
|
||||||
|
|
||||||
|
youmubot-db = { path = "../youmubot-db" }
|
||||||
|
youmubot-prelude = { path = "../youmubot-prelude" }
|
|
@ -1,7 +1,4 @@
|
||||||
use crate::{
|
use crate::db::{ServerSoftBans, SoftBans};
|
||||||
commands::args,
|
|
||||||
db::{ServerSoftBans, SoftBans},
|
|
||||||
};
|
|
||||||
use chrono::offset::Utc;
|
use chrono::offset::Utc;
|
||||||
use serenity::{
|
use serenity::{
|
||||||
framework::standard::{macros::command, Args, CommandError as Error, CommandResult},
|
framework::standard::{macros::command, Args, CommandError as Error, CommandResult},
|
||||||
|
@ -114,7 +111,7 @@ pub fn soft_ban_init(ctx: &mut Context, msg: &Message, mut args: Args) -> Comman
|
||||||
}
|
}
|
||||||
|
|
||||||
// Watch the soft bans.
|
// Watch the soft bans.
|
||||||
pub fn watch_soft_bans(client: &mut serenity::Client) -> impl FnOnce() -> () + 'static {
|
pub fn watch_soft_bans(client: &serenity::Client) -> impl FnOnce() -> () + 'static {
|
||||||
let cache_http = {
|
let cache_http = {
|
||||||
let cache_http = client.cache_and_http.clone();
|
let cache_http = client.cache_and_http.clone();
|
||||||
let cache: serenity::cache::CacheRwLock = cache_http.cache.clone().into();
|
let cache: serenity::cache::CacheRwLock = cache_http.cache.clone().into();
|
|
@ -1,4 +1,3 @@
|
||||||
use crate::commands::args::Duration as ParseDuration;
|
|
||||||
use serenity::framework::standard::CommandError as Error;
|
use serenity::framework::standard::CommandError as Error;
|
||||||
use serenity::{
|
use serenity::{
|
||||||
framework::standard::{macros::command, Args, CommandResult},
|
framework::standard::{macros::command, Args, CommandResult},
|
||||||
|
@ -11,7 +10,7 @@ use serenity::{
|
||||||
use std::collections::HashMap as Map;
|
use std::collections::HashMap as Map;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use youmubot_prelude::*;
|
use youmubot_prelude::{Duration as ParseDuration, *};
|
||||||
|
|
||||||
#[command]
|
#[command]
|
||||||
#[description = "🎌 Cast a poll upon everyone and ask them for opinions!"]
|
#[description = "🎌 Cast a poll upon everyone and ask them for opinions!"]
|
|
@ -2,24 +2,14 @@ use chrono::{DateTime, Utc};
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serenity::{
|
use serenity::{
|
||||||
framework::standard::CommandError as Error,
|
|
||||||
model::id::{RoleId, UserId},
|
model::id::{RoleId, UserId},
|
||||||
};
|
};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::path::Path;
|
|
||||||
use youmubot_db::{GuildMap, DB};
|
use youmubot_db::{GuildMap, DB};
|
||||||
use youmubot_prelude::*;
|
|
||||||
|
|
||||||
/// A list of SoftBans for all servers.
|
/// A list of SoftBans for all servers.
|
||||||
pub type SoftBans = DB<GuildMap<ServerSoftBans>>;
|
pub type SoftBans = DB<GuildMap<ServerSoftBans>>;
|
||||||
|
|
||||||
/// Sets up all databases in the client.
|
|
||||||
pub fn setup_db(path: &Path, data: &mut ShareMap) -> Result<(), Error> {
|
|
||||||
SoftBans::insert_into(&mut *data, &path.join("soft_bans.yaml"))?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// For the admin commands:
|
/// For the admin commands:
|
||||||
/// - Each server might have a `soft ban` role implemented.
|
/// - Each server might have a `soft ban` role implemented.
|
||||||
/// - We allow periodical `soft ban` applications.
|
/// - We allow periodical `soft ban` applications.
|
|
@ -57,7 +57,7 @@ fn message_command(ctx: &mut Context, msg: &Message, args: Args, rating: Rating)
|
||||||
|
|
||||||
// Gets an image URL.
|
// Gets an image URL.
|
||||||
fn get_image(
|
fn get_image(
|
||||||
client: &reqwest::blocking::Client,
|
client: &<HTTPClient as TypeMapKey>::Value,
|
||||||
rating: Rating,
|
rating: Rating,
|
||||||
tags: &str,
|
tags: &str,
|
||||||
) -> Result<Option<String>, Error> {
|
) -> Result<Option<String>, Error> {
|
|
@ -9,12 +9,27 @@ use youmubot_prelude::*;
|
||||||
|
|
||||||
pub mod admin;
|
pub mod admin;
|
||||||
pub mod community;
|
pub mod community;
|
||||||
|
mod db;
|
||||||
pub mod fun;
|
pub mod fun;
|
||||||
|
|
||||||
pub use admin::ADMIN_GROUP;
|
pub use admin::ADMIN_GROUP;
|
||||||
pub use community::COMMUNITY_GROUP;
|
pub use community::COMMUNITY_GROUP;
|
||||||
pub use fun::FUN_GROUP;
|
pub use fun::FUN_GROUP;
|
||||||
|
|
||||||
|
/// Sets up all databases in the client.
|
||||||
|
pub fn setup(
|
||||||
|
path: &std::path::Path,
|
||||||
|
client: &serenity::client::Client,
|
||||||
|
data: &mut youmubot_prelude::ShareMap,
|
||||||
|
) -> serenity::framework::standard::CommandResult {
|
||||||
|
db::SoftBans::insert_into(&mut *data, &path.join("soft_bans.yaml"))?;
|
||||||
|
|
||||||
|
// Create handler threads
|
||||||
|
std::thread::spawn(admin::watch_soft_bans(client));
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
// A help command
|
// A help command
|
||||||
#[help]
|
#[help]
|
||||||
pub fn help(
|
pub fn help(
|
|
@ -9,12 +9,8 @@ edition = "2018"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serenity = "0.8"
|
serenity = "0.8"
|
||||||
dotenv = "0.15"
|
dotenv = "0.15"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
|
||||||
chrono = "0.4.9"
|
|
||||||
rand = "0.7.2"
|
|
||||||
static_assertions = "1.1.0"
|
|
||||||
reqwest = "0.10.1"
|
|
||||||
youmubot-osu = { path = "../youmubot-osu" }
|
youmubot-osu = { path = "../youmubot-osu" }
|
||||||
youmubot-db = { path = "../youmubot-db" }
|
youmubot-db = { path = "../youmubot-db" }
|
||||||
youmubot-prelude = { path = "../youmubot-prelude" }
|
youmubot-prelude = { path = "../youmubot-prelude" }
|
||||||
|
youmubot-core = { path = "../youmubot-core" }
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,6 @@ use serenity::{
|
||||||
use youmubot_osu::discord::{setup as setup_osu, OSU_GROUP};
|
use youmubot_osu::discord::{setup as setup_osu, OSU_GROUP};
|
||||||
use youmubot_prelude::*;
|
use youmubot_prelude::*;
|
||||||
|
|
||||||
mod commands;
|
|
||||||
mod db;
|
|
||||||
|
|
||||||
const MESSAGE_HOOKS: [fn(&mut Context, &Message) -> (); 1] = [youmubot_osu::discord::hook];
|
const MESSAGE_HOOKS: [fn(&mut Context, &Message) -> (); 1] = [youmubot_osu::discord::hook];
|
||||||
|
|
||||||
struct Handler;
|
struct Handler;
|
||||||
|
@ -51,15 +48,12 @@ fn main() {
|
||||||
std::path::PathBuf::from("data")
|
std::path::PathBuf::from("data")
|
||||||
});
|
});
|
||||||
youmubot_prelude::setup::setup_prelude(&db_path, &mut data, &mut fw);
|
youmubot_prelude::setup::setup_prelude(&db_path, &mut data, &mut fw);
|
||||||
// Setup initial data
|
// Setup core
|
||||||
db::setup_db(&db_path, &mut data).expect("Setup db should succeed");
|
youmubot_core::setup(&db_path, &client, &mut data).expect("Setup db should succeed");
|
||||||
// osu!
|
// osu!
|
||||||
setup_osu(&db_path, &client, &mut data).expect("osu! is initialized");
|
setup_osu(&db_path, &client, &mut data).expect("osu! is initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create handler threads
|
|
||||||
std::thread::spawn(commands::admin::watch_soft_bans(&mut client));
|
|
||||||
|
|
||||||
println!("Starting...");
|
println!("Starting...");
|
||||||
if let Err(v) = client.start() {
|
if let Err(v) = client.start() {
|
||||||
panic!(v)
|
panic!(v)
|
||||||
|
@ -85,7 +79,7 @@ fn setup_framework(client: &Client) -> StandardFramework {
|
||||||
.delimiters(vec![" / ", "/ ", " /", "/"])
|
.delimiters(vec![" / ", "/ ", " /", "/"])
|
||||||
.owners([owner.id].iter().cloned().collect())
|
.owners([owner.id].iter().cloned().collect())
|
||||||
})
|
})
|
||||||
.help(&commands::HELP)
|
.help(&youmubot_core::HELP)
|
||||||
.before(|_, msg, command_name| {
|
.before(|_, msg, command_name| {
|
||||||
println!(
|
println!(
|
||||||
"Got command '{}' by user '{}'",
|
"Got command '{}' by user '{}'",
|
||||||
|
@ -134,8 +128,8 @@ fn setup_framework(client: &Client) -> StandardFramework {
|
||||||
c.delay(30).time_span(30).limit(1)
|
c.delay(30).time_span(30).limit(1)
|
||||||
})
|
})
|
||||||
// groups here
|
// groups here
|
||||||
.group(&commands::ADMIN_GROUP)
|
.group(&youmubot_core::ADMIN_GROUP)
|
||||||
.group(&commands::FUN_GROUP)
|
.group(&youmubot_core::FUN_GROUP)
|
||||||
.group(&commands::COMMUNITY_GROUP)
|
.group(&youmubot_core::COMMUNITY_GROUP)
|
||||||
.group(&OSU_GROUP)
|
.group(&OSU_GROUP)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue