diff --git a/Cargo.toml b/Cargo.toml index 45e271a9e470a3eba801a44f5cac5fc142b9d191..1b9c56495fb82eae7590595cddff250658718e67 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,3 +10,5 @@ rand = "^0.7.2" lazy_static = "^1.4.0" log = "^0.4.8" simplelog = "^0.7.4" +toml = "^0.5.6" +serde = "^1.0.104" diff --git a/src/config.rs b/src/config.rs index 8e4246ede351bf15afdad59bc5ac3f6f90cae1f3..d7aad5d132ecec266496bbfe850b1d7fde027ade 120000 --- a/src/config.rs +++ b/src/config.rs @@ -1,28 +1,20 @@ use serenity; +use std::fs; +use serde::Deserialize; +use toml; -pub const CONFIG: UccbotConfig = UccbotConfig { - discord_token: include_str!("discord_token"), - server_id: 606351521117896704, - main_channel: serenity::model::id::ChannelId(606351521117896706), - welcome_channel: serenity::model::id::ChannelId(606351613816209418), - announcement_channel: serenity::model::id::ChannelId(606351521117896706), - bot_id: 607078903969742848, - vote_pool_size: 2, - vote_role: 607478818038480937, - tiebreaker_role: 607509283483025409, - unregistered_member_role: 608282247350714408, - registered_member_role: 608282133118582815, - command_prefix: "!", - for_vote: "ðŸ‘", - against_vote: "👎", - abstain_vote: "🙊", - approve_react: "⬆", - disapprove_react: "⬇", - unsure_react: "â”", -}; +lazy_static! { + static ref CONFIG_FILE: String = fs::read_to_string("config.toml").unwrap(); +} + +lazy_static! { + pub static ref CONFIG: UccbotConfig = toml::from_str(&CONFIG_FILE).unwrap(); +} + +pub static DISCORD_TOKEN: &str = include_str!("discord_token"); +#[derive(Deserialize)] pub struct UccbotConfig { - pub discord_token: &'static str, pub server_id: u64, // #general pub main_channel: serenity::model::id::ChannelId, diff --git a/src/config.test.rs b/src/config.test.rs deleted file mode 100644 index 5fc3bb7609b2223a34b248e2df3b244c263e1cd3..0000000000000000000000000000000000000000 --- a/src/config.test.rs +++ /dev/null @@ -1,39 +0,0 @@ -use serenity; - -pub static DISCORD_TOKEN: &str = include_str!("discord_token"); - -pub static SERVER_ID: u64 = 606351521117896704; -// #general -pub static MAIN_CHANNEL: serenity::model::id::ChannelId = - serenity::model::id::ChannelId(606351521117896706); -// #the-corner -pub static WELCOME_CHANNEL: serenity::model::id::ChannelId = - serenity::model::id::ChannelId(606351613816209418); -// #general -pub static ANNOUNCEMENT_CHANNEL: serenity::model::id::ChannelId = - serenity::model::id::ChannelId(606351521117896706); - -pub static BOT_ID: u64 = 607078903969742848; - -pub static VOTE_POOL_SIZE: i8 = 2; -pub static VOTE_ROLE: u64 = 607478818038480937; -pub static TIEBREAKER_ROLE: u64 = 607509283483025409; -pub static UNREGISTERED_MEMBER_ROLE: u64 = 608282247350714408; -pub static REGISTERED_MEMBER_ROLE: u64 = 608282133118582815; - -pub static COMMAND_PREFIX: &str = "!"; - -pub static FOR_VOTE: &str = "ðŸ‘"; -pub static AGAINST_VOTE: &str = "👎"; -pub static ABSTAIN_VOTE: &str = "🙊"; -pub static APPROVE_REACT: &str = "⬆"; -pub static DISAPPROVE_REACT: &str = "⬇"; -pub static UNSURE_REACT: &str = "â”"; -pub static ALLOWED_REACTS: &[&'static str] = &[ - FOR_VOTE, - AGAINST_VOTE, - ABSTAIN_VOTE, - APPROVE_REACT, - DISAPPROVE_REACT, - UNSURE_REACT, -]; diff --git a/src/config.test.toml b/src/config.test.toml new file mode 100644 index 0000000000000000000000000000000000000000..bb0b38e6f59fdd20fd1638c7690b9171d7b5df32 --- /dev/null +++ b/src/config.test.toml @@ -0,0 +1,23 @@ +server_id = 606351521117896704 +#general +main_channel = 606351521117896706 +#the-corner +welcome_channel = 606351613816209418 +#general +announcement_channel = 606351521117896706 + +bot_id = 607078903969742848 + +vote_pool_size = 2 +vote_role = 607478818038480937 +tiebreaker_role = 607509283483025409 +unregistered_member_role = 608282247350714408 +registered_member_role = 608282133118582815 +command_prefix = "!" + +for_vote = "ðŸ‘" +against_vote = "👎" +abstain_vote = "🙊" +approve_react = "⬆" +disapprove_react = "⬇" +unsure_react = "â”" diff --git a/src/config.toml b/src/config.toml new file mode 100644 index 0000000000000000000000000000000000000000..bb0b38e6f59fdd20fd1638c7690b9171d7b5df32 --- /dev/null +++ b/src/config.toml @@ -0,0 +1,23 @@ +server_id = 606351521117896704 +#general +main_channel = 606351521117896706 +#the-corner +welcome_channel = 606351613816209418 +#general +announcement_channel = 606351521117896706 + +bot_id = 607078903969742848 + +vote_pool_size = 2 +vote_role = 607478818038480937 +tiebreaker_role = 607509283483025409 +unregistered_member_role = 608282247350714408 +registered_member_role = 608282133118582815 +command_prefix = "!" + +for_vote = "ðŸ‘" +against_vote = "👎" +abstain_vote = "🙊" +approve_react = "⬆" +disapprove_react = "⬇" +unsure_react = "â”" diff --git a/src/config.ucc.rs b/src/config.ucc.rs deleted file mode 100644 index 58aa01cc349d5631851a18104d290637f88abbcc..0000000000000000000000000000000000000000 --- a/src/config.ucc.rs +++ /dev/null @@ -1,39 +0,0 @@ -use serenity; - -pub static DISCORD_TOKEN: &str = include_str!("discord_token"); - -pub static SERVER_ID: u64 = 264401248676085760; -// #ucc -pub static MAIN_CHANNEL: serenity::model::id::ChannelId = - serenity::model::id::ChannelId(264401248676085760); -// #welcome -pub static WELCOME_CHANNEL: serenity::model::id::ChannelId = - serenity::model::id::ChannelId(606750983699300372); -// #committee -pub static ANNOUNCEMENT_CHANNEL: serenity::model::id::ChannelId = - serenity::model::id::ChannelId(264411219627212801); - -pub static BOT_ID: u64 = 635407267881156618; - -pub static VOTE_POOL_SIZE: i8 = 7; -pub static VOTE_ROLE: u64 = 269817189966544896; -pub static TIEBREAKER_ROLE: u64 = 635370432568098817; -pub static UNREGISTERED_MEMBER_ROLE: u64 = 0; // does not exist -pub static REGISTERED_MEMBER_ROLE: u64 = 0; // does not exist - -pub static COMMAND_PREFIX: &str = "!"; - -pub static FOR_VOTE: &str = "ðŸ‘"; -pub static AGAINST_VOTE: &str = "👎"; -pub static ABSTAIN_VOTE: &str = "🙊"; -pub static APPROVE_REACT: &str = "⬆"; -pub static DISAPPROVE_REACT: &str = "⬇"; -pub static UNSURE_REACT: &str = "â”"; -pub static ALLOWED_REACTS: &[&'static str] = &[ - FOR_VOTE, - AGAINST_VOTE, - ABSTAIN_VOTE, - APPROVE_REACT, - DISAPPROVE_REACT, - UNSURE_REACT, -]; diff --git a/src/config.ucc.toml b/src/config.ucc.toml new file mode 100644 index 0000000000000000000000000000000000000000..2c995db97c8425192c1a85d41715ee5bada28960 --- /dev/null +++ b/src/config.ucc.toml @@ -0,0 +1,24 @@ +server_id = 264401248676085760 +#ucc +main_channel = 264401248676085760 +#welcome +welcome_channel = 606750983699300372 +#committee +announcement_channel = 264411219627212801 + +bot_id = 635407267881156618 + +vote_pool_size = 7 +vote_role = 269817189966544896 +tiebreaker_role = 635370432568098817 +unregistered_member_role = 0 # does not exist +registered_member_role = 0 # does not exist + +command_prefix = "!" + +for_vote = "ðŸ‘" +against_vote = "👎" +abstain_vote = "🙊" +approve_react = "⬆" +disapprove_react = "⬇" +unsure_react = "â”" diff --git a/src/main.rs b/src/main.rs index bc28fa413461025eeaabb1ea84df08fe23063721..53cb2ffd779581d0cfb3dcf5e5e3886413b27697 100644 --- a/src/main.rs +++ b/src/main.rs @@ -155,7 +155,7 @@ fn main() { // Configure the client with your Discord bot token in the environment. - let token = CONFIG.discord_token; + let token = config::DISCORD_TOKEN; // Create a new instance of the Client, logging in as a bot. This will // automatically prepend your bot token with "Bot ", which is a requirement