Ejemplo n.º 1
0
 public async void StopVote()
 {
     try
     {
         if (ActivePoll == null)
         {
             return;
         }
         var oldPoll = ActivePoll;
         if (ActivePoll != null)
         {
             await ActivePoll.End();
         }
         if (pollTimer != null)
         {
             pollTimer.Enabled = false;
         }
         ActivePoll = null;
         await oldPoll?.PublishResult();
     }
     catch (Exception ex)
     {
         Trace.TraceError("Error stopping vote " + ex);
     }
 }
Ejemplo n.º 2
0
 public async Task RegisterVote(Say e, int vote)
 {
     if (ActivePoll != null)
     {
         if (await ActivePoll.Vote(e, vote))
         {
             StopVote();
         }
     }
     else
     {
         await Respond(e, "There is no poll going on, start some first");
     }
 }
Ejemplo n.º 3
0
        public async void StopVote(Say e = null)
        {
            var oldPoll = ActivePoll;

            if (ActivePoll != null)
            {
                await ActivePoll.End();
            }
            if (pollTimer != null)
            {
                pollTimer.Enabled = false;
            }
            ActivePoll = null;
            oldPoll.PublishResult();
        }
Ejemplo n.º 4
0
 public async Task RegisterVote(Say e, bool vote)
 {
     if (ActivePoll != null)
     {
         if (await ActivePoll.Vote(e, vote))
         {
             var oldPoll = ActivePoll;
             pollTimer.Enabled = false;
             ActivePoll        = null;
             oldPoll.PublishResult();
         }
     }
     else
     {
         await Respond(e, "There is no poll going on, start some first");
     }
 }
Ejemplo n.º 5
0
 private void pollTimer_Elapsed(object sender, ElapsedEventArgs e)
 {
     try
     {
         pollTimer.Stop();
         if (ActivePoll != null)
         {
             ActivePoll.End();
         }
         StopVote();
     }
     catch { }
     finally
     {
         pollTimer.Start();
     }
 }
Ejemplo n.º 6
0
        public async Task ActivatePollAsync(string id)
        {
            var poll = await this._dbContext.LoadAsync <PollDefinition>(id);

            var activeRecord = new ActivePoll
            {
                Id            = id,
                ActivatedTime = DateTime.Now
            };

            await _dbContext.SaveAsync <ActivePoll>(activeRecord);

            await UpdatePollStateAsync(id, PollDefinition.POLL_STATE_ACTIVE);

            var message = string.Format("Poll {0} was activated at {1} and will last until {2}", poll.Title, poll.StartTime, poll.EndTime);

            await this._snsClient.PublishAsync(poll.TopicArn, message, string.Format("Pollster Poll {0} Activated", poll.Title));
        }
Ejemplo n.º 7
0
        public void Execute(NewPollRequest request)
        {
            using (var db = databaseFactory.CreateNew())
            {
                var poll = new ActivePoll {
                    ChatId = request.ChatId, MessageId = request.MessageId, Deleted = false, TimeOffsetId = request.TimeOffsetId
                };
                if (request.EventId != null)
                {
                    poll.EventId = request.EventId;
                }
                else
                {
                    poll.RaidId = request.RaidId;
                }

                db.ActivePolls.Add(poll);
                db.SaveChanges();
            }
        }
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            string pollkey;

            if (command.Arguments.Length == 0)
            {
                Logger.Info(this, $"Starting heuristic poll result estimation for '{command.User}'");
                ActivePoll leadingpoll = module.GetMostActivePoll();
                if (leadingpoll == null)
                {
                    SendMessage(channel, command.User, "Since no one voted for anything i can't show you any poll.");
                    return;
                }

                SendMessage(channel, command.User, $"You seem to be too lazy to tell me which poll you want to know something about. I just guess you want to see poll '{leadingpoll.Name}' since it is the most active poll.");
                pollkey = leadingpoll.Name;
            }
            else
            {
                pollkey = command.Arguments[0];
            }

            Poll poll = module.GetPoll(pollkey);

            if (poll == null)
            {
                SendMessage(channel, command.User, $"There is no poll named '{pollkey}'");
                return;
            }

            PollDiagramData data = new PollDiagramData(module.GetWeightedVotes(pollkey));

            string message = $"Results for {pollkey}: {string.Join(", ", data.GetItems(100).Where(r => r.Count > 0).Select(r => $"{r.Item} [{r.Count}]"))}";

            SendMessage(channel, command.User, message);
        }
Ejemplo n.º 9
0
        public virtual async Task ProcessPlayerJoin(ConnectedUser user, string joinPassword)
        {
            if (IsPassworded && (Password != joinPassword))
            {
                await user.Respond("Invalid password");

                return;
            }

            if (IsKicked(user.Name))
            {
                await KickFromBattle(user.Name, "Banned for five minutes");

                return;
            }

            if ((user.MyBattle != null) && (user.MyBattle != this))
            {
                await user.Process(new LeaveBattle());
            }

            UserBattleStatus ubs;

            if (!Users.TryGetValue(user.Name, out ubs))
            {
                ubs = new UserBattleStatus(user.Name, user.User, GenerateClientScriptPassword(user.Name));
                Users[user.Name] = ubs;
            }

            ValidateBattleStatus(ubs);
            user.MyBattle = this;


            await server.TwoWaySyncUsers(user.Name, Users.Keys); // mutually sync user statuses

            await server.SyncUserToAll(user);

            await RecalcSpectators();

            await
            user.SendCommand(new JoinBattleSuccess()
            {
                BattleID = BattleID,
                Players  = Users.Values.Select(x => x.ToUpdateBattleStatus()).ToList(),
                Bots     = Bots.Values.Select(x => x.ToUpdateBotStatus()).ToList(),
                Options  = ModOptions
            });

            if (ActivePoll != null)
            {
                await user.SendCommand(ActivePoll.GetBattlePoll());
            }

            await server.Broadcast(Users.Keys.Where(x => x != user.Name), ubs.ToUpdateBattleStatus()); // send my UBS to others in battle

            if (spring.IsRunning)
            {
                spring.AddUser(ubs.Name, ubs.ScriptPassword, ubs.LobbyUser);
                var started = DateTime.UtcNow.Subtract(spring.IngameStartTime ?? RunningSince ?? DateTime.UtcNow);
                started = new TimeSpan((int)started.TotalHours, started.Minutes, started.Seconds);
                await SayBattle($"THIS GAME IS CURRENTLY IN PROGRESS, PLEASE WAIT UNTIL IT ENDS! Running for {started}", ubs.Name);
                await SayBattle("If you say !notify, I will message you when the current game ends.", ubs.Name);
            }

            try
            {
                var ret = PlayerJoinHandler.AutohostPlayerJoined(GetContext(), ubs.LobbyUser.AccountID);
                if (ret != null)
                {
                    if (!IsNullOrEmpty(ret.PrivateMessage))
                    {
                        await SayBattle(ret.PrivateMessage, ubs.Name);
                    }
                    if (!IsNullOrEmpty(ret.PublicMessage))
                    {
                        await SayBattle(ret.PublicMessage);
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
                await SayBattle("ServerManage error: " + ex);
            }
        }