Esempio n. 1
0
        private void Polltimer_Tick_Finish(object sender, EventArgs e)
        {
            polltimer.Stop();

            this.ReadPollResult();

            clsPollOption optionwon    = new clsPollOption();
            bool          multiplewons = false;

            if (activePoll.WinRatio == 0)
            {
                foreach (clsPollOption option in this.activePoll.options)
                {
                    if (option.Votes == optionwon.Votes)
                    {
                        multiplewons = true;
                    }
                    if (option.Votes > optionwon.Votes)
                    {
                        optionwon    = option;
                        multiplewons = false;
                    }
                }
            }
            else
            {
                int votesCount = 0;
                foreach (clsPollOption option in this.activePoll.options)
                {
                    votesCount = votesCount + option.Votes;
                }
                double votesneeded = Math.Ceiling(votesCount * activePoll.WinRatio);
                foreach (clsPollOption option in this.activePoll.options)
                {
                    if (option.Votes >= votesneeded)
                    {
                        optionwon    = option;
                        multiplewons = false;
                    }
                }
            }

            if (optionwon != null && !multiplewons)
            {
                foreach (string winMessage in optionwon.winningMessages)
                {
                    SendChatMessageEvent(winMessage);
                }
                optionwon.fireWonEvent();
            }
            else
            {
                SendChatMessageEvent("/me Es scheint keine Option gewonnen zu haben /allesfalsch Poll beendet.");
                //keine option hat gewonnen
            }


            this.activePoll    = null;
            this.pollIsRunning = false;
        }
Esempio n. 2
0
 public void CancelPoll()
 {
     if (pollIsRunning)
     {
         this.polltimer.Stop();
         this.polltimer  = null;
         pollIsRunning   = false;
         this.activePoll = null;
         SendChatMessageEvent("/me Poll abgebrochen. So funktioniert Demokratie /afd");
     }
 }
Esempio n. 3
0
        private clsPoll getPollFromDivBox(HtmlElement box)
        {
            clsPoll poll = new clsPoll();

            foreach (HtmlElement element in box.Children)
            {
                if (element.TagName.ToLower() == "button")
                {
                    if (element.InnerText.ToLower() == Config.PollHandler_ClosePoll_Button_Text.ToLower())
                    {
                        poll.ClosePollButton = element;
                    }
                    else if (element.InnerText.Contains("×"))
                    {
                        poll.RemovePollButton = element;
                    }
                }
                else if (element.TagName.ToLower() == "h3")
                {
                    poll.question = element.InnerText;
                }
                else if (element.GetAttribute("classname").ToLower().Contains(Config.PollHandler_Option_Class.ToLower()))
                {
                    clsPollOption option = new clsPollOption();

                    string outerdivtext = element.OuterHtml;
                    outerdivtext = outerdivtext.Remove(0, outerdivtext.LastIndexOf("</button>"));
                    outerdivtext = outerdivtext.Remove(0, 9);
                    outerdivtext = outerdivtext.Remove(outerdivtext.LastIndexOf("</div>"), 6);
                    option.text  = outerdivtext;
                    foreach (HtmlElement optiondivelement in element.Children)
                    {
                        if (optiondivelement.TagName.ToLower().Contains("button"))
                        {
                            option.Votes = Convert.ToInt32(optiondivelement.InnerText);
                        }
                    }
                    poll.options.Add(option);
                }
            }

            return(poll);
        }
Esempio n. 4
0
        public void OpenPoll(clsPoll poll)
        {
            if (this.checkIfPollIsRunning())
            {
                return;
            }
            this.activePoll = poll;
            this.polltimer  = new Timer();

            if (poll.waitingForResultInSecounds == 0)
            {
                SendChatMessageEvent(poll.getPollString());
            }
            else if (poll.waitingForResultInSecounds > 30)
            {
                int intervall = poll.waitingForResultInSecounds - 30;
                polltimer.Interval = (intervall * 1000);  //umrechnen
                polltimer.Tick    += Polltimer_Tick_30SecoundsLeft;
                SendChatMessageEvent(poll.getPollString());
                polltimer.Start();
            }
            else if (poll.waitingForResultInSecounds > 15)
            {
                int intervall = poll.waitingForResultInSecounds - 15;
                polltimer.Interval = (intervall * 1000); //umrechnen
                polltimer.Tick    += Polltimer_Tick_10SecoundsLeft;
                SendChatMessageEvent(poll.getPollString());
                polltimer.Start();
            }
            else
            {
                polltimer.Interval = (poll.waitingForResultInSecounds * 1000); //umrechnen
                polltimer.Tick    += Polltimer_Tick_10SecoundsLeft;
                SendChatMessageEvent(poll.getPollString());
                polltimer.Start();
            }

            pollIsRunning = true;
        }
Esempio n. 5
0
        public override void commandTriggered(List <string> args, string triggeredFromUsername, bool triggeredFromMod)
        {
            clsPoll poll = new clsPoll();

            poll.question = "Testfrage! Testfrage?";
            poll.Message_10SecoundsLeft     = "10 secounds left message";
            poll.Message_30SecoundsLeft     = "30 secounds left message";
            poll.waitingForResultInSecounds = 40;
            clsPollOption o1 = new clsPollOption();
            clsPollOption o2 = new clsPollOption();

            o1.text  = "option 1";
            o1.value = "option 1";
            o1.winningMessages.Add("option 1 won");
            o1.OptionWonEvent += O1_OptionWonEvent;
            o2.text            = "option 2";
            o2.value           = "option 2";
            o2.winningMessages.Add("option 2 won");
            o2.OptionWonEvent += O1_OptionWonEvent;
            poll.options.Add(o1);
            poll.options.Add(o2);
            pollhandler.OpenPoll(poll);
        }
Esempio n. 6
0
        public override void commandTriggered(List <string> args, string triggeredFromUsername, bool triggeredFromMod)
        {
            string username = triggeredFromUsername.ToLower();

            if (triggeredFromMod)
            {
                foreach (string arg in args)
                {
                    if (arg.ToLower() == "weck")
                    {
                        this.pollhandler.CancelPoll();
                        return;
                    }
                }
            }

            if (this.pollhandler.checkIfPollIsRunning())
            {
                return;
            }

            if (this.usernameTriggered.ContainsKey(username))
            {
                if (DateTime.Now.Date == this.usernameTriggered[username].Date)
                {
                    SendChatMessage(Config.Plugin_Aufraeumen_NotAgain_Message.Replace("[username]", triggeredFromUsername));
                    return;
                }
                else
                {
                    this.usernameTriggered[username] = DateTime.Now;
                }
            }
            else
            {
                this.usernameTriggered.Add(username, DateTime.Now);
            }

            string deleteVideosFromUser = string.Empty;

            foreach (string arg in args)
            {
                if (userlistwrapper.checkUsernameInChatlist(arg))
                {
                    deleteVideosFromUser = arg;
                    break;
                }
            }
            if (string.IsNullOrEmpty(deleteVideosFromUser))
            {
                return;
            }
            else
            {
                //check if user is mod
                if (!triggeredFromMod)
                {
                    if (this.checkIfUsernameIsMod(deleteVideosFromUser) || deleteVideosFromUser.ToLower() == Config.Bot_Username.ToLower())
                    {
                        SendChatMessage(Config.Plugin_Aufraeumen_ModMessage);
                        return;
                    }
                }
            }

            clsPoll       votekickpoll = new clsPoll(Config.Plugin_Aufraeumen_QuestionMessage.Replace("[username]", deleteVideosFromUser), Config.Plugin_Aufraeumen_10secondsMessage.Replace("[username]", deleteVideosFromUser), Config.Plugin_Aufraeumen_30secondsMessage.Replace("[username]", deleteVideosFromUser), 60);
            clsPollOption yes          = new clsPollOption(Config.Plugin_Aufraeumen_Option_Yes.Replace("[username]", deleteVideosFromUser), "F1");

            yes.winningMessages.Add(Config.Plugin_Aufraeumen_VoteSuccess.Replace("[username]", deleteVideosFromUser));
            yes.winningMessages.Add(Config.Plugin_Aufraeumen_VoteSuccess_Command.Replace("[username]", userlistwrapper.getUsernameCaseSensetive(deleteVideosFromUser.ToLower())));
            clsPollOption no = new clsPollOption(Config.Plugin_Aufraeumen_Option_No.Replace("[username]", deleteVideosFromUser));

            no.winningMessages.Add(Config.Plugin_Aufraeumen_VoteFailed);
            votekickpoll.options.Add(yes);
            votekickpoll.options.Add(no);

            this.pollhandler.OpenPoll(votekickpoll);
        }
Esempio n. 7
0
        public override void commandTriggered(List <string> args, string triggeredFromUsername, bool triggeredFromMod)
        {
            string username = triggeredFromUsername.ToLower();

            if (triggeredFromMod)
            {
                foreach (string arg in args)
                {
                    if (arg.ToLower() == "weck")
                    {
                        this.pollhandler.CancelPoll();
                        return;
                    }
                }
            }

            if (this.pollhandler.checkIfPollIsRunning())
            {
                return;
            }

            if (this.usernameTriggered.ContainsKey(username))
            {
                if (DateTime.Now.Subtract(this.usernameTriggered[username]).TotalMinutes <= Convert.ToInt32(Config.Plugin_Votekick_UserVote_Timeout))
                {
                    SendChatMessage(Config.Plugin_Votekick_NotAgain_Message.Replace("[username]", triggeredFromUsername));
                    return;
                }
                else
                {
                    this.usernameTriggered[username] = DateTime.Now;
                }
            }
            else
            {
                this.usernameTriggered.Add(username, DateTime.Now);
            }

            string kickuser = string.Empty;

            foreach (string arg in args)
            {
                if (userlistwrapper.checkUsernameInChatlist(arg))
                {
                    kickuser = arg;
                    break;
                }
            }
            if (string.IsNullOrEmpty(kickuser))
            {
                return;
            }
            else
            {
                //check if user is mod
                if (!triggeredFromMod)
                {
                    if (this.checkIfUsernameIsMod(kickuser) || kickuser.ToLower() == Config.Bot_Username.ToLower())
                    {
                        SendChatMessage(Config.Plugin_Votekick_ModKickMessage);
                        return;
                    }
                }
            }

            clsPoll votekickpoll = new clsPoll(Config.Plugin_Votekick_QuestionMessage.Replace("[username]", kickuser), Config.Plugin_Votekick_10secondsMessage.Replace("[username]", kickuser), Config.Plugin_Votekick_30secondsMessage.Replace("[username]", kickuser), 60);

            clsPollOption yes = new clsPollOption(Config.Plugin_Votekick_KickOption_Yes.Replace("[username]", kickuser), "F1");

            string mutemessage = string.Empty;
            int    mutedtime   = Convert.ToInt32(Config.Plugin_Votekick_MuteTimeInMin);

            //if (kickuser.ToLower() == "antipazifist")
            //{
            //    mutedtime = 120;
            //}

            //Prüfen ob auch gemuted werden soll
            if (mutedtime >= 0)
            {
                mutemessage = " und für " + mutedtime.ToString() + " Minuten gemuted";
                yes.winningMessages.Add(Config.Plugin_Votekick_KickOption_Yes_muteCommand.Replace("[username]", kickuser));
                yes.value = kickuser;
            }
            yes.winningMessages.Add(Config.Plugin_Votekick_KickMessage_VoteSuccess.Replace("[username]", kickuser).Replace("[mutemessage]", mutemessage));
            yes.winningMessages.Add(Config.Plugin_Votekick_KickOption_Yes_KickCommand.Replace("[username]", kickuser));
            yes.OptionWonEvent += (value) => Yes_OptionWonEvent(value, mutedtime);

            clsPollOption no = new clsPollOption(Config.Plugin_Votekick_KickOption_No.Replace("[username]", kickuser));

            no.winningMessages.Add(Config.Plugin_Votekick_KickMessage_VoteFailed.Replace("[username]", kickuser));
            votekickpoll.options.Add(yes);
            votekickpoll.options.Add(no);

            this.pollhandler.OpenPoll(votekickpoll);
        }