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); } }
public async Task BanAsync(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()); arg.RemoveAll(x => x.Contains(e.message.MentionedUserIds.First().ToString())); } else { if (arg.Count > 0) { bannedUser = await e.Guild.GetUserAsync(ulong.Parse(arg[0])); arg.RemoveAt(0); } } if (bannedUser == null) { await e.ErrorEmbed(e.GetResource("ban_error_user_null")) .QueueToChannel(e.Channel); return; } if (bannedUser.Hierarchy >= currentUser.Hierarchy) { await e.ErrorEmbed(e.GetResource("permission_error_low", "ban")) .QueueToChannel(e.Channel); return; } if (bannedUser.Hierarchy >= e.Author.Hierarchy) { await e.ErrorEmbed(e.GetResource("permission_user_error_low", "ban")) .QueueToChannel(e.Channel); return; } string reason = string.Join(" ", arg); IDiscordEmbed embed = Utils.Embed; embed.Title = "🛑 BAN"; embed.Description = e.GetResource("ban_header", $"**{e.Guild.Name}**"); if (!string.IsNullOrWhiteSpace(reason)) { embed.AddInlineField($"💬 {e.GetResource("miki_module_admin_kick_reason")}", reason); } embed.AddInlineField($"💁 {e.GetResource("miki_module_admin_kick_by")}", e.Author.Username + "#" + e.Author.Discriminator); await bannedUser.SendMessage(embed); await bannedUser.Ban(e.Guild, 1, reason); } else { await e.ErrorEmbed(e.GetResource("permission_needed_error", $"`{e.GetResource("permission_ban_members")}`")) .QueueToChannel(e.Channel); } }
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); } }
public async Task SetRoleLevelAsync(EventContext e) { using (var context = new MikiContext()) { Locale locale = Locale.GetEntity(e.Channel.Id.ToDbLong()); List <string> allArgs = new List <string>(); allArgs.AddRange(e.arguments.Split(' ')); if (allArgs.Count >= 2) { int levelrequirement = int.Parse(allArgs[allArgs.Count - 1]); allArgs.RemoveAt(allArgs.Count - 1); IDiscordRole role = e.Guild.Roles .Find(r => r.Name.ToLower() == string.Join(" ", allArgs).TrimEnd(' ').TrimStart(' ').ToLower()); if (role == null) { await e.ErrorEmbed(e.GetResource("error_role_not_found")) .QueueToChannel(e.Channel); return; } LevelRole lr = await context.LevelRoles.FindAsync(e.Guild.Id.ToDbLong(), role.Id.ToDbLong()); if (lr == null) { lr = context.LevelRoles.Add(new LevelRole() { GuildId = e.Guild.Id.ToDbLong(), RoleId = role.Id.ToDbLong(), RequiredLevel = levelrequirement }).Entity; IDiscordEmbed embed = Utils.Embed; embed.Title = "Added Role!"; embed.Description = $"I'll give someone the role {role.Name} when he/she reaches level {levelrequirement}!"; IDiscordUser currentUser = await e.GetCurrentUserAsync(); if (!currentUser.HasPermissions(e.Channel, DiscordGuildPermission.ManageRoles)) { embed.AddInlineField(e.GetResource("miki_warning"), e.GetResource("setrolelevel_error_no_permissions", $"`{e.GetResource("permission_manage_roles")}`")); } await embed.QueueToChannel(e.Channel); } else { lr.RequiredLevel = levelrequirement; IDiscordEmbed embed = Utils.Embed; embed.Title = "Updated Role!"; embed.Description = $"I'll give someone the role {role.Name} when he/she reaches level {levelrequirement}!"; await embed.QueueToChannel(e.Channel); } await context.SaveChangesAsync(); } else { await Utils.ErrorEmbed(locale, "Make sure to fill out both the role and the level when creating this!") .QueueToChannel(e.Channel); } } }