1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
use std::fmt; use serde::{Deserialize, Serialize}; pub mod response; #[derive(Debug, Serialize, Deserialize)] pub struct User { pub id: String, pub flags: usize, pub github: Option<String>, pub tag: String, pub username: String, pub bots: Vec<String>, } #[derive(Debug, Serialize, Deserialize)] pub struct Bot { pub id: String, pub flags: usize, pub name: String, pub tag: String, pub avatar: Option<String>, pub owners: Vec<User>, pub lib: String, pub prefix: String, pub votes: usize, pub servers: usize, pub intro: String, pub desc: String, #[serde(skip_serializing_if = "String::is_empty")] pub web: String, #[serde(skip_serializing_if = "String::is_empty")] pub git: String, #[serde(skip_serializing_if = "String::is_empty")] pub url: String, #[serde(skip_serializing_if = "String::is_empty")] pub discord: String, pub category: Vec<String>, pub vanity: Option<String>, #[serde(skip_serializing_if = "String::is_empty")] pub bg: String, #[serde(skip_serializing_if = "String::is_empty")] pub banner: String, pub status: Option<Status>, pub state: State, } #[derive(Debug, Serialize, Deserialize)] pub struct UserInfo { pub id: String, pub flags: usize, pub github: Option<String>, pub tag: String, pub username: String, pub bots: Vec<UserInfoBot>, } #[derive(Debug, Serialize, Deserialize)] pub struct UserInfoBot { pub id: String, pub flags: usize, pub name: String, pub tag: String, pub avatar: Option<String>, pub owners: Vec<String>, pub lib: String, pub prefix: String, pub votes: usize, pub servers: usize, pub intro: String, pub desc: String, #[serde(skip_serializing_if = "String::is_empty")] pub web: String, #[serde(skip_serializing_if = "String::is_empty")] pub git: String, #[serde(skip_serializing_if = "String::is_empty")] pub url: String, #[serde(skip_serializing_if = "String::is_empty")] pub discord: String, pub category: Vec<String>, pub vanity: Option<String>, #[serde(skip_serializing_if = "String::is_empty")] pub bg: String, #[serde(skip_serializing_if = "String::is_empty")] pub banner: String, pub status: Option<Status>, pub state: State, } #[derive(Debug, Serialize, Deserialize)] pub struct VoteCheck { pub voted: bool, #[serde(rename = "lastVote")] pub last_vote: usize, } #[derive(Debug, Serialize, Deserialize)] #[serde(untagged)] pub enum UserFlags { None = 0, Admin = 1 << 0, BugHunter = 1 << 1, BotReviewer = 1 << 2, PremiumUser = 1 << 3, } #[derive(Debug, Serialize, Deserialize)] #[serde(untagged)] pub enum BotFlags { None = 0, OfficialBot = 1 << 0, KoreaDiscordBotListCertifiedBot = 1 << 2, Partner = 1 << 3, DiscordVerifiedBot = 1 << 4, Premium = 1 << 5, OnestKoreaDiscordBotListHackathonWinnerBot = 1 << 6, } #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] pub enum Status { Online, Idle, Dnd, Streaming, Offline, } #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] pub enum State { Ok, Reported, Blocked, Private, Archived, } pub enum WidgetType { Votes, Servers, Status, } impl fmt::Display for WidgetType { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { WidgetType::Servers => write!(f, "servers"), WidgetType::Votes => write!(f, "votes"), WidgetType::Status => write!(f, "status"), } } } #[derive(Clone)] pub struct WidgetQuery { style: Option<&'static str>, scale: Option<f32>, icon: Option<bool>, } impl WidgetQuery { pub fn to_style(&self) -> &str { match self.style { Some("classic") => "classic", Some("flat") => "flat", None => "flat", _ => "flat", } } pub fn to_scale(&self) -> f32 { if Some(0.5) <= self.scale && self.scale <= Some(3.0) { self.scale.unwrap() } else { 1.0 } } pub fn to_icon(&self) -> &str { match self.icon { Some(true) => "true", Some(false) => "false", None => "true", } } }