예제 #1
0
        public async Task PunishMemberAsync(DiscordGuild guild, DiscordMember member, PunishmentActionType type, TimeSpan?cooldown = null, string reason = null)
        {
            try
            {
                DiscordRole   muteRole;
                SavedTaskInfo task;
                switch (type)
                {
                case PunishmentActionType.Kick:
                    await member.RemoveAsync(reason ?? this.reason);

                    break;

                case PunishmentActionType.PermanentMute:
                    muteRole = await this.GetOrCreateMuteRoleAsync(guild);

                    if (member.Roles.Contains(muteRole))
                    {
                        return;
                    }
                    await member.GrantRoleAsync(muteRole, reason ?? this.reason);

                    break;

                case PunishmentActionType.PermanentBan:
                    await member.BanAsync(1, reason : reason ?? this.reason);

                    break;

                case PunishmentActionType.TemporaryBan:
                    await member.BanAsync(0, reason : reason ?? this.reason);

                    task = new UnbanTaskInfo(guild.Id, member.Id, cooldown is null ? null : DateTimeOffset.Now + cooldown);
                    await SavedTaskExecutor.ScheduleAsync(this.shard.SharedData, this.shard.Database, this.shard.Client, task);

                    break;

                case PunishmentActionType.TemporaryMute:
                    muteRole = await this.GetOrCreateMuteRoleAsync(guild);

                    if (member.Roles.Contains(muteRole))
                    {
                        return;
                    }
                    await member.GrantRoleAsync(muteRole, reason ?? this.reason);

                    task = new UnmuteTaskInfo(guild.Id, member.Id, muteRole.Id, cooldown is null ? null : DateTimeOffset.Now + cooldown);
                    await SavedTaskExecutor.ScheduleAsync(this.shard.SharedData, this.shard.Database, this.shard.Client, task);

                    break;
                }
            } catch
            {
                var logchn = this.shard.SharedData.GetLogChannelForGuild(this.shard.Client, guild);
                if (!(logchn is null))
                {
                    var emb = new DiscordEmbedBuilder
                    {
                        Title = "User punish attemp failed! Check my permissions...",
                        Color = DiscordColor.Red
                    };
                    emb.AddField("User", member?.ToString() ?? "unknown", inline: true);
                    emb.AddField("Reason", reason ?? this.reason, inline: false);

                    await logchn.SendMessageAsync(embed : emb.Build());
                }
            }
        }
        public async Task Ban(CommandContext ctx, DiscordMember Member, [RemainingText] string Reason = null)
        {
            await Member.BanAsync(reason : Reason);

            await ctx.Message.DeleteAsync("Admin command hide");
        }
예제 #3
0
        public async Task ban(CommandContext ctx, DiscordMember member, string reason)
        {
            await member.BanAsync(0, reason);

            await ctx.Channel.SendMessageAsync(member.Mention + " has been banned for: " + reason).ConfigureAwait(false);
        }
        public async Task TempBanMemberAsync(CommandContext context,
                                             DiscordMember member,
                                             int numDays = 0,
                                             [Description("Duration to ban the member for (must be quoted if there are any spaces, however it should work with colloquial language)")]
                                             string durationOfBan = null,
                                             [RemainingText]
                                             string reason = null)
        {
            DateTimeV2ModelResult durationResult = DateTimeRecognizer
                                                   .RecognizeDateTime(durationOfBan, culture: Culture.English)
                                                   .Select(model => model.ToDateTimeV2ModelResult())
                                                   .Where(result => result.TypeName is DateTimeV2Type.Duration)
                                                   .FirstOrDefault();

            if (durationResult == null)
            {
                await context.RespondAsync("There was an error parsing the duration");

                return;
            }

            Duration duration       = (Duration)durationResult.Values.FirstOrDefault().Value;
            string   durationString = Period.FromSeconds((long)duration.TotalSeconds).AsHumanReadableString();

            DiscordEmbedBuilder messageEmbed = new DiscordEmbedBuilder()
                                               .WithTitle($"You have been temporarily banned from {context.Guild.Name}!")
                                               .AddField("Duration", durationString);

            if (reason != null)
            {
                messageEmbed.AddField("Reason:", reason);
            }

            using IBotAccessProvider provider = this.providerBuilder.Build();

            DiscordChannel logChannel = await SendModerationEmbedAndGetLogChannel(messageEmbed, member, context.Member, context.Guild, provider);

            await member.BanAsync(numDays, reason);

            await context.Message.CreateReactionAsync(DiscordEmoji.FromName(context.Client, ":white_check_mark:"));

            provider.AddModerationAuditRecord(context.Guild.Id, context.User.Id, member.Id, ModerationActionType.TEMPBAN, reason);

            if (logChannel == null)
            {
                return;
            }

            DiscordEmbedBuilder successEmbed = new DiscordEmbedBuilder()
                                               .WithTitle($"{member.Username} was temporarily banned")
                                               .AddField("Moderator", context.User.Username)
                                               .AddField("Time Banned", durationString)
                                               .WithFooter($"{this.clock.GetCurrentInstant():g}");

            if (reason != null)
            {
                successEmbed.AddField("Reason:", reason);
            }

            await logChannel.SendMessageAsync(embed : successEmbed);

            string jobId = BackgroundJob.Schedule <ModerationService>((service) =>
                                                                      service.UnbanAsync(context.Guild.Id, member.Id),
                                                                      duration.ToTimeSpan()
                                                                      );

            provider.AddGuildBackgroundJob(jobId, context.Guild.Id, $"Unban - {member.DisplayName}", this.clock.GetCurrentInstant() + duration, GuildJobType.TEMP_BAN);
        }
예제 #5
0
        private static async Task MainAsync(string[] args)
        {
            discord = new DiscordClient(new DiscordConfiguration
            {
                Token                 = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "token.txt"),
                TokenType             = TokenType.Bot,
                UseInternalLogHandler = true,
                LogLevel              = LogLevel.Debug,
            });

            discord.MessageCreated += async e =>
            {
                if (e.Message.Content.ToLower().Contains("n***a"))
                {
                    member = (DiscordMember)e.Author;
                }
                await member.BanAsync();
            };
            discord.MessageCreated += async e =>
            {
                if (e.Message.Content.ToLower().Contains("tranny"))
                {
                    member = (DiscordMember)e.Author;
                }
                await member.BanAsync();
            };
            discord.MessageCreated += async e =>
            {
                if (e.Message.Content.ToLower().Contains("retarded"))
                {
                    member = (DiscordMember)e.Author;
                }
                await member.BanAsync();
            };
            discord.MessageCreated += async e =>
            {
                if (e.Message.Content.ToLower().Contains("f****t"))
                {
                    member = (DiscordMember)e.Author;
                }
                await member.BanAsync();
            };
            discord.MessageCreated += async e =>
            {
                if (e.Message.Content.ToLower().Contains(";;bitch"))
                {
                    await message.DeleteAsync();
                }
            };

            discord.GuildMemberAdded += async e =>
            {
                guest = e.Guild.GetRole(609506619532771329);
                await e.Member.GrantRoleAsync(guest);
            };

            discord.Ready += async e =>
            {
                var game = new DiscordGame();
                game.Name = "Killing Sooper";
                await discord.UpdateStatusAsync(game : game);
            };

            commands = discord.UseCommandsNext(new CommandsNextConfiguration
            {
                StringPrefix = ";;"
            });

            var builder = new DiscordEmbedBuilder();

            builder.WithImageUrl("https://titles.trackercdn.com/destiny/common/destiny2_content/screenshots/3588934839.jpg");

            commands.RegisterCommands <Commands>();

            await discord.ConnectAsync();

            await Task.Delay(-1);
        }
예제 #6
0
        private async Task ModerateUser(CommandContext ctx, string suffix, ShimaConsts.ModerationType type)
        {
            int    userIndex    = string.IsNullOrWhiteSpace(suffix) ? -1 : suffix.IndexOf(" ");
            string userIdString = userIndex > 0 ? suffix.Substring(0, userIndex) : suffix;

            //get user to moderate
            List <ulong> userToModerateInList =
                Utils.GetIdListFromArray(ctx.Message.MentionedUsers, new string[] { userIdString });

            if (userToModerateInList.Count == 0)
            {
                await CTX.RespondSanitizedAsync(ctx,
                                                $"Please mention or type a user ID to {type.ToString().ToLower()}.");

                return;
            }
            ulong userToModerate = userToModerateInList[0];

            if (!ctx.Guild.Members.ContainsKey(userToModerate))
            {
                await CTX.RespondSanitizedAsync(ctx, $"Unable to find member with ID **{userToModerate}**");

                return;
            }

            DiscordMember exMember = ctx.Guild.Members[userToModerate];

            //get message
            string message = userIndex > 0 ? suffix.Substring(userIndex).TrimStart() : "";
            DiscordEmbedBuilder embed;

            //moderate
            switch (type)
            {
            case ShimaConsts.ModerationType.WARN:
                if (message.Length > 1024)
                {
                    await CTX.RespondSanitizedAsync(ctx, "Warning message must be under 1024 characters.");

                    return;
                }

                GuildWarn warn = (await ShimakazeBot.DbCtx.GuildWarn.AddAsync(new GuildWarn
                {
                    GuildId = ctx.Guild.Id,
                    UserId = userToModerate,
                    WarnMessage = message,
                    TimeStamp = DateTime.UtcNow
                })).Entity;
                await ShimakazeBot.DbCtx.SaveChangesAsync();

                embed = Utils.BaseEmbedBuilder(ctx,
                                               $"Added new warning for {exMember.DisplayName} ({userToModerate})",
                                               exMember.AvatarUrl,
                                               null, exMember.Color, $"warning ID: {warn.Id}");
                if (!string.IsNullOrWhiteSpace(message))
                {
                    embed.AddField("Message", message);
                }

                await CTX.RespondSanitizedAsync(ctx, null, false, embed);

                break;

            case ShimaConsts.ModerationType.KICK:
                try
                {
                    await exMember.RemoveAsync(message);

                    embed = Utils.BaseEmbedBuilder(ctx,
                                                   $"Kicked {exMember.DisplayName} ({userToModerate})",
                                                   exMember.AvatarUrl, null, exMember.Color);
                    if (!string.IsNullOrWhiteSpace(message))
                    {
                        embed.AddField("Reason", message);
                    }

                    await CTX.RespondSanitizedAsync(ctx, "Do you think they'll learn their lesson?", false, embed);
                }
                catch
                {
                    await CTX.RespondSanitizedAsync(ctx,
                                                    $"Failed to kick **{exMember.DisplayName}** ({userToModerate})");
                }
                break;

            case ShimaConsts.ModerationType.BAN:
                try
                {
                    await exMember.BanAsync(0, message);

                    embed = Utils.BaseEmbedBuilder(ctx,
                                                   $"Banned {exMember.DisplayName} ({userToModerate})",
                                                   exMember.AvatarUrl, null, exMember.Color);
                    if (!string.IsNullOrWhiteSpace(message))
                    {
                        embed.AddField("Reason", message);
                    }

                    await CTX.RespondSanitizedAsync(ctx, "Good riddance.", false, embed);
                }
                catch
                {
                    await CTX.RespondSanitizedAsync(ctx,
                                                    $"Failed to ban **{exMember.DisplayName}** ({userToModerate})");
                }
                break;
            }
        }
예제 #7
0
        public async Task Ban(CommandContext ctx, DiscordMember user)
        {
            await user.BanAsync();

            await user.SendMessageAsync("VAZA VERME, MEDIOCRE!!");
        }
예제 #8
0
        public async Task Ban(CommandContext ctx, [Description("The member to Ban.")] DiscordMember member, [Description("The reason on why to ban this member.")] string reason = "No reason given")
        {
            await member.BanAsync(7, reason : "Proty Ban : " + reason);

            await ctx.Channel.SendMessageAsync(MessageUtils.BuildSuccess($"Member {member.Mention} ({member.Id}) was banned from the server !"));
        }
예제 #9
0
        public async Task PunishMemberAsync(DiscordGuild guild, DiscordMember member, PunishmentAction type, TimeSpan?cooldown = null, string?reason = null)
        {
            Log.Debug("Punishing {Member} in guild {Guild} with action {ActionType} due to: {Reason}", member, guild, type, reason ?? this.reason);
            try {
                DiscordRole muteRole;
                GuildTask   gt;
                switch (type)
                {
                case PunishmentAction.Kick:
                    await member.RemoveAsync(reason ?? this.reason);

                    break;

                case PunishmentAction.PermanentMute:
                    muteRole = await this.GetOrCreateMuteRoleAsync(guild);

                    if (member.Roles.Contains(muteRole))
                    {
                        return;
                    }
                    await member.GrantRoleAsync(muteRole, reason ?? this.reason);

                    break;

                case PunishmentAction.PermanentBan:
                    await member.BanAsync(1, reason : reason ?? this.reason);

                    break;

                case PunishmentAction.TemporaryBan:
                    await member.BanAsync(0, reason : reason ?? this.reason);

                    gt = new GuildTask {
                        ExecutionTime = DateTimeOffset.Now + (cooldown ?? TimeSpan.FromDays(1)),
                        GuildId       = guild.Id,
                        UserId        = member.Id,
                        Type          = ScheduledTaskType.Unban,
                    };
                    await this.ss.ScheduleAsync(gt);

                    break;

                case PunishmentAction.TemporaryMute:
                    muteRole = await this.GetOrCreateMuteRoleAsync(guild);

                    if (member.Roles.Contains(muteRole))
                    {
                        return;
                    }
                    await member.GrantRoleAsync(muteRole, reason ?? this.reason);

                    gt = new GuildTask {
                        ExecutionTime = DateTimeOffset.Now + (cooldown ?? TimeSpan.FromHours(1)),
                        GuildId       = guild.Id,
                        RoleId        = muteRole.Id,
                        UserId        = member.Id,
                        Type          = ScheduledTaskType.Unmute,
                    };
                    await this.ss.ScheduleAsync(gt);

                    break;
                }
            } catch {
                if (this.ls.IsLogEnabledFor(guild.Id, out LocalizedEmbedBuilder emb))
                {
                    emb.WithLocalizedTitle("err-punish-failed");
                    emb.WithColor(DiscordColor.Red);
                    emb.AddLocalizedTitleField("str-user", member);
                    emb.AddLocalizedTitleField("str-rsn", reason ?? this.reason);
                    await this.ls.LogAsync(guild, emb.Build());
                }
            }
        }