Ejemplo n.º 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);
        }
Ejemplo n.º 2
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);
        }