コード例 #1
0
ファイル: BanEmbed.cs プロジェクト: DavidXLiu/Kamtro-Bot
        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;
            }
        }
コード例 #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
        /// <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);
        }
コード例 #4
0
        private static async Task AnnounceAchievement(SocketGuildUser user, TitleNode title)
        {
            AchievementNotifyEmbed ane = new AchievementNotifyEmbed(user, title);

            if ((int)title.Difficulty > (int)TitleNode.DifficultyLevel.HARD && !(title.Difficulty == TitleNode.DifficultyLevel.SECRET_EASY || title.Difficulty == TitleNode.DifficultyLevel.SECRET_MEDIUM || title.Difficulty == TitleNode.DifficultyLevel.SECRET_HARD))
            {
                await BotUtils.DMUserAsync(user, ane.GetEmbed());

                ane.Header = $"{user.GetDisplayName()} got an achievement!";
                await ane.Display(ServerData.BotChannel);
            }
            else
            {
                await BotUtils.DMUserAsync(user, ane.GetEmbed());

                // Don't notify for smaller achievements

                /*bool sent = await BotUtils.DMUserAsync(user, ane.GetEmbed());
                 *
                 * if(!sent) {
                 *  await ane.Display(ServerData.BotChannel); // Notify the user somehow
                 * }*/
            }
        }
コード例 #5
0
ファイル: RewardEmbed.cs プロジェクト: DavidXLiu/Kamtro-Bot
        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;
            }
        }
コード例 #6
0
ファイル: AdminModule.cs プロジェクト: DavidXLiu/Kamtro-Bot
        public async Task GenerateCrossBansAsync()
        {
            if (!ServerData.HasPermissionLevel(BotUtils.GetGUser(Context), ServerData.PermissionLevel.ADMIN))
            {
                return;                                                                                                // permissions checking
            }
            ScanInfoEmbed scan = new ScanInfoEmbed();

            await ReplyAsync(BotUtils.KamtroText("Scanning Kamexico for Bans..."));

            foreach (RestBan ban in await ServerData.Kamexico.GetBansAsync())
            {
                scan.KamexTotal++;
                scan.KamexUnique++;
                scan.Total++;

                GeneralHandler.CrossBan[ban.User.Id] = new CrossBanDataNode(1, ban.Reason);
            }

            await ReplyAsync(BotUtils.KamtroText("Scanning Kamexico for Bans..."));

            foreach (RestBan ban in await ServerData.Retropolis.GetBansAsync())
            {
                scan.RetroTotal++;
                scan.Total++;

                if (GeneralHandler.CrossBan.ContainsKey(ban.User.Id))
                {
                    // if it's a mutual ban
                    scan.Mutual++;
                    scan.KamexUnique--;
                }
                else
                {
                    // else if it's unique to retropolis
                    scan.RetroUnique++;
                }
            }

            int errcount = 0;

            foreach (ulong id in GeneralHandler.CrossBan.Keys)
            {
                if (BotUtils.GetGUser(id) != null)
                {
                    bool sent = await BotUtils.DMUserAsync(BotUtils.GetGUser(id), new BanNotifyEmbed($"You were banned on {GeneralHandler.CrossBan[id].GetServer()}, and therefore have been auto banned from Kamtro.\nOld ban reason:\n\n{GeneralHandler.CrossBan[id].Reason}").GetEmbed());

                    if (!sent)
                    {
                        errcount++;
                    }

                    await ServerData.Server.AddBanAsync(BotUtils.GetGUser(id));

                    scan.InKamtro++;
                }
            }

            if (errcount > 0)
            {
                await ReplyAsync(BotUtils.KamtroText($"{errcount} users could not be messaged."));
            }
            GeneralHandler.SaveList();

            await scan.Display(ServerData.AdminChannel);
        }