Exemplo n.º 1
0
        public override async Task ButtonAction(SocketReaction action)
        {
            switch (action.Emote.ToString())
            {
            case ReactionHandler.DECLINE_STR:
                EventQueueManager.RemoveMessageEvent(Context.User.Id);
                await Context.Message.Channel.SendMessageAsync(BotUtils.KamtroText("Thank you for editing the log."));

                await Message.DeleteAsync();

                return;

            case ReactionHandler.CHECK_STR:
                HandleConfirm();
                OpCursor = 0;     // reset the cursor
                break;

            case BACK:
                if (!BackMap.ContainsKey(PageNum) || PageNum == 14)
                {
                    PageNum = 1;
                    break;
                }

                PageNum = BackMap[PageNum];
                break;
            }

            await UpdateEmbed();
        }
Exemplo n.º 2
0
        public override async Task ButtonAction(SocketReaction action)
        {
            switch (action.Emote.ToString())
            {
            case ReactionHandler.CHECK_STR:
                // On confirm
                if (!AllFieldsFilled())
                {
                    return;                          // Do nothing if the fields are not filled.
                }
                // otherwise, add the strike.
                StrikeDataNode str     = new StrikeDataNode(Context.User, Reason);
                int            strikes = AdminDataManager.AddStrike(Target, str);

                if (strikes >= 3)
                {
                    await Context.Channel.SendMessageAsync(BotUtils.KamtroText($"{BotUtils.GetFullUsername(Target)} has 3 strikes"));

                    break;
                }

                await Context.Channel.SendMessageAsync(BotUtils.KamtroText($"Added strike for {BotUtils.GetFullUsername(Target)}. They now have {strikes} strike{((strikes == 1) ? "":"s")}."));

                if (notifyUser)
                {
                    bool sent = await BotUtils.DMUserAsync(BotUtils.GetGUser(Target.Id), new StrikeNotifyEmbed(str.Reason, strikes).GetEmbed());

                    if (!sent)
                    {
                        await Context.Channel.SendMessageAsync(BotUtils.BadDMResponse);
                    }
                }

                break;

            case diamond:
                // toggles the notification of the user
                notifyUser = !notifyUser;
                await UpdateEmbed();

                return;
            }

            EventQueueManager.RemoveMessageEvent(this); // now remove the event
        }
Exemplo n.º 3
0
        public override async Task PerformAction(SocketReaction action)
        {
            switch (action.Emote.ToString())
            {
            case ReactionHandler.DECLINE_STR:
                EventQueueManager.RemoveMessageEvent(this);
                await Message.DeleteAsync();

                await Context.Channel.SendMessageAsync(BotUtils.KamtroText($"The ban on {BotUtils.GetFullUsername(Target)} has been cancelled."));

                break;

            default:
                await ButtonAction(action);      // if none of the predefined actions were used, it must be a custom action.

                break;
            }
        }
Exemplo n.º 4
0
        public override async Task ButtonAction(SocketReaction action)
        {
            if (action.Emote.ToString() == ReactionHandler.CHECK_STR)
            {
                TimeZone.Replace(" ", "");
                if (Regex.IsMatch(TimeZone, PATTERN))
                {
                    TimeZoneNode node = new TimeZoneNode(Regex.Match(TimeZone, PATTERN).Value);
                    UserDataManager.GetUserData(BotUtils.GetGUser(Context)).TimeZone = node;
                    UserDataManager.SaveUserData();

                    EventQueueManager.RemoveMessageEvent(this);
                    await Message.DeleteAsync();

                    await Context.Channel.SendMessageAsync(BotUtils.KamtroText("Time zone set successfuly!"));
                }
                else
                {
                    BadFormat = true;
                    await UpdateEmbed();
                }
            }
        }
Exemplo n.º 5
0
        public override async Task ButtonAction(SocketReaction action)
        {
            switch (action.Emote.ToString())
            {
            case ReactionHandler.CHECK_STR:
                if (Remove)
                {
                    await RemRole();
                }
                else
                {
                    await AddRole();
                }

                Program.ReloadConfig();

                EventQueueManager.RemoveEvent(this);
                await Message.DeleteAsync();

                break;

            case ReactionHandler.DECLINE_STR:
                if (Remove)
                {
                    await Context.Channel.SendMessageAsync(BotUtils.KamtroText("Role deletion has been cancelled."));
                }
                else
                {
                    await Context.Channel.SendMessageAsync(BotUtils.KamtroText("Role addition has been cancelled."));
                }

                EventQueueManager.RemoveMessageEvent(this);
                await Context.Channel.DeleteMessageAsync(Message);

                break;
            }
        }
Exemplo n.º 6
0
        public override async Task ButtonAction(SocketReaction action)
        {
            switch (action.Emote.ToString())
            {
            case ReactionHandler.CHECK_STR:
                // verify inputs
                int k, t, p;      // kamtrokens, temp rep, and perm rep respectively
                if (!(int.TryParse(KamtrokenReward, out k) && int.TryParse(TempRepReward, out t) && int.TryParse(PermRepReward, out p)))
                {
                    InvalidNumberWarning = true;
                    await UpdateEmbed();

                    return;
                }

                // Color
                string c = EmbedColor.Replace("#", "").Replace("0x", "").Replace("x", "");
                uint   cc;

                if (!uint.TryParse(c, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out cc))
                {
                    InvalidNumberWarning = true;
                    await UpdateEmbed();

                    return;
                }

                Color ec = new Color(cc);

                // Add the stats
                UserDataNode data = UserDataManager.GetUserData(Winner);
                data.Kamtrokens       += k;
                data.ReputationToGive += t;
                data.MaxReputation    += p;
                UserDataManager.SaveUserData();

                // Send the gift
                string wins = "";

                if (k > 0)
                {
                    wins += $"{k} Kamtroken{(k == 1 ? "":"s")}";
                }

                if (t > 0)
                {
                    if (wins.Length != 0)
                    {
                        wins += ", ";
                    }
                    wins += $"{t} Temporary Reputation Point{(t == 1 ? "" : "s")}";
                }

                wins.TrimEnd(',', ' ');

                if (k == 0 && t == 0)
                {
                    wins = "";
                }

                if (p > 0)
                {
                    wins += $"\n\nIn addition, the amount of repuation you get per week has been increaced by {p}";
                }

                await BotUtils.DMUserAsync(Winner, new BasicEmbed("Congradulations!", $"You have won {(string.IsNullOrWhiteSpace(wins) ? "my appreciation!":wins)}", "Winnings", ec, "", MessageText).GetEmbed());

                // Update the embed
                GiftSent = true;
                await UpdateEmbed();

                EventQueueManager.RemoveMessageEvent(this);
                break;

            case ReactionHandler.DECLINE_STR:
                EventQueueManager.RemoveMessageEvent(this);
                await Message.DeleteAsync();

                await Context.Channel.SendMessageAsync(BotUtils.KamtroText("Reward Sending Canceled."));

                break;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Garbage collection thread method.
        /// This stops kamtro from waiting for interfaces that are going to be unused.
        /// </summary>
        /// <remarks>
        /// VERY IMPORTANT: This method has the potential to cause a race condition with the autosave thread. This is why the two should NEVER
        /// access the same variables.
        ///
        /// -C
        /// </remarks>
        public static void GarbageCollection()
        {
            DateTime now;
            TimeSpan span;

            while (GCReady && GCLoop)
            {
                if (PauseGC)
                {
                    Thread.Sleep(new TimeSpan(0, 1, 0));
                    continue;
                }

                GCInProgress = true;

                List <EventQueueNode> toRemove    = new List <EventQueueNode>();
                List <ulong>          toRemoveMsg = new List <ulong>();
                now = DateTime.Now;

                foreach (KeyValuePair <ulong, MessageEventNode> action in EventQueueManager.MessageEventQueue.AsEnumerable())
                {
                    span = now - action.Value.TimeCreated;

                    if (span > action.Value.Interface.Timeout)
                    {
                        toRemoveMsg.Add(action.Key);

                        // Let user know embed is disabled
                        action.Value.Interface.Message.ModifyAsync(x => x.Content = KamtroText("This embed is no longer in use."));
                        action.Value.Interface.Message.ModifyAsync(x => x.Embed   = null);
                    }
                }

                foreach (ulong node in toRemoveMsg)
                {
                    EventQueueManager.RemoveMessageEvent(node);
                    Console.WriteLine($"[GC] Message Event from user {node} removed.");
                }

                foreach (KeyValuePair <ulong, List <EventQueueNode> > action in EventQueueManager.EventQueue.AsEnumerable())
                {
                    foreach (EventQueueNode node in action.Value)
                    {
                        span = now - node.TimeCreated;

                        if (span > node.EventAction.Timeout || node.IsAlone && span > node.EventAction.Timeout)
                        {
                            toRemove.Add(node);

                            // Let user know embed is disabled
                            node.EventAction.Message.ModifyAsync(x => x.Content = KamtroText("This embed is no longer in use."));
                            node.EventAction.Message.ModifyAsync(x => x.Embed   = null);
                        }
                    }

                    foreach (EventQueueNode node in toRemove)
                    {
                        action.Value.Remove(node);
                        Console.WriteLine($"[GC] Event from user {action.Key} removed. {((node.IsAlone) ? "Event was paired with message event from same user." : "")}");
                    }
                }

                GCInProgress = false;

                Thread.Sleep(new TimeSpan(0, 1, 0));
            }
        }