コード例 #1
0
        /// <summary>
        /// Adds a strike to a user
        /// </summary>
        /// <param name="target"></param>
        /// <param name="strike"></param>
        /// <returns>The number of strikes the user has.</returns>
        public static int AddStrike(SocketUser target, StrikeDataNode strike)
        {
            ulong targetId = target.Id;
            int   pos      = GetEntryPos(targetId);

            ExcelRange cells = StrikeLog.Workbook.Worksheets[StrikeLogPage].Cells;

            if (!IsRowNew(pos))
            {
                // Add the srike to this row.
                // First, check the username.
                if (cells["B" + pos].Text != BotUtils.GetFullUsername(target))
                {
                    // if it doesn't check out, update it.
                    cells["B" + pos].Value = BotUtils.GetFullUsername(target);
                }

                // now for the strike address. This will be based off of the number of strikes.
                // This is in column C
                int strikes = cells["C" + pos].GetValue <int>();

                if (strikes == 2)
                {
                    return(4);               // 4 is the signal
                }
                // now to get the column. Fun ascii math.
                // 68 = ASCII for capital D.
                string range = char.ConvertFromUtf32(68 + strikes * 3) + pos + ":" + char.ConvertFromUtf32(70 + strikes * 3) + pos;

                cells[range].LoadFromArrays(strike.GetStrikeForExcel());

                cells[$"C:{pos}"].Value = (Convert.ToInt32(cells[$"C{pos}"].Text) + 1).ToString();
                StrikeLog.Save();

                KLog.Info($"Added strike {cells[$"C:{pos}"].Value.ToString()} for {BotUtils.GetFullUsername(target)} in cell range {range}");

                return(Convert.ToInt32(cells[$"C{pos}"].Text));
            }

            // The user doesn't have an entry. So make one.
            GenUserStrike(pos, target);

            // Now add the strike
            ExcelRange er = cells[$"D{pos}:F{pos}"];

            er.LoadFromArrays(strike.GetStrikeForExcel());
            // Set auto fit
            cells[StrikeLog.Workbook.Worksheets[StrikeLogPage].Dimension.Address].AutoFitColumns();
            StrikeLog.Save();
            KLog.Info($"Added strike for {BotUtils.GetFullUsername(target)} in cell range D{pos}:F{pos}");

            return(1);
        }
コード例 #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
        }
コード例 #3
0
        public static int AddStrike(ulong targetId, StrikeDataNode strike, string username = "", bool mod = false)
        {
            ExcelRange cells = StrikeLog.Workbook.Worksheets[StrikeLogPage].Cells;
            int        row   = GetEntryPos(targetId);

            if (!IsRowNew(row))
            {
                // Add the srike to this row.

                if (!string.IsNullOrEmpty(username))
                {
                    cells["B" + row].Value = username;
                }

                // now for the strike address. This will be based off of the number of strikes.
                // This is in column C
                int strikes = cells["C" + row].GetValue <int>();

                string rr;

                if (!mod)
                {
                    if (strikes == 2)
                    {
                        return(4);               // 4 is the signal
                    }
                    // now to get the column. Fun ascii math.
                    // 68 = ASCII for capital D.
                    rr = char.ConvertFromUtf32(68 + strikes * 3) + row + ":" + char.ConvertFromUtf32(70 + strikes * 3) + row;

                    cells[rr].LoadFromArrays(strike.GetStrikeForExcel());

                    cells[$"C:{row}"].Value = (Convert.ToInt32(cells[$"C{row}"].Text) + 1).ToString();
                }
                else
                {
                    // This does nothing really. Probably for the best.
                    strikes--;

                    rr = char.ConvertFromUtf32(68 + strikes * 3) + row + ":" + char.ConvertFromUtf32(70 + strikes * 3) + row;
                    cells[rr].LoadFromArrays(strike.GetStrikeForExcel());
                }

                StrikeLog.Save();

                KLog.Info($"Added strike {cells[$"C:{row}"].Value.ToString()} for {(string.IsNullOrEmpty(username) ? targetId.ToString() : username)} in cell range {rr}");

                return(Convert.ToInt32(cells[$"C{row}"].Text));
            }

            // The user doesn't have an entry. So make one.
            GenUserStrike(row, targetId, username);

            // Now add the strike
            // 68 = ASCII for   capital D.
            string range = char.ConvertFromUtf32(68 + GetStrikes(targetId) * 3) + row + ":" + char.ConvertFromUtf32(70 + GetStrikes(targetId) * 3) + row;

            cells[range].LoadFromArrays(strike.GetStrikeForExcel());
            // Set auto fit
            cells[StrikeLog.Workbook.Worksheets[StrikeLogPage].Dimension.Address].AutoFitColumns();
            StrikeLog.Save();
            KLog.Info($"Added strike for {(string.IsNullOrEmpty(username) ? targetId.ToString() : username)} in cell range D{row}:F{row}");

            return(1);
        }