Add lazy_static to dependencies

Replace multiple owner variables with a static variable
This commit is contained in:
Agatha 2020-04-03 02:01:53 +03:00
parent 5dae504c02
commit 5867137555
3 changed files with 12 additions and 6 deletions

1
Cargo.lock generated
View File

@ -1032,6 +1032,7 @@ dependencies = [
name = "rustcord"
version = "0.3.0"
dependencies = [
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"owoify 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.105 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -13,6 +13,7 @@ toml = "0.5.6"
sys-info = "0.6.0"
urbandict = "0.2.0"
owoify = "0.1.5"
lazy_static = "1.4.0"
[patch.crates-io]
openssl = { git = "https://github.com/ishitatsuyuki/rust-openssl", branch = "0.9.x" }

View File

@ -1,5 +1,8 @@
#![allow(clippy::unreadable_literal)]
#[macro_use]
extern crate lazy_static;
use rand::Rng;
use serenity::{
client::Client,
@ -40,6 +43,11 @@ impl EventHandler for Handler {
)]
struct General;
lazy_static! {
static ref OWNERS: std::vec::Vec<serenity::model::id::UserId> =
vec![UserId(254310746450690048), UserId(687740609703706630)];
}
// Calculates hash of a type that implements Hash
fn calculate_hash<T: Hash>(t: &T) -> u64 {
let mut s = DefaultHasher::new();
@ -55,11 +63,7 @@ fn main() {
StandardFramework::new()
.configure(|c| {
c.with_whitespace(true)
.owners(
vec![UserId(254310746450690048), UserId(687740609703706630)]
.into_iter()
.collect(),
)
.owners(OWNERS.clone().into_iter().collect())
.prefixes(vec!["owo ", "OwO "])
.no_dm_prefix(true)
.case_insensitivity(true)
@ -85,7 +89,7 @@ fn main() {
#[check]
#[name = "Owner"]
fn owner_check(_: &mut Context, msg: &Message, _: &mut Args, _: &CommandOptions) -> CheckResult {
if msg.author.id == 254310746450690048 || msg.author.id == 687740609703706630 {
if OWNERS.clone().contains(&msg.author.id) {
CheckResult::Success
} else {
CheckResult::Failure(Reason::Unknown)