예제 #1
0
        public static int InsertBallot(Ballot b)
        {
            var sql = CreateCommand();

            sql.CommandText = @"INSERT INTO ballots (createDt,motionId,moderatorId,choice) VALUES
                                                 (DATE('now'),@motionId,@moderatorId,@choice);";

            var p0 = sql.CreateParameter();

            p0.ParameterName = "@motionId";
            p0.Value         = b.Motion.Id;
            sql.Parameters.Add(p0);

            var p1 = sql.CreateParameter();

            p1.ParameterName = "@moderatorId";
            p1.Value         = b.Moderator.Id;
            sql.Parameters.Add(p1);

            var p2 = sql.CreateParameter();

            p2.ParameterName = "@choice";
            p2.Value         = (int)b.Choice;
            sql.Parameters.Add(p2);

            b.Id = ExecuteNonQuery(sql);
            return(b.Id);
        }
예제 #2
0
        public void CastBallot(Motion motion, Choice choice)
        {
            var b = new Ballot();

            b.Choice    = choice;
            b.Motion    = motion;
            b.Moderator = this;
            motion.Votes.Add(b);
            b.Insert();
        }
예제 #3
0
        public static int DeleteBallot(Ballot b)
        {
            var sql = CreateCommand();

            sql.CommandText = @"DELETE FROM ballots WHERE id = ?id";

            var p0 = sql.CreateParameter();

            p0.ParameterName = "?id";
            p0.Value         = b.Id;
            sql.Parameters.Add(p0);

            return(ExecuteNonQuery(sql));
        }
예제 #4
0
        public static void PostBallot(Ballot ballot)
        {
            var motion = ballot.Motion;

            if (motion.PostUrl == "")
            {
                return;
            }


            var reddit = new RedditSharp.Reddit(Config.RedditUser, Config.RedditPass, true);
            var post   = reddit.GetPost(new Uri(motion.PostUrl));

            post.Comment("###" + ballot.Moderator.Name + "###" + Environment.NewLine
                         + "*****" + Environment.NewLine
                         + DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss") + @" \(UTC\) : *" + ballot.Choice.ToString() + "*" + Environment.NewLine
                         );
        }
예제 #5
0
        public static Ballot GetBallot(int id)
        {
            var result = new Ballot();

            var sql = CreateCommand();

            sql.CommandText = @"SELECT id,motionId,moderatorId,choice FROM ballots WHERE id = ?id";

            var pId = sql.CreateParameter();

            pId.ParameterName = "?id";
            pId.Value         = id;
            sql.Parameters.Add(pId);

            var rs = ExecuteReader(sql);

            result.Choice    = (Choice)rs.GetInt32(3);
            result.Id        = rs.GetInt32(0);
            result.Moderator = GetModerator(rs.GetInt32(2));
            result.Motion    = GetMotion(rs.GetInt32(1));

            return(result);
        }
예제 #6
0
파일: Bot.cs 프로젝트: pimanac/ConsensusBot
        private void CommandCast(ChatCommand cmd, Moderator mod)
        {
            var usage = "usage: $vote cast [choice]{ yes | no | abstain } [motion id] ";

            if (cmd.Args.Length == 0)
            {
                WriteUser(usage, mod, cmd.Source);
                return;
            }

            var stuff = cmd.Args.Split(' ');

            if (stuff.GetUpperBound(0) < 1)
            {
                WriteUser(usage, mod, cmd.Source);
                return;
            }

            var id = -1;

            try
            {
                id = Int32.Parse(stuff[1]);
            }
            catch
            {
                WriteUser(usage, mod, cmd.Source);
                return;
            }

            Choice c     = Choice.Abstain;
            bool   error = false;

            switch (stuff[0].ToLower())
            {
            case "yes":
            case "y":
            case "+1":
            case "yay":
            case "yae":
            case "yea":
            case "oui":
            case "si":
            case "ja":
            case "da":
                c = Choice.Yes;
                break;

            case "no":
            case "n":
            case "-1":
            case "nae":
            case "nay":
            case "non":
            case "nein":
            case "neit":
                c = Choice.No;
                break;

            case "abstain":
            case "abs":
            case "0":
                c = Choice.Abstain;
                break;

            default:
                error = true;
                break;
            }

            if (error)
            {
                WriteUser(usage, mod);
                return;
            }

            WriteUser("Submitting ballot.  Please wait.", mod, cmd.Source);

            var motion = Motion.GetMotion(id);
            var b      = new Ballot();

            b.Choice    = c;
            b.Moderator = mod;
            b.Motion    = motion;
            b.Insert();

            WriteUser("Your ballot has been recorded", mod, cmd.Source);
        }