diff --git a/NadekoBot/Classes/Music/StreamRequest.cs b/NadekoBot/Classes/Music/StreamRequest.cs index 050f8093..8b02bfef 100644 --- a/NadekoBot/Classes/Music/StreamRequest.cs +++ b/NadekoBot/Classes/Music/StreamRequest.cs @@ -265,7 +265,7 @@ namespace NadekoBot.Classes.Music { Console.WriteLine("Nothing was buffered, try another song and check your GoogleApikey."); } - int blockSize = 1920 * NadekoBot.client.Services.Get().Config.Channels; + int blockSize = 1920 * NadekoBot.client.GetService().Config.Channels; byte[] voiceBuffer = new byte[blockSize]; if (parent.OnStarted != null) diff --git a/NadekoBot/Classes/NadekoStats.cs b/NadekoBot/Classes/NadekoStats.cs index add21e22..85df50ff 100644 --- a/NadekoBot/Classes/NadekoStats.cs +++ b/NadekoBot/Classes/NadekoStats.cs @@ -28,7 +28,7 @@ namespace NadekoBot static NadekoStats() { } private NadekoStats() { - _service = NadekoBot.client.Services.Get(); + _service = NadekoBot.client.GetService(); _client = NadekoBot.client; _statsSW = new Stopwatch(); diff --git a/NadekoBot/Classes/Permissions/PermissionHelper.cs b/NadekoBot/Classes/Permissions/PermissionHelper.cs index a5898199..9dca4eac 100644 --- a/NadekoBot/Classes/Permissions/PermissionHelper.cs +++ b/NadekoBot/Classes/Permissions/PermissionHelper.cs @@ -40,7 +40,7 @@ namespace NadekoBot.Classes { if (string.IsNullOrWhiteSpace(mod)) throw new ArgumentNullException(nameof(mod)); - foreach (var m in NadekoBot.client.Modules().Modules) { + foreach (var m in NadekoBot.client.GetService().Modules) { if (m.Name.ToLower().Equals(mod.ToLower())) return m.Name; } @@ -51,7 +51,7 @@ namespace NadekoBot.Classes { if (string.IsNullOrWhiteSpace(commandText)) throw new ArgumentNullException(nameof(commandText)); - foreach (var com in NadekoBot.client.Services.Get().AllCommands) { + foreach (var com in NadekoBot.client.GetService().AllCommands) { if (com.Text.ToLower().Equals(commandText.ToLower())) return com.Text; } diff --git a/NadekoBot/Commands/HelpCommand.cs b/NadekoBot/Commands/HelpCommand.cs index d0ea7b49..16e2b603 100644 --- a/NadekoBot/Commands/HelpCommand.cs +++ b/NadekoBot/Commands/HelpCommand.cs @@ -13,7 +13,7 @@ namespace NadekoBot string helpstr = "**COMMANDS DO NOT WORK IN PERSONAL MESSAGES**\nOfficial repo: **github.com/Kwoth/NadekoBot/**"; string lastCategory = ""; - foreach (var com in client.Services.Get().AllCommands) + foreach (var com in client.GetService().AllCommands) { if (com.Category != lastCategory) { @@ -38,7 +38,7 @@ namespace NadekoBot string helpstr = "Official repo: **github.com/Kwoth/NadekoBot/** \n"; string lastCategory = ""; - foreach (var com in client.Services.Get().AllCommands) { + foreach (var com in client.GetService().AllCommands) { if (com.Category != lastCategory) { helpstr += "\n### " + com.Category + " \n"; helpstr += "Command and aliases | Description | Usage\n"; diff --git a/NadekoBot/Commands/LogCommand.cs b/NadekoBot/Commands/LogCommand.cs new file mode 100644 index 00000000..c49b1298 --- /dev/null +++ b/NadekoBot/Commands/LogCommand.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Concurrent; +using System.Threading.Tasks; +using Discord.Commands; +using Discord; + +namespace NadekoBot.Commands { + class LogCommand : DiscordCommand { + + public LogCommand() : base() { + NadekoBot.client.MessageReceived += MsgRecivd; + NadekoBot.client.MessageDeleted += MsgDltd; + NadekoBot.client.MessageUpdated += MsgUpdtd; + NadekoBot.client.UserUpdated += UsrUpdtd; + } + + ConcurrentDictionary logs = new ConcurrentDictionary(); + + public override Func DoFunc() => async e => { + if (e.User.Id != NadekoBot.OwnerID || + e.User.Server.Owner.Id != e.User.Id) + return; + Channel ch; + if (!logs.TryRemove(e.Server, out ch)) { + logs.TryAdd(e.Server, e.Channel); + await e.Channel.SendMessage($"**I WILL BEGIN LOGGING SERVER ACTIVITY IN THIS CHANNEL**"); + return; + } + + await e.Channel.SendMessage($"**NO LONGER LOGGIN IN {ch.Mention} CHANNEL**"); + }; + + private async void MsgRecivd(object sender, MessageEventArgs e) { + if (e.Server == null || e.Channel.IsPrivate || e.User.Id == NadekoBot.client.CurrentUser.Id) + return; + Channel ch; + if (!logs.TryGetValue(e.Server, out ch) || e.Channel == ch) + return; + await ch.SendMessage($"`Type:` **Message received** `Time:` **{DateTime.Now}** `Channel:` **{e.Channel.Name}**\n`{e.User}:` {e.Message.Text}"); + } + private async void MsgDltd(object sender, MessageEventArgs e) { + if (e.Server == null || e.Channel.IsPrivate || e.User.Id == NadekoBot.client.CurrentUser.Id) + return; + Channel ch; + if (!logs.TryGetValue(e.Server, out ch) || e.Channel == ch) + return; + await ch.SendMessage($"`Type:` **Message deleted** `Time:` **{DateTime.Now}** `Channel:` **{e.Channel.Name}**\n`{e.User}:` {e.Message.Text}"); + } + private async void MsgUpdtd(object sender, MessageUpdatedEventArgs e) { + if (e.Server == null || e.Channel.IsPrivate || e.User.Id == NadekoBot.client.CurrentUser.Id) + return; + Channel ch; + if (!logs.TryGetValue(e.Server, out ch) || e.Channel == ch) + return; + await ch.SendMessage($"`Type:` **Message updated** `Time:` **{DateTime.Now}** `Channel:` **{e.Channel.Name}**\n**BEFORE**: `{e.User}:` {e.Before.Text}\n---------------\n**AFTER**: `{e.User}:` {e.Before.Text}"); + } + private async void UsrUpdtd(object sender, UserUpdatedEventArgs e) { + string str = $"`Type:` **User updated** `Time:` **{DateTime.Now}**\n"; + if (e.Before.Name != e.After.Name) + str += $"Name changed from `{e.Before.Name}` to `{e.After.Name}`"; + else if (e.Before.AvatarUrl != e.After.AvatarUrl) + str += $"Avatar url changed from `{e.Before.AvatarUrl}` to `{e.After.AvatarUrl}`"; + else if (e.Before.Status != e.After.Status) + str += $"Status changed from `{e.Before.AvatarUrl}` to `{e.After.AvatarUrl}`"; + } + public override void Init(CommandGroupBuilder cgb) { + cgb.CreateCommand(".logserver") + .Description("Toggles logging in this channel. Logs every message sent/deleted/edited on the server. BOT OWNER ONLY. SERVER OWNER ONLY.") + .Do(DoFunc()); + } + } +} diff --git a/NadekoBot/Modules/Administration.cs b/NadekoBot/Modules/Administration.cs index 9328cf6b..178ff9f1 100644 --- a/NadekoBot/Modules/Administration.cs +++ b/NadekoBot/Modules/Administration.cs @@ -20,6 +20,7 @@ namespace NadekoBot.Modules { class Administration : DiscordModule { public Administration() : base() { commands.Add(new ServerGreetCommand()); + commands.Add(new LogCommand()); } public override void Install(ModuleManager manager) { @@ -161,14 +162,14 @@ namespace NadekoBot.Modules { cgb.CreateCommand(".modules") .Description("List all bot modules") .Do(async e => { - await e.Send("`List of modules:` \n• " + string.Join("\n• ", NadekoBot.client.Modules().Modules.Select(m => m.Name))); + await e.Send("`List of modules:` \n• " + string.Join("\n• ", NadekoBot.client.GetService().Modules.Select(m => m.Name))); }); cgb.CreateCommand(".commands") .Description("List all of the bot's commands from a certain module.") .Parameter("module", ParameterType.Unparsed) .Do(async e => { - var commands = NadekoBot.client.Services.Get().AllCommands + var commands = NadekoBot.client.GetService().AllCommands .Where(c => c.Category.ToLower() == e.GetArg("module").Trim().ToLower()); if (commands == null || commands.Count() == 0) { await e.Send("That module does not exist."); @@ -430,12 +431,25 @@ namespace NadekoBot.Modules { ConcurrentDictionary clearDictionary = new ConcurrentDictionary(); cgb.CreateCommand(".clr") - .Description("Clears some of nadeko's messages from the current channel.") + .Description("Clears some of nadeko's (or some other user's if supplied) messages from the current channel.\n**Usage**: .clr @X") + .Parameter("user",ParameterType.Unparsed) .Do(async e => { + var usrId = NadekoBot.client.CurrentUser.Id; + if (!string.IsNullOrWhiteSpace(e.GetArg("user"))) { + var usr = e.Server.FindUsers(e.GetArg("user")).FirstOrDefault(); + if (usr != null) + usrId = usr.Id; + } await Task.Run(async () => { - var msgs = (await e.Channel.DownloadMessages(100)).Where(m => m.User.Id == NadekoBot.client.CurrentUser.Id); - foreach (var m in msgs) - await m.Delete(); + var msgs = (await e.Channel.DownloadMessages(100)).Where(m => m.User.Id == usrId); + foreach (var m in msgs) { + try { + await m.Delete(); + } + catch { } + await Task.Delay(200); + } + }); }); @@ -629,6 +643,26 @@ namespace NadekoBot.Modules { Console.WriteLine("---------------\nInner error:\n" + ex.InnerException); } }); + + cgb.CreateCommand(".videocall") + .Description("Creates a private appear.in video call link for you and other mentioned people and sends it in private messages") + .Parameter("arg", ParameterType.Unparsed) + .Do(async e => { + try { + string str = "http://appear.in/"; + var allUsrs = e.Message.MentionedUsers.Union(new User[] { e.User }); + foreach (var usr in allUsrs) { + str += Uri.EscapeUriString(usr.Name[0].ToString()); + } + str += new Random().Next(100000, 1000000); + foreach (var usr in allUsrs) { + await usr.SendMessage(str); + } + } + catch (Exception ex) { + Console.WriteLine(ex); + } + }); }); } diff --git a/NadekoBot/Modules/Permissions.cs b/NadekoBot/Modules/Permissions.cs index eea7544a..bdff87aa 100644 --- a/NadekoBot/Modules/Permissions.cs +++ b/NadekoBot/Modules/Permissions.cs @@ -349,7 +349,7 @@ namespace NadekoBot.Modules { try { bool state = PermissionHelper.ValidateBool(e.GetArg("bool")); - foreach (var module in NadekoBot.client.Modules().Modules) { + foreach (var module in NadekoBot.client.GetService().Modules) { PermsHandler.SetServerModulePermission(e.Server, module.Name, state); } await e.Send($"All modules have been **{(state ? "enabled" : "disabled")}** on this server."); @@ -371,7 +371,7 @@ namespace NadekoBot.Modules { bool state = PermissionHelper.ValidateBool(e.GetArg("bool")); string module = PermissionHelper.ValidateModule(e.GetArg("module")); - foreach (var command in NadekoBot.client.Services.Get().AllCommands.Where(c => c.Category == module)) { + foreach (var command in NadekoBot.client.GetService().AllCommands.Where(c => c.Category == module)) { PermsHandler.SetServerCommandPermission(e.Server, command.Text, state); } await e.Send($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** on this server."); @@ -392,7 +392,7 @@ namespace NadekoBot.Modules { try { bool state = PermissionHelper.ValidateBool(e.GetArg("bool")); Discord.Channel channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel")); - foreach (var module in NadekoBot.client.Modules().Modules) { + foreach (var module in NadekoBot.client.GetService().Modules) { PermsHandler.SetChannelModulePermission(channel, module.Name, state); } @@ -416,7 +416,7 @@ namespace NadekoBot.Modules { bool state = PermissionHelper.ValidateBool(e.GetArg("bool")); string module = PermissionHelper.ValidateModule(e.GetArg("module")); Discord.Channel channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel")); - foreach (var command in NadekoBot.client.Services.Get().AllCommands.Where(c => c.Category == module)) { + foreach (var command in NadekoBot.client.GetService().AllCommands.Where(c => c.Category == module)) { PermsHandler.SetChannelCommandPermission(channel, command.Text, state); } await e.Send($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel."); @@ -437,7 +437,7 @@ namespace NadekoBot.Modules { try { bool state = PermissionHelper.ValidateBool(e.GetArg("bool")); Discord.Role role = PermissionHelper.ValidateRole(e.Server, e.GetArg("role")); - foreach (var module in NadekoBot.client.Modules().Modules) { + foreach (var module in NadekoBot.client.GetService().Modules) { PermsHandler.SetRoleModulePermission(role, module.Name, state); } @@ -461,7 +461,7 @@ namespace NadekoBot.Modules { bool state = PermissionHelper.ValidateBool(e.GetArg("bool")); string module = PermissionHelper.ValidateModule(e.GetArg("module")); Discord.Role role = PermissionHelper.ValidateRole(e.Server, e.GetArg("channel")); - foreach (var command in NadekoBot.client.Services.Get().AllCommands.Where(c => c.Category == module)) { + foreach (var command in NadekoBot.client.GetService().AllCommands.Where(c => c.Category == module)) { PermsHandler.SetRoleCommandPermission(role, command.Text, state); } await e.Send($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role."); diff --git a/NadekoBot/NadekoBot.cs b/NadekoBot/NadekoBot.cs index 53c2bd58..7e5a3af0 100644 --- a/NadekoBot/NadekoBot.cs +++ b/NadekoBot/NadekoBot.cs @@ -62,7 +62,7 @@ namespace NadekoBot { //create new discord client client = new DiscordClient(new DiscordConfigBuilder() { - MessageCacheSize = 0, + MessageCacheSize = 20, ConnectionTimeout = 60000, }); @@ -77,13 +77,13 @@ namespace NadekoBot { client.MessageReceived += Client_MessageReceived; //add command service - var commands = client.Services.Add(commandService); + var commands = client.AddService(commandService); //create module service - var modules = client.Services.Add(new ModuleService()); + var modules = client.AddService(new ModuleService()); //add audio service - var audio = client.Services.Add(new AudioService(new AudioServiceConfigBuilder() { + var audio = client.AddService(new AudioService(new AudioServiceConfigBuilder() { Channels = 2, EnableEncryption = false, EnableMultiserver = true, diff --git a/NadekoBot/NadekoBot.csproj b/NadekoBot/NadekoBot.csproj index b23cc454..6a96ba0f 100644 --- a/NadekoBot/NadekoBot.csproj +++ b/NadekoBot/NadekoBot.csproj @@ -146,6 +146,7 @@ + diff --git a/NadekoBot/bin/Debug/Discord.Net.Audio.dll b/NadekoBot/bin/Debug/Discord.Net.Audio.dll index b8ea2458..893cd5ce 100644 Binary files a/NadekoBot/bin/Debug/Discord.Net.Audio.dll and b/NadekoBot/bin/Debug/Discord.Net.Audio.dll differ diff --git a/NadekoBot/bin/Debug/Discord.Net.Commands.dll b/NadekoBot/bin/Debug/Discord.Net.Commands.dll index db866cc7..9455f48d 100644 Binary files a/NadekoBot/bin/Debug/Discord.Net.Commands.dll and b/NadekoBot/bin/Debug/Discord.Net.Commands.dll differ diff --git a/NadekoBot/bin/Debug/Discord.Net.Modules.dll b/NadekoBot/bin/Debug/Discord.Net.Modules.dll index bf74a451..7bdb31f7 100644 Binary files a/NadekoBot/bin/Debug/Discord.Net.Modules.dll and b/NadekoBot/bin/Debug/Discord.Net.Modules.dll differ diff --git a/NadekoBot/bin/Debug/Discord.Net.dll b/NadekoBot/bin/Debug/Discord.Net.dll index 20009693..f53f8cc1 100644 Binary files a/NadekoBot/bin/Debug/Discord.Net.dll and b/NadekoBot/bin/Debug/Discord.Net.dll differ