From 5867137555a9e224f6c81539a9dc813405d5a45a Mon Sep 17 00:00:00 2001 From: Agatha Date: Fri, 3 Apr 2020 02:01:53 +0300 Subject: [PATCH] Add lazy_static to dependencies Replace multiple owner variables with a static variable --- Cargo.lock | 1 + Cargo.toml | 1 + src/main.rs | 16 ++++++++++------ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4cb27b8..4881f0d 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -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)", diff --git a/Cargo.toml b/Cargo.toml index c80ed85..e9814b4 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" } diff --git a/src/main.rs b/src/main.rs index 24ac792..0ccff13 100755 --- a/src/main.rs +++ b/src/main.rs @@ -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 = + vec![UserId(254310746450690048), UserId(687740609703706630)]; +} + // Calculates hash of a type that implements Hash fn calculate_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)