Esempio n. 1
0
        public async Task SoftbanAsync(EventContext e)
        {
            IDiscordUser currentUser = await e.GetCurrentUserAsync();

            if (currentUser.HasPermissions(e.Channel, DiscordGuildPermission.BanMembers))
            {
                List <string> arg        = e.arguments.Split(' ').ToList();
                IDiscordUser  bannedUser = null;

                if (e.message.MentionedUserIds.Count > 0)
                {
                    bannedUser = await e.Guild.GetUserAsync(e.message.MentionedUserIds.First());
                }
                else
                {
                    if (arg.Count > 0)
                    {
                        bannedUser = await e.Guild.GetUserAsync(ulong.Parse(arg[0]));
                    }
                }

                if (bannedUser == null)
                {
                    e.ErrorEmbed(e.GetResource("ban_error_user_null"))
                    .QueueToChannel(e.Channel);
                    return;
                }

                if (bannedUser.Hierarchy >= currentUser.Hierarchy)
                {
                    e.ErrorEmbed(e.GetResource("permission_error_low", "softban"))
                    .QueueToChannel(e.Channel);
                    return;
                }

                if (bannedUser.Hierarchy >= e.Author.Hierarchy)
                {
                    e.ErrorEmbed(e.GetResource("permission_user_error_low", "ban"))
                    .QueueToChannel(e.Channel);
                    return;
                }

                arg.RemoveAt(0);

                string reason = string.Join(" ", arg);

                IDiscordEmbed embed = Utils.Embed;
                embed.Title       = "⚠ SOFTBAN";
                embed.Description = $"You've been banned from **{e.Guild.Name}**!";

                if (!string.IsNullOrWhiteSpace(reason))
                {
                    embed.AddInlineField("💬 Reason", reason);
                }

                embed.AddInlineField("💁 Banned by", e.Author.Username + "#" + e.Author.Discriminator);

                await embed.SendToUser(bannedUser);

                await bannedUser.Ban(e.Guild, 1, reason);

                await bannedUser.Unban(e.Guild);
            }
            else
            {
                e.ErrorEmbed(e.GetResource("permission_needed_error", $"`{e.GetResource("permission_ban_members")}`"))
                .QueueToChannel(e.Channel);
            }
        }
Esempio n. 2
0
        public async Task KickAsync(EventContext e)
        {
            IDiscordUser currentUser = await e.GetCurrentUserAsync();

            if (currentUser.HasPermissions(e.Channel, DiscordGuildPermission.KickMembers))
            {
                List <string> arg = e.arguments.Split(' ').ToList();

                for (int i = 0; i < arg.Count; i++)
                {
                    if (string.IsNullOrWhiteSpace(arg[i]))
                    {
                        arg.RemoveAt(i);
                        i--;
                    }
                }

                IDiscordUser bannedUser = null;
                Locale       locale     = new Locale(e.Channel.Id);

                if (e.message.MentionedUserIds.Count > 0)
                {
                    bannedUser = await e.Guild.GetUserAsync(e.message.MentionedUserIds.First());
                }
                else
                {
                    if (arg.Count > 0)
                    {
                        bannedUser = await e.Guild.GetUserAsync(ulong.Parse(arg[0]));
                    }
                }

                if (bannedUser == null)
                {
                    e.ErrorEmbed(e.GetResource("ban_error_user_null"))
                    .QueueToChannel(e.Channel);
                    return;
                }

                if (bannedUser.Hierarchy >= currentUser.Hierarchy)
                {
                    e.ErrorEmbed(e.GetResource("permission_error_low", "kick"))
                    .QueueToChannel(e.Channel);
                    return;
                }

                if (bannedUser.Hierarchy >= e.Author.Hierarchy)
                {
                    e.ErrorEmbed(e.GetResource("permission_user_error_low", "ban"))
                    .QueueToChannel(e.Channel);
                    return;
                }

                arg.RemoveAt(0);

                string reason = string.Join(" ", arg);

                IDiscordEmbed embed = Utils.Embed;
                embed.Title       = locale.GetString("miki_module_admin_kick_header");
                embed.Description = locale.GetString("miki_module_admin_kick_description", new object[] { e.Guild.Name });

                if (!string.IsNullOrWhiteSpace(reason))
                {
                    embed.AddInlineField(locale.GetString("miki_module_admin_kick_reason"), reason);
                }

                embed.AddInlineField(locale.GetString("miki_module_admin_kick_by"), e.Author.Username + "#" + e.Author.Discriminator);

                embed.Color = new Miki.Common.Color(1, 1, 0);

                await embed.SendToUser(bannedUser);

                await bannedUser.Kick(reason);
            }
            else
            {
                e.ErrorEmbed(e.GetResource("permission_needed_error", $"`{e.GetResource("permission_kick_members")}`"))
                .QueueToChannel(e.Channel);
            }
        }