public override async Task PerformAction(SocketReaction option)
        {
            switch (option.Emote.ToString())
            {
            case ReactionHandler.CHECK_STR:
                Program.Settings.AdminUsers.Add(User.Id);
                Program.Settings.SaveJson();

                await Context.Channel.SendMessageAsync(BotUtils.KamtroText($"Added user {BotUtils.GetFullUsername(User)} as an admin."));

                KLog.Important($"User {BotUtils.GetFullUsername(User)} added as an admin");

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

                break;

            case ReactionHandler.DECLINE_STR:
                EventQueueManager.RemoveEvent(this);
                await Context.Channel.SendMessageAsync(BotUtils.KamtroText("Action Canceled."));

                await Message.DeleteAsync();

                break;
            }
        }
Exemple #2
0
        public BanDataNode(SocketUser mod, string reason)
        {
            Reason    = reason;
            Moderator = BotUtils.GetFullUsername(mod);

            Date = DateTime.Now;
        }
Exemple #3
0
        public override async Task ButtonAction(SocketReaction action)
        {
            switch (action.Emote.ToString())
            {
            case ReactionHandler.CHECK_STR:
                // Time for security checks

                /// These checks were done when the command was called - Arcy

                BanDataNode ban = new BanDataNode(Context.User, Reason);

                if (notifyTarget)
                {
                    bool sent = await BotUtils.DMUserAsync(BotUtils.GetGUser(Target.Id), new BanNotifyEmbed(ban.Reason).GetEmbed());

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

                AdminDataManager.AddBan(Target, ban);
                await Context.Channel.SendMessageAsync(BotUtils.KamtroAngry($"User {BotUtils.GetFullUsername(Target)} has been banned."));

                await ServerData.Server.AddBanAsync(Target.Id, 0, Reason);

                break;

            case diamond:
                notifyTarget = !notifyTarget;
                await UpdateEmbed();

                break;
            }
        }
Exemple #4
0
        public async Task ReplaceSettingsFileAsync([Remainder] string message = "")
        {
            if (!ServerData.HasPermissionLevel(BotUtils.GetGUser(Context), ServerData.PermissionLevel.ADMIN))
            {
                return;                                                                                                // This is an admin only command
            }
            if (Context.Message.Attachments.Count == 1)
            {
                Attachment file = Context.Message.Attachments.ElementAt(0);

                if (file.Filename != "settings.json")
                {
                    await ReplyAsync(BotUtils.KamtroText("The settings file must be a json file named settings.json!"));

                    return;
                }

                // At this point, the file is valid
                string url = file.Url;

                WebClient wc = new WebClient();
                wc.DownloadFile(url, AdminDataManager.StrikeLogPath);

                KLog.Info($"Settings file updated by {BotUtils.GetFullUsername(Context.User)}");
                await ReplyAsync(BotUtils.KamtroText("The settings file has been updated!"));
            }
        }
        /// <summary>
        /// Generates the base for a user entry. Does not generate the strike, only columns A through C
        /// </summary>
        /// <param name="pos">Row in the spreadsheet</param>
        /// <param name="target">Target user for entry</param>
        private static void GenUserStrike(int pos, SocketUser target, int strikes = 1)
        {
            KLog.Info($"User {BotUtils.GetFullUsername(target)} doesn't have a strike entry, creating one...");
            List <string[]> entry = new List <string[]>();

            entry.Add(new string[] { target.Id.ToString(), BotUtils.GetFullUsername(target), strikes.ToString() });

            StrikeLog.Workbook.Worksheets[StrikeLogPage].Cells[$"A{pos}:C{pos}"].LoadFromArrays(entry);
        }
        public override Embed GetEmbed()
        {
            EmbedBuilder eb = new EmbedBuilder();

            eb.WithTitle("Suggestion");
            eb.WithColor(BotUtils.Kamtro);
            eb.WithThumbnailUrl(User.GetAvatarUrl());

            eb.AddField($"The user {BotUtils.GetFullUsername(User)} has suggested:", Suggestion);

            return(eb.Build());
        }
        /// <summary>
        /// Happens when a user is unbanned from a server the bot is in.
        /// </summary>
        /// <param name="user">The user that was unbanned</param>
        /// <param name="server">The server they were unbanned from</param>
        /// <returns></returns>
        public async Task OnMemberUnban(SocketUser user, SocketGuild server) {
            if(CrossBan == null) {
                CrossBan = new Dictionary<ulong, CrossBanDataNode>();
                SaveList();
            }

            if (CrossBan.ContainsKey(user.Id) && server.Id == ServerData.Server.Id) {
                CrossBan.Remove(user.Id);
                KLog.Info($"Removed user {BotUtils.GetFullUsername(user)} from cross-ban list");
                SaveList();
            }
        }
        /// <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);
        }
        /// <summary>
        /// Updates the User Info data file to save the user's current username and nickname.
        /// Call this method when profiles are being checked.
        /// Author: Arcy, Carbon
        /// </summary>
        /// <param name="user">The user to update</param>
        private void UpdateUserNames(SocketGuildUser user)
        {
            UserDataManager.GetUserData(user).Username = BotUtils.GetFullUsername(user);

            if (user.Nickname != null)
            {
                UserDataManager.GetUserData(user).Nickname = user.Nickname;
            }
            else
            {
                UserDataManager.GetUserData(user).Nickname = BotUtils.GetFullUsername(user);  // Added check so that the bot updates with the user clears their username
            }
        }
Exemple #10
0
        private async Task PermCheck(SocketGuildUser user)
        {
            int perm = 0;

            if (ServerData.HasPermissionLevel(user, ServerData.PermissionLevel.USER))
            {
                perm++;

                if (ServerData.HasPermissionLevel(user, ServerData.PermissionLevel.TRUSTED))
                {
                    perm++;

                    if (ServerData.HasPermissionLevel(user, ServerData.PermissionLevel.MODERATOR))
                    {
                        perm++;

                        if (ServerData.HasPermissionLevel(user, ServerData.PermissionLevel.ADMIN))
                        {
                            perm++;
                        }
                    }
                }
            }

            BasicEmbed be;

            switch (perm)
            {
            case 1:
                be = new BasicEmbed($"Permission Level For User {BotUtils.GetFullUsername(user)}", "User", "Permission Level:", BotUtils.Kamtro, user.GetAvatarUrl());
                break;

            case 2:
                be = new BasicEmbed($"Permission Level For User {BotUtils.GetFullUsername(user)}", "Trusted", "Permission Level:", BotUtils.Green, user.GetAvatarUrl());
                break;

            case 3:
                be = new BasicEmbed($"Permission Level For User {BotUtils.GetFullUsername(user)}", "Moderator", "Permission Level:", BotUtils.Blue, user.GetAvatarUrl());
                break;

            case 4:
                be = new BasicEmbed($"Permission Level For User {BotUtils.GetFullUsername(user)}", "Admin", "Permission Level:", BotUtils.Purple, user.GetAvatarUrl());
                break;

            default:
                be = new BasicEmbed($"Permission Level For User {BotUtils.GetFullUsername(user)}", "Muted", "Permission Level:", BotUtils.Grey, user.GetAvatarUrl());
                break;
            }

            await be.Display(Context.Channel);
        }
        private async Task StrikeUser(SocketUser user)
        {
            // First, the classic null check
            if (BotUtils.GetGUser(Context) == null)
            {
                await Context.Channel.SendMessageAsync(BotUtils.KamtroText("That user does not exist!"));

                KLog.Info($"User {BotUtils.GetFullUsername(Context.User)} attempted to strike non-existant member {BotUtils.GetFullUsername(user)}");
                return;
            }

            // Flavor text for trying to strike yourself
            if (user.Id == Context.User.Id)
            {
                await Context.Channel.SendMessageAsync(BotUtils.KamtroText("We would like to save the strikes for those that deserve it."));

                return;
            }

            // next, check to see if Kamtro has perms to ban the user
            if (!BotUtils.HighestUser(BotUtils.GetGUser(Context.Client.CurrentUser.Id), BotUtils.GetGUser(user.Id)))
            {
                await Context.Channel.SendMessageAsync(BotUtils.KamtroText("The user is higher than me, so I cannot strike them."));

                KLog.Info($"User {BotUtils.GetFullUsername(Context.User)} attempted to strike member {BotUtils.GetFullUsername(user)} of higher status than bot");
                return;
            }

            // next, check if the caller can ban the user
            if (!ServerData.HasPermissionLevel(BotUtils.GetGUser(Context), ServerData.PermissionLevel.ADMIN))
            {
                if (BotUtils.HighestUser(BotUtils.GetGUser(user.Id), BotUtils.GetGUser(Context), true))
                {
                    await Context.Channel.SendMessageAsync(BotUtils.KamtroText("This user is higher or equal than you, and as such, you cannot strike them."));

                    KLog.Info($"User {BotUtils.GetFullUsername(Context.User)} attempted to strike member {BotUtils.GetFullUsername(user)} of higher status than caller");
                    return;
                }
            }

            if (AdminDataManager.GetStrikes(user) >= 2)
            {
                await BanUser(user);

                return;
            }

            StrikeEmbed se = new StrikeEmbed(Context, user);
            await se.Display();
        }
Exemple #12
0
        public override Embed GetEmbed()
        {
            EmbedBuilder eb = new EmbedBuilder();

            eb.WithTitle("Admin Addition Confirmation");
            eb.WithColor(BotUtils.Red);

            eb.AddField(BotUtils.ZeroSpace, "Are you sure?");

            eb.AddField("Member to Add", BotUtils.GetFullUsername(User));

            AddMenu(eb);

            return(eb.Build());
        }
Exemple #13
0
        /// <summary>
        /// Crafts the item. No checks in method
        /// </summary>
        /// <param name="item">The item to craft</param>
        private void Craft(uint itemId)
        {
            Item item = ItemManager.GetItem(itemId);

            foreach (uint k in item.GetRecipe().Keys)
            {
                LoseItem(k, item.GetRecipe()[k]);
            }

            AddItem(itemId);

            KLog.Info($"User {BotUtils.GetFullUsername(BotUtils.GetGUser(UserDataManager.UserData.FirstOrDefault(x => x.Value.Inventory == this).Key))} crafted item {item.Name} (ID: {itemId})");

            ParseInventory();
        }
Exemple #14
0
        public override Embed GetEmbed()
        {
            EmbedBuilder eb = new EmbedBuilder();

            eb.WithTitle($"Ban {BotUtils.GetFullUsername(Target)}");
            eb.WithThumbnailUrl(Target.GetAvatarUrl());
            eb.WithColor(BotUtils.Red);

            eb.AddField("User Strike Count:", AdminDataManager.GetStrikes(Target).ToString());

            eb.AddField("Will notify user?", notifyTarget ? "Yes" : "No");

            AddEmbedFields(eb);
            AddMenu(eb);

            return(eb.Build());
        }
        public static void AddBan(SocketUser target, BanDataNode ban)
        {
            int        pos   = GetEntryPos(target.Id);
            ExcelRange cells = StrikeLog.Workbook.Worksheets[StrikeLogPage].Cells;

            cells[$"J{pos}:L{pos}"].LoadFromArrays(ban.GetBanForExcel());
            KLog.Info($"Banned user {BotUtils.GetFullUsername(target)} by {ban.Moderator} for reason: {ban.Reason}. Ban added in cell range J{pos}:L{pos}.");
            SaveExcel();

            // User doesn't have an entry, so is likely just a troll.
            GenUserStrike(pos, target);
            cells[$"J{pos}:L{pos}"].LoadFromArrays(ban.GetBanForExcel());
            // Set auto fit
            cells[StrikeLog.Workbook.Worksheets[StrikeLogPage].Dimension.Address].AutoFitColumns();
            KLog.Info($"Banned user {BotUtils.GetFullUsername(target)} by {ban.Moderator} for reason: {ban.Reason}. Ban added in cell range J{pos}:L{pos}.");
            SaveExcel();
        }
Exemple #16
0
        public override Embed GetEmbed()
        {
            EmbedBuilder eb = new EmbedBuilder();

            eb.WithTitle($"Add Strike for {BotUtils.GetFullUsername(Target)}");
            eb.WithThumbnailUrl(Target.GetAvatarUrl());
            eb.WithColor(BotUtils.Orange);

            eb.AddField("User's current strike count:", $"{AdminDataManager.GetStrikes(Target)}");

            eb.AddField("Will notify user?", notifyUser ? "Yes":"No");

            AddEmbedFields(eb);
            AddMenu(eb);

            return(eb.Build());
        }
Exemple #17
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
        }
        /// <summary>
        /// Happens whenever a user joins a server the bot is in
        /// </summary>
        /// <param name="user">The user that joined</param>
        /// <returns></returns>
        public async Task OnMemberJoin(SocketGuildUser user) {
            // Add default roles
            await user.AddRoleAsync(ServerData.Kamexican);
            await user.AddRoleAsync(ServerData.Retropolitan);


            // For cross ban.
            if(CrossBan != null && CrossBan.ContainsKey(user.Id)) {
                await BotUtils.AdminLog($"Cross-banned user {BotUtils.GetFullUsername(user)}. " + CrossBan[user.Id].GetInfoText());
                AdminDataManager.AddBan(user, new BanDataNode(Program.Client.CurrentUser, $"[X-ban | {CrossBan[user.Id].GetServer()}] {CrossBan[user.Id].Reason}"));
                await ServerData.Server.AddBanAsync(user);

                KLog.Info($"Cross-banned user {BotUtils.GetFullUsername(user)}");
                return;
            }
            // welcome user 
            Embed e = new EmbedBuilder().WithTitle("Welcome to Kamtro!").WithColor(BotUtils.Kamtro).WithDescription(Program.Settings.WelcomeMessageTemplate).Build();
            await BotUtils.DMUserAsync(user, e);
        }
        private async Task BanUser(SocketUser user)
        {
            // First, the classic null check
            if (BotUtils.GetGUser(Context) == null)
            {
                await Context.Channel.SendMessageAsync(BotUtils.KamtroText("That user does not exist!"));

                KLog.Info($"User {BotUtils.GetFullUsername(Context.User)} attempted to ban non-existant member {BotUtils.GetFullUsername(user)}");
                return;
            }

            // Flavor text for trying to ban yourself
            if (user.Id == Context.User.Id)
            {
                await Context.Channel.SendMessageAsync(BotUtils.KamtroText("Sorry, but we still need you."));

                return;
            }

            // next, check to see if Kamtro has perms to ban the user
            if (!BotUtils.HighestUser(BotUtils.GetGUser(Context.Client.CurrentUser.Id), BotUtils.GetGUser(user.Id)))
            {
                await Context.Channel.SendMessageAsync(BotUtils.KamtroText("The user is higher than me, so I cannot ban them."));

                KLog.Info($"User {BotUtils.GetFullUsername(Context.User)} attempted to ban member {BotUtils.GetFullUsername(user)} of higher status than bot");
                return;
            }

            // next, check if the caller can ban the user
            if (!ServerData.HasPermissionLevel(BotUtils.GetGUser(Context), ServerData.PermissionLevel.ADMIN))
            {
                if (BotUtils.HighestUser(BotUtils.GetGUser(user.Id), BotUtils.GetGUser(Context), true))
                {
                    await Context.Channel.SendMessageAsync(BotUtils.KamtroText("This user is higher or equal than you, and as such, you cannot ban them."));

                    KLog.Info($"User {BotUtils.GetFullUsername(Context.User)} attempted to ban member {BotUtils.GetFullUsername(user)} of higher status than caller");
                    return;
                }
            }

            BanEmbed be = new BanEmbed(Context, user);
            await be.Display();
        }
        public NameChangeEmbed(SocketGuildUser before, SocketGuildUser after, bool nickname = false)
        {
            User     = after;
            Nickname = nickname;
            Url      = after.GetAvatarUrl();

            if (nickname)
            {
                Bef = before.Nickname;
                Aft = after.Nickname;
            }
            else
            {
                Bef = BotUtils.GetFullUsername(before);
                Aft = BotUtils.GetFullUsername(after);
            }

            MessageTimestamp = DateTimeOffset.Now;
        }
        /// <summary>
        /// Adds a user to the Database.
        /// </summary>
        /// <remarks>
        /// This method saves every time because there aren't going to be too many new users past a certain point
        /// </remarks>
        /// <param name="user">The User to add</param>
        /// <returns>The data node that was added</returns>
        public static Tuple <UserDataNode, UserSettingsNode> AddUser(SocketGuildUser user)
        {
            if (!UserData.ContainsKey(user.Id))
            {
                UserDataNode node = new UserDataNode(user.Username, user.Nickname ?? "");
                UserData.Add(user.Id, node);
                GetUserData(user).Inventory = new UserInventoryNode();
                SaveUserData();
            }

            if (!UserSettings.ContainsKey(user.Id))
            {
                UserSettingsNode node = new UserSettingsNode(BotUtils.GetFullUsername(user));
                UserSettings.Add(user.Id, node);
                SaveUserSettings();
            }

            Tuple <UserDataNode, UserSettingsNode> value = new Tuple <UserDataNode, UserSettingsNode>(GetUserData(user), GetUserSettings(user));

            return(value);
        }
        /// <summary>
        /// Happens whenever anything about a user (except roles) updates
        /// </summary>
        /// <remarks>
        /// This is pretty dumb. 
        /// It's up to you to figure out what changed. It could be anything from a new pfp or username,
        /// to changing your status from idle to online.
        /// </remarks>
        /// <param name="before">User before</param>
        /// <param name="after">User after</param>
        /// <returns></returns>
        public async Task OnMemberUpdate(SocketGuildUser before, SocketGuildUser after) {
            if (before.Guild != ServerData.Server || before.Status != after.Status) return; // If it's not on kamtro, or it was just a status update (online to AFK, etc), ignore it

            KLog.Debug($"Member {BotUtils.GetFullUsername(before)} updated.");

            if(BotUtils.GetFullUsername(before) != BotUtils.GetFullUsername(after)) {
                // If the user changed their name.
                KLog.Debug($"Username Change: {BotUtils.GetFullUsername(before)} --> {BotUtils.GetFullUsername(after)}");
                
                NameChangeEmbed nce = new NameChangeEmbed(before, after);
                await nce.Display(ServerData.LogChannel, after.Username + "#" + after.Discriminator);
            }

            KLog.Debug("FLAG GH-A");

            if (before.Nickname != after.Nickname) {
                // If the nickame changed
                KLog.Debug($"Nickname Change: {BotUtils.GetFullUsername(before)}: {(before.Nickname == null ? "[No Nickname]":$"'{before.Nickname}'")} --> {(after.Nickname == null ? "[No Nickname]" : $"'{after.Nickname}'")}");

                NameChangeEmbed nce = new NameChangeEmbed(before, after, true);
                await nce.Display(ServerData.LogChannel, after.Username + "#" + after.Discriminator);
            }
        public async Task EditStrikeLogAsync([Remainder] string args = "")
        {
            if (!ServerData.HasPermissionLevel(BotUtils.GetGUser(Context), ServerData.PermissionLevel.MODERATOR))
            {
                return;
            }

            if (Context.Message.Attachments.Count != 1)
            {
                StrikeLogEditEmbed sle = new StrikeLogEditEmbed(Context);
                await sle.Display();

                return;
            }

            // Alt version
            Attachment file = Context.Message.Attachments.ElementAt(0);

            if (file.Filename != "strikelog.xlsx")
            {
                await ReplyAsync(BotUtils.KamtroText("The strike log must be an excel file named strikelog.xlsx!"));

                return;
            }

            // At this point, the file is valid
            string url = file.Url;

            WebClient wc = new WebClient();

            wc.DownloadFile(url, AdminDataManager.StrikeLogPath);
            wc.Dispose();

            KLog.Info($"Strike log updated by {BotUtils.GetFullUsername(Context.User)}");
            await ReplyAsync(BotUtils.KamtroText("The strike log has been updated!"));
        }
        public static async Task OnChannelMessage(SocketUserMessage message)
        {
            if ((message.Author as SocketGuildUser) == null || message.Channel.Id == Program.Settings.BotChannelID)
            {
                return;                                                              // only count server messages
            }
            bool userAdded = AddUserIfNotExists(message.Author as SocketGuildUser);  // if the user does not have an entry, add it.
            // Add score
            // x = user's consecutive messages
            int x = GeneralHandler.ConsMessages[message.Channel.Id];

            int score;

            if (!UserData.ContainsKey(message.Author.Id))
            {
                UserData.Add(message.Author.Id, new UserDataNode(BotUtils.GetFullUsername(message.Author)));
            }

            if (UserData[message.Author.Id].WeeklyScore > SCORE_NERF)
            {
                score = Math.Max(0, 3 - x);  // If the user has a high enough score, nerf the gain rate
            }
            else
            {
                score = Math.Max(1, 6 - x);  // give the user a score of 5 if their message comes after another users, else give one less point for each consecutive message down to 1 point per message
            }

            await AddScore(BotUtils.GetGUser(message.Author.Id), score);

            // End of score calculation

            if (userAdded && !BotUtils.SaveInProgress)
            {
                SaveUserData();                                         // save the data if the user was added, but only if autosave isn't in progress.
            }
        }
        public static async Task AddTitle(SocketGuildUser user, int titleid)
        {
            if (!NodeMap.ContainsKey(titleid))
            {
                KLog.Error($"Attempted to give user {BotUtils.GetFullUsername(user)} invalid title ID #{titleid}");
                return;
            }

            TitleNode node = NodeMap[titleid];

            if (node == null)
            {
                KLog.Error($"Attempted to give user {BotUtils.GetFullUsername(user)} null title with ID #{titleid}");
                return;
            }

            UserDataNode u = UserDataManager.GetUserData(user);

            if (u.Titles == null)
            {
                u.Titles = new List <int>();
            }

            if (u.Titles.Contains(titleid))
            {
                return;                              // Don't give duplicate titles
            }
            u.Titles.Add(titleid);
            node.OnComplete(user);

            KLog.Important($"User {BotUtils.GetFullUsername(user)} has earned title {node.Name}");

            UserDataManager.SaveUserData();

            await AnnounceAchievement(user, node);
        }
        private void HandleConfirm()
        {
            LastPage = PageNum;

            switch (PageNum)
            {
            case 1:
                switch (OpCursor + 1)
                {
                case 1:
                    PageNum = 2;
                    break;

                case 2:
                    PageNum = 4;
                    break;

                case 3:
                    PageNum = 9;
                    break;
                }
                break;

            case 2:
                // autofill
                if (Autofill != null)
                {
                    InputFields[3][1].SetValue(Parse(Autofill.Id.ToString()));
                    InputFields[3][2].SetValue(Parse(BotUtils.GetFullUsername(Autofill)));
                    InputFields[3][3].SetValue(Parse(AdminDataManager.GetStrikeReason(Autofill.Id, 1)));
                    InputFields[3][4].SetValue(Parse(AdminDataManager.GetStrikeReason(Autofill.Id, 2)));
                    InputFields[3][5].SetValue(Parse(AdminDataManager.GetStrikeReason(Autofill.Id, 3)));
                }

                PageNum = 3;
                break;

            case 3:
                ulong id;
                if (!string.IsNullOrWhiteSpace(UserId) && ulong.TryParse(UserId, out id))
                {
                    bool strike1Added = false;
                    bool strike2Added = false;

                    if (!string.IsNullOrWhiteSpace(Strike1Reason) && Strike1Reason != DefaultText)
                    {
                        AdminDataManager.AddStrike(id, new StrikeDataNode(Context.User, Strike1Reason), BotUtils.GetFullUsername(BotUtils.GetGUser(id)), AdminDataManager.GetStrikes(id) >= 1);
                        strike1Added = true;
                    }

                    if (!string.IsNullOrWhiteSpace(Strike2Reason) && Strike2Reason != DefaultText)
                    {
                        if (!strike1Added && AdminDataManager.GetStrikes(id) == 0)
                        {
                            // Add strike 1 if it wasn't added a few lines ago, and it isn't already there
                            AdminDataManager.AddStrike(id, new StrikeDataNode(Context.User, Strike1Reason), BotUtils.GetFullUsername(BotUtils.GetGUser(id)), AdminDataManager.GetStrikes(id) >= 1);
                            strike1Added = true;
                        }

                        // Add strike 2
                        AdminDataManager.AddStrike(id, new StrikeDataNode(Context.User, Strike2Reason), BotUtils.GetFullUsername(BotUtils.GetGUser(id)), AdminDataManager.GetStrikes(id) >= 2);
                        strike2Added = true;
                    }

                    if (!string.IsNullOrWhiteSpace(BanReason) && BanReason != DefaultText)
                    {
                        if (!strike1Added && AdminDataManager.GetStrikes(id) == 0)
                        {
                            // Add strike 1 if it wasn't added a few lines ago, and it isn't already there
                            AdminDataManager.AddStrike(id, new StrikeDataNode(Context.User, Strike1Reason), BotUtils.GetFullUsername(BotUtils.GetGUser(id)), AdminDataManager.GetStrikes(id) >= 1);
                        }

                        if (!strike2Added && AdminDataManager.GetStrikes(id) == 1)
                        {
                            AdminDataManager.AddStrike(id, new StrikeDataNode(Context.User, Strike2Reason), BotUtils.GetFullUsername(BotUtils.GetGUser(id)), AdminDataManager.GetStrikes(id) >= 2);
                        }

                        AdminDataManager.AddBan(id, new BanDataNode(Context.User, BanReason), BotUtils.GetFullUsername(BotUtils.GetGUser(id)));
                    }

                    PageNum = 14;
                }
                break;

            case 4:
                // autofill
                if (Autofill != null)
                {
                    UserId       = Autofill.Id.ToString();
                    FullUsername = BotUtils.GetFullUsername(Autofill);
                    InputFields[6][1].SetValue(Parse(AdminDataManager.GetStrikeReason(Autofill.Id, 1)));
                    InputFields[7][1].SetValue(Parse(AdminDataManager.GetStrikeReason(Autofill.Id, 2)));
                    InputFields[8][1].SetValue(Parse(AdminDataManager.GetStrikeReason(Autofill.Id, 3)));
                }
                else
                {
                    return;     // you must specify a user
                }

                PageNum = 5;
                break;

            case 5:
                switch (OpCursor + 1)
                {
                case 1:
                    PageNum = 6;
                    break;

                case 2:
                    PageNum = 7;
                    break;

                case 3:
                    PageNum = 8;
                    break;
                }
                break;

            case 6:
                // handle confirm
                AdminDataManager.SetStrikeReason(Autofill.Id, 1, Strike1Reason6, BotUtils.GetGUser(Context));
                PageNum = 14;
                break;

            case 7:
                // handle confirm
                AdminDataManager.SetStrikeReason(Autofill.Id, 2, Strike2Reason7, BotUtils.GetGUser(Context));
                PageNum = 14;
                break;

            case 8:
                // handle confirm
                AdminDataManager.SetStrikeReason(Autofill.Id, 3, BanReason8, BotUtils.GetGUser(Context));
                PageNum = 14;
                break;

            case 9:
                // HC
                if (Autofill != null)
                {
                    UserId          = Autofill.Id.ToString();
                    FullUsername    = BotUtils.GetFullUsername(Autofill);
                    Strike1Reason11 = AdminDataManager.GetStrikeReason(Autofill.Id, 1);
                    Strike2Reason12 = AdminDataManager.GetStrikeReason(Autofill.Id, 2);
                    BanReason13     = AdminDataManager.GetStrikeReason(Autofill.Id, 3);
                }
                else
                {
                    return;     // you must specify a user
                }

                PageNum = 10;
                break;

            case 10:
                switch (OpCursor + 1)
                {
                case 1:
                    PageNum = 11;
                    break;

                case 2:
                    PageNum = 12;
                    break;

                case 3:
                    PageNum = 13;
                    break;
                }
                break;

            case 11:
                // handle confirm
                AdminDataManager.DeleteStrike(Autofill.Id, 1);
                PageNum = 14;
                break;

            case 12:
                // handle confirm
                AdminDataManager.DeleteStrike(Autofill.Id, 2);
                PageNum = 14;
                break;

            case 13:
                // handle confirm
                AdminDataManager.DeleteStrike(Autofill.Id, 3);
                PageNum = 14;
                break;
            }
        }
        public async Task MessageChannelAsync([Remainder] string args = "")
        {
            if (!ServerData.HasPermissionLevel(BotUtils.GetGUser(Context), ServerData.PermissionLevel.ADMIN))
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(args))
            {
                await ReplyAsync(BotUtils.KamtroText("You need to say a message!"));

                return;
            }

            SocketTextChannel target = null;

            // Check if a channel name was specified
            string[] arrayCheck = Context.Message.Content.Split(' ');
            string   channelToCheck;

            // Check if a channel was even in the message
            if (arrayCheck.Length > 1)
            {
                channelToCheck = arrayCheck[1];

                // Check if channel is mentioned in DMs
                if (Context.Channel is IDMChannel && channelToCheck.StartsWith("<#"))
                {
                    target = ServerData.Server.GetTextChannel(ulong.Parse(channelToCheck.Substring(2, channelToCheck.Length - 3)));
                }
                else
                {
                    // Check for name matches
                    foreach (SocketTextChannel textChannel in ServerData.Server.TextChannels)
                    {
                        if (UtilStringComparison.CompareWordScore(channelToCheck, textChannel.Name) > 0.66)
                        {
                            target = textChannel;
                            break;
                        }
                    }
                }
            }
            else if (Context.Message.MentionedChannels.Count < 1)
            {
                await ReplyAsync(BotUtils.KamtroText("You need to specify the channel!"));

                return;
            }

            if (target == null)
            {
                try
                {
                    target = Context.Message.MentionedChannels.ElementAt(0) as SocketTextChannel;
                } catch (Exception) { }
            }

            if (target == null)
            {
                await ReplyAsync(BotUtils.KamtroText("You need to specify a text channel!"));

                return;
            }

            List <string> msgl = args.Split(' ').ToList();

            msgl.RemoveAt(0);

            if (msgl.Count <= 0)
            {
                await ReplyAsync(BotUtils.KamtroText("You need to say a message!"));

                return;
            }

            string msg = string.Join(" ", msgl.ToArray());

            await target.SendMessageAsync(BotUtils.KamtroText(msg));

            await Context.Message.AddReactionAsync(ReactionHandler.CHECK_EM);

            KLog.Info($"Kamtro Message Sent in #{target.Name} from [{BotUtils.GetFullUsername(Context.User)}]: {msg}");
        }
Exemple #28
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;
            }
        }