Commit a6bba31d authored by Timothy du Heaume's avatar Timothy du Heaume

convert config file format from toml to yaml

This also involves changing ownership details in the config struct due to differing ownership strictness in the yaml deserializer.
parent 67a94e02
......@@ -10,6 +10,6 @@ rand = "^0.7.2"
lazy_static = "^1.4.0"
log = "^0.4.8"
simplelog = "^0.7.4"
toml = "^0.5.6"
serde_yaml = "^0.8"
serde = "^1.0.104"
chrono = "^0.4.10"
use serde::Deserialize;
use serenity;
use serenity::model::id;
use std::fs;
use toml;
use serde_yaml;
lazy_static! {
static ref CONFIG_FILE: String = fs::read_to_string("config.toml").unwrap();
pub static ref CONFIG: UccbotConfig = toml::from_str(&CONFIG_FILE).unwrap();
static ref CONFIG_FILE: String = fs::read_to_string("config.yaml").unwrap();
pub static ref CONFIG: UccbotConfig = serde_yaml::from_str(&CONFIG_FILE).unwrap();
}
#[derive(Deserialize)]
#[derive(Debug, Deserialize)]
pub struct UccbotConfig {
pub server_id: u64,
pub main_channel: serenity::model::id::ChannelId,
pub welcome_channel: serenity::model::id::ChannelId,
pub announcement_channel: serenity::model::id::ChannelId,
pub main_channel: id::ChannelId,
pub welcome_channel: id::ChannelId,
pub announcement_channel: id::ChannelId,
pub bot_id: u64,
pub vote_pool_size: i8,
pub vote_role: u64,
pub tiebreaker_role: u64,
pub unregistered_member_role: u64,
pub registered_member_role: u64,
pub command_prefix: &'static str,
pub for_vote: &'static str,
pub against_vote: &'static str,
pub abstain_vote: &'static str,
pub approve_react: &'static str,
pub disapprove_react: &'static str,
pub unsure_react: &'static str,
pub command_prefix: String,
pub for_vote: String,
pub against_vote: String,
pub abstain_vote: String,
pub approve_react: String,
pub disapprove_react: String,
pub unsure_react: String,
}
impl UccbotConfig {
......
server_id = 606351521117896704 # general
main_channel = 606351521117896706 # the-corner
welcome_channel = 606351613816209418 # general
announcement_channel = 606351521117896706 # the-corner
bot_id = 607078903969742848
vote_pool_size = 2
vote_role = 607478818038480937 # Vote Role
tiebreaker_role = 607509283483025409 # tie-breaker
unregistered_member_role = 608282247350714408 # unregistered
registered_member_role = 608282133118582815 # registered
command_prefix = "!"
for_vote = "👍"
against_vote = "👎"
abstain_vote = "🙊"
approve_react = "⬆"
disapprove_react = "⬇"
unsure_react = "❔"
server_id: 606351521117896704 # general
main_channel: 606351521117896706 # the-corner
welcome_channel: 606351613816209418 # general
announcement_channel: 606351521117896706 # the-corner
bot_id: 607078903969742848
vote_pool_size: 2
vote_role: 607478818038480937 # Vote Role
tiebreaker_role: 607509283483025409 # tie-breaker
unregistered_member_role: 608282247350714408 # unregistered
registered_member_role: 608282133118582815 # registered
command_prefix: "!"
for_vote: "👍"
against_vote: "👎"
abstain_vote: "🙊"
approve_react: "⬆"
disapprove_react: "⬇"
unsure_react: "❔"
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 = "❔"
server_id = 264401248676085760 # ucc
main_channel = 264401248676085760 # ucc
welcome_channel = 606750983699300372 # welcome
announcement_channel = 264411219627212801 # committee
bot_id = 635407267881156618
vote_pool_size = 7 # 4 exec + 3 ocm
vote_role = 269817189966544896 # @committee
tiebreaker_role = 635370432568098817 # @Presiding Presidenterino
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 = "❔"
server_id: 264401248676085760 # ucc
main_channel: 264401248676085760 # ucc
welcome_channel: 606750983699300372 # welcome
announcement_channel: 264411219627212801 # committee
bot_id: 635407267881156618
vote_pool_size: 7 # 4 exec + 3 ocm
vote_role: 269817189966544896 # @committee
tiebreaker_role: 635370432568098817 # @Presiding Presidenterino
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: "❔"
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: "❔"
......@@ -38,7 +38,7 @@ impl EventHandler for Handler {
// Event handlers are dispatched through a threadpool, and so multiple
// events can be dispatched simultaneously.
fn message(&self, ctx: Context, msg: Message) {
if !(msg.content.starts_with(CONFIG.command_prefix)) {
if !(msg.content.starts_with(&CONFIG.command_prefix)) {
return;
}
let message_content: Vec<_> = msg.content[1..].splitn(2, ' ').collect();
......
......@@ -163,7 +163,7 @@ fn create_poll(ctx: &Context, msg: &Message, topic: &str) {
#[derive(Debug, Clone)]
struct MotionInfo {
votes: HashMap<&'static str, Vec<serenity::model::user::User>>,
votes: HashMap<String, Vec<serenity::model::user::User>>,
}
lazy_static! {
......@@ -179,18 +179,18 @@ fn get_cached_motion(ctx: &Context, msg: &Message) -> MotionInfo {
votes: {
let mut m = HashMap::new();
m.insert(
CONFIG.for_vote,
msg.reaction_users(ctx, CONFIG.for_vote, None, None)
CONFIG.for_vote.to_string(),
msg.reaction_users(ctx, CONFIG.for_vote.to_string(), None, None)
.unwrap(),
);
m.insert(
CONFIG.against_vote,
msg.reaction_users(ctx, CONFIG.against_vote, None, None)
CONFIG.against_vote.to_string(),
msg.reaction_users(ctx, CONFIG.against_vote.to_string(), None, None)
.unwrap(),
);
m.insert(
CONFIG.abstain_vote,
msg.reaction_users(ctx, CONFIG.abstain_vote, None, None)
CONFIG.abstain_vote.to_string(),
msg.reaction_users(ctx, CONFIG.abstain_vote.to_string(), None, None)
.unwrap(),
);
m
......@@ -347,11 +347,11 @@ pub fn reaction_add(ctx: Context, add_reaction: channel::Reaction) {
match user.has_role(&ctx, CONFIG.server_id, CONFIG.vote_role) {
Ok(true) => {
// remove vote if already voted
for react in [CONFIG.for_vote, CONFIG.against_vote, CONFIG.abstain_vote]
for react in [CONFIG.for_vote.to_string(), CONFIG.against_vote.to_string(), CONFIG.abstain_vote.to_string()]
.iter()
.filter(|r| r != &&add_reaction.emoji.as_data().as_str())
{
for a_user in message.reaction_users(&ctx, *react, None, None).unwrap()
for a_user in message.reaction_users(&ctx, react.as_str(), None, None).unwrap()
{
if a_user.id.0 == user.id.0 {
if let Err(why) = add_reaction.delete(&ctx) {
......@@ -382,8 +382,8 @@ pub fn reaction_add(ctx: Context, add_reaction: channel::Reaction) {
update_motion(&ctx, &mut message, &user, "add", add_reaction);
}
Ok(false) => {
if ![CONFIG.approve_react, CONFIG.disapprove_react]
.contains(&add_reaction.emoji.as_data().as_str())
if ![CONFIG.approve_react.to_string(), CONFIG.disapprove_react.to_string()]
.contains(&add_reaction.emoji.as_data())
{
if let Err(why) = add_reaction.delete(&ctx) {
error!("Error deleting react: {:?}", why);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment