From 846e7120b4aa5092b0cc9c28117a38d5e51ebc64 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Thu, 18 Aug 2016 17:33:45 +0200 Subject: [PATCH] A lot more work on converting --- .vs/restore.dg | 4 - discord.net | 2 +- .../Administration/AdministrationModule.cs | 392 ++++---- .../Administration/Commands/AutoAssignRole.cs | 122 +-- .../Commands/CrossServerTextChannel.cs | 206 ++-- .../Commands/CustomReactionsCommands.cs | 412 ++++---- .../Commands/IncidentsCommands.cs | 88 +- .../Administration/Commands/LogCommand.cs | 906 +++++++++--------- .../Commands/MessageRepeater.cs | 230 ++--- .../Administration/Commands/PlayingRotate.cs | 314 +++--- .../Commands/RatelimitCommand.cs | 116 +-- .../Commands/SelfAssignedRolesCommand.cs | 398 ++++---- .../Administration/Commands/SelfCommands.cs | 80 +- .../Commands/ServerGreetCommand.cs | 564 +++++------ .../Commands/VoicePlusTextCommand.cs | 304 +++--- .../ClashOfClans/ClashOfClansModule.cs | 38 +- .../Modules/Games/Commands/LeetCommands.cs | 4 +- .../Modules/Games/Commands/PollCommands.cs | 6 +- .../Games/Commands/Trivia/TriviaGame.cs | 2 +- .../Modules/Games/Commands/TriviaCommands.cs | 6 +- src/NadekoBot/Modules/Games/GamesModule.cs | 12 +- src/NadekoBot/Modules/Help/HelpModule.cs | 14 +- src/NadekoBot/Modules/NSFW/NSFWModule.cs | 26 +- .../Modules/Pokemon/PokemonModule.cs | 2 +- .../Searches/Commands/AnimeSearchCommands.cs | 8 +- .../Searches/Commands/IMDB/ImdbScraper.cs | 2 +- .../Modules/Searches/Commands/JokeCommands.cs | 10 +- .../Searches/Commands/MemegenCommands.cs | 4 +- .../Commands/PokemonSearchCommands.cs | 8 +- .../Modules/Searches/SearchesModule.cs | 74 +- .../Modules/Translator/TranslatorModule.cs | 6 +- .../Modules/Utility/Commands/InfoCommands.cs | 4 +- .../Modules/Utility/UtilityModule.cs | 12 +- src/NadekoBot/NadekoBot.cs | 2 +- src/NadekoBot/Services/Impl/BotCredentials.cs | 5 +- src/NadekoBot/_Extensions/Extensions.cs | 28 +- src/NadekoBot/project.lock.json | 40 +- 37 files changed, 2199 insertions(+), 2252 deletions(-) delete mode 100644 .vs/restore.dg diff --git a/.vs/restore.dg b/.vs/restore.dg deleted file mode 100644 index 5807257f..00000000 --- a/.vs/restore.dg +++ /dev/null @@ -1,4 +0,0 @@ -#:C:\Users\Kwoth\Source\Repos\NadekoBot1.0\src\NadekoBot\NadekoBot.xproj -C:\Users\Kwoth\Source\Repos\NadekoBot1.0\src\NadekoBot\NadekoBot.xproj|C:\Users\Kwoth\Source\Repos\NadekoBot1.0\discord.net\src\Discord.Net\Discord.Net.xproj -C:\Users\Kwoth\Source\Repos\NadekoBot1.0\src\NadekoBot\NadekoBot.xproj|C:\Users\Kwoth\Source\Repos\NadekoBot1.0\discord.net\src\Discord.Net.Commands\Discord.Net.Commands.xproj -C:\Users\Kwoth\Source\Repos\NadekoBot1.0\discord.net\src\Discord.Net.Commands\Discord.Net.Commands.xproj|C:\Users\Kwoth\Source\Repos\NadekoBot1.0\discord.net\src\Discord.Net\Discord.Net.xproj diff --git a/discord.net b/discord.net index cf911456..a76956c8 160000 --- a/discord.net +++ b/discord.net @@ -1 +1 @@ -Subproject commit cf911456a751f4778fe4789973e028560624cfe8 +Subproject commit a76956c8ef516b3d5399fedc30b321043c86f112 diff --git a/src/NadekoBot/Modules/Administration/AdministrationModule.cs b/src/NadekoBot/Modules/Administration/AdministrationModule.cs index 4e35e603..2289420d 100644 --- a/src/NadekoBot/Modules/Administration/AdministrationModule.cs +++ b/src/NadekoBot/Modules/Administration/AdministrationModule.cs @@ -1,11 +1,6 @@ using Discord; using Discord.Commands; -using Discord.Modules; -using NadekoBot.Classes; -using NadekoBot.DataModels; using NadekoBot.Extensions; -using NadekoBot.Modules.Administration.Commands; -using NadekoBot.Modules.Permissions.Classes; using Newtonsoft.Json; using System; using System.Collections.Generic; @@ -14,6 +9,7 @@ using System.Text; using System.Threading.Tasks; using NadekoBot.Services; using NadekoBot.Attributes; +using System.Text.RegularExpressions; //todo fix delmsgoncmd //todo DB @@ -26,12 +22,12 @@ namespace NadekoBot.Modules.Administration { } - //todo owner only + ////todo owner only //[LocalizedCommand, LocalizedDescription, LocalizedSummary] //[RequireContext(ContextType.Guild)] //public async Task Restart(IMessage imsg) //{ - // var channel = imsg.Channel as IGuildChannel; + // var channel = imsg.Channel as ITextChannel; // await imsg.Channel.SendMessageAsync("`Restarting in 2 seconds...`"); // await Task.Delay(2000); @@ -39,12 +35,13 @@ namespace NadekoBot.Modules.Administration // Environment.Exit(0); //} + ////todo DB //[LocalizedCommand, LocalizedDescription, LocalizedSummary] //[RequireContext(ContextType.Guild)] //[RequirePermission(GuildPermission.ManageGuild)] //public async Task Delmsgoncmd(IMessage imsg) //{ - // var channel = imsg.Channel as IGuildChannel; + // var channel = imsg.Channel as ITextChannel; // var conf = SpecificConfigurations.Default.Of(channel.Guild.Id); // conf.AutoDeleteMessagesOnCommand = !conf.AutoDeleteMessagesOnCommand; @@ -58,30 +55,13 @@ namespace NadekoBot.Modules.Administration [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] [RequirePermission(GuildPermission.ManageRoles)] - public async Task Setrole(IMessage imsg, IUser userName, [Remainder] string roleName) + public async Task Setrole(IMessage imsg, IGuildUser usr, [Remainder] IRole role) { - var channel = imsg.Channel as IGuildChannel; - - if (string.IsNullOrWhiteSpace(roleName)) return; - - var usr = channel.Guild.FindUsers(userName).FirstOrDefault(); - if (usr == null) - { - await imsg.Channel.SendMessageAsync("You failed to supply a valid username").ConfigureAwait(false); - return; - } - - var role = channel.Guild.FindRoles(roleName).FirstOrDefault(); - if (role == null) - { - await imsg.Channel.SendMessageAsync("You failed to supply a valid role").ConfigureAwait(false); - return; - } - + var channel = imsg.Channel as ITextChannel; try { - await usr.AddRoles(role).ConfigureAwait(false); - await imsg.Channel.SendMessageAsync($"Successfully added role **{role.Name}** to user **{usr.Name}**").ConfigureAwait(false); + await usr.AddRolesAsync(role).ConfigureAwait(false); + await imsg.Channel.SendMessageAsync($"Successfully added role **{role.Name}** to user **{usr.Username}**").ConfigureAwait(false); } catch (Exception ex) { @@ -93,30 +73,12 @@ namespace NadekoBot.Modules.Administration [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] [RequirePermission(GuildPermission.ManageRoles)] - public async Task Removerole(IMessage imsg, IUser userName, [Remainder] string roleName) + public async Task Removerole(IMessage imsg, IGuildUser usr, [Remainder] IRole role) { - var channel = imsg.Channel as IGuildChannel; - - if (string.IsNullOrWhiteSpace(roleName)) return; - - var usr = channel.Guild.FindUsers(userName).FirstOrDefault(); - if (usr == null) - { - await imsg.Channel.SendMessageAsync("You failed to supply a valid username").ConfigureAwait(false); - return; - } - - var role = channel.Guild.FindRoles(roleName).FirstOrDefault(); - if (role == null) - { - await imsg.Channel.SendMessageAsync("You failed to supply a valid role").ConfigureAwait(false); - return; - } - try { - await usr.RemoveRoles(role).ConfigureAwait(false); - await imsg.Channel.SendMessageAsync($"Successfully removed role **{role.Name}** from user **{usr.Name}**").ConfigureAwait(false); + await usr.RemoveRolesAsync(role).ConfigureAwait(false); + await imsg.Channel.SendMessageAsync($"Successfully removed role **{role.Name}** from user **{usr.Username}**").ConfigureAwait(false); } catch { @@ -127,25 +89,17 @@ namespace NadekoBot.Modules.Administration [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] [RequirePermission(GuildPermission.ManageRoles)] - public async Task RenameRole(IMessage imsg, string r1, string r2) + public async Task RenameRole(IMessage imsg, IRole roleToEdit, string newname) { - var channel = imsg.Channel as IGuildChannel; - - var roleToEdit = channel.Guild.FindRoles(r1).FirstOrDefault(); - if (roleToEdit == null) - { - await imsg.Channel.SendMessageAsync("Can't find that role.").ConfigureAwait(false); - return; - } - + var channel = imsg.Channel as ITextChannel; try { - if (roleToEdit.Position > channel.Guild.CurrentUser.Roles.Max(r => r.Position)) + if (roleToEdit.Position > (await channel.Guild.GetCurrentUserAsync().ConfigureAwait(false)).Roles.Max(r => r.Position)) { - await imsg.Channel.SendMessageAsync("I can't edit roles higher than my highest role.").ConfigureAwait(false); + await imsg.Channel.SendMessageAsync("You can't edit roles higher than your highest role.").ConfigureAwait(false); return; } - await roleToEdit.Edit(r2); + await roleToEdit.ModifyAsync(g => g.Name = newname).ConfigureAwait(false); await imsg.Channel.SendMessageAsync("Role renamed.").ConfigureAwait(false); } catch (Exception) @@ -157,21 +111,14 @@ namespace NadekoBot.Modules.Administration [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] [RequirePermission(GuildPermission.ManageRoles)] - public async Task RemoveAllRoles(IMessage imsg, [Remainder] string userName) + public async Task RemoveAllRoles(IMessage imsg, [Remainder] IGuildUser user) { - var channel = imsg.Channel as IGuildChannel; - - var usr = channel.Guild.FindUsers(userName).FirstOrDefault(); - if (usr == null) - { - await imsg.Channel.SendMessageAsync("You failed to supply a valid username").ConfigureAwait(false); - return; - } + var channel = imsg.Channel as ITextChannel; try { - await usr.RemoveRoles(usr.Roles.ToArray()).ConfigureAwait(false); - await imsg.Channel.SendMessageAsync($"Successfully removed **all** roles from user **{usr.Name}**").ConfigureAwait(false); + await user.RemoveRolesAsync(user.Roles).ConfigureAwait(false); + await imsg.Channel.SendMessageAsync($"Successfully removed **all** roles from user **{user.Username}**").ConfigureAwait(false); } catch { @@ -182,16 +129,16 @@ namespace NadekoBot.Modules.Administration [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] [RequirePermission(GuildPermission.ManageRoles)] - public async Task CreateRole(IMessage imsg, [Remainder] string roleName) + public async Task CreateRole(IMessage imsg, [Remainder] string roleName = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; - if (string.IsNullOrWhiteSpace(e.GetArg("role_name"))) + if (string.IsNullOrWhiteSpace(roleName)) return; try { - var r = await channel.Guild.CreateRole(e.GetArg("role_name")).ConfigureAwait(false); + var r = await channel.Guild.CreateRoleAsync(roleName).ConfigureAwait(false); await imsg.Channel.SendMessageAsync($"Successfully created role **{r.Name}**.").ConfigureAwait(false); } catch (Exception) @@ -203,19 +150,17 @@ namespace NadekoBot.Modules.Administration [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] [RequirePermission(GuildPermission.ManageRoles)] - public async Task RoleColor(IMessage imsg, string roleName, string r="", string g="", string b="") + public async Task RoleColor(IMessage imsg, params string[] args) { - var channel = imsg.Channel as IGuildChannel; - - var args = e.Args.Where(s => s != string.Empty); + var channel = imsg.Channel as ITextChannel; if (args.Count() != 2 && args.Count() != 4) { await imsg.Channel.SendMessageAsync("The parameters are invalid.").ConfigureAwait(false); return; } - - var role = channel.Guild.FindRoles(e.Args[0]).FirstOrDefault(); + var roleName = args[0].ToUpperInvariant(); + var role = channel.Guild.Roles.Where(r=>r.Name.ToUpperInvariant() == roleName).FirstOrDefault(); if (role == null) { @@ -225,13 +170,13 @@ namespace NadekoBot.Modules.Administration try { var rgb = args.Count() == 4; - var arg1 = e.Args[1].Replace("#", ""); + var arg1 = args[1].Replace("#", ""); var red = Convert.ToByte(rgb ? int.Parse(arg1) : Convert.ToInt32(arg1.Substring(0, 2), 16)); - var green = Convert.ToByte(rgb ? int.Parse(e.Args[2]) : Convert.ToInt32(arg1.Substring(2, 2), 16)); - var blue = Convert.ToByte(rgb ? int.Parse(e.Args[3]) : Convert.ToInt32(arg1.Substring(4, 2), 16)); - - await role.Edit(color: new Color(red, green, blue)).ConfigureAwait(false); + var green = Convert.ToByte(rgb ? int.Parse(args[2]) : Convert.ToInt32(arg1.Substring(2, 2), 16)); + var blue = Convert.ToByte(rgb ? int.Parse(args[3]) : Convert.ToInt32(arg1.Substring(4, 2), 16)); + + await role.ModifyAsync(r => r.Color = new Color(red, green, blue).RawValue).ConfigureAwait(false); await imsg.Channel.SendMessageAsync($"Role {role.Name}'s color has been changed.").ConfigureAwait(false); } catch (Exception) @@ -243,25 +188,21 @@ namespace NadekoBot.Modules.Administration [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] [RequirePermission(GuildPermission.BanMembers)] - public async Task Ban(IMessage imsg, IUser user, [Remainder] string msg) + public async Task Ban(IMessage imsg, IGuildUser user, [Remainder] string msg = null) { - var channel = imsg.Channel as IGuildChannel; - if (user == null) - { - await imsg.Channel.SendMessageAsync("User not found.").ConfigureAwait(false); - return; - } + var channel = imsg.Channel as ITextChannel; + if (!string.IsNullOrWhiteSpace(msg)) { - await user.SendMessage($"**You have been BANNED from `{channel.Guild.Name}` server.**\n" + + await (await user.CreateDMChannelAsync()).SendMessageAsync($"**You have been BANNED from `{channel.Guild.Name}` server.**\n" + $"Reason: {msg}").ConfigureAwait(false); await Task.Delay(2000).ConfigureAwait(false); // temp solution; give time for a message to be send, fu volt } try { - await channel.Guild.Ban(user, 7).ConfigureAwait(false); + await channel.Guild.AddBanAsync(user, 7).ConfigureAwait(false); - await imsg.Channel.SendMessageAsync("Banned user " + user.Name + " Id: " + user.Id).ConfigureAwait(false); + await imsg.Channel.SendMessageAsync("Banned user " + user.Username + " Id: " + user.Id).ConfigureAwait(false); } catch { @@ -272,10 +213,10 @@ namespace NadekoBot.Modules.Administration [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] [RequirePermission(GuildPermission.BanMembers)] - public async Task Softban(IMessage imsg, IUser user, [Remainder] string msg) + public async Task Softban(IMessage imsg, IGuildUser user, [Remainder] string msg = null) { - var channel = imsg.Channel as IGuildChannel; - + var channel = imsg.Channel as ITextChannel; + if (user == null) { await imsg.Channel.SendMessageAsync("User not found.").ConfigureAwait(false); @@ -283,14 +224,14 @@ namespace NadekoBot.Modules.Administration } if (!string.IsNullOrWhiteSpace(msg)) { - await user.SendMessage($"**You have been SOFT-BANNED from `{channel.Guild.Name}` server.**\n" + + await user.SendMessageAsync($"**You have been SOFT-BANNED from `{channel.Guild.Name}` server.**\n" + $"Reason: {msg}").ConfigureAwait(false); await Task.Delay(2000).ConfigureAwait(false); // temp solution; give time for a message to be send, fu volt } try { - await channel.Guild.Ban(user, 7).ConfigureAwait(false); - await channel.Guild.Unban(user).ConfigureAwait(false); + await channel.Guild.AddBanAsync(user, 7).ConfigureAwait(false); + await channel.Guild.RemoveBanAsync(user).ConfigureAwait(false); await imsg.Channel.SendMessageAsync("Soft-Banned user " + user.Username + " Id: " + user.Id).ConfigureAwait(false); } @@ -302,26 +243,25 @@ namespace NadekoBot.Modules.Administration [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task Kick(IMessage imsg, IUser user, [Remainder] string msg) + public async Task Kick(IMessage imsg, IGuildUser user, [Remainder] string msg = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; - var usr = channel.Guild.FindUsers(user).FirstOrDefault(); - if (usr == null) + if (user == null) { await imsg.Channel.SendMessageAsync("User not found.").ConfigureAwait(false); return; } if (!string.IsNullOrWhiteSpace(msg)) { - await usr.SendMessage($"**You have been KICKED from `{channel.Guild.Name}` server.**\n" + + await user.SendMessageAsync($"**You have been KICKED from `{channel.Guild.Name}` server.**\n" + $"Reason: {msg}").ConfigureAwait(false); await Task.Delay(2000).ConfigureAwait(false); // temp solution; give time for a message to be send, fu volt } try { - await usr.Kick().ConfigureAwait(false); - await imsg.Channel.SendMessageAsync("Kicked user " + usr.Name + " Id: " + usr.Id).ConfigureAwait(false); + await user.KickAsync().ConfigureAwait(false); + await imsg.Channel.SendMessageAsync("Kicked user " + user.Username + " Id: " + user.Id).ConfigureAwait(false); } catch { @@ -332,17 +272,17 @@ namespace NadekoBot.Modules.Administration [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] [RequirePermission(GuildPermission.MuteMembers)] - public async Task Mute(IMessage imsg, [Remainder] string throwaway) + public async Task Mute(IMessage imsg, params IGuildUser[] users) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; - if (!e.Message.MentionedUsers.Any()) + if (!users.Any()) return; try { - foreach (var u in e.Message.MentionedUsers) + foreach (var u in users) { - await u.Edit(isMuted: true).ConfigureAwait(false); + await u.ModifyAsync(usr => usr.Mute = true).ConfigureAwait(false); } await imsg.Channel.SendMessageAsync("Mute successful").ConfigureAwait(false); } @@ -354,17 +294,18 @@ namespace NadekoBot.Modules.Administration [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task Unmute(IMessage imsg, [Remainder] string throwaway) + [RequirePermission(GuildPermission.MuteMembers)] + public async Task Unmute(IMessage imsg, params IGuildUser[] users) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; - if (!e.Message.MentionedUsers.Any()) + if (!users.Any()) return; try { - foreach (var u in e.Message.MentionedUsers) + foreach (var u in users) { - await u.Edit(isMuted: false).ConfigureAwait(false); + await u.ModifyAsync(usr => usr.Mute = false).ConfigureAwait(false); } await imsg.Channel.SendMessageAsync("Unmute successful").ConfigureAwait(false); } @@ -377,17 +318,17 @@ namespace NadekoBot.Modules.Administration [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] [RequirePermission(GuildPermission.DeafenMembers)] - public async Task Deafen(IMessage imsg, [Remainder] string throwaway) + public async Task Deafen(IMessage imsg, params IGuildUser[] users) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; - if (!e.Message.MentionedUsers.Any()) + if (!users.Any()) return; try { - foreach (var u in e.Message.MentionedUsers) + foreach (var u in users) { - await u.Edit(isDeafened: true).ConfigureAwait(false); + await u.ModifyAsync(usr=>usr.Deaf = true).ConfigureAwait(false); } await imsg.Channel.SendMessageAsync("Deafen successful").ConfigureAwait(false); } @@ -400,17 +341,17 @@ namespace NadekoBot.Modules.Administration [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] [RequirePermission(GuildPermission.DeafenMembers)] - public async Task UnDeafen(IMessage imsg, [Remainder] string throwaway) + public async Task UnDeafen(IMessage imsg, params IGuildUser[] users) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; - if (!e.Message.MentionedUsers.Any()) + if (!users.Any()) return; try { - foreach (var u in e.Message.MentionedUsers) + foreach (var u in users) { - await u.Edit(isDeafened: false).ConfigureAwait(false); + await u.ModifyAsync(usr=> usr.Deaf = false).ConfigureAwait(false); } await imsg.Channel.SendMessageAsync("Undeafen successful").ConfigureAwait(false); } @@ -422,69 +363,64 @@ namespace NadekoBot.Modules.Administration [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task DelVoiChanl(IMessage imsg, [Remainder] channelName) + [RequirePermission(GuildPermission.ManageChannels)] + public async Task DelVoiChanl(IMessage imsg, [Remainder] IVoiceChannel channel) { - var channel = imsg.Channel as IGuildChannel; - var ch = channel.Guild.FindChannels(channelName, ChannelType.Voice).FirstOrDefault(); - if (ch == null) - return; - await ch.Delete().ConfigureAwait(false); - await imsg.Channel.SendMessageAsync($"Removed channel **{channelName}**.").ConfigureAwait(false); + await channel.DeleteAsync().ConfigureAwait(false); + await imsg.Channel.SendMessageAsync($"Removed channel **{channel.Name}**.").ConfigureAwait(false); } [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] + [RequirePermission(GuildPermission.ManageChannels)] public async Task CreatVoiChanl(IMessage imsg, [Remainder] string channelName) { - var channel = imsg.Channel as IGuildChannel; - - await channel.Guild.CreateChannel(e.GetArg("channel_name"), ChannelType.Voice).ConfigureAwait(false); - await imsg.Channel.SendMessageAsync($"Created voice channel **{e.GetArg("channel_name")}**.").ConfigureAwait(false); - } - - [LocalizedCommand, LocalizedDescription, LocalizedSummary] - [RequireContext(ContextType.Guild)] - public async Task DelTxtChanl(IMessage imsg, [Remainder] string channelName) - { - var channel = imsg.Channel as IGuildChannel; - - var channel = channel.Guild.FindChannels(e.GetArg("channel_name"), ChannelType.Text).FirstOrDefault(); - if (channel == null) return; - await channel.Delete().ConfigureAwait(false); - await imsg.Channel.SendMessageAsync($"Removed text channel **{e.GetArg("channel_name")}**.").ConfigureAwait(false); + var channel = imsg.Channel as ITextChannel; + //todo actually print info about created channel + await channel.Guild.CreateVoiceChannelAsync(channelName).ConfigureAwait(false); + await imsg.Channel.SendMessageAsync($"Created voice channel **{channelName}**.").ConfigureAwait(false); } [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] [RequirePermission(GuildPermission.ManageChannels)] - public async Task CreaTxtChanl(IMessage imsg, [Remainder] string arg) + public async Task DelTxtChanl(IMessage imsg, [Remainder] ITextChannel channel) { - var channel = imsg.Channel as IGuildChannel; - await channel.Guild.CreateChannel(e.GetArg("channel_name"), ChannelType.Text).ConfigureAwait(false); - await imsg.Channel.SendMessageAsync($"Added text channel **{e.GetArg("channel_name")}**.").ConfigureAwait(false); + await channel.DeleteAsync().ConfigureAwait(false); + await imsg.Channel.SendMessageAsync($"Removed text channel **{channel.Name}**.").ConfigureAwait(false); } [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] [RequirePermission(GuildPermission.ManageChannels)] - public async Task SetTopic(IMessage imsg, [Remainder] string arg) + public async Task CreaTxtChanl(IMessage imsg, [Remainder] string channelName) { - var topic = e.GetArg("topic")?.Trim() ?? ""; - await e.Channel.Edit(topic: topic).ConfigureAwait(false); + var channel = imsg.Channel as ITextChannel; + //todo actually print info about created channel + var txtCh = await channel.Guild.CreateTextChannelAsync(channelName).ConfigureAwait(false); + await imsg.Channel.SendMessageAsync($"Added text channel **{channelName}**.").ConfigureAwait(false); + } + + [LocalizedCommand, LocalizedDescription, LocalizedSummary] + [RequireContext(ContextType.Guild)] + [RequirePermission(GuildPermission.ManageChannels)] + public async Task SetTopic(IMessage imsg, [Remainder] string topic = null) + { + var channel = imsg.Channel as ITextChannel; + topic = topic ?? ""; + await (channel as ITextChannel).ModifyAsync(c => c.Topic = topic); + //await (channel).ModifyAsync(c => c).ConfigureAwait(false); await imsg.Channel.SendMessageAsync(":ok: **New channel topic set.**").ConfigureAwait(false); } [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] [RequirePermission(GuildPermission.ManageChannels)] - public async Task SetChanlName(IMessage imsg, [Remainder] string arg) + public async Task SetChanlName(IMessage imsg, [Remainder] string name) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; - var name = e.GetArg("name"); - if (string.IsNullOrWhiteSpace(name)) - return; - await e.Channel.Edit(name: name).ConfigureAwait(false); + await channel.ModifyAsync(c => c.Name = name).ConfigureAwait(false); await imsg.Channel.SendMessageAsync(":ok: **New channel name set.**").ConfigureAwait(false); } @@ -494,7 +430,7 @@ namespace NadekoBot.Modules.Administration [RequireContext(ContextType.Guild)] public async Task Prune(IMessage msg, [Remainder] string target = null) { - var channel = msg.Channel as IGuildChannel; + var channel = msg.Channel as ITextChannel; var user = await channel.Guild.GetCurrentUserAsync(); if (string.IsNullOrWhiteSpace(target)) @@ -561,7 +497,7 @@ namespace NadekoBot.Modules.Administration //[RequireContext(ContextType.Guild)] //public async Task Die(IMessage imsg) //{ - // var channel = imsg.Channel as IGuildChannel; + // var channel = imsg.Channel as ITextChannel; // await imsg.Channel.SendMessageAsync("`Shutting down.`").ConfigureAwait(false); // await Task.Delay(2000).ConfigureAwait(false); @@ -571,18 +507,18 @@ namespace NadekoBot.Modules.Administration ////todo owner only //[LocalizedCommand, LocalizedDescription, LocalizedSummary] //[RequireContext(ContextType.Guild)] - //public async Task Setname(IMessage imsg, [Remainder] string newName) + //public async Task Setname(IMessage imsg, [Remainder] string newName = null) //{ - // var channel = imsg.Channel as IGuildChannel; + // var channel = imsg.Channel as ITextChannel; //} ////todo owner only //[LocalizedCommand, LocalizedDescription, LocalizedSummary] //[RequireContext(ContextType.Guild)] - //public async Task NewAvatar(IMessage imsg, [Remainder] string img) + //public async Task NewAvatar(IMessage imsg, [Remainder] string img = null) //{ - // var channel = imsg.Channel as IGuildChannel; + // var channel = imsg.Channel as ITextChannel; // if (string.IsNullOrWhiteSpace(e.GetArg("img"))) // return; @@ -599,9 +535,9 @@ namespace NadekoBot.Modules.Administration ////todo owner only //[LocalizedCommand, LocalizedDescription, LocalizedSummary] //[RequireContext(ContextType.Guild)] - //public async Task SetGame(IMessage imsg, [Remainder] string game) + //public async Task SetGame(IMessage imsg, [Remainder] string game = null) //{ - // var channel = imsg.Channel as IGuildChannel; + // var channel = imsg.Channel as ITextChannel; // game = game ?? ""; @@ -611,9 +547,9 @@ namespace NadekoBot.Modules.Administration ////todo owner only //[LocalizedCommand, LocalizedDescription, LocalizedSummary] //[RequireContext(ContextType.Guild)] - //public async Task Send(IMessage imsg, string where, [Remainder] string msg) + //public async Task Send(IMessage imsg, string where, [Remainder] string msg = null) //{ - // var channel = imsg.Channel as IGuildChannel; + // var channel = imsg.Channel as ITextChannel; // if (string.IsNullOrWhiteSpace(msg)) // return; @@ -659,7 +595,7 @@ namespace NadekoBot.Modules.Administration //[RequireContext(ContextType.Guild)] //public async Task Donadd(IMessage imsg, IUser donator, int amount) //{ - // var channel = imsg.Channel as IGuildChannel; + // var channel = imsg.Channel as ITextChannel; // var donator = channel.Guild.FindUsers(e.GetArg("donator")).FirstOrDefault(); // var amount = int.Parse(e.GetArg("amount")); // if (donator == null) return; @@ -677,75 +613,77 @@ namespace NadekoBot.Modules.Administration //} - //todo owner only - [LocalizedCommand, LocalizedDescription, LocalizedSummary] - [RequireContext(ContextType.Guild)] - public async Task Announce(IMessage imsg, [Remainder] string message) - { - var channel = imsg.Channel as IGuildChannel; + ////todo owner only + //[LocalizedCommand, LocalizedDescription, LocalizedSummary] + //[RequireContext(ContextType.Guild)] + //public async Task Announce(IMessage imsg, [Remainder] string message) + //{ + // var channel = imsg.Channel as ITextChannel; + // foreach (var ch in (await _client.GetGuildsAsync().ConfigureAwait(false)).Select(async g => await g.GetDefaultChannelAsync().ConfigureAwait(false))) + // { + // await imsg.Channel.SendMessageAsync(message).ConfigureAwait(false); + // } - foreach (var ch in NadekoBot.Client.Servers.Select(s => s.DefaultChannel)) - { - await ch.SendMessage(e.GetArg("msg")).ConfigureAwait(false); - } + // await imsg.Channel.SendMessageAsync(":ok:").ConfigureAwait(false); + //} - await imsg.Channel.SendMessageAsync(":ok:").ConfigureAwait(false); - } + ////todo owner only + //[LocalizedCommand, LocalizedDescription, LocalizedSummary] + //[RequireContext(ContextType.Guild)] + //public async Task SaveChat(IMessage imsg, int cnt) + //{ + // var channel = imsg.Channel as ITextChannel; - //todo owner only - [LocalizedCommand, LocalizedDescription, LocalizedSummary] - [RequireContext(ContextType.Guild)] - public async Task SaveChat(IMessage imsg, int cnt) - { - var channel = imsg.Channel as IGuildChannel; + // ulong? lastmsgId = null; + // var sb = new StringBuilder(); + // var msgs = new List(cnt); + // while (cnt > 0) + // { + // var dlcnt = cnt < 100 ? cnt : 100; + // IReadOnlyCollection dledMsgs; + // if (lastmsgId == null) + // dledMsgs = await imsg.Channel.GetMessagesAsync(cnt).ConfigureAwait(false); + // else + // dledMsgs = await imsg.Channel.GetMessagesAsync(lastmsgId.Value, Direction.Before, dlcnt); - ulong? lastmsgId = null; - var sb = new StringBuilder(); - var msgs = new List(cnt); - while (cnt > 0) - { - var dlcnt = cnt < 100 ? cnt : 100; + // if (!dledMsgs.Any()) + // break; - var dledMsgs = await e.Channel.DownloadMessages(dlcnt, lastmsgId); - if (!dledMsgs.Any()) - break; - msgs.AddRange(dledMsgs); - lastmsgId = msgs[msgs.Count - 1].Id; - cnt -= 100; - } - await e.User.SendFile($"Chatlog-{channel.Guild.Name}/#{e.Channel.Name}-{DateTime.Now}.txt", - JsonConvert.SerializeObject(new { Messages = msgs.Select(s => s.ToString()) }, Formatting.Indented).ToStream()).ConfigureAwait(false); - } + // msgs.AddRange(dledMsgs); + // lastmsgId = msgs[msgs.Count - 1].Id; + // cnt -= 100; + // } + // var title = $"Chatlog-{channel.Guild.Name}/#{channel.Name}-{DateTime.Now}.txt"; + // await (imsg.Author as IGuildUser).SendFileAsync( + // await JsonConvert.SerializeObject(new { Messages = msgs.Select(s => s.ToString()) }, Formatting.Indented).ToStream().ConfigureAwait(false), + // title, title).ConfigureAwait(false); + //} [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] [RequirePermission(GuildPermission.MentionEveryone)] - public async Task MentionRole(IMessage imsg, [Remainder] string roles) + public async Task MentionRole(IMessage imsg, params IRole[] roles) { - var channel = imsg.Channel as IGuildChannel; - - var arg = e.GetArg("roles").Split(',').Select(r => r.Trim()); - string send = $"--{e.User.Mention} has invoked a mention on the following roles--"; - foreach (var roleStr in arg.Where(str => !string.IsNullOrWhiteSpace(str))) - { - var role = channel.Guild.FindRoles(roleStr).FirstOrDefault(); - if (role == null) continue; + var channel = imsg.Channel as ITextChannel; + + string send = $"--{imsg.Author.Mention} has invoked a mention on the following roles--"; + foreach (var role in roles) + { send += $"\n`{role.Name}`\n"; - send += string.Join(", ", role.Members.Select(r => r.Mention)); + send += string.Join(", ", (await channel.Guild.GetUsersAsync()).Where(u => u.Roles.Contains(role)).Distinct()); } while (send.Length > 2000) { var curstr = send.Substring(0, 2000); - await - e.Channel.Send(curstr.Substring(0, + await channel.SendMessageAsync(curstr.Substring(0, curstr.LastIndexOf(", ", StringComparison.Ordinal) + 1)).ConfigureAwait(false); send = curstr.Substring(curstr.LastIndexOf(", ", StringComparison.Ordinal) + 1) + send.Substring(2000); } - await e.Channel.Send(send).ConfigureAwait(false); + await channel.SendMessageAsync(send).ConfigureAwait(false); } //todo DB @@ -753,7 +691,7 @@ namespace NadekoBot.Modules.Administration //[RequireContext(ContextType.Guild)] //public async Task Donators(IMessage imsg) //{ - // var channel = imsg.Channel as IGuildChannel; + // var channel = imsg.Channel as ITextChannel; // var rows = DbHandler.Instance.GetAllRows(); // var donatorsOrdered = rows.OrderByDescending(d => d.Amount); diff --git a/src/NadekoBot/Modules/Administration/Commands/AutoAssignRole.cs b/src/NadekoBot/Modules/Administration/Commands/AutoAssignRole.cs index 44a1f763..82b8a61b 100644 --- a/src/NadekoBot/Modules/Administration/Commands/AutoAssignRole.cs +++ b/src/NadekoBot/Modules/Administration/Commands/AutoAssignRole.cs @@ -1,72 +1,72 @@ -using Discord.Commands; -using NadekoBot.Classes; -using NadekoBot.Modules.Permissions.Classes; -using System; -using System.Linq; +//using Discord.Commands; +//using NadekoBot.Classes; +//using NadekoBot.Modules.Permissions.Classes; +//using System; +//using System.Linq; -namespace NadekoBot.Modules.Administration.Commands -{ - class AutoAssignRole : DiscordCommand - { - public AutoAssignRole(DiscordModule module) : base(module) - { - NadekoBot.Client.UserJoined += (s, e) => - { - try - { - var config = SpecificConfigurations.Default.Of(e.Server.Id); +//namespace NadekoBot.Modules.Administration.Commands +//{ +// class AutoAssignRole : DiscordCommand +// { +// public AutoAssignRole(DiscordModule module) : base(module) +// { +// NadekoBot.Client.UserJoined += (s, e) => +// { +// try +// { +// var config = SpecificConfigurations.Default.Of(e.Server.Id); - var role = e.Server.Roles.Where(r => r.Id == config.AutoAssignedRole).FirstOrDefault(); +// var role = e.Server.Roles.Where(r => r.Id == config.AutoAssignedRole).FirstOrDefault(); - if (role == null) - return; +// if (role == null) +// return; - e.User.AddRoles(role); - } - catch (Exception ex) - { - Console.WriteLine($"aar exception. {ex}"); - } - }; - } +// e.User.AddRoles(role); +// } +// catch (Exception ex) +// { +// Console.WriteLine($"aar exception. {ex}"); +// } +// }; +// } - internal override void Init(CommandGroupBuilder cgb) - { - cgb.CreateCommand(Module.Prefix + "autoassignrole") - .Alias(Module.Prefix + "aar") - .Description($"Automaticaly assigns a specified role to every user who joins the server. **Needs Manage Roles Permissions.** |`{Prefix}aar` to disable, `{Prefix}aar Role Name` to enable") - .Parameter("role", ParameterType.Unparsed) - .AddCheck(new SimpleCheckers.ManageRoles()) - .Do(async e => - { - if (!e.Server.CurrentUser.ServerPermissions.ManageRoles) - { - await imsg.Channel.SendMessageAsync("I do not have the permission to manage roles.").ConfigureAwait(false); - return; - } - var r = e.GetArg("role")?.Trim(); +// internal override void Init(CommandGroupBuilder cgb) +// { +// cgb.CreateCommand(Module.Prefix + "autoassignrole") +// .Alias(Module.Prefix + "aar") +// .Description($"Automaticaly assigns a specified role to every user who joins the server. **Needs Manage Roles Permissions.** |`{Prefix}aar` to disable, `{Prefix}aar Role Name` to enable") +// .Parameter("role", ParameterType.Unparsed) +// .AddCheck(new SimpleCheckers.ManageRoles()) +// .Do(async e => +// { +// if (!e.Server.CurrentUser.ServerPermissions.ManageRoles) +// { +// await imsg.Channel.SendMessageAsync("I do not have the permission to manage roles.").ConfigureAwait(false); +// return; +// } +// var r = e.GetArg("role")?.Trim(); - var config = SpecificConfigurations.Default.Of(e.Server.Id); +// var config = SpecificConfigurations.Default.Of(e.Server.Id); - if (string.IsNullOrWhiteSpace(r)) //if role is not specified, disable - { - config.AutoAssignedRole = 0; +// if (string.IsNullOrWhiteSpace(r)) //if role is not specified, disable +// { +// config.AutoAssignedRole = 0; - await imsg.Channel.SendMessageAsync("`Auto assign role on user join is now disabled.`").ConfigureAwait(false); - return; - } - var role = e.Server.FindRoles(r).FirstOrDefault(); +// await imsg.Channel.SendMessageAsync("`Auto assign role on user join is now disabled.`").ConfigureAwait(false); +// return; +// } +// var role = e.Server.FindRoles(r).FirstOrDefault(); - if (role == null) - { - await imsg.Channel.SendMessageAsync("💢 `Role not found.`").ConfigureAwait(false); - return; - } +// if (role == null) +// { +// await imsg.Channel.SendMessageAsync("💢 `Role not found.`").ConfigureAwait(false); +// return; +// } - config.AutoAssignedRole = role.Id; - await imsg.Channel.SendMessageAsync("`Auto assigned role is set.`").ConfigureAwait(false); +// config.AutoAssignedRole = role.Id; +// await imsg.Channel.SendMessageAsync("`Auto assigned role is set.`").ConfigureAwait(false); - }); - } - } -} +// }); +// } +// } +//} diff --git a/src/NadekoBot/Modules/Administration/Commands/CrossServerTextChannel.cs b/src/NadekoBot/Modules/Administration/Commands/CrossServerTextChannel.cs index f53b53bb..9c014ddb 100644 --- a/src/NadekoBot/Modules/Administration/Commands/CrossServerTextChannel.cs +++ b/src/NadekoBot/Modules/Administration/Commands/CrossServerTextChannel.cs @@ -1,110 +1,110 @@ -using Discord; -using Discord.Commands; -using NadekoBot.Classes; -using NadekoBot.Modules.Permissions.Classes; -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Linq; +//using Discord; +//using Discord.Commands; +//using NadekoBot.Classes; +//using NadekoBot.Modules.Permissions.Classes; +//using System; +//using System.Collections.Concurrent; +//using System.Collections.Generic; +//using System.Linq; -namespace NadekoBot.Modules.Administration.Commands -{ - class CrossServerTextChannel : DiscordCommand - { - public CrossServerTextChannel(DiscordModule module) : base(module) - { - NadekoBot.Client.MessageReceived += async (s, e) => - { - try - { - if (e.User.Id == NadekoBot.Client.CurrentUser.Id) return; - foreach (var subscriber in Subscribers) - { - var set = subscriber.Value; - if (!set.Contains(e.Channel)) - continue; - foreach (var chan in set.Except(new[] { e.Channel })) - { - await chan.SendMessage(GetText(e.Server, e.Channel, e.User, e.Message)).ConfigureAwait(false); - } - } - } - catch { } - }; - NadekoBot.Client.MessageUpdated += async (s, e) => - { - try - { - if (e.After?.User?.Id == null || e.After.User.Id == NadekoBot.Client.CurrentUser.Id) return; - foreach (var subscriber in Subscribers) - { - var set = subscriber.Value; - if (!set.Contains(e.Channel)) - continue; - foreach (var chan in set.Except(new[] { e.Channel })) - { - var msg = chan.Messages - .FirstOrDefault(m => - m.RawText == GetText(e.Server, e.Channel, e.User, e.Before)); - if (msg != default(Message)) - await msg.Edit(GetText(e.Server, e.Channel, e.User, e.After)).ConfigureAwait(false); - } - } +//namespace NadekoBot.Modules.Administration.Commands +//{ +// class CrossServerTextChannel : DiscordCommand +// { +// public CrossServerTextChannel(DiscordModule module) : base(module) +// { +// NadekoBot.Client.MessageReceived += async (s, e) => +// { +// try +// { +// if (e.User.Id == NadekoBot.Client.CurrentUser.Id) return; +// foreach (var subscriber in Subscribers) +// { +// var set = subscriber.Value; +// if (!set.Contains(e.Channel)) +// continue; +// foreach (var chan in set.Except(new[] { e.Channel })) +// { +// await chan.SendMessage(GetText(e.Server, e.Channel, e.User, e.Message)).ConfigureAwait(false); +// } +// } +// } +// catch { } +// }; +// NadekoBot.Client.MessageUpdated += async (s, e) => +// { +// try +// { +// if (e.After?.User?.Id == null || e.After.User.Id == NadekoBot.Client.CurrentUser.Id) return; +// foreach (var subscriber in Subscribers) +// { +// var set = subscriber.Value; +// if (!set.Contains(e.Channel)) +// continue; +// foreach (var chan in set.Except(new[] { e.Channel })) +// { +// var msg = chan.Messages +// .FirstOrDefault(m => +// m.RawText == GetText(e.Server, e.Channel, e.User, e.Before)); +// if (msg != default(Message)) +// await msg.Edit(GetText(e.Server, e.Channel, e.User, e.After)).ConfigureAwait(false); +// } +// } - } - catch { } - }; - } +// } +// catch { } +// }; +// } - private string GetText(Server server, Channel channel, User user, Message message) => - $"**{server.Name} | {channel.Name}** `{user.Name}`: " + message.RawText; +// private string GetText(Server server, Channel channel, User user, Message message) => +// $"**{server.Name} | {channel.Name}** `{user.Name}`: " + message.RawText; - public static readonly ConcurrentDictionary> Subscribers = new ConcurrentDictionary>(); +// public static readonly ConcurrentDictionary> Subscribers = new ConcurrentDictionary>(); - internal override void Init(CommandGroupBuilder cgb) - { - cgb.CreateCommand(Module.Prefix + "scsc") - .Description("Starts an instance of cross server channel. You will get a token as a DM " + - $"that other people will use to tune in to the same instance. **Bot Owner Only.** | `{Prefix}scsc`") - .AddCheck(SimpleCheckers.OwnerOnly()) - .Do(async e => - { - var token = new Random().Next(); - var set = new HashSet(); - if (Subscribers.TryAdd(token, set)) - { - set.Add(e.Channel); - await e.User.SendMessage("This is your CSC token:" + token.ToString()).ConfigureAwait(false); - } - }); +// internal override void Init(CommandGroupBuilder cgb) +// { +// cgb.CreateCommand(Module.Prefix + "scsc") +// .Description("Starts an instance of cross server channel. You will get a token as a DM " + +// $"that other people will use to tune in to the same instance. **Bot Owner Only.** | `{Prefix}scsc`") +// .AddCheck(SimpleCheckers.OwnerOnly()) +// .Do(async e => +// { +// var token = new Random().Next(); +// var set = new HashSet(); +// if (Subscribers.TryAdd(token, set)) +// { +// set.Add(e.Channel); +// await e.User.SendMessage("This is your CSC token:" + token.ToString()).ConfigureAwait(false); +// } +// }); - cgb.CreateCommand(Module.Prefix + "jcsc") - .Description($"Joins current channel to an instance of cross server channel using the token. **Needs Manage Server Permissions.**| `{Prefix}jcsc`") - .Parameter("token") - .AddCheck(SimpleCheckers.ManageServer()) - .Do(async e => - { - int token; - if (!int.TryParse(e.GetArg("token"), out token)) - return; - HashSet set; - if (!Subscribers.TryGetValue(token, out set)) - return; - set.Add(e.Channel); - await imsg.Channel.SendMessageAsync(":ok:").ConfigureAwait(false); - }); +// cgb.CreateCommand(Module.Prefix + "jcsc") +// .Description($"Joins current channel to an instance of cross server channel using the token. **Needs Manage Server Permissions.**| `{Prefix}jcsc`") +// .Parameter("token") +// .AddCheck(SimpleCheckers.ManageServer()) +// .Do(async e => +// { +// int token; +// if (!int.TryParse(e.GetArg("token"), out token)) +// return; +// HashSet set; +// if (!Subscribers.TryGetValue(token, out set)) +// return; +// set.Add(e.Channel); +// await imsg.Channel.SendMessageAsync(":ok:").ConfigureAwait(false); +// }); - cgb.CreateCommand(Module.Prefix + "lcsc") - .Description($"Leaves Cross server channel instance from this channel. **Needs Manage Server Permissions.**| `{Prefix}lcsc`") - .AddCheck(SimpleCheckers.ManageServer()) - .Do(async e => - { - foreach (var subscriber in Subscribers) - { - subscriber.Value.Remove(e.Channel); - } - await imsg.Channel.SendMessageAsync(":ok:").ConfigureAwait(false); - }); - } - } -} +// cgb.CreateCommand(Module.Prefix + "lcsc") +// .Description($"Leaves Cross server channel instance from this channel. **Needs Manage Server Permissions.**| `{Prefix}lcsc`") +// .AddCheck(SimpleCheckers.ManageServer()) +// .Do(async e => +// { +// foreach (var subscriber in Subscribers) +// { +// subscriber.Value.Remove(e.Channel); +// } +// await imsg.Channel.SendMessageAsync(":ok:").ConfigureAwait(false); +// }); +// } +// } +//} diff --git a/src/NadekoBot/Modules/Administration/Commands/CustomReactionsCommands.cs b/src/NadekoBot/Modules/Administration/Commands/CustomReactionsCommands.cs index b170c33f..68ab5509 100644 --- a/src/NadekoBot/Modules/Administration/Commands/CustomReactionsCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/CustomReactionsCommands.cs @@ -1,225 +1,225 @@ -using Discord; -using Discord.Commands; -using NadekoBot.Classes; -using NadekoBot.Modules.Permissions.Classes; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +//using Discord; +//using Discord.Commands; +//using NadekoBot.Classes; +//using NadekoBot.Modules.Permissions.Classes; +//using System; +//using System.Collections.Generic; +//using System.Linq; +//using System.Text; +//using System.Threading.Tasks; -namespace NadekoBot.Modules.Administration.Commands -{ - class CustomReactionsCommands : DiscordCommand - { - public CustomReactionsCommands(DiscordModule module) : base(module) - { +//namespace NadekoBot.Modules.Administration.Commands +//{ +// class CustomReactionsCommands : DiscordCommand +// { +// public CustomReactionsCommands(DiscordModule module) : base(module) +// { - } +// } - internal override void Init(CommandGroupBuilder cgb) - { - var Prefix = Module.Prefix; +// internal override void Init(CommandGroupBuilder cgb) +// { +// var Prefix = Module.Prefix; - cgb.CreateCommand(Prefix + "addcustreact") - .Alias(Prefix + "acr") - .Description($"Add a custom reaction. Guide here: **Bot Owner Only!** | `{Prefix}acr \"hello\" I love saying hello to %user%`") - .AddCheck(SimpleCheckers.OwnerOnly()) - .Parameter("name", ParameterType.Required) - .Parameter("message", ParameterType.Unparsed) - .Do(async e => - { - var name = e.GetArg("name"); - var message = e.GetArg("message")?.Trim(); - if (string.IsNullOrWhiteSpace(message)) - { - await imsg.Channel.SendMessageAsync($"Incorrect command usage. See -h {Prefix}acr for correct formatting").ConfigureAwait(false); - return; - } - if (NadekoBot.Config.CustomReactions.ContainsKey(name)) - NadekoBot.Config.CustomReactions[name].Add(message); - else - NadekoBot.Config.CustomReactions.Add(name, new System.Collections.Generic.List() { message }); - await Classes.JSONModels.ConfigHandler.SaveConfig().ConfigureAwait(false); - await imsg.Channel.SendMessageAsync($"Added {name} : {message}").ConfigureAwait(false); +// cgb.CreateCommand(Prefix + "addcustreact") +// .Alias(Prefix + "acr") +// .Description($"Add a custom reaction. Guide here: **Bot Owner Only!** | `{Prefix}acr \"hello\" I love saying hello to %user%`") +// .AddCheck(SimpleCheckers.OwnerOnly()) +// .Parameter("name", ParameterType.Required) +// .Parameter("message", ParameterType.Unparsed) +// .Do(async e => +// { +// var name = e.GetArg("name"); +// var message = e.GetArg("message")?.Trim(); +// if (string.IsNullOrWhiteSpace(message)) +// { +// await imsg.Channel.SendMessageAsync($"Incorrect command usage. See -h {Prefix}acr for correct formatting").ConfigureAwait(false); +// return; +// } +// if (NadekoBot.Config.CustomReactions.ContainsKey(name)) +// NadekoBot.Config.CustomReactions[name].Add(message); +// else +// NadekoBot.Config.CustomReactions.Add(name, new System.Collections.Generic.List() { message }); +// await Classes.JSONModels.ConfigHandler.SaveConfig().ConfigureAwait(false); +// await imsg.Channel.SendMessageAsync($"Added {name} : {message}").ConfigureAwait(false); - }); +// }); - cgb.CreateCommand(Prefix + "listcustreact") - .Alias(Prefix + "lcr") - .Description($"Lists custom reactions (paginated with 30 commands per page). Use 'all' instead of page number to get all custom reactions DM-ed to you. |`{Prefix}lcr 1`") - .Parameter("num", ParameterType.Required) - .Do(async e => - { - var numStr = e.GetArg("num"); +// cgb.CreateCommand(Prefix + "listcustreact") +// .Alias(Prefix + "lcr") +// .Description($"Lists custom reactions (paginated with 30 commands per page). Use 'all' instead of page number to get all custom reactions DM-ed to you. |`{Prefix}lcr 1`") +// .Parameter("num", ParameterType.Required) +// .Do(async e => +// { +// var numStr = e.GetArg("num"); - if (numStr.ToUpperInvariant() == "ALL") - { - var fullstr = String.Join("\n", NadekoBot.Config.CustomReactions.Select(kvp => kvp.Key)); - do - { - var str = string.Concat(fullstr.Take(1900)); - fullstr = new string(fullstr.Skip(1900).ToArray()); - await e.User.SendMessage("```xl\n" + str + "```"); - } while (fullstr.Length != 0); - return; - } - int num; - if (!int.TryParse(numStr, out num) || num <= 0) num = 1; - var cmds = GetCustomsOnPage(num - 1); - if (!cmds.Any()) - { - await imsg.Channel.SendMessageAsync("`There are no custom reactions.`"); - } - else - { - string result = SearchHelper.ShowInPrettyCode(cmds, s => $"{s,-25}"); //People prefer starting with 1 - await imsg.Channel.SendMessageAsync($"`Showing page {num}:`\n" + result).ConfigureAwait(false); - } - }); +// if (numStr.ToUpperInvariant() == "ALL") +// { +// var fullstr = String.Join("\n", NadekoBot.Config.CustomReactions.Select(kvp => kvp.Key)); +// do +// { +// var str = string.Concat(fullstr.Take(1900)); +// fullstr = new string(fullstr.Skip(1900).ToArray()); +// await e.User.SendMessage("```xl\n" + str + "```"); +// } while (fullstr.Length != 0); +// return; +// } +// int num; +// if (!int.TryParse(numStr, out num) || num <= 0) num = 1; +// var cmds = GetCustomsOnPage(num - 1); +// if (!cmds.Any()) +// { +// await imsg.Channel.SendMessageAsync("`There are no custom reactions.`"); +// } +// else +// { +// string result = SearchHelper.ShowInPrettyCode(cmds, s => $"{s,-25}"); //People prefer starting with 1 +// await imsg.Channel.SendMessageAsync($"`Showing page {num}:`\n" + result).ConfigureAwait(false); +// } +// }); - cgb.CreateCommand(Prefix + "showcustreact") - .Alias(Prefix + "scr") - .Description($"Shows all possible responses from a single custom reaction. |`{Prefix}scr %mention% bb`") - .Parameter("name", ParameterType.Unparsed) - .Do(async e => - { - var name = e.GetArg("name")?.Trim(); - if (string.IsNullOrWhiteSpace(name)) - return; - if (!NadekoBot.Config.CustomReactions.ContainsKey(name)) - { - await imsg.Channel.SendMessageAsync("`Can't find that custom reaction.`").ConfigureAwait(false); - return; - } - var items = NadekoBot.Config.CustomReactions[name]; - var message = new StringBuilder($"Responses for {Format.Bold(name)}:\n"); - var last = items.Last(); +// cgb.CreateCommand(Prefix + "showcustreact") +// .Alias(Prefix + "scr") +// .Description($"Shows all possible responses from a single custom reaction. |`{Prefix}scr %mention% bb`") +// .Parameter("name", ParameterType.Unparsed) +// .Do(async e => +// { +// var name = e.GetArg("name")?.Trim(); +// if (string.IsNullOrWhiteSpace(name)) +// return; +// if (!NadekoBot.Config.CustomReactions.ContainsKey(name)) +// { +// await imsg.Channel.SendMessageAsync("`Can't find that custom reaction.`").ConfigureAwait(false); +// return; +// } +// var items = NadekoBot.Config.CustomReactions[name]; +// var message = new StringBuilder($"Responses for {Format.Bold(name)}:\n"); +// var last = items.Last(); - int i = 1; - foreach (var reaction in items) - { - message.AppendLine($"[{i++}] " + Format.Code(Format.Escape(reaction))); - } - await imsg.Channel.SendMessageAsync(message.ToString()); - }); +// int i = 1; +// foreach (var reaction in items) +// { +// message.AppendLine($"[{i++}] " + Format.Code(Format.Escape(reaction))); +// } +// await imsg.Channel.SendMessageAsync(message.ToString()); +// }); - cgb.CreateCommand(Prefix + "editcustreact") - .Alias(Prefix + "ecr") - .Description($"Edits a custom reaction, arguments are custom reactions name, index to change, and a (multiword) message **Bot Owner Only** | `{Prefix}ecr \"%mention% disguise\" 2 Test 123`") - .Parameter("name", ParameterType.Required) - .Parameter("index", ParameterType.Required) - .Parameter("message", ParameterType.Unparsed) - .AddCheck(SimpleCheckers.OwnerOnly()) - .Do(async e => - { - var name = e.GetArg("name")?.Trim(); - if (string.IsNullOrWhiteSpace(name)) - return; - var indexstr = e.GetArg("index")?.Trim(); - if (string.IsNullOrWhiteSpace(indexstr)) - return; - var msg = e.GetArg("message")?.Trim(); - if (string.IsNullOrWhiteSpace(msg)) - return; +// cgb.CreateCommand(Prefix + "editcustreact") +// .Alias(Prefix + "ecr") +// .Description($"Edits a custom reaction, arguments are custom reactions name, index to change, and a (multiword) message **Bot Owner Only** | `{Prefix}ecr \"%mention% disguise\" 2 Test 123`") +// .Parameter("name", ParameterType.Required) +// .Parameter("index", ParameterType.Required) +// .Parameter("message", ParameterType.Unparsed) +// .AddCheck(SimpleCheckers.OwnerOnly()) +// .Do(async e => +// { +// var name = e.GetArg("name")?.Trim(); +// if (string.IsNullOrWhiteSpace(name)) +// return; +// var indexstr = e.GetArg("index")?.Trim(); +// if (string.IsNullOrWhiteSpace(indexstr)) +// return; +// var msg = e.GetArg("message")?.Trim(); +// if (string.IsNullOrWhiteSpace(msg)) +// return; - if (!NadekoBot.Config.CustomReactions.ContainsKey(name)) - { - await imsg.Channel.SendMessageAsync("`Could not find given commandname`").ConfigureAwait(false); - return; - } +// if (!NadekoBot.Config.CustomReactions.ContainsKey(name)) +// { +// await imsg.Channel.SendMessageAsync("`Could not find given commandname`").ConfigureAwait(false); +// return; +// } - int index; - if (!int.TryParse(indexstr, out index) || index < 1 || index > NadekoBot.Config.CustomReactions[name].Count) - { - await imsg.Channel.SendMessageAsync("`Invalid index.`").ConfigureAwait(false); - return; - } - index = index - 1; - NadekoBot.Config.CustomReactions[name][index] = msg; +// int index; +// if (!int.TryParse(indexstr, out index) || index < 1 || index > NadekoBot.Config.CustomReactions[name].Count) +// { +// await imsg.Channel.SendMessageAsync("`Invalid index.`").ConfigureAwait(false); +// return; +// } +// index = index - 1; +// NadekoBot.Config.CustomReactions[name][index] = msg; - await Classes.JSONModels.ConfigHandler.SaveConfig().ConfigureAwait(false); - await imsg.Channel.SendMessageAsync($"Edited response #{index + 1} from `{name}`").ConfigureAwait(false); - }); +// await Classes.JSONModels.ConfigHandler.SaveConfig().ConfigureAwait(false); +// await imsg.Channel.SendMessageAsync($"Edited response #{index + 1} from `{name}`").ConfigureAwait(false); +// }); - cgb.CreateCommand(Prefix + "delcustreact") - .Alias(Prefix + "dcr") - .Description($"Deletes a custom reaction with given name (and index). **Bot Owner Only.**| `{Prefix}dcr index`") - .Parameter("name", ParameterType.Required) - .Parameter("index", ParameterType.Optional) - .AddCheck(SimpleCheckers.OwnerOnly()) - .Do(async e => - { - var name = e.GetArg("name")?.Trim(); - if (string.IsNullOrWhiteSpace(name)) - return; - if (!NadekoBot.Config.CustomReactions.ContainsKey(name)) - { - await imsg.Channel.SendMessageAsync("Could not find given commandname").ConfigureAwait(false); - return; - } - string message = ""; - int index; - if (int.TryParse(e.GetArg("index")?.Trim() ?? "", out index)) - { - index = index - 1; - if (index < 0 || index > NadekoBot.Config.CustomReactions[name].Count) - { - await imsg.Channel.SendMessageAsync("Given index was out of range").ConfigureAwait(false); - return; +// cgb.CreateCommand(Prefix + "delcustreact") +// .Alias(Prefix + "dcr") +// .Description($"Deletes a custom reaction with given name (and index). **Bot Owner Only.**| `{Prefix}dcr index`") +// .Parameter("name", ParameterType.Required) +// .Parameter("index", ParameterType.Optional) +// .AddCheck(SimpleCheckers.OwnerOnly()) +// .Do(async e => +// { +// var name = e.GetArg("name")?.Trim(); +// if (string.IsNullOrWhiteSpace(name)) +// return; +// if (!NadekoBot.Config.CustomReactions.ContainsKey(name)) +// { +// await imsg.Channel.SendMessageAsync("Could not find given commandname").ConfigureAwait(false); +// return; +// } +// string message = ""; +// int index; +// if (int.TryParse(e.GetArg("index")?.Trim() ?? "", out index)) +// { +// index = index - 1; +// if (index < 0 || index > NadekoBot.Config.CustomReactions[name].Count) +// { +// await imsg.Channel.SendMessageAsync("Given index was out of range").ConfigureAwait(false); +// return; - } - NadekoBot.Config.CustomReactions[name].RemoveAt(index); - if (!NadekoBot.Config.CustomReactions[name].Any()) - { - NadekoBot.Config.CustomReactions.Remove(name); - } - message = $"Deleted response #{index + 1} from `{name}`"; - } - else - { - NadekoBot.Config.CustomReactions.Remove(name); - message = $"Deleted custom reaction: `{name}`"; - } - await Classes.JSONModels.ConfigHandler.SaveConfig().ConfigureAwait(false); - await imsg.Channel.SendMessageAsync(message).ConfigureAwait(false); - }); - } +// } +// NadekoBot.Config.CustomReactions[name].RemoveAt(index); +// if (!NadekoBot.Config.CustomReactions[name].Any()) +// { +// NadekoBot.Config.CustomReactions.Remove(name); +// } +// message = $"Deleted response #{index + 1} from `{name}`"; +// } +// else +// { +// NadekoBot.Config.CustomReactions.Remove(name); +// message = $"Deleted custom reaction: `{name}`"; +// } +// await Classes.JSONModels.ConfigHandler.SaveConfig().ConfigureAwait(false); +// await imsg.Channel.SendMessageAsync(message).ConfigureAwait(false); +// }); +// } - private readonly int ItemsPerPage = 30; +// private readonly int ItemsPerPage = 30; - private IEnumerable GetCustomsOnPage(int page) - { - var items = NadekoBot.Config.CustomReactions.Skip(page * ItemsPerPage).Take(ItemsPerPage); - if (!items.Any()) - { - return Enumerable.Empty(); - } - return items.Select(kvp => kvp.Key); - /* - var message = new StringBuilder($"--- Custom reactions - page {page + 1} ---\n"); - foreach (var cr in items) - { - message.Append($"{Format.Code(cr.Key)}\n"); - int i = 1; - var last = cr.Value.Last(); - foreach (var reaction in cr.Value) - { - if (last != reaction) - message.AppendLine(" `├" + i++ + "─`" + Format.Bold(reaction)); - else - message.AppendLine(" `└" + i++ + "─`" + Format.Bold(reaction)); - } - } - return message.ToString() + "\n"; - */ - } - } -} -// zeta is a god -//├ -//─ -//│ -//└ +// private IEnumerable GetCustomsOnPage(int page) +// { +// var items = NadekoBot.Config.CustomReactions.Skip(page * ItemsPerPage).Take(ItemsPerPage); +// if (!items.Any()) +// { +// return Enumerable.Empty(); +// } +// return items.Select(kvp => kvp.Key); +// /* +// var message = new StringBuilder($"--- Custom reactions - page {page + 1} ---\n"); +// foreach (var cr in items) +// { +// message.Append($"{Format.Code(cr.Key)}\n"); +// int i = 1; +// var last = cr.Value.Last(); +// foreach (var reaction in cr.Value) +// { +// if (last != reaction) +// message.AppendLine(" `├" + i++ + "─`" + Format.Bold(reaction)); +// else +// message.AppendLine(" `└" + i++ + "─`" + Format.Bold(reaction)); +// } +// } +// return message.ToString() + "\n"; +// */ +// } +// } +//} +//// zeta is a god +////├ +////─ +////│ +////└ diff --git a/src/NadekoBot/Modules/Administration/Commands/IncidentsCommands.cs b/src/NadekoBot/Modules/Administration/Commands/IncidentsCommands.cs index ab93693a..531c7cf6 100644 --- a/src/NadekoBot/Modules/Administration/Commands/IncidentsCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/IncidentsCommands.cs @@ -1,47 +1,47 @@ -using Discord.Commands; -using NadekoBot.Classes; -using NadekoBot.DataModels; -using NadekoBot.Modules.Permissions.Classes; -using System.IO; -using System.Linq; +//using Discord.Commands; +//using NadekoBot.Classes; +//using NadekoBot.DataModels; +//using NadekoBot.Modules.Permissions.Classes; +//using System.IO; +//using System.Linq; -namespace NadekoBot.Modules.Administration.Commands -{ - internal class IncidentsCommands : DiscordCommand - { - public IncidentsCommands(DiscordModule module) : base(module) { } - internal override void Init(CommandGroupBuilder cgb) - { - cgb.CreateCommand(Module.Prefix + "listincidents") - .Alias(Prefix + "lin") - .Description($"List all UNREAD incidents and flags them as read. **Needs Manage Server Permissions.**| `{Prefix}lin`") - .AddCheck(SimpleCheckers.ManageServer()) - .Do(async e => - { - var sid = (long)e.Server.Id; - var incs = DbHandler.Instance.FindAll(i => i.ServerId == sid && i.Read == false); - DbHandler.Instance.Connection.UpdateAll(incs.Select(i => { i.Read = true; return i; })); +//namespace NadekoBot.Modules.Administration.Commands +//{ +// internal class IncidentsCommands : DiscordCommand +// { +// public IncidentsCommands(DiscordModule module) : base(module) { } +// internal override void Init(CommandGroupBuilder cgb) +// { +// cgb.CreateCommand(Module.Prefix + "listincidents") +// .Alias(Prefix + "lin") +// .Description($"List all UNREAD incidents and flags them as read. **Needs Manage Server Permissions.**| `{Prefix}lin`") +// .AddCheck(SimpleCheckers.ManageServer()) +// .Do(async e => +// { +// var sid = (long)e.Server.Id; +// var incs = DbHandler.Instance.FindAll(i => i.ServerId == sid && i.Read == false); +// DbHandler.Instance.Connection.UpdateAll(incs.Select(i => { i.Read = true; return i; })); - await e.User.SendMessage(string.Join("\n----------------------", incs.Select(i => i.Text))); - }); +// await e.User.SendMessage(string.Join("\n----------------------", incs.Select(i => i.Text))); +// }); - cgb.CreateCommand(Module.Prefix + "listallincidents") - .Alias(Prefix + "lain") - .Description($"Sends you a file containing all incidents and flags them as read. **Needs Manage Server Permissions.**| `{Prefix}lain`") - .AddCheck(SimpleCheckers.ManageServer()) - .Do(async e => - { - var sid = (long)e.Server.Id; - var incs = DbHandler.Instance.FindAll(i => i.ServerId == sid); - DbHandler.Instance.Connection.UpdateAll(incs.Select(i => { i.Read = true; return i; })); - var data = string.Join("\n----------------------\n", incs.Select(i => i.Text)); - MemoryStream ms = new MemoryStream(); - var sw = new StreamWriter(ms); - sw.WriteLine(data); - sw.Flush(); - sw.BaseStream.Position = 0; - await e.User.SendFile("incidents.txt", sw.BaseStream); - }); - } - } -} +// cgb.CreateCommand(Module.Prefix + "listallincidents") +// .Alias(Prefix + "lain") +// .Description($"Sends you a file containing all incidents and flags them as read. **Needs Manage Server Permissions.**| `{Prefix}lain`") +// .AddCheck(SimpleCheckers.ManageServer()) +// .Do(async e => +// { +// var sid = (long)e.Server.Id; +// var incs = DbHandler.Instance.FindAll(i => i.ServerId == sid); +// DbHandler.Instance.Connection.UpdateAll(incs.Select(i => { i.Read = true; return i; })); +// var data = string.Join("\n----------------------\n", incs.Select(i => i.Text)); +// MemoryStream ms = new MemoryStream(); +// var sw = new StreamWriter(ms); +// sw.WriteLine(data); +// sw.Flush(); +// sw.BaseStream.Position = 0; +// await e.User.SendFile("incidents.txt", sw.BaseStream); +// }); +// } +// } +//} diff --git a/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs b/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs index 38363d11..1efb04f2 100644 --- a/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs @@ -1,483 +1,483 @@ -using Discord; -using Discord.Commands; -using NadekoBot.Classes; -using NadekoBot.Extensions; -using NadekoBot.Modules.Permissions.Classes; -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +//using Discord; +//using Discord.Commands; +//using NadekoBot.Classes; +//using NadekoBot.Extensions; +//using NadekoBot.Modules.Permissions.Classes; +//using System; +//using System.Collections.Concurrent; +//using System.Collections.Generic; +//using System.Linq; +//using System.Threading.Tasks; -namespace NadekoBot.Modules.Administration.Commands -{ - internal class LogCommand : DiscordCommand - { - private string prettyCurrentTime => $"【{DateTime.Now:HH:mm:ss}】"; +//namespace NadekoBot.Modules.Administration.Commands +//{ +// internal class LogCommand : DiscordCommand +// { +// private string prettyCurrentTime => $"【{DateTime.Now:HH:mm:ss}】"; - private ConcurrentBag> voicePresenceUpdates = new ConcurrentBag>(); +// private ConcurrentBag> voicePresenceUpdates = new ConcurrentBag>(); - public LogCommand(DiscordModule module) : base(module) - { - NadekoBot.Client.MessageReceived += MsgRecivd; - NadekoBot.Client.MessageDeleted += MsgDltd; - NadekoBot.Client.MessageUpdated += MsgUpdtd; - NadekoBot.Client.UserUpdated += UsrUpdtd; - NadekoBot.Client.UserBanned += UsrBanned; - NadekoBot.Client.UserLeft += UsrLeft; - NadekoBot.Client.UserJoined += UsrJoined; - NadekoBot.Client.UserUnbanned += UsrUnbanned; - NadekoBot.Client.ChannelCreated += ChannelCreated; - NadekoBot.Client.ChannelDestroyed += ChannelDestroyed; - NadekoBot.Client.ChannelUpdated += ChannelUpdated; +// public LogCommand(DiscordModule module) : base(module) +// { +// NadekoBot.Client.MessageReceived += MsgRecivd; +// NadekoBot.Client.MessageDeleted += MsgDltd; +// NadekoBot.Client.MessageUpdated += MsgUpdtd; +// NadekoBot.Client.UserUpdated += UsrUpdtd; +// NadekoBot.Client.UserBanned += UsrBanned; +// NadekoBot.Client.UserLeft += UsrLeft; +// NadekoBot.Client.UserJoined += UsrJoined; +// NadekoBot.Client.UserUnbanned += UsrUnbanned; +// NadekoBot.Client.ChannelCreated += ChannelCreated; +// NadekoBot.Client.ChannelDestroyed += ChannelDestroyed; +// NadekoBot.Client.ChannelUpdated += ChannelUpdated; - NadekoBot.Client.MessageReceived += async (s, e) => - { - if (e.Channel.IsPrivate || e.User.Id == NadekoBot.Client.CurrentUser.Id) - return; - if (!SpecificConfigurations.Default.Of(e.Server.Id).SendPrivateMessageOnMention) return; - try - { - var usr = e.Message.MentionedUsers.FirstOrDefault(u => u != e.User); - if (usr?.Status != UserStatus.Offline) - return; - await imsg.Channel.SendMessageAsync($"User `{usr.Name}` is offline. PM sent.").ConfigureAwait(false); - await usr.SendMessage( - $"User `{e.User.Name}` mentioned you on " + - $"`{e.Server.Name}` server while you were offline.\n" + - $"`Message:` {e.Message.Text}").ConfigureAwait(false); - } - catch { } - }; +// NadekoBot.Client.MessageReceived += async (s, e) => +// { +// if (e.Channel.IsPrivate || e.User.Id == NadekoBot.Client.CurrentUser.Id) +// return; +// if (!SpecificConfigurations.Default.Of(e.Server.Id).SendPrivateMessageOnMention) return; +// try +// { +// var usr = e.Message.MentionedUsers.FirstOrDefault(u => u != e.User); +// if (usr?.Status != UserStatus.Offline) +// return; +// await imsg.Channel.SendMessageAsync($"User `{usr.Name}` is offline. PM sent.").ConfigureAwait(false); +// await usr.SendMessage( +// $"User `{e.User.Name}` mentioned you on " + +// $"`{e.Server.Name}` server while you were offline.\n" + +// $"`Message:` {e.Message.Text}").ConfigureAwait(false); +// } +// catch { } +// }; - // start the userpresence queue +// // start the userpresence queue - NadekoBot.OnReady += () => Task.Run(async () => - { - while (true) - { - var toSend = new Dictionary(); - //take everything from the queue and merge the messages which are going to the same channel - KeyValuePair item; - while (voicePresenceUpdates.TryTake(out item)) - { - if (toSend.ContainsKey(item.Key)) - { - toSend[item.Key] = toSend[item.Key] + Environment.NewLine + item.Value; - } - else - { - toSend.Add(item.Key, item.Value); - } - } - //send merged messages to each channel - foreach (var k in toSend) - { - try { await k.Key.SendMessage(Environment.NewLine + k.Value).ConfigureAwait(false); } catch { } - } +// NadekoBot.OnReady += () => Task.Run(async () => +// { +// while (true) +// { +// var toSend = new Dictionary(); +// //take everything from the queue and merge the messages which are going to the same channel +// KeyValuePair item; +// while (voicePresenceUpdates.TryTake(out item)) +// { +// if (toSend.ContainsKey(item.Key)) +// { +// toSend[item.Key] = toSend[item.Key] + Environment.NewLine + item.Value; +// } +// else +// { +// toSend.Add(item.Key, item.Value); +// } +// } +// //send merged messages to each channel +// foreach (var k in toSend) +// { +// try { await k.Key.SendMessage(Environment.NewLine + k.Value).ConfigureAwait(false); } catch { } +// } - await Task.Delay(5000); - } - }); - } +// await Task.Delay(5000); +// } +// }); +// } - private async void ChannelUpdated(object sender, ChannelUpdatedEventArgs e) - { - try - { - var config = SpecificConfigurations.Default.Of(e.Server.Id); - var chId = config.LogServerChannel; - if (chId == null || config.LogserverIgnoreChannels.Contains(e.After.Id)) - return; - Channel ch; - if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) - return; - if (e.Before.Name != e.After.Name) - await ch.SendMessage($@"`{prettyCurrentTime}` **Channel Name Changed** `#{e.Before.Name}` (*{e.After.Id}*) - `New:` {e.After.Name}").ConfigureAwait(false); - else if (e.Before.Topic != e.After.Topic) - await ch.SendMessage($@"`{prettyCurrentTime}` **Channel Topic Changed** `#{e.After.Name}` (*{e.After.Id}*) - `Old:` {e.Before.Topic} - `New:` {e.After.Topic}").ConfigureAwait(false); - } - catch { } - } +// private async void ChannelUpdated(object sender, ChannelUpdatedEventArgs e) +// { +// try +// { +// var config = SpecificConfigurations.Default.Of(e.Server.Id); +// var chId = config.LogServerChannel; +// if (chId == null || config.LogserverIgnoreChannels.Contains(e.After.Id)) +// return; +// Channel ch; +// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) +// return; +// if (e.Before.Name != e.After.Name) +// await ch.SendMessage($@"`{prettyCurrentTime}` **Channel Name Changed** `#{e.Before.Name}` (*{e.After.Id}*) +// `New:` {e.After.Name}").ConfigureAwait(false); +// else if (e.Before.Topic != e.After.Topic) +// await ch.SendMessage($@"`{prettyCurrentTime}` **Channel Topic Changed** `#{e.After.Name}` (*{e.After.Id}*) +// `Old:` {e.Before.Topic} +// `New:` {e.After.Topic}").ConfigureAwait(false); +// } +// catch { } +// } - private async void ChannelDestroyed(object sender, ChannelEventArgs e) - { - try - { - var config = SpecificConfigurations.Default.Of(e.Server.Id); - var chId = config.LogServerChannel; - if (chId == null || config.LogserverIgnoreChannels.Contains(e.Channel.Id)) - return; - Channel ch; - if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) - return; - await ch.SendMessage($"❗`{prettyCurrentTime}`❗`Channel Deleted:` #{e.Channel.Name} (*{e.Channel.Id}*)").ConfigureAwait(false); - } - catch { } - } +// private async void ChannelDestroyed(object sender, ChannelEventArgs e) +// { +// try +// { +// var config = SpecificConfigurations.Default.Of(e.Server.Id); +// var chId = config.LogServerChannel; +// if (chId == null || config.LogserverIgnoreChannels.Contains(e.Channel.Id)) +// return; +// Channel ch; +// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) +// return; +// await ch.SendMessage($"❗`{prettyCurrentTime}`❗`Channel Deleted:` #{e.Channel.Name} (*{e.Channel.Id}*)").ConfigureAwait(false); +// } +// catch { } +// } - private async void ChannelCreated(object sender, ChannelEventArgs e) - { - try - { - var config = SpecificConfigurations.Default.Of(e.Server.Id); - var chId = config.LogServerChannel; - if (chId == null || config.LogserverIgnoreChannels.Contains(e.Channel.Id)) - return; - Channel ch; - if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) - return; - await ch.SendMessage($"`{prettyCurrentTime}`🆕`Channel Created:` #{e.Channel.Mention} (*{e.Channel.Id}*)").ConfigureAwait(false); - } - catch { } - } +// private async void ChannelCreated(object sender, ChannelEventArgs e) +// { +// try +// { +// var config = SpecificConfigurations.Default.Of(e.Server.Id); +// var chId = config.LogServerChannel; +// if (chId == null || config.LogserverIgnoreChannels.Contains(e.Channel.Id)) +// return; +// Channel ch; +// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) +// return; +// await ch.SendMessage($"`{prettyCurrentTime}`🆕`Channel Created:` #{e.Channel.Mention} (*{e.Channel.Id}*)").ConfigureAwait(false); +// } +// catch { } +// } - private async void UsrUnbanned(object sender, UserEventArgs e) - { - try - { - var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel; - if (chId == null) - return; - Channel ch; - if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) - return; - await ch.SendMessage($"`{prettyCurrentTime}`♻`User was unbanned:` **{e.User.Name}** ({e.User.Id})").ConfigureAwait(false); - } - catch { } - } +// private async void UsrUnbanned(object sender, UserEventArgs e) +// { +// try +// { +// var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel; +// if (chId == null) +// return; +// Channel ch; +// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) +// return; +// await ch.SendMessage($"`{prettyCurrentTime}`♻`User was unbanned:` **{e.User.Name}** ({e.User.Id})").ConfigureAwait(false); +// } +// catch { } +// } - private async void UsrJoined(object sender, UserEventArgs e) - { - try - { - var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel; - if (chId == null) - return; - Channel ch; - if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) - return; - await ch.SendMessage($"`{prettyCurrentTime}`✅`User joined:` **{e.User.Name}** ({e.User.Id})").ConfigureAwait(false); - } - catch { } - } +// private async void UsrJoined(object sender, UserEventArgs e) +// { +// try +// { +// var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel; +// if (chId == null) +// return; +// Channel ch; +// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) +// return; +// await ch.SendMessage($"`{prettyCurrentTime}`✅`User joined:` **{e.User.Name}** ({e.User.Id})").ConfigureAwait(false); +// } +// catch { } +// } - private async void UsrLeft(object sender, UserEventArgs e) - { - try - { - var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel; - if (chId == null) - return; - Channel ch; - if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) - return; - await ch.SendMessage($"`{prettyCurrentTime}`❗`User left:` **{e.User.Name}** ({e.User.Id})").ConfigureAwait(false); - } - catch { } - } +// private async void UsrLeft(object sender, UserEventArgs e) +// { +// try +// { +// var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel; +// if (chId == null) +// return; +// Channel ch; +// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) +// return; +// await ch.SendMessage($"`{prettyCurrentTime}`❗`User left:` **{e.User.Name}** ({e.User.Id})").ConfigureAwait(false); +// } +// catch { } +// } - private async void UsrBanned(object sender, UserEventArgs e) - { - try - { - var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel; - if (chId == null) - return; - Channel ch; - if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) - return; - await ch.SendMessage($"❗`{prettyCurrentTime}`❌`User banned:` **{e.User.Name}** ({e.User.Id})").ConfigureAwait(false); - } - catch { } - } +// private async void UsrBanned(object sender, UserEventArgs e) +// { +// try +// { +// var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel; +// if (chId == null) +// return; +// Channel ch; +// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) +// return; +// await ch.SendMessage($"❗`{prettyCurrentTime}`❌`User banned:` **{e.User.Name}** ({e.User.Id})").ConfigureAwait(false); +// } +// catch { } +// } - private async void MsgRecivd(object sender, MessageEventArgs e) - { - try - { - if (e.Server == null || e.Channel.IsPrivate || e.User.Id == NadekoBot.Client.CurrentUser.Id) - return; - var config = SpecificConfigurations.Default.Of(e.Server.Id); - var chId = config.LogServerChannel; - if (chId == null || e.Channel.Id == chId || config.LogserverIgnoreChannels.Contains(e.Channel.Id)) - return; - Channel ch; - if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) - return; - if (!string.IsNullOrWhiteSpace(e.Message.Text)) - { - await ch.SendMessage( - $@"🕔`{prettyCurrentTime}` **New Message** `#{e.Channel.Name}` -👤`{e.User?.ToString() ?? ("NULL")}` {e.Message.Text.Unmention()}").ConfigureAwait(false); - } - else - { - await ch.SendMessage( - $@"🕔`{prettyCurrentTime}` **File Uploaded** `#{e.Channel.Name}` -👤`{e.User?.ToString() ?? ("NULL")}` {e.Message.Attachments.FirstOrDefault()?.ProxyUrl}").ConfigureAwait(false); - } +// private async void MsgRecivd(object sender, MessageEventArgs e) +// { +// try +// { +// if (e.Server == null || e.Channel.IsPrivate || e.User.Id == NadekoBot.Client.CurrentUser.Id) +// return; +// var config = SpecificConfigurations.Default.Of(e.Server.Id); +// var chId = config.LogServerChannel; +// if (chId == null || e.Channel.Id == chId || config.LogserverIgnoreChannels.Contains(e.Channel.Id)) +// return; +// Channel ch; +// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) +// return; +// if (!string.IsNullOrWhiteSpace(e.Message.Text)) +// { +// await ch.SendMessage( +// $@"🕔`{prettyCurrentTime}` **New Message** `#{e.Channel.Name}` +//👤`{e.User?.ToString() ?? ("NULL")}` {e.Message.Text.Unmention()}").ConfigureAwait(false); +// } +// else +// { +// await ch.SendMessage( +// $@"🕔`{prettyCurrentTime}` **File Uploaded** `#{e.Channel.Name}` +//👤`{e.User?.ToString() ?? ("NULL")}` {e.Message.Attachments.FirstOrDefault()?.ProxyUrl}").ConfigureAwait(false); +// } - } - catch { } - } - private async void MsgDltd(object sender, MessageEventArgs e) - { - try - { - if (e.Server == null || e.Channel.IsPrivate || e.User?.Id == NadekoBot.Client.CurrentUser.Id) - return; - var config = SpecificConfigurations.Default.Of(e.Server.Id); - var chId = config.LogServerChannel; - if (chId == null || e.Channel.Id == chId || config.LogserverIgnoreChannels.Contains(e.Channel.Id)) - return; - Channel ch; - if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) - return; - if (!string.IsNullOrWhiteSpace(e.Message.Text)) - { - await ch.SendMessage( - $@"🕔`{prettyCurrentTime}` **Message** 🚮 `#{e.Channel.Name}` -👤`{e.User?.ToString() ?? ("NULL")}` {e.Message.Text.Unmention()}").ConfigureAwait(false); - } - else - { - await ch.SendMessage( - $@"🕔`{prettyCurrentTime}` **File Deleted** `#{e.Channel.Name}` -👤`{e.User?.ToString() ?? ("NULL")}` {e.Message.Attachments.FirstOrDefault()?.ProxyUrl}").ConfigureAwait(false); - } - } - catch { } - } - private async void MsgUpdtd(object sender, MessageUpdatedEventArgs e) - { - try - { - if (e.Server == null || e.Channel.IsPrivate || e.User?.Id == NadekoBot.Client.CurrentUser.Id) - return; - var config = SpecificConfigurations.Default.Of(e.Server.Id); - var chId = config.LogServerChannel; - if (chId == null || e.Channel.Id == chId || config.LogserverIgnoreChannels.Contains(e.Channel.Id)) - return; - Channel ch; - if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) - return; - await ch.SendMessage( - $@"🕔`{prettyCurrentTime}` **Message** 📝 `#{e.Channel.Name}` -👤`{e.User?.ToString() ?? ("NULL")}` - `Old:` {e.Before.Text.Unmention()} - `New:` {e.After.Text.Unmention()}").ConfigureAwait(false); - } - catch { } - } - private async void UsrUpdtd(object sender, UserUpdatedEventArgs e) - { - var config = SpecificConfigurations.Default.Of(e.Server.Id); - try - { - var chId = config.LogPresenceChannel; - if (chId != null) - { - Channel ch; - if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) != null) - { - if (e.Before.Status != e.After.Status) - { - voicePresenceUpdates.Add(new KeyValuePair(ch, $"`{prettyCurrentTime}`**{e.Before.Name}** is now **{e.After.Status}**.")); - } - } - } - } - catch { } +// } +// catch { } +// } +// private async void MsgDltd(object sender, MessageEventArgs e) +// { +// try +// { +// if (e.Server == null || e.Channel.IsPrivate || e.User?.Id == NadekoBot.Client.CurrentUser.Id) +// return; +// var config = SpecificConfigurations.Default.Of(e.Server.Id); +// var chId = config.LogServerChannel; +// if (chId == null || e.Channel.Id == chId || config.LogserverIgnoreChannels.Contains(e.Channel.Id)) +// return; +// Channel ch; +// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) +// return; +// if (!string.IsNullOrWhiteSpace(e.Message.Text)) +// { +// await ch.SendMessage( +// $@"🕔`{prettyCurrentTime}` **Message** 🚮 `#{e.Channel.Name}` +//👤`{e.User?.ToString() ?? ("NULL")}` {e.Message.Text.Unmention()}").ConfigureAwait(false); +// } +// else +// { +// await ch.SendMessage( +// $@"🕔`{prettyCurrentTime}` **File Deleted** `#{e.Channel.Name}` +//👤`{e.User?.ToString() ?? ("NULL")}` {e.Message.Attachments.FirstOrDefault()?.ProxyUrl}").ConfigureAwait(false); +// } +// } +// catch { } +// } +// private async void MsgUpdtd(object sender, MessageUpdatedEventArgs e) +// { +// try +// { +// if (e.Server == null || e.Channel.IsPrivate || e.User?.Id == NadekoBot.Client.CurrentUser.Id) +// return; +// var config = SpecificConfigurations.Default.Of(e.Server.Id); +// var chId = config.LogServerChannel; +// if (chId == null || e.Channel.Id == chId || config.LogserverIgnoreChannels.Contains(e.Channel.Id)) +// return; +// Channel ch; +// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) +// return; +// await ch.SendMessage( +// $@"🕔`{prettyCurrentTime}` **Message** 📝 `#{e.Channel.Name}` +//👤`{e.User?.ToString() ?? ("NULL")}` +// `Old:` {e.Before.Text.Unmention()} +// `New:` {e.After.Text.Unmention()}").ConfigureAwait(false); +// } +// catch { } +// } +// private async void UsrUpdtd(object sender, UserUpdatedEventArgs e) +// { +// var config = SpecificConfigurations.Default.Of(e.Server.Id); +// try +// { +// var chId = config.LogPresenceChannel; +// if (chId != null) +// { +// Channel ch; +// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) != null) +// { +// if (e.Before.Status != e.After.Status) +// { +// voicePresenceUpdates.Add(new KeyValuePair(ch, $"`{prettyCurrentTime}`**{e.Before.Name}** is now **{e.After.Status}**.")); +// } +// } +// } +// } +// catch { } - try - { - ulong notifyChBeforeId; - ulong notifyChAfterId; - Channel notifyChBefore = null; - Channel notifyChAfter = null; - var beforeVch = e.Before.VoiceChannel; - var afterVch = e.After.VoiceChannel; - var notifyLeave = false; - var notifyJoin = false; - if ((beforeVch != null || afterVch != null) && (beforeVch != afterVch)) // this means we need to notify for sure. - { - if (beforeVch != null && config.VoiceChannelLog.TryGetValue(beforeVch.Id, out notifyChBeforeId) && (notifyChBefore = e.Before.Server.TextChannels.FirstOrDefault(tc => tc.Id == notifyChBeforeId)) != null) - { - notifyLeave = true; - } - if (afterVch != null && config.VoiceChannelLog.TryGetValue(afterVch.Id, out notifyChAfterId) && (notifyChAfter = e.After.Server.TextChannels.FirstOrDefault(tc => tc.Id == notifyChAfterId)) != null) - { - notifyJoin = true; - } - if ((notifyLeave && notifyJoin) && (notifyChAfter == notifyChBefore)) - { - await notifyChAfter.SendMessage($"🎼`{prettyCurrentTime}` {e.Before.Name} moved from **{beforeVch.Mention}** to **{afterVch.Mention}** voice channel.").ConfigureAwait(false); - } - else if (notifyJoin) - { - await notifyChAfter.SendMessage($"🎼`{prettyCurrentTime}` {e.Before.Name} has joined **{afterVch.Mention}** voice channel.").ConfigureAwait(false); - } - else if (notifyLeave) - { - await notifyChBefore.SendMessage($"🎼`{prettyCurrentTime}` {e.Before.Name} has left **{beforeVch.Mention}** voice channel.").ConfigureAwait(false); - } - } - } - catch { } +// try +// { +// ulong notifyChBeforeId; +// ulong notifyChAfterId; +// Channel notifyChBefore = null; +// Channel notifyChAfter = null; +// var beforeVch = e.Before.VoiceChannel; +// var afterVch = e.After.VoiceChannel; +// var notifyLeave = false; +// var notifyJoin = false; +// if ((beforeVch != null || afterVch != null) && (beforeVch != afterVch)) // this means we need to notify for sure. +// { +// if (beforeVch != null && config.VoiceChannelLog.TryGetValue(beforeVch.Id, out notifyChBeforeId) && (notifyChBefore = e.Before.Server.TextChannels.FirstOrDefault(tc => tc.Id == notifyChBeforeId)) != null) +// { +// notifyLeave = true; +// } +// if (afterVch != null && config.VoiceChannelLog.TryGetValue(afterVch.Id, out notifyChAfterId) && (notifyChAfter = e.After.Server.TextChannels.FirstOrDefault(tc => tc.Id == notifyChAfterId)) != null) +// { +// notifyJoin = true; +// } +// if ((notifyLeave && notifyJoin) && (notifyChAfter == notifyChBefore)) +// { +// await notifyChAfter.SendMessage($"🎼`{prettyCurrentTime}` {e.Before.Name} moved from **{beforeVch.Mention}** to **{afterVch.Mention}** voice channel.").ConfigureAwait(false); +// } +// else if (notifyJoin) +// { +// await notifyChAfter.SendMessage($"🎼`{prettyCurrentTime}` {e.Before.Name} has joined **{afterVch.Mention}** voice channel.").ConfigureAwait(false); +// } +// else if (notifyLeave) +// { +// await notifyChBefore.SendMessage($"🎼`{prettyCurrentTime}` {e.Before.Name} has left **{beforeVch.Mention}** voice channel.").ConfigureAwait(false); +// } +// } +// } +// catch { } - try - { - var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel; - if (chId == null) - return; - Channel ch; - if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) - return; - string str = $"🕔`{prettyCurrentTime}`"; - if (e.Before.Name != e.After.Name) - str += $"**Name Changed**👤`{e.Before?.ToString()}`\n\t\t`New:`{e.After.ToString()}`"; - else if (e.Before.Nickname != e.After.Nickname) - str += $"**Nickname Changed**👤`{e.Before?.ToString()}`\n\t\t`Old:` {e.Before.Nickname}#{e.Before.Discriminator}\n\t\t`New:` {e.After.Nickname}#{e.After.Discriminator}"; - else if (e.Before.AvatarUrl != e.After.AvatarUrl) - str += $"**Avatar Changed**👤`{e.Before?.ToString()}`\n\t {await e.Before.AvatarUrl.ShortenUrl()} `=>` {await e.After.AvatarUrl.ShortenUrl()}"; - else if (!e.Before.Roles.SequenceEqual(e.After.Roles)) - { - if (e.Before.Roles.Count() < e.After.Roles.Count()) - { - var diffRoles = e.After.Roles.Where(r => !e.Before.Roles.Contains(r)).Select(r => "`" + r.Name + "`"); - str += $"**User's Roles changed ⚔➕**👤`{e.Before?.ToString()}`\n\tNow has {string.Join(", ", diffRoles)} role."; - } - else if (e.Before.Roles.Count() > e.After.Roles.Count()) - { - var diffRoles = e.Before.Roles.Where(r => !e.After.Roles.Contains(r)).Select(r => "`" + r.Name + "`"); - str += $"**User's Roles changed ⚔➖**👤`{e.Before?.ToString()}`\n\tNo longer has {string.Join(", ", diffRoles)} role."; - } - else - { - Console.WriteLine("SEQUENCE NOT EQUAL BUT NO DIFF ROLES - REPORT TO KWOTH on #NADEKOLOG server"); - return; - } +// try +// { +// var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel; +// if (chId == null) +// return; +// Channel ch; +// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) +// return; +// string str = $"🕔`{prettyCurrentTime}`"; +// if (e.Before.Name != e.After.Name) +// str += $"**Name Changed**👤`{e.Before?.ToString()}`\n\t\t`New:`{e.After.ToString()}`"; +// else if (e.Before.Nickname != e.After.Nickname) +// str += $"**Nickname Changed**👤`{e.Before?.ToString()}`\n\t\t`Old:` {e.Before.Nickname}#{e.Before.Discriminator}\n\t\t`New:` {e.After.Nickname}#{e.After.Discriminator}"; +// else if (e.Before.AvatarUrl != e.After.AvatarUrl) +// str += $"**Avatar Changed**👤`{e.Before?.ToString()}`\n\t {await e.Before.AvatarUrl.ShortenUrl()} `=>` {await e.After.AvatarUrl.ShortenUrl()}"; +// else if (!e.Before.Roles.SequenceEqual(e.After.Roles)) +// { +// if (e.Before.Roles.Count() < e.After.Roles.Count()) +// { +// var diffRoles = e.After.Roles.Where(r => !e.Before.Roles.Contains(r)).Select(r => "`" + r.Name + "`"); +// str += $"**User's Roles changed ⚔➕**👤`{e.Before?.ToString()}`\n\tNow has {string.Join(", ", diffRoles)} role."; +// } +// else if (e.Before.Roles.Count() > e.After.Roles.Count()) +// { +// var diffRoles = e.Before.Roles.Where(r => !e.After.Roles.Contains(r)).Select(r => "`" + r.Name + "`"); +// str += $"**User's Roles changed ⚔➖**👤`{e.Before?.ToString()}`\n\tNo longer has {string.Join(", ", diffRoles)} role."; +// } +// else +// { +// Console.WriteLine("SEQUENCE NOT EQUAL BUT NO DIFF ROLES - REPORT TO KWOTH on #NADEKOLOG server"); +// return; +// } - } - else - return; - await ch.SendMessage(str).ConfigureAwait(false); - } - catch { } - } +// } +// else +// return; +// await ch.SendMessage(str).ConfigureAwait(false); +// } +// catch { } +// } - internal override void Init(CommandGroupBuilder cgb) - { +// internal override void Init(CommandGroupBuilder cgb) +// { - cgb.CreateCommand(Module.Prefix + "spmom") - .Description($"Toggles whether mentions of other offline users on your server will send a pm to them. **Needs Manage Server Permissions.**| `{Prefix}spmom`") - .AddCheck(SimpleCheckers.ManageServer()) - .Do(async e => - { - var specificConfig = SpecificConfigurations.Default.Of(e.Server.Id); - specificConfig.SendPrivateMessageOnMention = - !specificConfig.SendPrivateMessageOnMention; - if (specificConfig.SendPrivateMessageOnMention) - await imsg.Channel.SendMessageAsync(":ok: I will send private messages " + - "to mentioned offline users.").ConfigureAwait(false); - else - await imsg.Channel.SendMessageAsync(":ok: I won't send private messages " + - "to mentioned offline users anymore.").ConfigureAwait(false); - }); +// cgb.CreateCommand(Module.Prefix + "spmom") +// .Description($"Toggles whether mentions of other offline users on your server will send a pm to them. **Needs Manage Server Permissions.**| `{Prefix}spmom`") +// .AddCheck(SimpleCheckers.ManageServer()) +// .Do(async e => +// { +// var specificConfig = SpecificConfigurations.Default.Of(e.Server.Id); +// specificConfig.SendPrivateMessageOnMention = +// !specificConfig.SendPrivateMessageOnMention; +// if (specificConfig.SendPrivateMessageOnMention) +// await imsg.Channel.SendMessageAsync(":ok: I will send private messages " + +// "to mentioned offline users.").ConfigureAwait(false); +// else +// await imsg.Channel.SendMessageAsync(":ok: I won't send private messages " + +// "to mentioned offline users anymore.").ConfigureAwait(false); +// }); - cgb.CreateCommand(Module.Prefix + "logserver") - .Description($"Toggles logging in this channel. Logs every message sent/deleted/edited on the server. **Bot Owner Only!** | `{Prefix}logserver`") - .AddCheck(SimpleCheckers.OwnerOnly()) - .AddCheck(SimpleCheckers.ManageServer()) - .Do(async e => - { - var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel; - if (chId == null) - { - SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel = e.Channel.Id; - await imsg.Channel.SendMessageAsync($"❗**I WILL BEGIN LOGGING SERVER ACTIVITY IN THIS CHANNEL**❗").ConfigureAwait(false); - return; - } - Channel ch; - if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) - return; +// cgb.CreateCommand(Module.Prefix + "logserver") +// .Description($"Toggles logging in this channel. Logs every message sent/deleted/edited on the server. **Bot Owner Only!** | `{Prefix}logserver`") +// .AddCheck(SimpleCheckers.OwnerOnly()) +// .AddCheck(SimpleCheckers.ManageServer()) +// .Do(async e => +// { +// var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel; +// if (chId == null) +// { +// SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel = e.Channel.Id; +// await imsg.Channel.SendMessageAsync($"❗**I WILL BEGIN LOGGING SERVER ACTIVITY IN THIS CHANNEL**❗").ConfigureAwait(false); +// return; +// } +// Channel ch; +// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) +// return; - SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel = null; - await imsg.Channel.SendMessageAsync($"❗**NO LONGER LOGGING IN {ch.Mention} CHANNEL**❗").ConfigureAwait(false); - }); +// SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel = null; +// await imsg.Channel.SendMessageAsync($"❗**NO LONGER LOGGING IN {ch.Mention} CHANNEL**❗").ConfigureAwait(false); +// }); - cgb.CreateCommand(Prefix + "logignore") - .Description($"Toggles whether the {Prefix}logserver command ignores this channel. Useful if you have hidden admin channel and public log channel. **Bot Owner Only!**| `{Prefix}logignore`") - .AddCheck(SimpleCheckers.OwnerOnly()) - .AddCheck(SimpleCheckers.ManageServer()) - .Do(async e => - { - var config = SpecificConfigurations.Default.Of(e.Server.Id); - if (config.LogserverIgnoreChannels.Remove(e.Channel.Id)) - { - await imsg.Channel.SendMessageAsync($"`{Prefix}logserver will stop ignoring this channel.`"); - } - else - { - config.LogserverIgnoreChannels.Add(e.Channel.Id); - await imsg.Channel.SendMessageAsync($"`{Prefix}logserver will ignore this channel.`"); - } - }); +// cgb.CreateCommand(Prefix + "logignore") +// .Description($"Toggles whether the {Prefix}logserver command ignores this channel. Useful if you have hidden admin channel and public log channel. **Bot Owner Only!**| `{Prefix}logignore`") +// .AddCheck(SimpleCheckers.OwnerOnly()) +// .AddCheck(SimpleCheckers.ManageServer()) +// .Do(async e => +// { +// var config = SpecificConfigurations.Default.Of(e.Server.Id); +// if (config.LogserverIgnoreChannels.Remove(e.Channel.Id)) +// { +// await imsg.Channel.SendMessageAsync($"`{Prefix}logserver will stop ignoring this channel.`"); +// } +// else +// { +// config.LogserverIgnoreChannels.Add(e.Channel.Id); +// await imsg.Channel.SendMessageAsync($"`{Prefix}logserver will ignore this channel.`"); +// } +// }); - cgb.CreateCommand(Module.Prefix + "userpresence") - .Description($"Starts logging to this channel when someone from the server goes online/offline/idle. **Needs Manage Server Permissions.**| `{Prefix}userpresence`") - .AddCheck(SimpleCheckers.ManageServer()) - .Do(async e => - { - var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogPresenceChannel; - if (chId == null) - { - SpecificConfigurations.Default.Of(e.Server.Id).LogPresenceChannel = e.Channel.Id; - await imsg.Channel.SendMessageAsync($"**User presence notifications enabled.**").ConfigureAwait(false); - return; - } - SpecificConfigurations.Default.Of(e.Server.Id).LogPresenceChannel = null; - await imsg.Channel.SendMessageAsync($"**User presence notifications disabled.**").ConfigureAwait(false); - }); +// cgb.CreateCommand(Module.Prefix + "userpresence") +// .Description($"Starts logging to this channel when someone from the server goes online/offline/idle. **Needs Manage Server Permissions.**| `{Prefix}userpresence`") +// .AddCheck(SimpleCheckers.ManageServer()) +// .Do(async e => +// { +// var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogPresenceChannel; +// if (chId == null) +// { +// SpecificConfigurations.Default.Of(e.Server.Id).LogPresenceChannel = e.Channel.Id; +// await imsg.Channel.SendMessageAsync($"**User presence notifications enabled.**").ConfigureAwait(false); +// return; +// } +// SpecificConfigurations.Default.Of(e.Server.Id).LogPresenceChannel = null; +// await imsg.Channel.SendMessageAsync($"**User presence notifications disabled.**").ConfigureAwait(false); +// }); - cgb.CreateCommand(Module.Prefix + "voicepresence") - .Description($"Toggles logging to this channel whenever someone joins or leaves a voice channel you are in right now. **Needs Manage Server Permissions.**| `{Prefix}voicerpresence`") - .Parameter("all", ParameterType.Optional) - .AddCheck(SimpleCheckers.ManageServer()) - .Do(async e => - { +// cgb.CreateCommand(Module.Prefix + "voicepresence") +// .Description($"Toggles logging to this channel whenever someone joins or leaves a voice channel you are in right now. **Needs Manage Server Permissions.**| `{Prefix}voicerpresence`") +// .Parameter("all", ParameterType.Optional) +// .AddCheck(SimpleCheckers.ManageServer()) +// .Do(async e => +// { - var config = SpecificConfigurations.Default.Of(e.Server.Id); - if (e.GetArg("all")?.ToLower() == "all") - { - foreach (var voiceChannel in e.Server.VoiceChannels) - { - config.VoiceChannelLog.TryAdd(voiceChannel.Id, e.Channel.Id); - } - await imsg.Channel.SendMessageAsync("Started logging user presence for **ALL** voice channels!").ConfigureAwait(false); - return; - } +// var config = SpecificConfigurations.Default.Of(e.Server.Id); +// if (e.GetArg("all")?.ToLower() == "all") +// { +// foreach (var voiceChannel in e.Server.VoiceChannels) +// { +// config.VoiceChannelLog.TryAdd(voiceChannel.Id, e.Channel.Id); +// } +// await imsg.Channel.SendMessageAsync("Started logging user presence for **ALL** voice channels!").ConfigureAwait(false); +// return; +// } - if (e.User.VoiceChannel == null) - { - await imsg.Channel.SendMessageAsync("💢 You are not in a voice channel right now. If you are, please rejoin it.").ConfigureAwait(false); - return; - } - ulong throwaway; - if (!config.VoiceChannelLog.TryRemove(e.User.VoiceChannel.Id, out throwaway)) - { - config.VoiceChannelLog.TryAdd(e.User.VoiceChannel.Id, e.Channel.Id); - await imsg.Channel.SendMessageAsync($"`Logging user updates for` {e.User.VoiceChannel.Mention} `voice channel.`").ConfigureAwait(false); - } - else - await imsg.Channel.SendMessageAsync($"`Stopped logging user updates for` {e.User.VoiceChannel.Mention} `voice channel.`").ConfigureAwait(false); - }); - } - } -} +// if (e.User.VoiceChannel == null) +// { +// await imsg.Channel.SendMessageAsync("💢 You are not in a voice channel right now. If you are, please rejoin it.").ConfigureAwait(false); +// return; +// } +// ulong throwaway; +// if (!config.VoiceChannelLog.TryRemove(e.User.VoiceChannel.Id, out throwaway)) +// { +// config.VoiceChannelLog.TryAdd(e.User.VoiceChannel.Id, e.Channel.Id); +// await imsg.Channel.SendMessageAsync($"`Logging user updates for` {e.User.VoiceChannel.Mention} `voice channel.`").ConfigureAwait(false); +// } +// else +// await imsg.Channel.SendMessageAsync($"`Stopped logging user updates for` {e.User.VoiceChannel.Mention} `voice channel.`").ConfigureAwait(false); +// }); +// } +// } +//} diff --git a/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs b/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs index b7e09f94..3e521c2d 100644 --- a/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs +++ b/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs @@ -1,129 +1,129 @@ -using Discord; -using Discord.Commands; -using NadekoBot.Classes; -using NadekoBot.Modules.Permissions.Classes; -using System; -using System.Collections.Concurrent; -using System.Threading.Tasks; -using System.Timers; +//using Discord; +//using Discord.Commands; +//using NadekoBot.Classes; +//using NadekoBot.Modules.Permissions.Classes; +//using System; +//using System.Collections.Concurrent; +//using System.Threading.Tasks; +//using System.Timers; -namespace NadekoBot.Modules.Administration.Commands -{ - class MessageRepeater : DiscordCommand - { - private readonly ConcurrentDictionary repeaters = new ConcurrentDictionary(); - private class Repeater - { - [Newtonsoft.Json.JsonIgnore] - public Timer MessageTimer { get; set; } - [Newtonsoft.Json.JsonIgnore] - public Channel RepeatingChannel { get; set; } +//namespace NadekoBot.Modules.Administration.Commands +//{ +// class MessageRepeater : DiscordCommand +// { +// private readonly ConcurrentDictionary repeaters = new ConcurrentDictionary(); +// private class Repeater +// { +// [Newtonsoft.Json.JsonIgnore] +// public Timer MessageTimer { get; set; } +// [Newtonsoft.Json.JsonIgnore] +// public Channel RepeatingChannel { get; set; } - public ulong RepeatingServerId { get; set; } - public ulong RepeatingChannelId { get; set; } - public Message lastMessage { get; set; } = null; - public string RepeatingMessage { get; set; } - public int Interval { get; set; } +// public ulong RepeatingServerId { get; set; } +// public ulong RepeatingChannelId { get; set; } +// public Message lastMessage { get; set; } = null; +// public string RepeatingMessage { get; set; } +// public int Interval { get; set; } - public Repeater Start() - { - MessageTimer = new Timer { Interval = Interval }; - MessageTimer.Elapsed += async (s, e) => await Invoke(); - return this; - } +// public Repeater Start() +// { +// MessageTimer = new Timer { Interval = Interval }; +// MessageTimer.Elapsed += async (s, e) => await Invoke(); +// return this; +// } - public async Task Invoke() - { - var ch = RepeatingChannel; - var msg = RepeatingMessage; - if (ch != null && !string.IsNullOrWhiteSpace(msg)) - { - try - { - if (lastMessage != null) - await lastMessage.Delete().ConfigureAwait(false); - } - catch { } - try - { - lastMessage = await ch.SendMessage(msg).ConfigureAwait(false); - } - catch { } - } - } - } - internal override void Init(CommandGroupBuilder cgb) - { +// public async Task Invoke() +// { +// var ch = RepeatingChannel; +// var msg = RepeatingMessage; +// if (ch != null && !string.IsNullOrWhiteSpace(msg)) +// { +// try +// { +// if (lastMessage != null) +// await lastMessage.Delete().ConfigureAwait(false); +// } +// catch { } +// try +// { +// lastMessage = await ch.SendMessage(msg).ConfigureAwait(false); +// } +// catch { } +// } +// } +// } +// internal override void Init(CommandGroupBuilder cgb) +// { - cgb.CreateCommand(Module.Prefix + "repeatinvoke") - .Alias(Module.Prefix + "repinv") - .Description($"Immediately shows the repeat message and restarts the timer. **Needs Manage Messages Permissions.**| `{Prefix}repinv`") - .AddCheck(SimpleCheckers.ManageMessages()) - .Do(async e => - { - Repeater rep; - if (!repeaters.TryGetValue(e.Server, out rep)) - { - await imsg.Channel.SendMessageAsync("`No repeating message found on this server.`"); - return; - } +// cgb.CreateCommand(Module.Prefix + "repeatinvoke") +// .Alias(Module.Prefix + "repinv") +// .Description($"Immediately shows the repeat message and restarts the timer. **Needs Manage Messages Permissions.**| `{Prefix}repinv`") +// .AddCheck(SimpleCheckers.ManageMessages()) +// .Do(async e => +// { +// Repeater rep; +// if (!repeaters.TryGetValue(e.Server, out rep)) +// { +// await imsg.Channel.SendMessageAsync("`No repeating message found on this server.`"); +// return; +// } - await rep.Invoke(); - }); +// await rep.Invoke(); +// }); - cgb.CreateCommand(Module.Prefix + "repeat") - .Description("Repeat a message every X minutes. If no parameters are specified, " + - $"repeat is disabled. **Needs Manage Messages Permissions.** |`{Prefix}repeat 5 Hello there`") - .Parameter("minutes", ParameterType.Optional) - .Parameter("msg", ParameterType.Unparsed) - .AddCheck(SimpleCheckers.ManageMessages()) - .Do(async e => - { - var minutesStr = e.GetArg("minutes"); - var msg = e.GetArg("msg"); +// cgb.CreateCommand(Module.Prefix + "repeat") +// .Description("Repeat a message every X minutes. If no parameters are specified, " + +// $"repeat is disabled. **Needs Manage Messages Permissions.** |`{Prefix}repeat 5 Hello there`") +// .Parameter("minutes", ParameterType.Optional) +// .Parameter("msg", ParameterType.Unparsed) +// .AddCheck(SimpleCheckers.ManageMessages()) +// .Do(async e => +// { +// var minutesStr = e.GetArg("minutes"); +// var msg = e.GetArg("msg"); - // if both null, disable - if (string.IsNullOrWhiteSpace(msg) && string.IsNullOrWhiteSpace(minutesStr)) - { +// // if both null, disable +// if (string.IsNullOrWhiteSpace(msg) && string.IsNullOrWhiteSpace(minutesStr)) +// { - Repeater rep; - if (!repeaters.TryRemove(e.Server, out rep)) - return; - rep.MessageTimer.Stop(); - await imsg.Channel.SendMessageAsync("Repeating disabled").ConfigureAwait(false); - return; - } - int minutes; - if (!int.TryParse(minutesStr, out minutes) || minutes < 1 || minutes > 1440) - { - await imsg.Channel.SendMessageAsync("Invalid value").ConfigureAwait(false); - return; - } +// Repeater rep; +// if (!repeaters.TryRemove(e.Server, out rep)) +// return; +// rep.MessageTimer.Stop(); +// await imsg.Channel.SendMessageAsync("Repeating disabled").ConfigureAwait(false); +// return; +// } +// int minutes; +// if (!int.TryParse(minutesStr, out minutes) || minutes < 1 || minutes > 1440) +// { +// await imsg.Channel.SendMessageAsync("Invalid value").ConfigureAwait(false); +// return; +// } - var repeater = repeaters.GetOrAdd( - e.Server, - s => new Repeater - { - Interval = minutes * 60 * 1000, - RepeatingChannel = e.Channel, - RepeatingChannelId = e.Channel.Id, - RepeatingServerId = e.Server.Id, - }.Start() - ); +// var repeater = repeaters.GetOrAdd( +// e.Server, +// s => new Repeater +// { +// Interval = minutes * 60 * 1000, +// RepeatingChannel = e.Channel, +// RepeatingChannelId = e.Channel.Id, +// RepeatingServerId = e.Server.Id, +// }.Start() +// ); - if (!string.IsNullOrWhiteSpace(msg)) - repeater.RepeatingMessage = msg; +// if (!string.IsNullOrWhiteSpace(msg)) +// repeater.RepeatingMessage = msg; - repeater.MessageTimer.Stop(); - repeater.MessageTimer.Start(); +// repeater.MessageTimer.Stop(); +// repeater.MessageTimer.Start(); - await imsg.Channel.SendMessageAsync(String.Format("👌 Repeating `{0}` every " + - "**{1}** minutes on {2} channel.", - repeater.RepeatingMessage, minutes, repeater.RepeatingChannel)) - .ConfigureAwait(false); - }); - } +// await imsg.Channel.SendMessageAsync(String.Format("👌 Repeating `{0}` every " + +// "**{1}** minutes on {2} channel.", +// repeater.RepeatingMessage, minutes, repeater.RepeatingChannel)) +// .ConfigureAwait(false); +// }); +// } - public MessageRepeater(DiscordModule module) : base(module) { } - } -} +// public MessageRepeater(DiscordModule module) : base(module) { } +// } +//} diff --git a/src/NadekoBot/Modules/Administration/Commands/PlayingRotate.cs b/src/NadekoBot/Modules/Administration/Commands/PlayingRotate.cs index 6b583ae7..2328adb4 100644 --- a/src/NadekoBot/Modules/Administration/Commands/PlayingRotate.cs +++ b/src/NadekoBot/Modules/Administration/Commands/PlayingRotate.cs @@ -1,167 +1,167 @@ -using Discord.Commands; -using NadekoBot.Classes; -using NadekoBot.Classes.JSONModels; -using NadekoBot.Modules.Music; -using NadekoBot.Modules.Permissions.Classes; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using System.Timers; -using Timer = System.Timers.Timer; +//using Discord.Commands; +//using NadekoBot.Classes; +//using NadekoBot.Classes.JSONModels; +//using NadekoBot.Modules.Music; +//using NadekoBot.Modules.Permissions.Classes; +//using System; +//using System.Collections.Generic; +//using System.Linq; +//using System.Text; +//using System.Threading; +//using System.Threading.Tasks; +//using System.Timers; +//using Timer = System.Timers.Timer; -namespace NadekoBot.Modules.Administration.Commands -{ - internal class PlayingRotate : DiscordCommand - { - private static readonly Timer timer = new Timer(20000); +//namespace NadekoBot.Modules.Administration.Commands +//{ +// internal class PlayingRotate : DiscordCommand +// { +// private static readonly Timer timer = new Timer(20000); - public static Dictionary> PlayingPlaceholders { get; } = - new Dictionary> { - {"%servers%", () => NadekoBot.Client.Servers.Count().ToString()}, - {"%users%", () => NadekoBot.Client.Servers.SelectMany(s => s.Users).Count().ToString()}, - {"%playing%", () => { - var cnt = MusicModule.MusicPlayers.Count(kvp => kvp.Value.CurrentSong != null); - if (cnt != 1) return cnt.ToString(); - try { - var mp = MusicModule.MusicPlayers.FirstOrDefault(); - return mp.Value.CurrentSong.SongInfo.Title; - } - catch { - return "No songs"; - } - } - }, - {"%queued%", () => MusicModule.MusicPlayers.Sum(kvp => kvp.Value.Playlist.Count).ToString()}, - {"%trivia%", () => Games.Commands.TriviaCommands.RunningTrivias.Count.ToString()} - }; +// public static Dictionary> PlayingPlaceholders { get; } = +// new Dictionary> { +// {"%servers%", () => NadekoBot.Client.Servers.Count().ToString()}, +// {"%users%", () => NadekoBot.Client.Servers.SelectMany(s => s.Users).Count().ToString()}, +// {"%playing%", () => { +// var cnt = MusicModule.MusicPlayers.Count(kvp => kvp.Value.CurrentSong != null); +// if (cnt != 1) return cnt.ToString(); +// try { +// var mp = MusicModule.MusicPlayers.FirstOrDefault(); +// return mp.Value.CurrentSong.SongInfo.Title; +// } +// catch { +// return "No songs"; +// } +// } +// }, +// {"%queued%", () => MusicModule.MusicPlayers.Sum(kvp => kvp.Value.Playlist.Count).ToString()}, +// {"%trivia%", () => Games.Commands.TriviaCommands.RunningTrivias.Count.ToString()} +// }; - private readonly SemaphoreSlim playingPlaceholderLock = new SemaphoreSlim(1,1); +// private readonly SemaphoreSlim playingPlaceholderLock = new SemaphoreSlim(1,1); - public PlayingRotate(DiscordModule module) : base(module) - { - var i = -1; - timer.Elapsed += async (s, e) => - { - try - { - i++; - var status = ""; - //wtf am i doing, just use a queue ffs - await playingPlaceholderLock.WaitAsync().ConfigureAwait(false); - try - { - if (PlayingPlaceholders.Count == 0 - || NadekoBot.Config.RotatingStatuses.Count == 0 - || i >= NadekoBot.Config.RotatingStatuses.Count) - { - i = 0; - } - status = NadekoBot.Config.RotatingStatuses[i]; - status = PlayingPlaceholders.Aggregate(status, - (current, kvp) => current.Replace(kvp.Key, kvp.Value())); - } - finally { playingPlaceholderLock.Release(); } - if (string.IsNullOrWhiteSpace(status)) - return; - await Task.Run(() => { NadekoBot.Client.SetGame(status); }); - } - catch { } - }; +// public PlayingRotate(DiscordModule module) : base(module) +// { +// var i = -1; +// timer.Elapsed += async (s, e) => +// { +// try +// { +// i++; +// var status = ""; +// //wtf am i doing, just use a queue ffs +// await playingPlaceholderLock.WaitAsync().ConfigureAwait(false); +// try +// { +// if (PlayingPlaceholders.Count == 0 +// || NadekoBot.Config.RotatingStatuses.Count == 0 +// || i >= NadekoBot.Config.RotatingStatuses.Count) +// { +// i = 0; +// } +// status = NadekoBot.Config.RotatingStatuses[i]; +// status = PlayingPlaceholders.Aggregate(status, +// (current, kvp) => current.Replace(kvp.Key, kvp.Value())); +// } +// finally { playingPlaceholderLock.Release(); } +// if (string.IsNullOrWhiteSpace(status)) +// return; +// await Task.Run(() => { NadekoBot.Client.SetGame(status); }); +// } +// catch { } +// }; - timer.Enabled = NadekoBot.Config.IsRotatingStatus; - } +// timer.Enabled = NadekoBot.Config.IsRotatingStatus; +// } - public Func DoFunc() => async e => - { - await playingPlaceholderLock.WaitAsync().ConfigureAwait(false); - try - { - if (timer.Enabled) - timer.Stop(); - else - timer.Start(); - NadekoBot.Config.IsRotatingStatus = timer.Enabled; - await ConfigHandler.SaveConfig().ConfigureAwait(false); - } - finally { - playingPlaceholderLock.Release(); - } - await imsg.Channel.SendMessageAsync($"❗`Rotating playing status has been {(timer.Enabled ? "enabled" : "disabled")}.`").ConfigureAwait(false); - }; +// public Func DoFunc() => async e => +// { +// await playingPlaceholderLock.WaitAsync().ConfigureAwait(false); +// try +// { +// if (timer.Enabled) +// timer.Stop(); +// else +// timer.Start(); +// NadekoBot.Config.IsRotatingStatus = timer.Enabled; +// await ConfigHandler.SaveConfig().ConfigureAwait(false); +// } +// finally { +// playingPlaceholderLock.Release(); +// } +// await imsg.Channel.SendMessageAsync($"❗`Rotating playing status has been {(timer.Enabled ? "enabled" : "disabled")}.`").ConfigureAwait(false); +// }; - internal override void Init(CommandGroupBuilder cgb) - { - cgb.CreateCommand(Module.Prefix + "rotateplaying") - .Alias(Module.Prefix + "ropl") - .Description($"Toggles rotation of playing status of the dynamic strings you specified earlier. **Bot Owner Only!** | `{Prefix}ropl`") - .AddCheck(SimpleCheckers.OwnerOnly()) - .Do(DoFunc()); +// internal override void Init(CommandGroupBuilder cgb) +// { +// cgb.CreateCommand(Module.Prefix + "rotateplaying") +// .Alias(Module.Prefix + "ropl") +// .Description($"Toggles rotation of playing status of the dynamic strings you specified earlier. **Bot Owner Only!** | `{Prefix}ropl`") +// .AddCheck(SimpleCheckers.OwnerOnly()) +// .Do(DoFunc()); - cgb.CreateCommand(Module.Prefix + "addplaying") - .Alias(Module.Prefix + "adpl") - .Description("Adds a specified string to the list of playing strings to rotate. " + - "Supported placeholders: " + string.Join(", ", PlayingPlaceholders.Keys)+ $" **Bot Owner Only!**| `{Prefix}adpl`") - .Parameter("text", ParameterType.Unparsed) - .AddCheck(SimpleCheckers.OwnerOnly()) - .Do(async e => - { - var arg = e.GetArg("text"); - if (string.IsNullOrWhiteSpace(arg)) - return; - await playingPlaceholderLock.WaitAsync().ConfigureAwait(false); - try - { - NadekoBot.Config.RotatingStatuses.Add(arg); - await ConfigHandler.SaveConfig(); - } - finally - { - playingPlaceholderLock.Release(); - } - await imsg.Channel.SendMessageAsync("🆗 `Added a new playing string.`").ConfigureAwait(false); - }); +// cgb.CreateCommand(Module.Prefix + "addplaying") +// .Alias(Module.Prefix + "adpl") +// .Description("Adds a specified string to the list of playing strings to rotate. " + +// "Supported placeholders: " + string.Join(", ", PlayingPlaceholders.Keys)+ $" **Bot Owner Only!**| `{Prefix}adpl`") +// .Parameter("text", ParameterType.Unparsed) +// .AddCheck(SimpleCheckers.OwnerOnly()) +// .Do(async e => +// { +// var arg = e.GetArg("text"); +// if (string.IsNullOrWhiteSpace(arg)) +// return; +// await playingPlaceholderLock.WaitAsync().ConfigureAwait(false); +// try +// { +// NadekoBot.Config.RotatingStatuses.Add(arg); +// await ConfigHandler.SaveConfig(); +// } +// finally +// { +// playingPlaceholderLock.Release(); +// } +// await imsg.Channel.SendMessageAsync("🆗 `Added a new playing string.`").ConfigureAwait(false); +// }); - cgb.CreateCommand(Module.Prefix + "listplaying") - .Alias(Module.Prefix + "lipl") - .Description($"Lists all playing statuses with their corresponding number. **Bot Owner Only!**| `{Prefix}lipl`") - .AddCheck(SimpleCheckers.OwnerOnly()) - .Do(async e => - { - if (NadekoBot.Config.RotatingStatuses.Count == 0) - await imsg.Channel.SendMessageAsync("`There are no playing strings. " + - "Add some with .addplaying [text] command.`").ConfigureAwait(false); - var sb = new StringBuilder(); - for (var i = 0; i < NadekoBot.Config.RotatingStatuses.Count; i++) - { - sb.AppendLine($"`{i + 1}.` {NadekoBot.Config.RotatingStatuses[i]}"); - } - await imsg.Channel.SendMessageAsync(sb.ToString()).ConfigureAwait(false); - }); +// cgb.CreateCommand(Module.Prefix + "listplaying") +// .Alias(Module.Prefix + "lipl") +// .Description($"Lists all playing statuses with their corresponding number. **Bot Owner Only!**| `{Prefix}lipl`") +// .AddCheck(SimpleCheckers.OwnerOnly()) +// .Do(async e => +// { +// if (NadekoBot.Config.RotatingStatuses.Count == 0) +// await imsg.Channel.SendMessageAsync("`There are no playing strings. " + +// "Add some with .addplaying [text] command.`").ConfigureAwait(false); +// var sb = new StringBuilder(); +// for (var i = 0; i < NadekoBot.Config.RotatingStatuses.Count; i++) +// { +// sb.AppendLine($"`{i + 1}.` {NadekoBot.Config.RotatingStatuses[i]}"); +// } +// await imsg.Channel.SendMessageAsync(sb.ToString()).ConfigureAwait(false); +// }); - cgb.CreateCommand(Module.Prefix + "removeplaying") - .Alias(Module.Prefix + "repl", Module.Prefix + "rmpl") - .Description($"Removes a playing string on a given number. **Bot Owner Only!**| `{Prefix}rmpl`") - .Parameter("number", ParameterType.Required) - .AddCheck(SimpleCheckers.OwnerOnly()) - .Do(async e => - { - var arg = e.GetArg("number"); - int num; - string str; - await playingPlaceholderLock.WaitAsync().ConfigureAwait(false); - try { - if (!int.TryParse(arg.Trim(), out num) || num <= 0 || num > NadekoBot.Config.RotatingStatuses.Count) - return; - str = NadekoBot.Config.RotatingStatuses[num - 1]; - NadekoBot.Config.RotatingStatuses.RemoveAt(num - 1); - await ConfigHandler.SaveConfig().ConfigureAwait(false); - } - finally { playingPlaceholderLock.Release(); } - await imsg.Channel.SendMessageAsync($"🆗 `Removed playing string #{num}`({str})").ConfigureAwait(false); - }); - } - } -} +// cgb.CreateCommand(Module.Prefix + "removeplaying") +// .Alias(Module.Prefix + "repl", Module.Prefix + "rmpl") +// .Description($"Removes a playing string on a given number. **Bot Owner Only!**| `{Prefix}rmpl`") +// .Parameter("number", ParameterType.Required) +// .AddCheck(SimpleCheckers.OwnerOnly()) +// .Do(async e => +// { +// var arg = e.GetArg("number"); +// int num; +// string str; +// await playingPlaceholderLock.WaitAsync().ConfigureAwait(false); +// try { +// if (!int.TryParse(arg.Trim(), out num) || num <= 0 || num > NadekoBot.Config.RotatingStatuses.Count) +// return; +// str = NadekoBot.Config.RotatingStatuses[num - 1]; +// NadekoBot.Config.RotatingStatuses.RemoveAt(num - 1); +// await ConfigHandler.SaveConfig().ConfigureAwait(false); +// } +// finally { playingPlaceholderLock.Release(); } +// await imsg.Channel.SendMessageAsync($"🆗 `Removed playing string #{num}`({str})").ConfigureAwait(false); +// }); +// } +// } +//} diff --git a/src/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs b/src/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs index 63e92e99..cbb5564c 100644 --- a/src/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs @@ -1,63 +1,63 @@ -using Discord.Commands; -using NadekoBot.Classes; -using NadekoBot.Modules.Permissions.Classes; -using System; -using System.Collections.Concurrent; +//using Discord.Commands; +//using NadekoBot.Classes; +//using NadekoBot.Modules.Permissions.Classes; +//using System; +//using System.Collections.Concurrent; -namespace NadekoBot.Modules.Administration.Commands -{ - internal class RatelimitCommand : DiscordCommand - { +//namespace NadekoBot.Modules.Administration.Commands +//{ +// internal class RatelimitCommand : DiscordCommand +// { - public static ConcurrentDictionary> RatelimitingChannels = new ConcurrentDictionary>(); +// public static ConcurrentDictionary> RatelimitingChannels = new ConcurrentDictionary>(); - private static readonly TimeSpan ratelimitTime = new TimeSpan(0, 0, 0, 5); +// private static readonly TimeSpan ratelimitTime = new TimeSpan(0, 0, 0, 5); - public RatelimitCommand(DiscordModule module) : base(module) - { - NadekoBot.Client.MessageReceived += async (s, e) => - { - if (e.Channel.IsPrivate || e.User.Id == NadekoBot.Client.CurrentUser.Id) - return; - ConcurrentDictionary userTimePair; - if (!RatelimitingChannels.TryGetValue(e.Channel.Id, out userTimePair)) return; - DateTime lastMessageTime; - if (userTimePair.TryGetValue(e.User.Id, out lastMessageTime)) - { - if (DateTime.Now - lastMessageTime < ratelimitTime) - { - try - { - await e.Message.Delete().ConfigureAwait(false); - } - catch { } - return; - } - } - userTimePair.AddOrUpdate(e.User.Id, id => DateTime.Now, (id, dt) => DateTime.Now); - }; - } +// public RatelimitCommand(DiscordModule module) : base(module) +// { +// NadekoBot.Client.MessageReceived += async (s, e) => +// { +// if (e.Channel.IsPrivate || e.User.Id == NadekoBot.Client.CurrentUser.Id) +// return; +// ConcurrentDictionary userTimePair; +// if (!RatelimitingChannels.TryGetValue(e.Channel.Id, out userTimePair)) return; +// DateTime lastMessageTime; +// if (userTimePair.TryGetValue(e.User.Id, out lastMessageTime)) +// { +// if (DateTime.Now - lastMessageTime < ratelimitTime) +// { +// try +// { +// await e.Message.Delete().ConfigureAwait(false); +// } +// catch { } +// return; +// } +// } +// userTimePair.AddOrUpdate(e.User.Id, id => DateTime.Now, (id, dt) => DateTime.Now); +// }; +// } - internal override void Init(CommandGroupBuilder cgb) - { - cgb.CreateCommand(Module.Prefix + "slowmode") - .Description($"Toggles slow mode. When ON, users will be able to send only 1 message every 5 seconds. **Needs Manage Messages Permissions.**| `{Prefix}slowmode`") - .AddCheck(SimpleCheckers.ManageMessages()) - .Do(async e => - { - ConcurrentDictionary throwaway; - if (RatelimitingChannels.TryRemove(e.Channel.Id, out throwaway)) - { - await imsg.Channel.SendMessageAsync("Slow mode disabled.").ConfigureAwait(false); - return; - } - if (RatelimitingChannels.TryAdd(e.Channel.Id, new ConcurrentDictionary())) - { - await imsg.Channel.SendMessageAsync("Slow mode initiated. " + - "Users can't send more than 1 message every 5 seconds.") - .ConfigureAwait(false); - } - }); - } - } -} \ No newline at end of file +// internal override void Init(CommandGroupBuilder cgb) +// { +// cgb.CreateCommand(Module.Prefix + "slowmode") +// .Description($"Toggles slow mode. When ON, users will be able to send only 1 message every 5 seconds. **Needs Manage Messages Permissions.**| `{Prefix}slowmode`") +// .AddCheck(SimpleCheckers.ManageMessages()) +// .Do(async e => +// { +// ConcurrentDictionary throwaway; +// if (RatelimitingChannels.TryRemove(e.Channel.Id, out throwaway)) +// { +// await imsg.Channel.SendMessageAsync("Slow mode disabled.").ConfigureAwait(false); +// return; +// } +// if (RatelimitingChannels.TryAdd(e.Channel.Id, new ConcurrentDictionary())) +// { +// await imsg.Channel.SendMessageAsync("Slow mode initiated. " + +// "Users can't send more than 1 message every 5 seconds.") +// .ConfigureAwait(false); +// } +// }); +// } +// } +//} \ No newline at end of file diff --git a/src/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs b/src/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs index 633e90ea..1cb67524 100644 --- a/src/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs @@ -1,207 +1,207 @@ -using Discord.Commands; -using Discord.Net; -using NadekoBot.Classes; -using NadekoBot.Modules.Permissions.Classes; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +//using Discord.Commands; +//using Discord.Net; +//using NadekoBot.Classes; +//using NadekoBot.Modules.Permissions.Classes; +//using System; +//using System.Collections.Generic; +//using System.Linq; +//using System.Text; +//using System.Threading.Tasks; -namespace NadekoBot.Modules.Administration.Commands -{ - internal class SelfAssignedRolesCommand : DiscordCommand - { - public SelfAssignedRolesCommand(DiscordModule module) : base(module) { } - internal override void Init(CommandGroupBuilder cgb) - { - cgb.CreateCommand(Module.Prefix + "asar") - .Description("Adds a role, or list of roles separated by whitespace" + - $"(use quotations for multiword roles) to the list of self-assignable roles. **Needs Manage Roles Permissions.**| `{Prefix}asar Gamer`") - .Parameter("roles", ParameterType.Multiple) - .AddCheck(SimpleCheckers.CanManageRoles) - .Do(async e => - { - var config = SpecificConfigurations.Default.Of(e.Server.Id); - var msg = new StringBuilder(); - foreach (var arg in e.Args) - { - var role = e.Server.FindRoles(arg.Trim()).FirstOrDefault(); - if (role == null) - msg.AppendLine($":anger:Role **{arg}** not found."); - else - { - if (config.ListOfSelfAssignableRoles.Contains(role.Id)) - { - msg.AppendLine($":anger:Role **{role.Name}** is already in the list."); - continue; - } - config.ListOfSelfAssignableRoles.Add(role.Id); - msg.AppendLine($":ok:Role **{role.Name}** added to the list."); - } - } - await imsg.Channel.SendMessageAsync(msg.ToString()).ConfigureAwait(false); - }); +//namespace NadekoBot.Modules.Administration.Commands +//{ +// internal class SelfAssignedRolesCommand : DiscordCommand +// { +// public SelfAssignedRolesCommand(DiscordModule module) : base(module) { } +// internal override void Init(CommandGroupBuilder cgb) +// { +// cgb.CreateCommand(Module.Prefix + "asar") +// .Description("Adds a role, or list of roles separated by whitespace" + +// $"(use quotations for multiword roles) to the list of self-assignable roles. **Needs Manage Roles Permissions.**| `{Prefix}asar Gamer`") +// .Parameter("roles", ParameterType.Multiple) +// .AddCheck(SimpleCheckers.CanManageRoles) +// .Do(async e => +// { +// var config = SpecificConfigurations.Default.Of(e.Server.Id); +// var msg = new StringBuilder(); +// foreach (var arg in e.Args) +// { +// var role = e.Server.FindRoles(arg.Trim()).FirstOrDefault(); +// if (role == null) +// msg.AppendLine($":anger:Role **{arg}** not found."); +// else +// { +// if (config.ListOfSelfAssignableRoles.Contains(role.Id)) +// { +// msg.AppendLine($":anger:Role **{role.Name}** is already in the list."); +// continue; +// } +// config.ListOfSelfAssignableRoles.Add(role.Id); +// msg.AppendLine($":ok:Role **{role.Name}** added to the list."); +// } +// } +// await imsg.Channel.SendMessageAsync(msg.ToString()).ConfigureAwait(false); +// }); - cgb.CreateCommand(Module.Prefix + "rsar") - .Description($"Removes a specified role from the list of self-assignable roles. | `{Prefix}rsar`") - .Parameter("role", ParameterType.Unparsed) - .AddCheck(SimpleCheckers.CanManageRoles) - .Do(async e => - { - var roleName = e.GetArg("role")?.Trim(); - if (string.IsNullOrWhiteSpace(roleName)) - return; - var role = e.Server.FindRoles(roleName).FirstOrDefault(); - if (role == null) - { - await imsg.Channel.SendMessageAsync(":anger:That role does not exist.").ConfigureAwait(false); - return; - } - var config = SpecificConfigurations.Default.Of(e.Server.Id); - if (!config.ListOfSelfAssignableRoles.Contains(role.Id)) - { - await imsg.Channel.SendMessageAsync(":anger:That role is not self-assignable.").ConfigureAwait(false); - return; - } - config.ListOfSelfAssignableRoles.Remove(role.Id); - await imsg.Channel.SendMessageAsync($":ok:**{role.Name}** has been removed from the list of self-assignable roles").ConfigureAwait(false); - }); +// cgb.CreateCommand(Module.Prefix + "rsar") +// .Description($"Removes a specified role from the list of self-assignable roles. | `{Prefix}rsar`") +// .Parameter("role", ParameterType.Unparsed) +// .AddCheck(SimpleCheckers.CanManageRoles) +// .Do(async e => +// { +// var roleName = e.GetArg("role")?.Trim(); +// if (string.IsNullOrWhiteSpace(roleName)) +// return; +// var role = e.Server.FindRoles(roleName).FirstOrDefault(); +// if (role == null) +// { +// await imsg.Channel.SendMessageAsync(":anger:That role does not exist.").ConfigureAwait(false); +// return; +// } +// var config = SpecificConfigurations.Default.Of(e.Server.Id); +// if (!config.ListOfSelfAssignableRoles.Contains(role.Id)) +// { +// await imsg.Channel.SendMessageAsync(":anger:That role is not self-assignable.").ConfigureAwait(false); +// return; +// } +// config.ListOfSelfAssignableRoles.Remove(role.Id); +// await imsg.Channel.SendMessageAsync($":ok:**{role.Name}** has been removed from the list of self-assignable roles").ConfigureAwait(false); +// }); - cgb.CreateCommand(Module.Prefix + "lsar") - .Description($"Lists all self-assignable roles. | `{Prefix}lsar`") - .Parameter("roles", ParameterType.Multiple) - .Do(async e => - { - var config = SpecificConfigurations.Default.Of(e.Server.Id); - var msg = new StringBuilder($"There are `{config.ListOfSelfAssignableRoles.Count}` self assignable roles:\n"); - var toRemove = new HashSet(); - foreach (var roleId in config.ListOfSelfAssignableRoles.OrderBy(r => r.ToString())) - { - var role = e.Server.GetRole(roleId); - if (role == null) - { - msg.Append($"`{roleId} not found. Cleaned up.`, "); - toRemove.Add(roleId); - } - else - { - msg.Append($"**{role.Name}**, "); - } - } - foreach (var id in toRemove) - { - config.ListOfSelfAssignableRoles.Remove(id); - } - await imsg.Channel.SendMessageAsync(msg.ToString()).ConfigureAwait(false); - }); +// cgb.CreateCommand(Module.Prefix + "lsar") +// .Description($"Lists all self-assignable roles. | `{Prefix}lsar`") +// .Parameter("roles", ParameterType.Multiple) +// .Do(async e => +// { +// var config = SpecificConfigurations.Default.Of(e.Server.Id); +// var msg = new StringBuilder($"There are `{config.ListOfSelfAssignableRoles.Count}` self assignable roles:\n"); +// var toRemove = new HashSet(); +// foreach (var roleId in config.ListOfSelfAssignableRoles.OrderBy(r => r.ToString())) +// { +// var role = e.Server.GetRole(roleId); +// if (role == null) +// { +// msg.Append($"`{roleId} not found. Cleaned up.`, "); +// toRemove.Add(roleId); +// } +// else +// { +// msg.Append($"**{role.Name}**, "); +// } +// } +// foreach (var id in toRemove) +// { +// config.ListOfSelfAssignableRoles.Remove(id); +// } +// await imsg.Channel.SendMessageAsync(msg.ToString()).ConfigureAwait(false); +// }); - cgb.CreateCommand(Module.Prefix + "togglexclsar").Alias(Module.Prefix + "tesar") - .Description($"toggle whether the self-assigned roles should be exclusive | `{Prefix}tesar`") - .AddCheck(SimpleCheckers.CanManageRoles) - .Do(async e => - { - var config = SpecificConfigurations.Default.Of(e.Server.Id); - config.ExclusiveSelfAssignedRoles = !config.ExclusiveSelfAssignedRoles; - string exl = config.ExclusiveSelfAssignedRoles ? "exclusive" : "not exclusive"; - await imsg.Channel.SendMessageAsync("Self assigned roles are now " + exl); - }); +// cgb.CreateCommand(Module.Prefix + "togglexclsar").Alias(Module.Prefix + "tesar") +// .Description($"toggle whether the self-assigned roles should be exclusive | `{Prefix}tesar`") +// .AddCheck(SimpleCheckers.CanManageRoles) +// .Do(async e => +// { +// var config = SpecificConfigurations.Default.Of(e.Server.Id); +// config.ExclusiveSelfAssignedRoles = !config.ExclusiveSelfAssignedRoles; +// string exl = config.ExclusiveSelfAssignedRoles ? "exclusive" : "not exclusive"; +// await imsg.Channel.SendMessageAsync("Self assigned roles are now " + exl); +// }); - cgb.CreateCommand(Module.Prefix + "iam") - .Description("Adds a role to you that you choose. " + - "Role must be on a list of self-assignable roles." + - $" | `{Prefix}iam Gamer`") - .Parameter("role", ParameterType.Unparsed) - .Do(async e => - { - var roleName = e.GetArg("role")?.Trim(); - if (string.IsNullOrWhiteSpace(roleName)) - return; - var role = e.Server.FindRoles(roleName).FirstOrDefault(); - if (role == null) - { - await imsg.Channel.SendMessageAsync(":anger:That role does not exist.").ConfigureAwait(false); - return; - } - var config = SpecificConfigurations.Default.Of(e.Server.Id); - if (!config.ListOfSelfAssignableRoles.Contains(role.Id)) - { - await imsg.Channel.SendMessageAsync(":anger:That role is not self-assignable.").ConfigureAwait(false); - return; - } - if (e.User.HasRole(role)) - { - await imsg.Channel.SendMessageAsync($":anger:You already have {role.Name} role.").ConfigureAwait(false); - return; - } - var sameRoles = e.User.Roles.Where(r => config.ListOfSelfAssignableRoles.Contains(r.Id)); - if (config.ExclusiveSelfAssignedRoles && sameRoles.Any()) - { - await imsg.Channel.SendMessageAsync($":anger:You already have {sameRoles.FirstOrDefault().Name} role.").ConfigureAwait(false); - return; - } - try - { - await e.User.AddRoles(role).ConfigureAwait(false); - } - catch (HttpException ex) when (ex.StatusCode == System.Net.HttpStatusCode.InternalServerError) - { - } - catch (Exception ex) - { - await imsg.Channel.SendMessageAsync($":anger:`I am unable to add that role to you. I can't add roles to owners or other roles higher than my role in the role hierarchy.`").ConfigureAwait(false); - return; - } - var msg = await imsg.Channel.SendMessageAsync($":ok:You now have {role.Name} role.").ConfigureAwait(false); - await Task.Delay(3000).ConfigureAwait(false); - await msg.Delete().ConfigureAwait(false); - try - { - await e.Message.Delete().ConfigureAwait(false); - } - catch { } - }); +// cgb.CreateCommand(Module.Prefix + "iam") +// .Description("Adds a role to you that you choose. " + +// "Role must be on a list of self-assignable roles." + +// $" | `{Prefix}iam Gamer`") +// .Parameter("role", ParameterType.Unparsed) +// .Do(async e => +// { +// var roleName = e.GetArg("role")?.Trim(); +// if (string.IsNullOrWhiteSpace(roleName)) +// return; +// var role = e.Server.FindRoles(roleName).FirstOrDefault(); +// if (role == null) +// { +// await imsg.Channel.SendMessageAsync(":anger:That role does not exist.").ConfigureAwait(false); +// return; +// } +// var config = SpecificConfigurations.Default.Of(e.Server.Id); +// if (!config.ListOfSelfAssignableRoles.Contains(role.Id)) +// { +// await imsg.Channel.SendMessageAsync(":anger:That role is not self-assignable.").ConfigureAwait(false); +// return; +// } +// if (e.User.HasRole(role)) +// { +// await imsg.Channel.SendMessageAsync($":anger:You already have {role.Name} role.").ConfigureAwait(false); +// return; +// } +// var sameRoles = e.User.Roles.Where(r => config.ListOfSelfAssignableRoles.Contains(r.Id)); +// if (config.ExclusiveSelfAssignedRoles && sameRoles.Any()) +// { +// await imsg.Channel.SendMessageAsync($":anger:You already have {sameRoles.FirstOrDefault().Name} role.").ConfigureAwait(false); +// return; +// } +// try +// { +// await e.User.AddRoles(role).ConfigureAwait(false); +// } +// catch (HttpException ex) when (ex.StatusCode == System.Net.HttpStatusCode.InternalServerError) +// { +// } +// catch (Exception ex) +// { +// await imsg.Channel.SendMessageAsync($":anger:`I am unable to add that role to you. I can't add roles to owners or other roles higher than my role in the role hierarchy.`").ConfigureAwait(false); +// return; +// } +// var msg = await imsg.Channel.SendMessageAsync($":ok:You now have {role.Name} role.").ConfigureAwait(false); +// await Task.Delay(3000).ConfigureAwait(false); +// await msg.Delete().ConfigureAwait(false); +// try +// { +// await e.Message.Delete().ConfigureAwait(false); +// } +// catch { } +// }); - cgb.CreateCommand(Module.Prefix + "iamnot") - .Alias(Module.Prefix + "iamn") - .Description("Removes a role to you that you choose. " + - "Role must be on a list of self-assignable roles." + - $" | `{Prefix}iamn Gamer`") - .Parameter("role", ParameterType.Unparsed) - .Do(async e => - { - var roleName = e.GetArg("role")?.Trim(); - if (string.IsNullOrWhiteSpace(roleName)) - return; - var role = e.Server.FindRoles(roleName).FirstOrDefault(); - if (role == null) - { - await imsg.Channel.SendMessageAsync(":anger:That role does not exist.").ConfigureAwait(false); - return; - } - var config = SpecificConfigurations.Default.Of(e.Server.Id); - if (!config.ListOfSelfAssignableRoles.Contains(role.Id)) - { - await imsg.Channel.SendMessageAsync(":anger:That role is not self-assignable.").ConfigureAwait(false); - return; - } - if (!e.User.HasRole(role)) - { - await imsg.Channel.SendMessageAsync($":anger:You don't have {role.Name} role.").ConfigureAwait(false); - return; - } - await e.User.RemoveRoles(role).ConfigureAwait(false); - var msg = await imsg.Channel.SendMessageAsync($":ok:Successfuly removed {role.Name} role from you.").ConfigureAwait(false); - await Task.Delay(3000).ConfigureAwait(false); - await msg.Delete().ConfigureAwait(false); - try - { - await e.Message.Delete().ConfigureAwait(false); - } - catch { } - }); - } - } -} +// cgb.CreateCommand(Module.Prefix + "iamnot") +// .Alias(Module.Prefix + "iamn") +// .Description("Removes a role to you that you choose. " + +// "Role must be on a list of self-assignable roles." + +// $" | `{Prefix}iamn Gamer`") +// .Parameter("role", ParameterType.Unparsed) +// .Do(async e => +// { +// var roleName = e.GetArg("role")?.Trim(); +// if (string.IsNullOrWhiteSpace(roleName)) +// return; +// var role = e.Server.FindRoles(roleName).FirstOrDefault(); +// if (role == null) +// { +// await imsg.Channel.SendMessageAsync(":anger:That role does not exist.").ConfigureAwait(false); +// return; +// } +// var config = SpecificConfigurations.Default.Of(e.Server.Id); +// if (!config.ListOfSelfAssignableRoles.Contains(role.Id)) +// { +// await imsg.Channel.SendMessageAsync(":anger:That role is not self-assignable.").ConfigureAwait(false); +// return; +// } +// if (!e.User.HasRole(role)) +// { +// await imsg.Channel.SendMessageAsync($":anger:You don't have {role.Name} role.").ConfigureAwait(false); +// return; +// } +// await e.User.RemoveRoles(role).ConfigureAwait(false); +// var msg = await imsg.Channel.SendMessageAsync($":ok:Successfuly removed {role.Name} role from you.").ConfigureAwait(false); +// await Task.Delay(3000).ConfigureAwait(false); +// await msg.Delete().ConfigureAwait(false); +// try +// { +// await e.Message.Delete().ConfigureAwait(false); +// } +// catch { } +// }); +// } +// } +//} diff --git a/src/NadekoBot/Modules/Administration/Commands/SelfCommands.cs b/src/NadekoBot/Modules/Administration/Commands/SelfCommands.cs index ed3f3437..ffee2d13 100644 --- a/src/NadekoBot/Modules/Administration/Commands/SelfCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/SelfCommands.cs @@ -1,42 +1,42 @@ -using Discord.Commands; -using NadekoBot.Classes; -using NadekoBot.Modules.Permissions.Classes; -using System.Linq; +//using Discord.Commands; +//using NadekoBot.Classes; +//using NadekoBot.Modules.Permissions.Classes; +//using System.Linq; -namespace NadekoBot.Modules.Administration.Commands -{ - class SelfCommands : DiscordCommand - { - public SelfCommands(DiscordModule module) : base(module) - { - } +//namespace NadekoBot.Modules.Administration.Commands +//{ +// class SelfCommands : DiscordCommand +// { +// public SelfCommands(DiscordModule module) : base(module) +// { +// } - internal override void Init(CommandGroupBuilder cgb) - { - cgb.CreateCommand(Module.Prefix + "leave") - .Description($"Makes Nadeko leave the server. Either name or id required. **Bot Owner Only!**| `{Prefix}leave 123123123331`") - .Parameter("arg", ParameterType.Required) - .AddCheck(SimpleCheckers.OwnerOnly()) - .Do(async e => - { - var arg = e.GetArg("arg").Trim(); - var server = NadekoBot.Client.Servers.FirstOrDefault(s => s.Id.ToString() == arg) ?? - NadekoBot.Client.FindServers(arg).FirstOrDefault(); - if (server == null) - { - await imsg.Channel.SendMessageAsync("Cannot find that server").ConfigureAwait(false); - return; - } - if (!server.IsOwner) - { - await server.Leave().ConfigureAwait(false); - } - else - { - await server.Delete().ConfigureAwait(false); - } - await NadekoBot.SendMessageToOwner("Left server " + server.Name).ConfigureAwait(false); - }); - } - } -} +// internal override void Init(CommandGroupBuilder cgb) +// { +// cgb.CreateCommand(Module.Prefix + "leave") +// .Description($"Makes Nadeko leave the server. Either name or id required. **Bot Owner Only!**| `{Prefix}leave 123123123331`") +// .Parameter("arg", ParameterType.Required) +// .AddCheck(SimpleCheckers.OwnerOnly()) +// .Do(async e => +// { +// var arg = e.GetArg("arg").Trim(); +// var server = NadekoBot.Client.Servers.FirstOrDefault(s => s.Id.ToString() == arg) ?? +// NadekoBot.Client.FindServers(arg).FirstOrDefault(); +// if (server == null) +// { +// await imsg.Channel.SendMessageAsync("Cannot find that server").ConfigureAwait(false); +// return; +// } +// if (!server.IsOwner) +// { +// await server.Leave().ConfigureAwait(false); +// } +// else +// { +// await server.Delete().ConfigureAwait(false); +// } +// await NadekoBot.SendMessageToOwner("Left server " + server.Name).ConfigureAwait(false); +// }); +// } +// } +//} diff --git a/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommand.cs b/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommand.cs index 1b70769c..4b94530d 100644 --- a/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommand.cs @@ -1,332 +1,332 @@ -using Discord; -using Discord.Commands; -using NadekoBot.Classes; -using System.Collections.Concurrent; -using System.Linq; -using System.Threading.Tasks; +//using Discord; +//using Discord.Commands; +//using NadekoBot.Classes; +//using System.Collections.Concurrent; +//using System.Linq; +//using System.Threading.Tasks; -/* Voltana's legacy -public class AsyncLazy : Lazy> -{ - public AsyncLazy(Func valueFactory) : - base(() => Task.Factory.StartNew(valueFactory)) { } +///* Voltana's legacy +//public class AsyncLazy : Lazy> +//{ +// public AsyncLazy(Func valueFactory) : +// base(() => Task.Factory.StartNew(valueFactory)) { } - public AsyncLazy(Func> taskFactory) : - base(() => Task.Factory.StartNew(() => taskFactory()).Unwrap()) { } +// public AsyncLazy(Func> taskFactory) : +// base(() => Task.Factory.StartNew(() => taskFactory()).Unwrap()) { } - public TaskAwaiter GetAwaiter() { return Value.GetAwaiter(); } -} -*/ +// public TaskAwaiter GetAwaiter() { return Value.GetAwaiter(); } +//} +//*/ -namespace NadekoBot.Modules.Administration.Commands -{ - internal class ServerGreetCommand : DiscordCommand - { +//namespace NadekoBot.Modules.Administration.Commands +//{ +// internal class ServerGreetCommand : DiscordCommand +// { - public static ConcurrentDictionary AnnouncementsDictionary; +// public static ConcurrentDictionary AnnouncementsDictionary; - public static long Greeted = 0; +// public static long Greeted = 0; - public ServerGreetCommand(DiscordModule module) : base(module) - { - AnnouncementsDictionary = new ConcurrentDictionary(); +// public ServerGreetCommand(DiscordModule module) : base(module) +// { +// AnnouncementsDictionary = new ConcurrentDictionary(); - NadekoBot.Client.UserJoined += UserJoined; - NadekoBot.Client.UserLeft += UserLeft; +// NadekoBot.Client.UserJoined += UserJoined; +// NadekoBot.Client.UserLeft += UserLeft; - var data = Classes.DbHandler.Instance.GetAllRows(); +// var data = Classes.DbHandler.Instance.GetAllRows(); - if (!data.Any()) return; - foreach (var obj in data) - AnnouncementsDictionary.TryAdd((ulong)obj.ServerId, new AnnounceControls(obj)); - } +// if (!data.Any()) return; +// foreach (var obj in data) +// AnnouncementsDictionary.TryAdd((ulong)obj.ServerId, new AnnounceControls(obj)); +// } - private async void UserLeft(object sender, UserEventArgs e) - { - try - { - if (!AnnouncementsDictionary.ContainsKey(e.Server.Id) || - !AnnouncementsDictionary[e.Server.Id].Bye) return; +// private async void UserLeft(object sender, UserEventArgs e) +// { +// try +// { +// if (!AnnouncementsDictionary.ContainsKey(e.Server.Id) || +// !AnnouncementsDictionary[e.Server.Id].Bye) return; - var controls = AnnouncementsDictionary[e.Server.Id]; - var channel = NadekoBot.Client.GetChannel(controls.ByeChannel); - var msg = controls.ByeText.Replace("%user%", "**" + e.User.Name + "**").Trim(); - if (string.IsNullOrEmpty(msg)) - return; +// var controls = AnnouncementsDictionary[e.Server.Id]; +// var channel = NadekoBot.Client.GetChannel(controls.ByeChannel); +// var msg = controls.ByeText.Replace("%user%", "**" + e.User.Name + "**").Trim(); +// if (string.IsNullOrEmpty(msg)) +// return; - if (controls.ByePM) - { - Greeted++; - try - { - await e.User.SendMessage($"`Farewell Message From {e.Server?.Name}`\n" + msg).ConfigureAwait(false); +// if (controls.ByePM) +// { +// Greeted++; +// try +// { +// await e.User.SendMessage($"`Farewell Message From {e.Server?.Name}`\n" + msg).ConfigureAwait(false); - } - catch { } - } - else - { - if (channel == null) return; - Greeted++; - var toDelete = await channel.SendMessage(msg).ConfigureAwait(false); - if (e.Server.CurrentUser.GetPermissions(channel).ManageMessages && controls.DeleteGreetMessages) - { - await Task.Delay(30000).ConfigureAwait(false); // 5 minutes - await toDelete.Delete().ConfigureAwait(false); - } - } - } - catch { } - } +// } +// catch { } +// } +// else +// { +// if (channel == null) return; +// Greeted++; +// var toDelete = await channel.SendMessage(msg).ConfigureAwait(false); +// if (e.Server.CurrentUser.GetPermissions(channel).ManageMessages && controls.DeleteGreetMessages) +// { +// await Task.Delay(30000).ConfigureAwait(false); // 5 minutes +// await toDelete.Delete().ConfigureAwait(false); +// } +// } +// } +// catch { } +// } - private async void UserJoined(object sender, Discord.UserEventArgs e) - { - try - { - if (!AnnouncementsDictionary.ContainsKey(e.Server.Id) || - !AnnouncementsDictionary[e.Server.Id].Greet) return; +// private async void UserJoined(object sender, Discord.UserEventArgs e) +// { +// try +// { +// if (!AnnouncementsDictionary.ContainsKey(e.Server.Id) || +// !AnnouncementsDictionary[e.Server.Id].Greet) return; - var controls = AnnouncementsDictionary[e.Server.Id]; - var channel = NadekoBot.Client.GetChannel(controls.GreetChannel); +// var controls = AnnouncementsDictionary[e.Server.Id]; +// var channel = NadekoBot.Client.GetChannel(controls.GreetChannel); - var msg = controls.GreetText.Replace("%user%", e.User.Mention).Trim(); - if (string.IsNullOrEmpty(msg)) - return; - if (controls.GreetPM) - { - Greeted++; - await e.User.SendMessage($"`Welcome Message From {e.Server.Name}`\n" + msg).ConfigureAwait(false); - } - else - { - if (channel == null) return; - Greeted++; - var toDelete = await channel.SendMessage(msg).ConfigureAwait(false); - if (e.Server.CurrentUser.GetPermissions(channel).ManageMessages && controls.DeleteGreetMessages) - { - await Task.Delay(30000).ConfigureAwait(false); // 5 minutes - await toDelete.Delete().ConfigureAwait(false); - } - } - } - catch { } - } +// var msg = controls.GreetText.Replace("%user%", e.User.Mention).Trim(); +// if (string.IsNullOrEmpty(msg)) +// return; +// if (controls.GreetPM) +// { +// Greeted++; +// await e.User.SendMessage($"`Welcome Message From {e.Server.Name}`\n" + msg).ConfigureAwait(false); +// } +// else +// { +// if (channel == null) return; +// Greeted++; +// var toDelete = await channel.SendMessage(msg).ConfigureAwait(false); +// if (e.Server.CurrentUser.GetPermissions(channel).ManageMessages && controls.DeleteGreetMessages) +// { +// await Task.Delay(30000).ConfigureAwait(false); // 5 minutes +// await toDelete.Delete().ConfigureAwait(false); +// } +// } +// } +// catch { } +// } - public class AnnounceControls - { - private DataModels.Announcement _model { get; } +// public class AnnounceControls +// { +// private DataModels.Announcement _model { get; } - public bool Greet { - get { return _model.Greet; } - set { _model.Greet = value; Save(); } - } +// public bool Greet { +// get { return _model.Greet; } +// set { _model.Greet = value; Save(); } +// } - public ulong GreetChannel { - get { return (ulong)_model.GreetChannelId; } - set { _model.GreetChannelId = (long)value; Save(); } - } +// public ulong GreetChannel { +// get { return (ulong)_model.GreetChannelId; } +// set { _model.GreetChannelId = (long)value; Save(); } +// } - public bool GreetPM { - get { return _model.GreetPM; } - set { _model.GreetPM = value; Save(); } - } +// public bool GreetPM { +// get { return _model.GreetPM; } +// set { _model.GreetPM = value; Save(); } +// } - public bool ByePM { - get { return _model.ByePM; } - set { _model.ByePM = value; Save(); } - } +// public bool ByePM { +// get { return _model.ByePM; } +// set { _model.ByePM = value; Save(); } +// } - public string GreetText { - get { return _model.GreetText; } - set { _model.GreetText = value; Save(); } - } +// public string GreetText { +// get { return _model.GreetText; } +// set { _model.GreetText = value; Save(); } +// } - public bool Bye { - get { return _model.Bye; } - set { _model.Bye = value; Save(); } - } - public ulong ByeChannel { - get { return (ulong)_model.ByeChannelId; } - set { _model.ByeChannelId = (long)value; Save(); } - } +// public bool Bye { +// get { return _model.Bye; } +// set { _model.Bye = value; Save(); } +// } +// public ulong ByeChannel { +// get { return (ulong)_model.ByeChannelId; } +// set { _model.ByeChannelId = (long)value; Save(); } +// } - public string ByeText { - get { return _model.ByeText; } - set { _model.ByeText = value; Save(); } - } +// public string ByeText { +// get { return _model.ByeText; } +// set { _model.ByeText = value; Save(); } +// } - public ulong ServerId { - get { return (ulong)_model.ServerId; } - set { _model.ServerId = (long)value; } - } +// public ulong ServerId { +// get { return (ulong)_model.ServerId; } +// set { _model.ServerId = (long)value; } +// } - public bool DeleteGreetMessages { - get { - return _model.DeleteGreetMessages; - } - set { - _model.DeleteGreetMessages = value; Save(); - } - } +// public bool DeleteGreetMessages { +// get { +// return _model.DeleteGreetMessages; +// } +// set { +// _model.DeleteGreetMessages = value; Save(); +// } +// } - public AnnounceControls(DataModels.Announcement model) - { - this._model = model; - } +// public AnnounceControls(DataModels.Announcement model) +// { +// this._model = model; +// } - public AnnounceControls(ulong serverId) - { - this._model = new DataModels.Announcement(); - ServerId = serverId; - } +// public AnnounceControls(ulong serverId) +// { +// this._model = new DataModels.Announcement(); +// ServerId = serverId; +// } - internal bool ToggleBye(ulong id) - { - if (Bye) - { - return Bye = false; - } - else - { - ByeChannel = id; - return Bye = true; - } - } +// internal bool ToggleBye(ulong id) +// { +// if (Bye) +// { +// return Bye = false; +// } +// else +// { +// ByeChannel = id; +// return Bye = true; +// } +// } - internal bool ToggleGreet(ulong id) - { - if (Greet) - { - return Greet = false; - } - else - { - GreetChannel = id; - return Greet = true; - } - } +// internal bool ToggleGreet(ulong id) +// { +// if (Greet) +// { +// return Greet = false; +// } +// else +// { +// GreetChannel = id; +// return Greet = true; +// } +// } - internal bool ToggleDelete() => DeleteGreetMessages = !DeleteGreetMessages; - internal bool ToggleGreetPM() => GreetPM = !GreetPM; - internal bool ToggleByePM() => ByePM = !ByePM; +// internal bool ToggleDelete() => DeleteGreetMessages = !DeleteGreetMessages; +// internal bool ToggleGreetPM() => GreetPM = !GreetPM; +// internal bool ToggleByePM() => ByePM = !ByePM; - private void Save() - { - Classes.DbHandler.Instance.Save(_model); - } - } +// private void Save() +// { +// Classes.DbHandler.Instance.Save(_model); +// } +// } - internal override void Init(CommandGroupBuilder cgb) - { - cgb.CreateCommand(Module.Prefix + "grdel") - .Description($"Toggles automatic deletion of greet and bye messages. **Needs Manage Server Permissions.**| `{Prefix}grdel`") - .Do(async e => - { - if (!e.User.ServerPermissions.ManageServer) return; - var ann = AnnouncementsDictionary.GetOrAdd(e.Server.Id, new AnnounceControls(e.Server.Id)); +// internal override void Init(CommandGroupBuilder cgb) +// { +// cgb.CreateCommand(Module.Prefix + "grdel") +// .Description($"Toggles automatic deletion of greet and bye messages. **Needs Manage Server Permissions.**| `{Prefix}grdel`") +// .Do(async e => +// { +// if (!e.User.ServerPermissions.ManageServer) return; +// var ann = AnnouncementsDictionary.GetOrAdd(e.Server.Id, new AnnounceControls(e.Server.Id)); - if (ann.ToggleDelete()) - await imsg.Channel.SendMessageAsync("`Automatic deletion of greet and bye messages has been enabled.`").ConfigureAwait(false); - else - await imsg.Channel.SendMessageAsync("`Automatic deletion of greet and bye messages has been disabled.`").ConfigureAwait(false); - }); +// if (ann.ToggleDelete()) +// await imsg.Channel.SendMessageAsync("`Automatic deletion of greet and bye messages has been enabled.`").ConfigureAwait(false); +// else +// await imsg.Channel.SendMessageAsync("`Automatic deletion of greet and bye messages has been disabled.`").ConfigureAwait(false); +// }); - cgb.CreateCommand(Module.Prefix + "greet") - .Description($"Toggles anouncements on the current channel when someone joins the server. **Needs Manage Server Permissions.**| `{Prefix}greet`") - .Do(async e => - { - if (!e.User.ServerPermissions.ManageServer) return; - var ann = AnnouncementsDictionary.GetOrAdd(e.Server.Id, new AnnounceControls(e.Server.Id)); +// cgb.CreateCommand(Module.Prefix + "greet") +// .Description($"Toggles anouncements on the current channel when someone joins the server. **Needs Manage Server Permissions.**| `{Prefix}greet`") +// .Do(async e => +// { +// if (!e.User.ServerPermissions.ManageServer) return; +// var ann = AnnouncementsDictionary.GetOrAdd(e.Server.Id, new AnnounceControls(e.Server.Id)); - if (ann.ToggleGreet(e.Channel.Id)) - await imsg.Channel.SendMessageAsync("Greet announcements enabled on this channel.").ConfigureAwait(false); - else - await imsg.Channel.SendMessageAsync("Greet announcements disabled.").ConfigureAwait(false); - }); +// if (ann.ToggleGreet(e.Channel.Id)) +// await imsg.Channel.SendMessageAsync("Greet announcements enabled on this channel.").ConfigureAwait(false); +// else +// await imsg.Channel.SendMessageAsync("Greet announcements disabled.").ConfigureAwait(false); +// }); - cgb.CreateCommand(Module.Prefix + "greetmsg") - .Description($"Sets a new join announcement message. Type %user% if you want to mention the new member. Using it with no message will show the current greet message. **Needs Manage Server Permissions.**| `{Prefix}greetmsg Welcome to the server, %user%.`") - .Parameter("msg", ParameterType.Unparsed) - .Do(async e => - { - if (!e.User.ServerPermissions.ManageServer) return; - var ann = AnnouncementsDictionary.GetOrAdd(e.Server.Id, new AnnounceControls(e.Server.Id)); - if (string.IsNullOrWhiteSpace(e.GetArg("msg"))) - { - await imsg.Channel.SendMessageAsync("`Current greet message:` " + ann.GreetText); - return; - } +// cgb.CreateCommand(Module.Prefix + "greetmsg") +// .Description($"Sets a new join announcement message. Type %user% if you want to mention the new member. Using it with no message will show the current greet message. **Needs Manage Server Permissions.**| `{Prefix}greetmsg Welcome to the server, %user%.`") +// .Parameter("msg", ParameterType.Unparsed) +// .Do(async e => +// { +// if (!e.User.ServerPermissions.ManageServer) return; +// var ann = AnnouncementsDictionary.GetOrAdd(e.Server.Id, new AnnounceControls(e.Server.Id)); +// if (string.IsNullOrWhiteSpace(e.GetArg("msg"))) +// { +// await imsg.Channel.SendMessageAsync("`Current greet message:` " + ann.GreetText); +// return; +// } - ann.GreetText = e.GetArg("msg"); - await imsg.Channel.SendMessageAsync("New greet message set.").ConfigureAwait(false); - if (!ann.Greet) - await imsg.Channel.SendMessageAsync("Enable greet messsages by typing `.greet`").ConfigureAwait(false); - }); +// ann.GreetText = e.GetArg("msg"); +// await imsg.Channel.SendMessageAsync("New greet message set.").ConfigureAwait(false); +// if (!ann.Greet) +// await imsg.Channel.SendMessageAsync("Enable greet messsages by typing `.greet`").ConfigureAwait(false); +// }); - cgb.CreateCommand(Module.Prefix + "bye") - .Description($"Toggles anouncements on the current channel when someone leaves the server. | `{Prefix}bye`") - .Do(async e => - { - if (!e.User.ServerPermissions.ManageServer) return; - var ann = AnnouncementsDictionary.GetOrAdd(e.Server.Id, new AnnounceControls(e.Server.Id)); +// cgb.CreateCommand(Module.Prefix + "bye") +// .Description($"Toggles anouncements on the current channel when someone leaves the server. | `{Prefix}bye`") +// .Do(async e => +// { +// if (!e.User.ServerPermissions.ManageServer) return; +// var ann = AnnouncementsDictionary.GetOrAdd(e.Server.Id, new AnnounceControls(e.Server.Id)); - if (ann.ToggleBye(e.Channel.Id)) - await imsg.Channel.SendMessageAsync("Bye announcements enabled on this channel.").ConfigureAwait(false); - else - await imsg.Channel.SendMessageAsync("Bye announcements disabled.").ConfigureAwait(false); - }); +// if (ann.ToggleBye(e.Channel.Id)) +// await imsg.Channel.SendMessageAsync("Bye announcements enabled on this channel.").ConfigureAwait(false); +// else +// await imsg.Channel.SendMessageAsync("Bye announcements disabled.").ConfigureAwait(false); +// }); - cgb.CreateCommand(Module.Prefix + "byemsg") - .Description($"Sets a new leave announcement message. Type %user% if you want to mention the new member. Using it with no message will show the current bye message. **Needs Manage Server Permissions.**| `{Prefix}byemsg %user% has left the server.`") - .Parameter("msg", ParameterType.Unparsed) - .Do(async e => - { - if (!e.User.ServerPermissions.ManageServer) return; - var ann = AnnouncementsDictionary.GetOrAdd(e.Server.Id, new AnnounceControls(e.Server.Id)); - if (string.IsNullOrWhiteSpace(e.GetArg("msg"))) - { - await imsg.Channel.SendMessageAsync("`Current bye message:` " + ann.ByeText); - return; - } +// cgb.CreateCommand(Module.Prefix + "byemsg") +// .Description($"Sets a new leave announcement message. Type %user% if you want to mention the new member. Using it with no message will show the current bye message. **Needs Manage Server Permissions.**| `{Prefix}byemsg %user% has left the server.`") +// .Parameter("msg", ParameterType.Unparsed) +// .Do(async e => +// { +// if (!e.User.ServerPermissions.ManageServer) return; +// var ann = AnnouncementsDictionary.GetOrAdd(e.Server.Id, new AnnounceControls(e.Server.Id)); +// if (string.IsNullOrWhiteSpace(e.GetArg("msg"))) +// { +// await imsg.Channel.SendMessageAsync("`Current bye message:` " + ann.ByeText); +// return; +// } - ann.ByeText = e.GetArg("msg"); - await imsg.Channel.SendMessageAsync("New bye message set.").ConfigureAwait(false); - if (!ann.Bye) - await imsg.Channel.SendMessageAsync("Enable bye messsages by typing `.bye`.").ConfigureAwait(false); - }); +// ann.ByeText = e.GetArg("msg"); +// await imsg.Channel.SendMessageAsync("New bye message set.").ConfigureAwait(false); +// if (!ann.Bye) +// await imsg.Channel.SendMessageAsync("Enable bye messsages by typing `.bye`.").ConfigureAwait(false); +// }); - cgb.CreateCommand(Module.Prefix + "byepm") - .Description($"Toggles whether the good bye messages will be sent in a PM or in the text channel. **Needs Manage Server Permissions.**| `{Prefix}byepm`") - .Do(async e => - { - if (!e.User.ServerPermissions.ManageServer) return; - var ann = AnnouncementsDictionary.GetOrAdd(e.Server.Id, new AnnounceControls(e.Server.Id)); +// cgb.CreateCommand(Module.Prefix + "byepm") +// .Description($"Toggles whether the good bye messages will be sent in a PM or in the text channel. **Needs Manage Server Permissions.**| `{Prefix}byepm`") +// .Do(async e => +// { +// if (!e.User.ServerPermissions.ManageServer) return; +// var ann = AnnouncementsDictionary.GetOrAdd(e.Server.Id, new AnnounceControls(e.Server.Id)); - if (ann.ToggleByePM()) - await imsg.Channel.SendMessageAsync("Bye messages will be sent in a PM from now on.\n ⚠ Keep in mind this might fail if the user and the bot have no common servers after the user leaves.").ConfigureAwait(false); - else - await imsg.Channel.SendMessageAsync("Bye messages will be sent in a bound channel from now on.").ConfigureAwait(false); - if (!ann.Bye) - await imsg.Channel.SendMessageAsync("Enable bye messsages by typing `.bye`, and set the bye message using `.byemsg`").ConfigureAwait(false); - }); +// if (ann.ToggleByePM()) +// await imsg.Channel.SendMessageAsync("Bye messages will be sent in a PM from now on.\n ⚠ Keep in mind this might fail if the user and the bot have no common servers after the user leaves.").ConfigureAwait(false); +// else +// await imsg.Channel.SendMessageAsync("Bye messages will be sent in a bound channel from now on.").ConfigureAwait(false); +// if (!ann.Bye) +// await imsg.Channel.SendMessageAsync("Enable bye messsages by typing `.bye`, and set the bye message using `.byemsg`").ConfigureAwait(false); +// }); - cgb.CreateCommand(Module.Prefix + "greetpm") - .Description($"Toggles whether the greet messages will be sent in a PM or in the text channel. **Needs Manage Server Permissions.**| `{Prefix}greetpm`") - .Do(async e => - { - if (!e.User.ServerPermissions.ManageServer) return; +// cgb.CreateCommand(Module.Prefix + "greetpm") +// .Description($"Toggles whether the greet messages will be sent in a PM or in the text channel. **Needs Manage Server Permissions.**| `{Prefix}greetpm`") +// .Do(async e => +// { +// if (!e.User.ServerPermissions.ManageServer) return; - var ann = AnnouncementsDictionary.GetOrAdd(e.Server.Id, new AnnounceControls(e.Server.Id)); +// var ann = AnnouncementsDictionary.GetOrAdd(e.Server.Id, new AnnounceControls(e.Server.Id)); - if (ann.ToggleGreetPM()) - await imsg.Channel.SendMessageAsync("Greet messages will be sent in a PM from now on.").ConfigureAwait(false); - else - await imsg.Channel.SendMessageAsync("Greet messages will be sent in a bound channel from now on.").ConfigureAwait(false); - if (!ann.Greet) - await imsg.Channel.SendMessageAsync("Enable greet messsages by typing `.greet`, and set the greet message using `.greetmsg`").ConfigureAwait(false); - }); - } - } -} +// if (ann.ToggleGreetPM()) +// await imsg.Channel.SendMessageAsync("Greet messages will be sent in a PM from now on.").ConfigureAwait(false); +// else +// await imsg.Channel.SendMessageAsync("Greet messages will be sent in a bound channel from now on.").ConfigureAwait(false); +// if (!ann.Greet) +// await imsg.Channel.SendMessageAsync("Enable greet messsages by typing `.greet`, and set the greet message using `.greetmsg`").ConfigureAwait(false); +// }); +// } +// } +//} diff --git a/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommand.cs b/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommand.cs index 53f3f01d..43d9480d 100644 --- a/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommand.cs @@ -1,164 +1,164 @@ -using Discord; -using Discord.Commands; -using NadekoBot.Classes; -using NadekoBot.Extensions; -using NadekoBot.Modules.Permissions.Classes; -using System; -using System.Linq; -using System.Text.RegularExpressions; -using System.Threading.Tasks; -using ChPermOverride = Discord.ChannelPermissionOverrides; +//using Discord; +//using Discord.Commands; +//using NadekoBot.Classes; +//using NadekoBot.Extensions; +//using NadekoBot.Modules.Permissions.Classes; +//using System; +//using System.Linq; +//using System.Text.RegularExpressions; +//using System.Threading.Tasks; +//using ChPermOverride = Discord.ChannelPermissionOverrides; -namespace NadekoBot.Modules.Administration.Commands -{ - internal class VoicePlusTextCommand : DiscordCommand - { - Regex channelNameRegex = new Regex(@"[^a-zA-Z0-9 -]", RegexOptions.Compiled); - public VoicePlusTextCommand(DiscordModule module) : base(module) - { - // changing servers may cause bugs - NadekoBot.Client.UserUpdated += async (sender, e) => - { - try - { - if (e.Server == null) - return; - var config = SpecificConfigurations.Default.Of(e.Server.Id); - if (e.Before.VoiceChannel == e.After.VoiceChannel) return; - if (!config.VoicePlusTextEnabled) - return; - var serverPerms = e.Server.GetUser(NadekoBot.Client.CurrentUser.Id)?.ServerPermissions; - if (serverPerms == null) - return; - if (!serverPerms.Value.ManageChannels || !serverPerms.Value.ManageRoles) - { +//namespace NadekoBot.Modules.Administration.Commands +//{ +// internal class VoicePlusTextCommand : DiscordCommand +// { +// Regex channelNameRegex = new Regex(@"[^a-zA-Z0-9 -]", RegexOptions.Compiled); +// public VoicePlusTextCommand(DiscordModule module) : base(module) +// { +// // changing servers may cause bugs +// NadekoBot.Client.UserUpdated += async (sender, e) => +// { +// try +// { +// if (e.Server == null) +// return; +// var config = SpecificConfigurations.Default.Of(e.Server.Id); +// if (e.Before.VoiceChannel == e.After.VoiceChannel) return; +// if (!config.VoicePlusTextEnabled) +// return; +// var serverPerms = e.Server.GetUser(NadekoBot.Client.CurrentUser.Id)?.ServerPermissions; +// if (serverPerms == null) +// return; +// if (!serverPerms.Value.ManageChannels || !serverPerms.Value.ManageRoles) +// { - try - { - await e.Server.Owner.SendMessage( - "I don't have manage server and/or Manage Channels permission," + - $" so I cannot run voice+text on **{e.Server.Name}** server.").ConfigureAwait(false); - } - catch { } // meh - config.VoicePlusTextEnabled = false; - return; - } +// try +// { +// await e.Server.Owner.SendMessage( +// "I don't have manage server and/or Manage Channels permission," + +// $" so I cannot run voice+text on **{e.Server.Name}** server.").ConfigureAwait(false); +// } +// catch { } // meh +// config.VoicePlusTextEnabled = false; +// return; +// } - var beforeVch = e.Before.VoiceChannel; - if (beforeVch != null) - { - var textChannel = - e.Server.FindChannels(GetChannelName(beforeVch.Name), ChannelType.Text).FirstOrDefault(); - if (textChannel != null) - await textChannel.AddPermissionsRule(e.Before, - new ChPermOverride(readMessages: PermValue.Deny, - sendMessages: PermValue.Deny)).ConfigureAwait(false); - } - var afterVch = e.After.VoiceChannel; - if (afterVch != null && e.Server.AFKChannel != afterVch) - { - var textChannel = e.Server.FindChannels( - GetChannelName(afterVch.Name), - ChannelType.Text) - .FirstOrDefault(); - if (textChannel == null) - { - textChannel = (await e.Server.CreateChannel(GetChannelName(afterVch.Name), ChannelType.Text).ConfigureAwait(false)); - await textChannel.AddPermissionsRule(e.Server.EveryoneRole, - new ChPermOverride(readMessages: PermValue.Deny, - sendMessages: PermValue.Deny)).ConfigureAwait(false); - } - await textChannel.AddPermissionsRule(e.After, - new ChPermOverride(readMessages: PermValue.Allow, - sendMessages: PermValue.Allow)).ConfigureAwait(false); - } - } - catch (Exception ex) - { - Console.WriteLine(ex); - } - }; - } +// var beforeVch = e.Before.VoiceChannel; +// if (beforeVch != null) +// { +// var textChannel = +// e.Server.FindChannels(GetChannelName(beforeVch.Name), ChannelType.Text).FirstOrDefault(); +// if (textChannel != null) +// await textChannel.AddPermissionsRule(e.Before, +// new ChPermOverride(readMessages: PermValue.Deny, +// sendMessages: PermValue.Deny)).ConfigureAwait(false); +// } +// var afterVch = e.After.VoiceChannel; +// if (afterVch != null && e.Server.AFKChannel != afterVch) +// { +// var textChannel = e.Server.FindChannels( +// GetChannelName(afterVch.Name), +// ChannelType.Text) +// .FirstOrDefault(); +// if (textChannel == null) +// { +// textChannel = (await e.Server.CreateChannel(GetChannelName(afterVch.Name), ChannelType.Text).ConfigureAwait(false)); +// await textChannel.AddPermissionsRule(e.Server.EveryoneRole, +// new ChPermOverride(readMessages: PermValue.Deny, +// sendMessages: PermValue.Deny)).ConfigureAwait(false); +// } +// await textChannel.AddPermissionsRule(e.After, +// new ChPermOverride(readMessages: PermValue.Allow, +// sendMessages: PermValue.Allow)).ConfigureAwait(false); +// } +// } +// catch (Exception ex) +// { +// Console.WriteLine(ex); +// } +// }; +// } - private string GetChannelName(string voiceName) => - channelNameRegex.Replace(voiceName, "").Trim().Replace(" ", "-").TrimTo(90, true) + "-voice"; +// private string GetChannelName(string voiceName) => +// channelNameRegex.Replace(voiceName, "").Trim().Replace(" ", "-").TrimTo(90, true) + "-voice"; - internal override void Init(CommandGroupBuilder cgb) - { - cgb.CreateCommand(Module.Prefix + "cleanv+t") - .Alias(Module.Prefix + "cv+t") - .Description($"Deletes all text channels ending in `-voice` for which voicechannels are not found. **Use at your own risk.\nNeeds Manage Roles and Manage Channels Permissions.** | `{Prefix}cleanv+t`") - .AddCheck(SimpleCheckers.CanManageRoles) - .AddCheck(SimpleCheckers.ManageChannels()) - .Do(async e => - { - if (!e.Server.CurrentUser.ServerPermissions.ManageChannels) - { - await imsg.Channel.SendMessageAsync("`I have insufficient permission to do that.`"); - return; - } +// internal override void Init(CommandGroupBuilder cgb) +// { +// cgb.CreateCommand(Module.Prefix + "cleanv+t") +// .Alias(Module.Prefix + "cv+t") +// .Description($"Deletes all text channels ending in `-voice` for which voicechannels are not found. **Use at your own risk.\nNeeds Manage Roles and Manage Channels Permissions.** | `{Prefix}cleanv+t`") +// .AddCheck(SimpleCheckers.CanManageRoles) +// .AddCheck(SimpleCheckers.ManageChannels()) +// .Do(async e => +// { +// if (!e.Server.CurrentUser.ServerPermissions.ManageChannels) +// { +// await imsg.Channel.SendMessageAsync("`I have insufficient permission to do that.`"); +// return; +// } - var allTxtChannels = e.Server.TextChannels.Where(c => c.Name.EndsWith("-voice")); - var validTxtChannelNames = e.Server.VoiceChannels.Select(c => GetChannelName(c.Name)); +// var allTxtChannels = e.Server.TextChannels.Where(c => c.Name.EndsWith("-voice")); +// var validTxtChannelNames = e.Server.VoiceChannels.Select(c => GetChannelName(c.Name)); - var invalidTxtChannels = allTxtChannels.Where(c => !validTxtChannelNames.Contains(c.Name)); +// var invalidTxtChannels = allTxtChannels.Where(c => !validTxtChannelNames.Contains(c.Name)); - foreach (var c in invalidTxtChannels) - { - try - { - await c.Delete(); - } - catch { } - await Task.Delay(500); - } +// foreach (var c in invalidTxtChannels) +// { +// try +// { +// await c.Delete(); +// } +// catch { } +// await Task.Delay(500); +// } - await imsg.Channel.SendMessageAsync("`Done.`"); - }); +// await imsg.Channel.SendMessageAsync("`Done.`"); +// }); - cgb.CreateCommand(Module.Prefix + "voice+text") - .Alias(Module.Prefix + "v+t") - .Description("Creates a text channel for each voice channel only users in that voice channel can see." + - $"If you are server owner, keep in mind you will see them all the time regardless. **Needs Manage Roles and Manage Channels Permissions.**| `{Prefix}voice+text`") - .AddCheck(SimpleCheckers.ManageChannels()) - .AddCheck(SimpleCheckers.CanManageRoles) - .Do(async e => - { - try - { - var config = SpecificConfigurations.Default.Of(e.Server.Id); - if (config.VoicePlusTextEnabled == true) - { - config.VoicePlusTextEnabled = false; - foreach (var textChannel in e.Server.TextChannels.Where(c => c.Name.EndsWith("-voice"))) - { - try - { - await textChannel.Delete().ConfigureAwait(false); - } - catch - { - await imsg.Channel.SendMessageAsync( - ":anger: Error: Most likely i don't have permissions to do this.") - .ConfigureAwait(false); - return; - } - } - await imsg.Channel.SendMessageAsync("Successfuly removed voice + text feature.").ConfigureAwait(false); - return; - } - config.VoicePlusTextEnabled = true; - await imsg.Channel.SendMessageAsync("Successfuly enabled voice + text feature. " + - "**Make sure the bot has manage roles and manage channels permissions**") - .ConfigureAwait(false); +// cgb.CreateCommand(Module.Prefix + "voice+text") +// .Alias(Module.Prefix + "v+t") +// .Description("Creates a text channel for each voice channel only users in that voice channel can see." + +// $"If you are server owner, keep in mind you will see them all the time regardless. **Needs Manage Roles and Manage Channels Permissions.**| `{Prefix}voice+text`") +// .AddCheck(SimpleCheckers.ManageChannels()) +// .AddCheck(SimpleCheckers.CanManageRoles) +// .Do(async e => +// { +// try +// { +// var config = SpecificConfigurations.Default.Of(e.Server.Id); +// if (config.VoicePlusTextEnabled == true) +// { +// config.VoicePlusTextEnabled = false; +// foreach (var textChannel in e.Server.TextChannels.Where(c => c.Name.EndsWith("-voice"))) +// { +// try +// { +// await textChannel.Delete().ConfigureAwait(false); +// } +// catch +// { +// await imsg.Channel.SendMessageAsync( +// ":anger: Error: Most likely i don't have permissions to do this.") +// .ConfigureAwait(false); +// return; +// } +// } +// await imsg.Channel.SendMessageAsync("Successfuly removed voice + text feature.").ConfigureAwait(false); +// return; +// } +// config.VoicePlusTextEnabled = true; +// await imsg.Channel.SendMessageAsync("Successfuly enabled voice + text feature. " + +// "**Make sure the bot has manage roles and manage channels permissions**") +// .ConfigureAwait(false); - } - catch (Exception ex) - { - await imsg.Channel.SendMessageAsync(ex.ToString()).ConfigureAwait(false); - } - }); - } - } -} +// } +// catch (Exception ex) +// { +// await imsg.Channel.SendMessageAsync(ex.ToString()).ConfigureAwait(false); +// } +// }); +// } +// } +//} diff --git a/src/NadekoBot/Modules/ClashOfClans/ClashOfClansModule.cs b/src/NadekoBot/Modules/ClashOfClans/ClashOfClansModule.cs index e254075f..a949577b 100644 --- a/src/NadekoBot/Modules/ClashOfClans/ClashOfClansModule.cs +++ b/src/NadekoBot/Modules/ClashOfClans/ClashOfClansModule.cs @@ -37,9 +37,9 @@ namespace NadekoBot.Modules.ClashOfClans [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task CreateWar(IMessage imsg, int size, [Remainder] string enemyClan) + public async Task CreateWar(IMessage imsg, int size, [Remainder] string enemyClan = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; if (!(imsg.Author as IGuildUser).GuildPermissions.ManageChannels) return; @@ -70,9 +70,9 @@ namespace NadekoBot.Modules.ClashOfClans [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task StartWar(IMessage imsg, [Remainder] string number) + public async Task StartWar(IMessage imsg, [Remainder] string number = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; int num = 0; int.TryParse(number, out num); @@ -97,9 +97,9 @@ namespace NadekoBot.Modules.ClashOfClans [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task ListWar(IMessage imsg, [Remainder] string number) + public async Task ListWar(IMessage imsg, [Remainder] string number = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; // if number is null, print all wars in a short way if (string.IsNullOrWhiteSpace(number)) @@ -140,9 +140,9 @@ namespace NadekoBot.Modules.ClashOfClans [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task Claim(IMessage imsg, int number, int baseNumber, [Remainder] string other_name) + public async Task Claim(IMessage imsg, int number, int baseNumber, [Remainder] string other_name = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; var warsInfo = GetWarInfo(imsg, number); if (warsInfo == null || warsInfo.Item1.Count == 0) { @@ -167,25 +167,25 @@ namespace NadekoBot.Modules.ClashOfClans [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task ClaimFinish1(IMessage imsg, int number, int baseNumber, [Remainder] string other_name) + public async Task ClaimFinish1(IMessage imsg, int number, int baseNumber, [Remainder] string other_name = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; await FinishClaim(imsg, number, baseNumber, other_name, 1); } [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task ClaimFinish2(IMessage imsg, int number, int baseNumber, [Remainder] string other_name) + public async Task ClaimFinish2(IMessage imsg, int number, int baseNumber, [Remainder] string other_name = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; await FinishClaim(imsg, number, baseNumber, other_name, 2); } [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task ClaimFinish(IMessage imsg, int number, int baseNumber, [Remainder] string other_name) + public async Task ClaimFinish(IMessage imsg, int number, int baseNumber, [Remainder] string other_name = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; await FinishClaim(imsg, number, baseNumber, other_name); } @@ -193,7 +193,7 @@ namespace NadekoBot.Modules.ClashOfClans [RequireContext(ContextType.Guild)] public async Task EndWar(IMessage imsg, int number) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; var warsInfo = GetWarInfo(imsg,number); if (warsInfo == null) @@ -210,9 +210,9 @@ namespace NadekoBot.Modules.ClashOfClans [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task Unclaim(IMessage imsg, int number, [Remainder] string otherName) + public async Task Unclaim(IMessage imsg, int number, [Remainder] string otherName = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; var warsInfo = GetWarInfo(imsg, number); if (warsInfo == null || warsInfo.Item1.Count == 0) @@ -238,7 +238,7 @@ namespace NadekoBot.Modules.ClashOfClans private async Task FinishClaim(IMessage imsg, int number, int baseNumber, [Remainder] string other_name, int stars = 3) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; var warInfo = GetWarInfo(imsg, number); if (warInfo == null || warInfo.Item1.Count == 0) { @@ -264,7 +264,7 @@ namespace NadekoBot.Modules.ClashOfClans private static Tuple, int> GetWarInfo(IMessage imsg, int num) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; //check if there are any wars List wars = null; ClashWars.TryGetValue(channel.Guild.Id, out wars); diff --git a/src/NadekoBot/Modules/Games/Commands/LeetCommands.cs b/src/NadekoBot/Modules/Games/Commands/LeetCommands.cs index 0f5bf1ba..708fd642 100644 --- a/src/NadekoBot/Modules/Games/Commands/LeetCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/LeetCommands.cs @@ -14,9 +14,9 @@ namespace NadekoBot.Modules.Games.Commands { [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task Leet(IMessage imsg, int level, [Remainder] string text) + public async Task Leet(IMessage imsg, int level, [Remainder] string text = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; text = text.Trim(); if (string.IsNullOrWhiteSpace(text)) diff --git a/src/NadekoBot/Modules/Games/Commands/PollCommands.cs b/src/NadekoBot/Modules/Games/Commands/PollCommands.cs index ef447afd..4e897b80 100644 --- a/src/NadekoBot/Modules/Games/Commands/PollCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/PollCommands.cs @@ -18,9 +18,9 @@ namespace NadekoBot.Modules.Games.Commands [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task Poll(IMessage imsg, [Remainder] string arg) + public async Task Poll(IMessage imsg, [Remainder] string arg = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; if (!(imsg.Author as IGuildUser).GuildPermissions.ManageChannels) return; @@ -41,7 +41,7 @@ namespace NadekoBot.Modules.Games.Commands [RequireContext(ContextType.Guild)] public async Task Pollend(IMessage imsg) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; if (!(imsg.Author as IGuildUser).GuildPermissions.ManageChannels) return; diff --git a/src/NadekoBot/Modules/Games/Commands/Trivia/TriviaGame.cs b/src/NadekoBot/Modules/Games/Commands/Trivia/TriviaGame.cs index 2aed794d..203914ce 100644 --- a/src/NadekoBot/Modules/Games/Commands/Trivia/TriviaGame.cs +++ b/src/NadekoBot/Modules/Games/Commands/Trivia/TriviaGame.cs @@ -107,7 +107,7 @@ namespace NadekoBot.Modules.Games.Commands.Trivia try { if (!(imsg.Channel is IGuildChannel && imsg.Channel is ITextChannel)) return; - if ((imsg.Channel as IGuildChannel).Guild != guild) return; + if ((imsg.Channel as ITextChannel).Guild != guild) return; if (imsg.Author.Id == (await NadekoBot.Client.GetCurrentUserAsync()).Id) return; var guildUser = imsg.Author as IGuildUser; diff --git a/src/NadekoBot/Modules/Games/Commands/TriviaCommands.cs b/src/NadekoBot/Modules/Games/Commands/TriviaCommands.cs index fbba1be2..3838d2c5 100644 --- a/src/NadekoBot/Modules/Games/Commands/TriviaCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/TriviaCommands.cs @@ -21,7 +21,7 @@ namespace NadekoBot.Modules.Games.Commands [RequireContext(ContextType.Guild)] public async Task Trivia(IMessage imsg, string[] args) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; TriviaGame trivia; if (!RunningTrivias.TryGetValue(channel.Guild.Id, out trivia)) @@ -48,7 +48,7 @@ namespace NadekoBot.Modules.Games.Commands [RequireContext(ContextType.Guild)] public async Task Tl(IMessage imsg) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; TriviaGame trivia; if (RunningTrivias.TryGetValue(channel.Guild.Id, out trivia)) @@ -61,7 +61,7 @@ namespace NadekoBot.Modules.Games.Commands [RequireContext(ContextType.Guild)] public async Task Tq(IMessage imsg) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; TriviaGame trivia; if (RunningTrivias.TryRemove(channel.Guild.Id, out trivia)) diff --git a/src/NadekoBot/Modules/Games/GamesModule.cs b/src/NadekoBot/Modules/Games/GamesModule.cs index 0cce65b0..f7787c73 100644 --- a/src/NadekoBot/Modules/Games/GamesModule.cs +++ b/src/NadekoBot/Modules/Games/GamesModule.cs @@ -21,9 +21,9 @@ namespace NadekoBot.Modules.Games [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task Choose(IMessage imsg, [Remainder] string list) + public async Task Choose(IMessage imsg, [Remainder] string list = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; if (string.IsNullOrWhiteSpace(list)) return; var listArr = list.Split(';'); @@ -35,9 +35,9 @@ namespace NadekoBot.Modules.Games [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task _8Ball(IMessage imsg, [Remainder] string question) + public async Task _8Ball(IMessage imsg, [Remainder] string question = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; if (string.IsNullOrWhiteSpace(question)) return; @@ -50,7 +50,7 @@ namespace NadekoBot.Modules.Games [RequireContext(ContextType.Guild)] public async Task Rps(IMessage imsg, string input) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; Func GetRPSPick = (p) => { @@ -100,7 +100,7 @@ namespace NadekoBot.Modules.Games [RequireContext(ContextType.Guild)] public async Task Linux(IMessage imsg, string guhnoo, string loonix) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; await imsg.Channel.SendMessageAsync( $@"I'd just like to interject for moment. What you're refering to as {loonix}, is in fact, {guhnoo}/{loonix}, or as I've recently taken to calling it, {guhnoo} plus {loonix}. {loonix} is not an operating system unto itself, but rather another free component of a fully functioning {guhnoo} system made useful by the {guhnoo} corelibs, shell utilities and vital system components comprising a full OS as defined by POSIX. diff --git a/src/NadekoBot/Modules/Help/HelpModule.cs b/src/NadekoBot/Modules/Help/HelpModule.cs index 566994c6..039cc1c2 100644 --- a/src/NadekoBot/Modules/Help/HelpModule.cs +++ b/src/NadekoBot/Modules/Help/HelpModule.cs @@ -28,7 +28,7 @@ namespace NadekoBot.Modules.Help [RequireContext(ContextType.Guild)] public async Task Modules(IMessage imsg) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; await imsg.Channel.SendMessageAsync("`List of modules:` \n• " + string.Join("\n• ", _commands.Modules.Select(m => m.Name)) + $"\n`Type \"-commands module_name\" to get a list of commands in that module.`") .ConfigureAwait(false); @@ -36,9 +36,9 @@ namespace NadekoBot.Modules.Help [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task Commands(IMessage imsg, [Remainder] string module) + public async Task Commands(IMessage imsg, [Remainder] string module = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; module = module?.Trim().ToUpperInvariant(); if (string.IsNullOrWhiteSpace(module)) @@ -66,9 +66,9 @@ namespace NadekoBot.Modules.Help [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task Help(IMessage imsg, [Remainder] string comToFind) + public async Task Help(IMessage imsg, [Remainder] string comToFind = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; comToFind = comToFind?.ToLowerInvariant(); if (string.IsNullOrWhiteSpace(comToFind)) @@ -116,7 +116,7 @@ namespace NadekoBot.Modules.Help [RequireContext(ContextType.Guild)] public async Task Guide(IMessage imsg) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; await imsg.Channel.SendMessageAsync( @"**LIST OF COMMANDS**: @@ -127,7 +127,7 @@ namespace NadekoBot.Modules.Help [RequireContext(ContextType.Guild)] public async Task Donate(IMessage imsg) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; await imsg.Channel.SendMessageAsync( $@"You can support the project on patreon. or diff --git a/src/NadekoBot/Modules/NSFW/NSFWModule.cs b/src/NadekoBot/Modules/NSFW/NSFWModule.cs index 3e36374e..9978da9a 100644 --- a/src/NadekoBot/Modules/NSFW/NSFWModule.cs +++ b/src/NadekoBot/Modules/NSFW/NSFWModule.cs @@ -21,9 +21,9 @@ namespace NadekoBot.Modules.NSFW [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task Hentai(IMessage imsg, [Remainder] string tag) + public async Task Hentai(IMessage imsg, [Remainder] string tag = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; tag = tag?.Trim() ?? ""; @@ -40,9 +40,9 @@ namespace NadekoBot.Modules.NSFW [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task Danbooru(IMessage imsg, [Remainder] string tag) + public async Task Danbooru(IMessage imsg, [Remainder] string tag = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; tag = tag?.Trim() ?? ""; var link = await GetDanbooruImageLink(tag).ConfigureAwait(false); @@ -54,9 +54,9 @@ namespace NadekoBot.Modules.NSFW [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task Gelbooru(IMessage imsg, [Remainder] string tag) + public async Task Gelbooru(IMessage imsg, [Remainder] string tag = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; tag = tag?.Trim() ?? ""; var link = await GetRule34ImageLink(tag).ConfigureAwait(false); @@ -68,9 +68,9 @@ namespace NadekoBot.Modules.NSFW [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task Rule34(IMessage imsg, [Remainder] string tag) + public async Task Rule34(IMessage imsg, [Remainder] string tag = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; tag = tag?.Trim() ?? ""; var link = await GetGelbooruImageLink(tag).ConfigureAwait(false); @@ -82,9 +82,9 @@ namespace NadekoBot.Modules.NSFW [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task E621(IMessage imsg, [Remainder] string tag) + public async Task E621(IMessage imsg, [Remainder] string tag = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; tag = tag?.Trim() ?? ""; var link = await GetE621ImageLink(tag).ConfigureAwait(false); @@ -98,7 +98,7 @@ namespace NadekoBot.Modules.NSFW [RequireContext(ContextType.Guild)] public async Task Cp(IMessage imsg) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; await imsg.Channel.SendMessageAsync("http://i.imgur.com/MZkY1md.jpg").ConfigureAwait(false); } @@ -107,7 +107,7 @@ namespace NadekoBot.Modules.NSFW [RequireContext(ContextType.Guild)] public async Task Boobs(IMessage imsg) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; try { JToken obj; @@ -127,7 +127,7 @@ namespace NadekoBot.Modules.NSFW [RequireContext(ContextType.Guild)] public async Task Butts(IMessage imsg) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; try { diff --git a/src/NadekoBot/Modules/Pokemon/PokemonModule.cs b/src/NadekoBot/Modules/Pokemon/PokemonModule.cs index 7749ca39..f8a8a6e1 100644 --- a/src/NadekoBot/Modules/Pokemon/PokemonModule.cs +++ b/src/NadekoBot/Modules/Pokemon/PokemonModule.cs @@ -18,7 +18,7 @@ namespace NadekoBot.Modules.Games.Commands [RequireContext(ContextType.Guild)] public async Task Poke(IMessage imsg) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; } diff --git a/src/NadekoBot/Modules/Searches/Commands/AnimeSearchCommands.cs b/src/NadekoBot/Modules/Searches/Commands/AnimeSearchCommands.cs index 10d4c8c4..4f095bbd 100644 --- a/src/NadekoBot/Modules/Searches/Commands/AnimeSearchCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/AnimeSearchCommands.cs @@ -13,9 +13,9 @@ // { // [LocalizedCommand, LocalizedDescription, LocalizedSummary] // [RequireContext(ContextType.Guild)] -// public async Task Anime(IMessage imsg, [Remainder] string query) +// public async Task Anime(IMessage imsg, [Remainder] string query = null) // { -// var channel = imsg.Channel as IGuildChannel; +// var channel = imsg.Channel as ITextChannel; // if (!(await ValidateQuery(imsg.Channel as ITextChannel, query).ConfigureAwait(false))) return; // string result; @@ -34,9 +34,9 @@ // [LocalizedCommand, LocalizedDescription, LocalizedSummary] // [RequireContext(ContextType.Guild)] -// public async Task Manga(IMessage imsg, [Remainder] string query) +// public async Task Manga(IMessage imsg, [Remainder] string query = null) // { -// var channel = imsg.Channel as IGuildChannel; +// var channel = imsg.Channel as ITextChannel; // if (!(await ValidateQuery(imsg.Channel as ITextChannel, query).ConfigureAwait(false))) return; // string result; diff --git a/src/NadekoBot/Modules/Searches/Commands/IMDB/ImdbScraper.cs b/src/NadekoBot/Modules/Searches/Commands/IMDB/ImdbScraper.cs index b922d1a5..b7ac2751 100644 --- a/src/NadekoBot/Modules/Searches/Commands/IMDB/ImdbScraper.cs +++ b/src/NadekoBot/Modules/Searches/Commands/IMDB/ImdbScraper.cs @@ -71,7 +71,7 @@ namespace NadekoBot.Modules.Searches.Commands.IMDB mov.Status = true; mov.Title = match(@"(IMDb \- )*(.*?) \(.*?", html, 2); mov.OriginalTitle = match(@"title-extra"">(.*?)<", html); - mov.Year = match(@".*?\(.*?(\d{4}).*?\).*?", match(@"(.*?)", html)); + mov.Year = match(@".*?\(.*?(\d{4}).*?).*?", match(@"(.*?)", html)); mov.Rating = match(@"(\d.\d)/10", html); mov.Genres = MatchAll(@"(.*?)", match(@"Genre.?:(.*?)(|See more)", html)).Cast().ToList(); mov.Plot = match(@"Plot:.*?
(.*?)(>(await http.GetStringAsync("http://memegen.link/templates/")) @@ -37,7 +37,7 @@ namespace NadekoBot.Modules.Searches.Commands [RequireContext(ContextType.Guild)] public async Task Memegen(IMessage imsg, string meme, string topText, string botText) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; var top = Uri.EscapeDataString(topText.Replace(' ', '-')); var bot = Uri.EscapeDataString(botText.Replace(' ', '-')); diff --git a/src/NadekoBot/Modules/Searches/Commands/PokemonSearchCommands.cs b/src/NadekoBot/Modules/Searches/Commands/PokemonSearchCommands.cs index edaf5111..cfcc9940 100644 --- a/src/NadekoBot/Modules/Searches/Commands/PokemonSearchCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/PokemonSearchCommands.cs @@ -26,9 +26,9 @@ namespace NadekoBot.Modules.Searches.Commands [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task Pokemon(IMessage imsg, [Remainder] string pokemon) + public async Task Pokemon(IMessage imsg, [Remainder] string pokemon = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; pokemon = pokemon?.Trim().ToUpperInvariant(); if (string.IsNullOrWhiteSpace(pokemon)) @@ -47,9 +47,9 @@ namespace NadekoBot.Modules.Searches.Commands [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task PokemonAbility(IMessage imsg, [Remainder] string ability) + public async Task PokemonAbility(IMessage imsg, [Remainder] string ability = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; ability = ability?.Trim().ToUpperInvariant().Replace(" ", ""); if (string.IsNullOrWhiteSpace(ability)) diff --git a/src/NadekoBot/Modules/Searches/SearchesModule.cs b/src/NadekoBot/Modules/Searches/SearchesModule.cs index 0d698220..d1383cd3 100644 --- a/src/NadekoBot/Modules/Searches/SearchesModule.cs +++ b/src/NadekoBot/Modules/Searches/SearchesModule.cs @@ -33,7 +33,7 @@ namespace NadekoBot.Modules.Searches [RequireContext(ContextType.Guild)] public async Task Weather(IMessage imsg, string city, string country) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; city = city.Replace(" ", ""); country = city.Replace(" ", ""); string response; @@ -52,9 +52,9 @@ $@"🌍 **Weather for** 【{obj["target"]}】 [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task Youtube(IMessage imsg, [Remainder] string query) + public async Task Youtube(IMessage imsg, [Remainder] string query = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; if (!(await ValidateQuery(imsg.Channel as ITextChannel, query).ConfigureAwait(false))) return; var result = (await _yt.FindVideosByKeywordsAsync(query, 1)).FirstOrDefault(); if (string.IsNullOrWhiteSpace(result)) @@ -68,9 +68,9 @@ $@"🌍 **Weather for** 【{obj["target"]}】 [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task Imdb(IMessage imsg, [Remainder] string query) + public async Task Imdb(IMessage imsg, [Remainder] string query = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; if (!(await ValidateQuery(imsg.Channel as ITextChannel, query).ConfigureAwait(false))) return; await imsg.Channel.TriggerTypingAsync().ConfigureAwait(false); @@ -94,7 +94,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】 [RequireContext(ContextType.Guild)] public async Task RandomCat(IMessage imsg) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; using (var http = new HttpClient()) { await imsg.Channel.SendMessageAsync(JObject.Parse( @@ -107,7 +107,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】 [RequireContext(ContextType.Guild)] public async Task RandomDog(IMessage imsg) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; using (var http = new HttpClient()) { await imsg.Channel.SendMessageAsync("http://random.dog/" + await http.GetStringAsync("http://random.dog/woof").ConfigureAwait(false)).ConfigureAwait(false); @@ -116,9 +116,9 @@ $@"🌍 **Weather for** 【{obj["target"]}】 [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task I(IMessage imsg, [Remainder] string query) + public async Task I(IMessage imsg, [Remainder] string query = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; if (string.IsNullOrWhiteSpace(query)) return; @@ -146,9 +146,9 @@ $@"🌍 **Weather for** 【{obj["target"]}】 [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task Ir(IMessage imsg, [Remainder] string query) + public async Task Ir(IMessage imsg, [Remainder] string query = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; if (string.IsNullOrWhiteSpace(query)) return; @@ -177,9 +177,9 @@ $@"🌍 **Weather for** 【{obj["target"]}】 [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task Lmgtfy(IMessage imsg, [Remainder] string ffs) + public async Task Lmgtfy(IMessage imsg, [Remainder] string ffs = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; if (string.IsNullOrWhiteSpace(ffs)) @@ -191,9 +191,9 @@ $@"🌍 **Weather for** 【{obj["target"]}】 [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task Google(IMessage imsg, [Remainder] string terms) + public async Task Google(IMessage imsg, [Remainder] string terms = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; terms = terms?.Trim(); @@ -205,9 +205,9 @@ $@"🌍 **Weather for** 【{obj["target"]}】 ////todo drawing //[LocalizedCommand, LocalizedDescription, LocalizedSummary] //[RequireContext(ContextType.Guild)] - //public async Task Hearthstone(IMessage imsg, [Remainder] string name) + //public async Task Hearthstone(IMessage imsg, [Remainder] string name = null) //{ - // var channel = imsg.Channel as IGuildChannel; + // var channel = imsg.Channel as ITextChannel; // var arg = e.GetArg("name"); // if (string.IsNullOrWhiteSpace(arg)) // { @@ -250,9 +250,9 @@ $@"🌍 **Weather for** 【{obj["target"]}】 [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task UrbanDictionary(IMessage imsg, [Remainder] string query) + public async Task UrbanDictionary(IMessage imsg, [Remainder] string query = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; var arg = query; if (string.IsNullOrWhiteSpace(arg)) @@ -284,9 +284,9 @@ $@"🌍 **Weather for** 【{obj["target"]}】 [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task Hashtag(IMessage imsg, [Remainder] string query) + public async Task Hashtag(IMessage imsg, [Remainder] string query = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; var arg = query; if (string.IsNullOrWhiteSpace(arg)) @@ -321,7 +321,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】 //[RequireContext(ContextType.Guild)] //public async Task Quote(IMessage imsg) //{ - // var channel = imsg.Channel as IGuildChannel; + // var channel = imsg.Channel as ITextChannel; // var quote = NadekoBot.Config.Quotes[rng.Next(0, NadekoBot.Config.Quotes.Count)].ToString(); // await imsg.Channel.SendMessageAsync(quote).ConfigureAwait(false); @@ -331,7 +331,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】 [RequireContext(ContextType.Guild)] public async Task Catfact(IMessage imsg) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; using (var http = new HttpClient()) { var response = await http.GetStringAsync("http://catfacts-api.appspot.com/api/facts").ConfigureAwait(false); @@ -343,9 +343,9 @@ $@"🌍 **Weather for** 【{obj["target"]}】 [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task Revav(IMessage imsg, [Remainder] string arg) + public async Task Revav(IMessage imsg, [Remainder] string arg = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; var usrStr = arg?.Trim().ToUpperInvariant(); if (string.IsNullOrWhiteSpace(usrStr)) @@ -360,9 +360,9 @@ $@"🌍 **Weather for** 【{obj["target"]}】 [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task Revimg(IMessage imsg, [Remainder] string imageLink) + public async Task Revimg(IMessage imsg, [Remainder] string imageLink = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; imageLink = imageLink?.Trim() ?? ""; if (string.IsNullOrWhiteSpace(imageLink)) @@ -372,9 +372,9 @@ $@"🌍 **Weather for** 【{obj["target"]}】 [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task Safebooru(IMessage imsg, [Remainder] string tag) + public async Task Safebooru(IMessage imsg, [Remainder] string tag = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; tag = tag?.Trim() ?? ""; var link = await GetSafebooruImageLink(tag).ConfigureAwait(false); @@ -386,9 +386,9 @@ $@"🌍 **Weather for** 【{obj["target"]}】 [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task Wiki(IMessage imsg, [Remainder] string query) + public async Task Wiki(IMessage imsg, [Remainder] string query = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; query = query?.Trim(); if (string.IsNullOrWhiteSpace(query)) @@ -407,9 +407,9 @@ $@"🌍 **Weather for** 【{obj["target"]}】 ////todo drawing //[LocalizedCommand, LocalizedDescription, LocalizedSummary] //[RequireContext(ContextType.Guild)] - //public async Task Clr(IMessage imsg, [Remainder] string color) + //public async Task Clr(IMessage imsg, [Remainder] string color = null) //{ - // var channel = imsg.Channel as IGuildChannel; + // var channel = imsg.Channel as ITextChannel; // color = color?.Trim().Replace("#", ""); // if (string.IsNullOrWhiteSpace((string)color)) @@ -432,9 +432,9 @@ $@"🌍 **Weather for** 【{obj["target"]}】 [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task Videocall(IMessage imsg, [Remainder] string arg) + public async Task Videocall(IMessage imsg, [Remainder] string arg = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; try { @@ -455,9 +455,9 @@ $@"🌍 **Weather for** 【{obj["target"]}】 [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task Avatar(IMessage imsg, [Remainder] string mention) + public async Task Avatar(IMessage imsg, [Remainder] string mention = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; var usr = imsg.MentionedUsers.FirstOrDefault(); if (usr == null) diff --git a/src/NadekoBot/Modules/Translator/TranslatorModule.cs b/src/NadekoBot/Modules/Translator/TranslatorModule.cs index c51631fe..c060da90 100644 --- a/src/NadekoBot/Modules/Translator/TranslatorModule.cs +++ b/src/NadekoBot/Modules/Translator/TranslatorModule.cs @@ -17,9 +17,9 @@ namespace NadekoBot.Modules.Translator [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task Translate(IMessage imsg, string langs, [Remainder] string text) + public async Task Translate(IMessage imsg, string langs, [Remainder] string text = null) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; try { @@ -47,7 +47,7 @@ namespace NadekoBot.Modules.Translator [RequireContext(ContextType.Guild)] public async Task Translangs(IMessage imsg) { - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; await imsg.Channel.SendTableAsync(GoogleTranslator.Instance.Languages, str => str, columns: 4); } diff --git a/src/NadekoBot/Modules/Utility/Commands/InfoCommands.cs b/src/NadekoBot/Modules/Utility/Commands/InfoCommands.cs index 1c242b45..acb8e5de 100644 --- a/src/NadekoBot/Modules/Utility/Commands/InfoCommands.cs +++ b/src/NadekoBot/Modules/Utility/Commands/InfoCommands.cs @@ -15,7 +15,7 @@ namespace NadekoBot.Modules.Utility [RequireContext(ContextType.Guild)] public async Task ServerInfo(IMessage msg, string guild = null) { - var channel = msg.Channel as IGuildChannel; + var channel = msg.Channel as ITextChannel; guild = guild?.ToUpperInvariant(); IGuild server; if (guild == null) @@ -66,7 +66,7 @@ namespace NadekoBot.Modules.Utility [RequireContext(ContextType.Guild)] public async Task UserInfo(IMessage msg, IGuildUser usr = null) { - var channel = msg.Channel as IGuildChannel; + var channel = msg.Channel as ITextChannel; var user = usr ?? msg.Author as IGuildUser; if (user == null) return; diff --git a/src/NadekoBot/Modules/Utility/UtilityModule.cs b/src/NadekoBot/Modules/Utility/UtilityModule.cs index 9b79914e..2db615de 100644 --- a/src/NadekoBot/Modules/Utility/UtilityModule.cs +++ b/src/NadekoBot/Modules/Utility/UtilityModule.cs @@ -24,7 +24,7 @@ namespace NadekoBot.Modules.Utility [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task WhoPlays(IMessage imsg, [Remainder] string game) + public async Task WhoPlays(IMessage imsg, [Remainder] string game = null) { var chnl = (IGuildChannel)imsg.Channel; game = game.Trim().ToUpperInvariant(); @@ -44,11 +44,11 @@ namespace NadekoBot.Modules.Utility [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task InRole(IMessage imsg, [Remainder] string roles) + public async Task InRole(IMessage imsg, [Remainder] string roles = null) { if (string.IsNullOrWhiteSpace(roles)) return; - var channel = imsg.Channel as IGuildChannel; + var channel = imsg.Channel as ITextChannel; var arg = roles.Split(',').Select(r => r.Trim().ToUpperInvariant()); string send = _l["`Here is a list of users in a specfic role:`"]; foreach (var roleStr in arg.Where(str => !string.IsNullOrWhiteSpace(str) && str != "@EVERYONE" && str != "EVERYONE")) @@ -110,21 +110,21 @@ namespace NadekoBot.Modules.Utility [RequireContext(ContextType.Guild)] public async Task ServerId(IMessage msg) { - await msg.Reply($"This server's ID is {(msg.Channel as IGuildChannel).Guild.Id}"); + await msg.Reply($"This server's ID is {(msg.Channel as ITextChannel).Guild.Id}"); } [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] public async Task Roles(IMessage msg, IGuildUser target = null) { - var guild = (msg.Channel as IGuildChannel).Guild; + var guild = (msg.Channel as ITextChannel).Guild; if (target != null) { await msg.Reply($"`List of roles for **{target.Username}**:` \n• " + string.Join("\n• ", target.Roles.Except(new[] { guild.EveryoneRole }))); } else { - await msg.Reply("`List of roles:` \n• " + string.Join("\n• ", (msg.Channel as IGuildChannel).Guild.Roles.Except(new[] { guild.EveryoneRole }))); + await msg.Reply("`List of roles:` \n• " + string.Join("\n• ", (msg.Channel as ITextChannel).Guild.Roles.Except(new[] { guild.EveryoneRole }))); } } } diff --git a/src/NadekoBot/NadekoBot.cs b/src/NadekoBot/NadekoBot.cs index 2995215f..e9445be9 100644 --- a/src/NadekoBot/NadekoBot.cs +++ b/src/NadekoBot/NadekoBot.cs @@ -62,7 +62,7 @@ namespace NadekoBot private async Task Client_MessageReceived(IMessage arg) { var t = await Commands.Execute(arg, 0); - if(!t.IsSuccess) + if(!t.IsSuccess && t.Error != CommandError.UnknownCommand) Console.WriteLine(t.ErrorReason); } } diff --git a/src/NadekoBot/Services/Impl/BotCredentials.cs b/src/NadekoBot/Services/Impl/BotCredentials.cs index 0ef1c6a2..09ebac3b 100644 --- a/src/NadekoBot/Services/Impl/BotCredentials.cs +++ b/src/NadekoBot/Services/Impl/BotCredentials.cs @@ -3,13 +3,14 @@ using System.Collections.Generic; namespace NadekoBot.Services.Impl { + //todo load creds public class BotCredentials : IBotCredentials { public string ClientId { get; } public string GoogleApiKey { get { - throw new NotImplementedException(); + return ""; } } @@ -17,7 +18,7 @@ namespace NadekoBot.Services.Impl public string Token { get { - throw new NotImplementedException(); + return ""; } } } diff --git a/src/NadekoBot/_Extensions/Extensions.cs b/src/NadekoBot/_Extensions/Extensions.cs index c8da875f..b1f66415 100644 --- a/src/NadekoBot/_Extensions/Extensions.cs +++ b/src/NadekoBot/_Extensions/Extensions.cs @@ -13,12 +13,25 @@ namespace NadekoBot.Extensions { public static class Extensions { - public static async Task Reply(this IMessage msg, string content) => await msg.Channel.SendMessageAsync(content); + public static async Task SendMessageAsync(this IGuildUser user, string message, bool isTTS = false) => + await (await user.CreateDMChannelAsync().ConfigureAwait(false)).SendMessageAsync(message, isTTS).ConfigureAwait(false); + + public static async Task SendFileAsync(this IGuildUser user, string filePath, string caption = null, bool isTTS = false) => + await (await user.CreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(filePath, caption, isTTS).ConfigureAwait(false); + + public static async Task SendFileAsync(this IGuildUser user, Stream fileStream, string fileName, string caption = null, bool isTTS = false) => + await (await user.CreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(fileStream, fileName, caption, isTTS).ConfigureAwait(false); + + public static async Task Reply(this IMessage msg, string content) => + await msg.Channel.SendMessageAsync(content).ConfigureAwait(false); + + public static async Task> Members(this IRole role) => + await role.Members(); public static async Task ReplyLong(this IMessage msg, string content, string breakOn = "\n", string addToEnd = "", string addToStart = "") { - if (content.Length < 2000) return new[] { await msg.Channel.SendMessageAsync(content) }; + if (content.Length < 2000) return new[] { await msg.Channel.SendMessageAsync(content).ConfigureAwait(false) }; var list = new List(); var temp = Regex.Split(content, breakOn).Select(x => x += breakOn).ToList(); @@ -204,6 +217,17 @@ namespace NadekoBot.Extensions return d[n, m]; } + public static async Task ToStream(this string str) + { + var ms = new MemoryStream(); + var sw = new StreamWriter(ms); + await sw.WriteAsync(str); + await sw.FlushAsync(); + ms.Position = 0; + return ms; + + } + public static int KiB(this int value) => value * 1024; public static int KB(this int value) => value * 1000; diff --git a/src/NadekoBot/project.lock.json b/src/NadekoBot/project.lock.json index 22716989..950d70aa 100644 --- a/src/NadekoBot/project.lock.json +++ b/src/NadekoBot/project.lock.json @@ -339,7 +339,7 @@ "Microsoft.NETCore.Jit/1.0.2": { "type": "package" }, - "Microsoft.NETCore.Platforms/1.0.2-beta-24410-01": { + "Microsoft.NETCore.Platforms/1.0.1": { "type": "package", "compile": { "lib/netstandard1.0/_._": {} @@ -1353,11 +1353,7 @@ "ref/netstandard1.3/System.Net.Security.dll": {} }, "runtimeTargets": { - "runtimes/unix/lib/netstandard1.6/System.Net.Security.dll": { - "assetType": "runtime", - "rid": "unix" - }, - "runtimes/win/lib/netstandard1.3/System.Net.Security.dll": { + "runtimes/win/lib/netstandard1.3/_._": { "assetType": "runtime", "rid": "win" } @@ -1407,20 +1403,16 @@ "lib/netstandard1.3/System.Net.WebSockets.dll": {} } }, - "System.Net.WebSockets.Client/4.0.1-beta-24410-01": { + "System.Net.WebSockets.Client/4.0.0": { "type": "package", "dependencies": { - "Microsoft.NETCore.Platforms": "1.0.2-beta-24410-01", + "Microsoft.NETCore.Platforms": "1.0.1", "Microsoft.Win32.Primitives": "4.0.1", "System.Collections": "4.0.11", "System.Diagnostics.Debug": "4.0.11", "System.Diagnostics.Tracing": "4.1.0", "System.Globalization": "4.0.11", - "System.IO": "4.1.0", - "System.Net.NameResolution": "4.0.0", "System.Net.Primitives": "4.0.11", - "System.Net.Security": "4.0.0", - "System.Net.Sockets": "4.1.0", "System.Net.WebHeaderCollection": "4.0.1", "System.Net.WebSockets": "4.0.0", "System.Resources.ResourceManager": "4.0.1", @@ -1428,14 +1420,10 @@ "System.Runtime.Extensions": "4.1.0", "System.Runtime.Handles": "4.0.1", "System.Runtime.InteropServices": "4.1.0", - "System.Security.Cryptography.Algorithms": "4.2.0", - "System.Security.Cryptography.Primitives": "4.0.0", "System.Security.Cryptography.X509Certificates": "4.1.0", "System.Text.Encoding": "4.0.11", - "System.Text.Encoding.Extensions": "4.0.11", "System.Threading": "4.0.11", - "System.Threading.Tasks": "4.0.11", - "System.Threading.Timer": "4.0.1" + "System.Threading.Tasks": "4.0.11" }, "compile": { "ref/netstandard1.3/System.Net.WebSockets.Client.dll": {} @@ -2374,7 +2362,7 @@ "System.Net.Http": "4.1.0", "System.Net.NameResolution": "4.0.0", "System.Net.Sockets": "4.1.0", - "System.Net.WebSockets.Client": "4.0.1-beta-24410-01", + "System.Net.WebSockets.Client": "4.0.0", "System.Reflection.Extensions": "4.0.1", "System.Runtime.InteropServices": "4.1.0", "System.Runtime.InteropServices.RuntimeInformation": "4.0.0", @@ -2758,12 +2746,12 @@ "runtime.json" ] }, - "Microsoft.NETCore.Platforms/1.0.2-beta-24410-01": { - "sha512": "uc/pGYdE4sVy3OovFF8hg79MvCxptzICxn0jdA6WusGWZa7VieqFoZYc+a6bHUVhMI0s/7SfBriux0RUq+PpbA==", + "Microsoft.NETCore.Platforms/1.0.1": { + "sha512": "2G6OjjJzwBfNOO8myRV/nFrbTw5iA+DEm0N+qUqhrOmaVtn4pC77h38I1jsXGw5VH55+dPfQsqHD0We9sCl9FQ==", "type": "package", - "path": "Microsoft.NETCore.Platforms/1.0.2-beta-24410-01", + "path": "Microsoft.NETCore.Platforms/1.0.1", "files": [ - "Microsoft.NETCore.Platforms.1.0.2-beta-24410-01.nupkg.sha512", + "Microsoft.NETCore.Platforms.1.0.1.nupkg.sha512", "Microsoft.NETCore.Platforms.nuspec", "ThirdPartyNotices.txt", "dotnet_library_license.txt", @@ -5109,12 +5097,12 @@ "ref/xamarinwatchos10/_._" ] }, - "System.Net.WebSockets.Client/4.0.1-beta-24410-01": { - "sha512": "IOqAcR7k+3LwNI6aL7qN61HcCOA9X4MM9LbrZhDeNbeB/IeWTk7zpeb7kh3d7H678s7ndIqN6a7okO8dAAfcYQ==", + "System.Net.WebSockets.Client/4.0.0": { + "sha512": "GY5h9cn0ZVsG4ORQqMytTldrqxet2RC2CSEsgWGf4XNW5jhL5SxzcUZph03xbZsgn7K3qMr+Rq+gkbJNI+FEXg==", "type": "package", - "path": "System.Net.WebSockets.Client/4.0.1-beta-24410-01", + "path": "System.Net.WebSockets.Client/4.0.0", "files": [ - "System.Net.WebSockets.Client.4.0.1-beta-24410-01.nupkg.sha512", + "System.Net.WebSockets.Client.4.0.0.nupkg.sha512", "System.Net.WebSockets.Client.nuspec", "ThirdPartyNotices.txt", "dotnet_library_license.txt",