parent
839d6f80ab
commit
6118231117
@ -0,0 +1,15 @@
|
||||
guilds:
|
||||
# Tegaki Tuesday
|
||||
- id: 814700630958276649
|
||||
channel: 819038172927098910
|
||||
hidden: true
|
||||
# English-Japanese Language Exchange
|
||||
- id: 189571157446492161
|
||||
channel: 352299136307036160
|
||||
recommended: true
|
||||
# 日本語と英語 - JP & EN
|
||||
- id: 116379774825267202
|
||||
channel: 346809059376234497
|
||||
# Yudai La Piñata
|
||||
- id: 582147335476346880
|
||||
channel: 839852933377425488
|
@ -0,0 +1,56 @@
|
||||
use derive_more::From;
|
||||
use poise::serenity_prelude::Http;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fs;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Settings {
|
||||
pub guilds: Vec<Guild>,
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
pub async fn new(http: &Http) -> Result<Self, GetSettingsError> {
|
||||
let file = fs::read_to_string("settings.yaml").unwrap();
|
||||
let mut settings: Self = serde_yaml::from_str(&file)?;
|
||||
settings.load(http).await?;
|
||||
Ok(settings)
|
||||
}
|
||||
|
||||
pub async fn load(&mut self, http: &Http) -> poise::serenity_prelude::Result<()> {
|
||||
for guild in self.guilds.iter_mut() {
|
||||
guild.load(http).await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(From, Debug)]
|
||||
pub enum GetSettingsError {
|
||||
Io(std::io::Error),
|
||||
Deserialize(serde_yaml::Error),
|
||||
Serenity(poise::serenity_prelude::Error),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Guild {
|
||||
pub id: u64,
|
||||
#[serde(default)]
|
||||
pub hidden: bool,
|
||||
#[serde(default)]
|
||||
pub recommended: bool,
|
||||
pub channel: u64,
|
||||
// None case means guild is not yet loaded
|
||||
#[serde(default)]
|
||||
pub icon: Option<Option<String>>,
|
||||
#[serde(default)]
|
||||
pub name: Option<String>,
|
||||
}
|
||||
|
||||
impl Guild {
|
||||
pub async fn load(&mut self, http: &Http) -> poise::serenity_prelude::Result<()> {
|
||||
let server = http.get_guild(self.id).await?;
|
||||
self.icon = Some(server.icon);
|
||||
self.name = Some(server.name);
|
||||
Ok(())
|
||||
}
|
||||
}
|
Loading…
Reference in new issue