diff --git a/NadekoBot.sln b/NadekoBot.sln index 350bd395..3380667d 100644 --- a/NadekoBot.sln +++ b/NadekoBot.sln @@ -12,13 +12,17 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "NadekoBot", "src\NadekoBot\NadekoBot.xproj", "{45EC1473-C678-4857-A544-07DFE0D0B478}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Discord.Net.WebSocket", "Discord.Net\src\Discord.Net.WebSocket\Discord.Net.WebSocket.xproj", "{E9800F7A-3354-41B1-BDBB-2D59F8124EC9}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Discord.Net", "discord.net\src\Discord.Net\Discord.Net.xproj", "{91E9E7BD-75C9-4E98-84AA-2C271922E5C2}" +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Discord.Net.Commands", "discord.net\src\Discord.Net.Commands\Discord.Net.Commands.xproj", "{078DD7E6-943D-4D09-AFC2-D2BA58B76C9C}" EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Discord.Net.Core", "Discord.Net\src\Discord.Net.Core\Discord.Net.Core.xproj", "{E5F4786F-58F3-469E-8C87-1908A95436B7}" EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Discord.Net.Rest", "Discord.Net\src\Discord.Net.Rest\Discord.Net.Rest.xproj", "{63F5B5C8-56FE-4B53-8003-B58CEB451EF9}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Discord.Net.Commands", "Discord.Net\src\Discord.Net.Commands\Discord.Net.Commands.xproj", "{8CBA56CD-A954-481E-8358-F36273757A6B}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Discord.Net.Rpc", "discord.net\src\Discord.Net.Rpc\Discord.Net.Rpc.xproj", "{0E741C78-869B-4E05-A300-0C5B32F07734}" +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Discord.Net.WebSocket", "Discord.Net\src\Discord.Net.WebSocket\Discord.Net.WebSocket.xproj", "{E9800F7A-3354-41B1-BDBB-2D59F8124EC9}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -33,12 +37,18 @@ Global {45EC1473-C678-4857-A544-07DFE0D0B478}.GlobalNadeko|Any CPU.Build.0 = GlobalNadeko|Any CPU {45EC1473-C678-4857-A544-07DFE0D0B478}.Release|Any CPU.ActiveCfg = Release|Any CPU {45EC1473-C678-4857-A544-07DFE0D0B478}.Release|Any CPU.Build.0 = Release|Any CPU - {E9800F7A-3354-41B1-BDBB-2D59F8124EC9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E9800F7A-3354-41B1-BDBB-2D59F8124EC9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E9800F7A-3354-41B1-BDBB-2D59F8124EC9}.GlobalNadeko|Any CPU.ActiveCfg = Debug|Any CPU - {E9800F7A-3354-41B1-BDBB-2D59F8124EC9}.GlobalNadeko|Any CPU.Build.0 = Debug|Any CPU - {E9800F7A-3354-41B1-BDBB-2D59F8124EC9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E9800F7A-3354-41B1-BDBB-2D59F8124EC9}.Release|Any CPU.Build.0 = Release|Any CPU + {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.GlobalNadeko|Any CPU.ActiveCfg = Release|Any CPU + {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.GlobalNadeko|Any CPU.Build.0 = Release|Any CPU + {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Release|Any CPU.Build.0 = Release|Any CPU + {078DD7E6-943D-4D09-AFC2-D2BA58B76C9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {078DD7E6-943D-4D09-AFC2-D2BA58B76C9C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {078DD7E6-943D-4D09-AFC2-D2BA58B76C9C}.GlobalNadeko|Any CPU.ActiveCfg = Release|Any CPU + {078DD7E6-943D-4D09-AFC2-D2BA58B76C9C}.GlobalNadeko|Any CPU.Build.0 = Release|Any CPU + {078DD7E6-943D-4D09-AFC2-D2BA58B76C9C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {078DD7E6-943D-4D09-AFC2-D2BA58B76C9C}.Release|Any CPU.Build.0 = Release|Any CPU {E5F4786F-58F3-469E-8C87-1908A95436B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E5F4786F-58F3-469E-8C87-1908A95436B7}.Debug|Any CPU.Build.0 = Debug|Any CPU {E5F4786F-58F3-469E-8C87-1908A95436B7}.GlobalNadeko|Any CPU.ActiveCfg = Debug|Any CPU @@ -51,12 +61,18 @@ Global {63F5B5C8-56FE-4B53-8003-B58CEB451EF9}.GlobalNadeko|Any CPU.Build.0 = Debug|Any CPU {63F5B5C8-56FE-4B53-8003-B58CEB451EF9}.Release|Any CPU.ActiveCfg = Release|Any CPU {63F5B5C8-56FE-4B53-8003-B58CEB451EF9}.Release|Any CPU.Build.0 = Release|Any CPU - {8CBA56CD-A954-481E-8358-F36273757A6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8CBA56CD-A954-481E-8358-F36273757A6B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8CBA56CD-A954-481E-8358-F36273757A6B}.GlobalNadeko|Any CPU.ActiveCfg = Debug|Any CPU - {8CBA56CD-A954-481E-8358-F36273757A6B}.GlobalNadeko|Any CPU.Build.0 = Debug|Any CPU - {8CBA56CD-A954-481E-8358-F36273757A6B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8CBA56CD-A954-481E-8358-F36273757A6B}.Release|Any CPU.Build.0 = Release|Any CPU + {0E741C78-869B-4E05-A300-0C5B32F07734}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0E741C78-869B-4E05-A300-0C5B32F07734}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0E741C78-869B-4E05-A300-0C5B32F07734}.GlobalNadeko|Any CPU.ActiveCfg = Debug|Any CPU + {0E741C78-869B-4E05-A300-0C5B32F07734}.GlobalNadeko|Any CPU.Build.0 = Debug|Any CPU + {0E741C78-869B-4E05-A300-0C5B32F07734}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0E741C78-869B-4E05-A300-0C5B32F07734}.Release|Any CPU.Build.0 = Release|Any CPU + {E9800F7A-3354-41B1-BDBB-2D59F8124EC9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E9800F7A-3354-41B1-BDBB-2D59F8124EC9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E9800F7A-3354-41B1-BDBB-2D59F8124EC9}.GlobalNadeko|Any CPU.ActiveCfg = Debug|Any CPU + {E9800F7A-3354-41B1-BDBB-2D59F8124EC9}.GlobalNadeko|Any CPU.Build.0 = Debug|Any CPU + {E9800F7A-3354-41B1-BDBB-2D59F8124EC9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E9800F7A-3354-41B1-BDBB-2D59F8124EC9}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/NadekoBot/Modules/Administration/Administration.cs b/src/NadekoBot/Modules/Administration/Administration.cs index a79b6fc3..8bf3901a 100644 --- a/src/NadekoBot/Modules/Administration/Administration.cs +++ b/src/NadekoBot/Modules/Administration/Administration.cs @@ -25,6 +25,8 @@ namespace NadekoBot.Modules.Administration private static ConcurrentDictionary GuildMuteRoles { get; } = new ConcurrentDictionary(); + private static ConcurrentHashSet DeleteMessagesOnCommand { get; } = new ConcurrentHashSet(); + private new static Logger _log { get; } public Administration() : base() @@ -36,6 +38,7 @@ namespace NadekoBot.Modules.Administration _log = LogManager.GetCurrentClassLogger(); NadekoBot.CommandHandler.CommandExecuted += DelMsgOnCmd_Handler; + DeleteMessagesOnCommand = new ConcurrentHashSet(NadekoBot.AllGuildConfigs.Where(g => g.DeleteMessageOnCommand).Select(g => g.GuildId)); } @@ -46,15 +49,7 @@ namespace NadekoBot.Modules.Administration var channel = msg.Channel as SocketTextChannel; if (channel == null) return; - - //todo cache this - bool shouldDelete; - using (var uow = DbHandler.UnitOfWork()) - { - shouldDelete = uow.GuildConfigs.For(channel.Guild.Id, set => set).DeleteMessageOnCommand; - } - - if (shouldDelete) + if (DeleteMessagesOnCommand.Contains(channel.Guild.Id)) await msg.DeleteAsync().ConfigureAwait(false); } catch (Exception ex) @@ -99,9 +94,15 @@ namespace NadekoBot.Modules.Administration await uow.CompleteAsync(); } if (enabled) + { + DeleteMessagesOnCommand.Add(Context.Guild.Id); await Context.Channel.SendConfirmAsync("✅ **Now automatically deleting successful command invokations.**").ConfigureAwait(false); + } else + { + DeleteMessagesOnCommand.TryRemove(Context.Guild.Id); await Context.Channel.SendConfirmAsync("❗**Stopped automatic deletion of successful command invokations.**").ConfigureAwait(false); + } } [NadekoCommand, Usage, Description, Aliases] diff --git a/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs b/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs index 4ee08f4b..10840d81 100644 --- a/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs +++ b/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs @@ -38,9 +38,6 @@ namespace NadekoBot.Modules.ClashOfClans .ToDictionary(g => g.Key, g => g.ToList())); } } - public ClashOfClans() : base() - { - } private static async Task CheckWar(TimeSpan callExpire, ClashWar war) { @@ -52,7 +49,7 @@ namespace NadekoBot.Modules.ClashOfClans { Bases[i] = null; try { await war.Channel.SendErrorAsync($"❗🔰**Claim from @{Bases[i].CallUser} for a war against {war.ShortPrint()} has expired.**").ConfigureAwait(false); } catch { } - } + } } } diff --git a/src/NadekoBot/Modules/DiscordModule.cs b/src/NadekoBot/Modules/DiscordModule.cs index be453f43..711431d5 100644 --- a/src/NadekoBot/Modules/DiscordModule.cs +++ b/src/NadekoBot/Modules/DiscordModule.cs @@ -3,7 +3,7 @@ using NLog; namespace NadekoBot.Modules { - public class DiscordModule : ModuleBase + public abstract class DiscordModule : ModuleBase { protected Logger _log { get; } protected string _prefix { get; } diff --git a/src/NadekoBot/Modules/Gambling/Commands/DiceRollCommand.cs b/src/NadekoBot/Modules/Gambling/Commands/DiceRollCommand.cs index 217b74d2..a3148dab 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/DiceRollCommand.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/DiceRollCommand.cs @@ -21,6 +21,11 @@ namespace NadekoBot.Modules.Gambling { private Regex dndRegex { get; } = new Regex(@"^(?\d+)d(?\d+)(?:\+(?\d+))?(?:\-(?\d+))?$", RegexOptions.Compiled); + public enum RoleOrderType { + Ordered, + Unordered + } + [NadekoCommand, Usage, Description, Aliases] public async Task Roll() { @@ -43,37 +48,6 @@ namespace NadekoBot.Modules.Gambling await Context.Channel.SendFileAsync(imageStream, "dice.png", $"{Context.User.Mention} rolled " + Format.Code(gen.ToString())).ConfigureAwait(false); } - //todo merge into internallDndRoll and internalRoll - [NadekoCommand, Usage, Description, Aliases] - [Priority(1)] - public async Task Roll(string arg) - { - var ordered = true; - var rng = new NadekoRandom(); - Match match; - if ((match = dndRegex.Match(arg)).Length != 0) - { - int n1; - int n2; - if (int.TryParse(match.Groups["n1"].ToString(), out n1) && - int.TryParse(match.Groups["n2"].ToString(), out n2) && - n1 <= 50 && n2 <= 100000 && n1 > 0 && n2 > 0) - { - var add = 0; - var sub = 0; - int.TryParse(match.Groups["add"].Value, out add); - int.TryParse(match.Groups["sub"].Value, out sub); - - var arr = new int[n1]; - for (int i = 0; i < n1; i++) - { - arr[i] = rng.Next(1, n2 + 1) + add - sub; - } - var elemCnt = 0; - await Context.Channel.SendConfirmAsync($"{Context.User.Mention} rolled {n1} {(n1 == 1 ? "die" : "dice")} `1 to {n2}` +`{add}` -`{sub}`.\n`Result:` " + string.Join(", ", (ordered ? arr.OrderBy(x => x).AsEnumerable() : arr).Select(x => elemCnt++ % 2 == 0 ? $"**{x}**" : x.ToString()))).ConfigureAwait(false); - } - } - } [NadekoCommand, Usage, Description, Aliases] [Priority(0)] @@ -123,37 +97,7 @@ namespace NadekoBot.Modules.Gambling ms.Position = 0; await Context.Channel.SendFileAsync(ms, "dice.png", $"{Context.User.Mention} rolled {values.Count} {(values.Count == 1 ? "die" : "dice")}. Total: **{values.Sum()}** Average: **{(values.Sum() / (1.0f * values.Count)).ToString("N2")}**").ConfigureAwait(false); } - - [NadekoCommand, Usage, Description, Aliases] - public async Task Rolluo(string arg) - { - var ordered = false; - var rng = new NadekoRandom(); - Match match; - if ((match = dndRegex.Match(arg)).Length != 0) - { - int n1; - int n2; - if (int.TryParse(match.Groups["n1"].ToString(), out n1) && - int.TryParse(match.Groups["n2"].ToString(), out n2) && - n1 <= 50 && n2 <= 100000 && n1 > 0 && n2 > 0) - { - var add = 0; - var sub = 0; - int.TryParse(match.Groups["add"].Value, out add); - int.TryParse(match.Groups["sub"].Value, out sub); - - var arr = new int[n1]; - for (int i = 0; i < n1; i++) - { - arr[i] = rng.Next(1, n2 + 1) + add - sub; - } - var elemCnt = 0; - await Context.Channel.SendConfirmAsync($"{Context.User.Mention} rolled {n1} {(n1 == 1 ? "die" : "dice")} `1 to {n2}` +`{add}` -`{sub}`.\n`Result:` " + string.Join(", ", (ordered ? arr.OrderBy(x => x).AsEnumerable() : arr).Select(x => elemCnt++ % 2 == 0 ? $"**{x}**" : x.ToString()))).ConfigureAwait(false); - } - } - } - + [NadekoCommand, Usage, Description, Aliases] public async Task Rolluo(int num) { @@ -202,6 +146,73 @@ namespace NadekoBot.Modules.Gambling await Context.Channel.SendFileAsync(ms, "dice.png", $"{Context.User.Mention} rolled {values.Count} {(values.Count == 1 ? "die" : "dice")}. Total: **{values.Sum()}** Average: **{(values.Sum() / (1.0f * values.Count)).ToString("N2")}**").ConfigureAwait(false); } + //todo merge into internallDndRoll and internalRoll + [NadekoCommand, Usage, Description, Aliases] + [Priority(1)] + public async Task Roll(string arg) + { + + } + + [NadekoCommand, Usage, Description, Aliases] + public async Task Rolluo(string arg) + { + var ordered = false; + var rng = new NadekoRandom(); + Match match; + if ((match = dndRegex.Match(arg)).Length != 0) + { + int n1; + int n2; + if (int.TryParse(match.Groups["n1"].ToString(), out n1) && + int.TryParse(match.Groups["n2"].ToString(), out n2) && + n1 <= 50 && n2 <= 100000 && n1 > 0 && n2 > 0) + { + var add = 0; + var sub = 0; + int.TryParse(match.Groups["add"].Value, out add); + int.TryParse(match.Groups["sub"].Value, out sub); + + var arr = new int[n1]; + for (int i = 0; i < n1; i++) + { + arr[i] = rng.Next(1, n2 + 1) + add - sub; + } + var elemCnt = 0; + await Context.Channel.SendConfirmAsync($"{Context.User.Mention} rolled {n1} {(n1 == 1 ? "die" : "dice")} `1 to {n2}` +`{add}` -`{sub}`.\n`Result:` " + string.Join(", ", (ordered ? arr.OrderBy(x => x).AsEnumerable() : arr).Select(x => elemCnt++ % 2 == 0 ? $"**{x}**" : x.ToString()))).ConfigureAwait(false); + } + } + } + + private async Task InternalDndRoll(string arg, RoleOrderType ordType) + { + var ordered = ordType == RoleOrderType.Ordered; + var rng = new NadekoRandom(); + Match match; + if ((match = dndRegex.Match(arg)).Length != 0) + { + int n1; + int n2; + if (int.TryParse(match.Groups["n1"].ToString(), out n1) && + int.TryParse(match.Groups["n2"].ToString(), out n2) && + n1 <= 50 && n2 <= 100000 && n1 > 0 && n2 > 0) + { + var add = 0; + var sub = 0; + int.TryParse(match.Groups["add"].Value, out add); + int.TryParse(match.Groups["sub"].Value, out sub); + + var arr = new int[n1]; + for (int i = 0; i < n1; i++) + { + arr[i] = rng.Next(1, n2 + 1) + add - sub; + } + var elemCnt = 0; + await Context.Channel.SendConfirmAsync($"{Context.User.Mention} rolled {n1} {(n1 == 1 ? "die" : "dice")} `1 to {n2}` +`{add}` -`{sub}`.\n`Result:` " + string.Join(", ", (ordered ? arr.OrderBy(x => x).AsEnumerable() : arr).Select(x => elemCnt++ % 2 == 0 ? $"**{x}**" : x.ToString()))).ConfigureAwait(false); + } + } + } + [NadekoCommand, Usage, Description, Aliases] public async Task NRoll([Remainder] string range) { @@ -215,7 +226,7 @@ namespace NadekoBot.Modules.Gambling .Select(int.Parse) .ToArray(); if (arr[0] > arr[1]) - throw new ArgumentException("First argument should be bigger than the second one."); + throw new ArgumentException("Second argument must be larger than the first one."); rolled = new NadekoRandom().Next(arr[0], arr[1] + 1); } else diff --git a/src/NadekoBot/Modules/Gambling/Commands/DrawCommand.cs b/src/NadekoBot/Modules/Gambling/Commands/DrawCommand.cs index abece27e..a57a4872 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/DrawCommand.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/DrawCommand.cs @@ -53,7 +53,6 @@ namespace NadekoBot.Modules.Gambling MemoryStream bitmapStream = new MemoryStream(); images.Merge().SaveAsPng(bitmapStream); bitmapStream.Position = 0; - //todo CARD NAMES? var toSend = $"{Context.User.Mention}"; if (cardObjects.Count == 5) toSend += $" drew `{Cards.GetHandValue(cardObjects)}`"; diff --git a/src/NadekoBot/Modules/Gambling/Commands/FlipCoinCommand.cs b/src/NadekoBot/Modules/Gambling/Commands/FlipCoinCommand.cs index fc6c60a6..e1c05a05 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/FlipCoinCommand.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/FlipCoinCommand.cs @@ -64,16 +64,10 @@ namespace NadekoBot.Modules.Gambling .ConfigureAwait(false); return; } - // todo update this - long userFlowers; - using (var uow = DbHandler.UnitOfWork()) + var removed = await CurrencyHandler.RemoveCurrencyAsync((IGuildUser)Context.User, "Betflip Gamble", amount, false).ConfigureAwait(false); + if (!removed) { - userFlowers = uow.Currency.GetOrCreate(Context.User.Id).Amount; - } - - if (userFlowers < amount) - { - await Context.Channel.SendErrorAsync($"{Context.User.Mention} You don't have enough {Gambling.CurrencyPluralName}. You only have {userFlowers}{Gambling.CurrencySign}.").ConfigureAwait(false); + await Context.Channel.SendErrorAsync($"{Context.User.Mention} You don't have enough {Gambling.CurrencyPluralName}.").ConfigureAwait(false); return; } diff --git a/src/NadekoBot/Modules/Games/Commands/Hangman/HangmanGame.cs b/src/NadekoBot/Modules/Games/Commands/Hangman/HangmanGame.cs index cd5b8a70..c2a93f63 100644 --- a/src/NadekoBot/Modules/Games/Commands/Hangman/HangmanGame.cs +++ b/src/NadekoBot/Modules/Games/Commands/Hangman/HangmanGame.cs @@ -143,9 +143,7 @@ namespace NadekoBot.Modules.Games.Commands.Hangman return Task.CompletedTask; var guess = char.ToUpperInvariant(msg.Content[0]); - // todo hmmmm - // how do i want to limit the users on guessing? - // one guess every 5 seconds if wrong? + Task.Run(async () => { try diff --git a/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs b/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs index 04e43058..88bcc91e 100644 --- a/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs @@ -16,8 +16,6 @@ using System.Threading.Tasks; namespace NadekoBot.Modules.Games { - //todo make currency generation change and cooldown modifyable - //only by bot owner through commands public partial class Games { /// diff --git a/src/NadekoBot/Modules/Games/Commands/TriviaCommands.cs b/src/NadekoBot/Modules/Games/Commands/TriviaCommands.cs index dfa55eea..90492643 100644 --- a/src/NadekoBot/Modules/Games/Commands/TriviaCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/TriviaCommands.cs @@ -8,7 +8,7 @@ using System.Collections.Concurrent; using System.Linq; using System.Threading.Tasks; -//todo Rewrite? Fix trivia not stopping bug + namespace NadekoBot.Modules.Games { public partial class Games diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index 16fb59f3..53ae37d7 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -38,9 +38,9 @@ namespace NadekoBot.Modules.Help public async Task Modules() { + var mdls = NadekoBot.CommandService.Modules.GroupBy(mi => mi.GetTopLevelModule()).Select(m => m.Key.Name).OrderBy(m => m); await Context.Channel.SendMessageAsync("📜 **List of modules:** ```css\n• " + string.Join("\n• ", - NadekoBot.CommandService.Modules.GroupBy(mi => mi.GetTopLevelModule()).Select(m => m.Key.Name).OrderBy(m => m)) + - $"\n``` ℹ️ **Type** `-commands module_name` **to get a list of commands in that module.** ***e.g.*** `-commands games`") + mdls) + $"\n``` ℹ️ **Type** `-commands module_name` **to get a list of commands in that module.** ***e.g.*** `-commands games`") .ConfigureAwait(false); } diff --git a/src/NadekoBot/Modules/Music/Classes/MusicControls.cs b/src/NadekoBot/Modules/Music/Classes/MusicControls.cs index 8555d3a3..dea84b09 100644 --- a/src/NadekoBot/Modules/Music/Classes/MusicControls.cs +++ b/src/NadekoBot/Modules/Music/Classes/MusicControls.cs @@ -130,6 +130,7 @@ namespace NadekoBot.Modules.Music.Classes { Console.WriteLine("Music thread almost crashed."); Console.WriteLine(ex); + await Task.Delay(30000); } finally { diff --git a/src/NadekoBot/Modules/Music/Classes/Song.cs b/src/NadekoBot/Modules/Music/Classes/Song.cs index 2623f680..379d8caf 100644 --- a/src/NadekoBot/Modules/Music/Classes/Song.cs +++ b/src/NadekoBot/Modules/Music/Classes/Song.cs @@ -24,22 +24,22 @@ namespace NadekoBot.Modules.Music.Classes public string Query { get; set; } public string Title { get; set; } public string Uri { get; set; } - public string AlbumArt { get; set; } + public string AlbumArt { get; set; } } public class Song { - public StreamState State { get; set; } + public StreamState State { get; set; } public string PrettyName => $"**{SongInfo.Title.TrimTo(55)} `{(SongInfo.Provider ?? "-")} by {QueuerName}`**"; - //$"{SongInfo.Title.TrimTo(70)}"; + //$"{SongInfo.Title.TrimTo(70)}"; public SongInfo SongInfo { get; } public MusicPlayer MusicPlayer { get; set; } - - public string PrettyUser => + + public string PrettyUser => $"{QueuerName}"; public string QueuerName { get; set; } - - public string PrettyProvider => + + public string PrettyProvider => $"{(SongInfo.Provider ?? "No Provider")}"; public string PrettyCurrentTime() @@ -320,7 +320,7 @@ namespace NadekoBot.Modules.Music.Classes Uri = svideo.StreamLink, ProviderType = musicType, Query = svideo.TrackLink, - AlbumArt = svideo.artwork_url, + AlbumArt = svideo.artwork_url, }) { TotalLength = TimeSpan.FromMilliseconds(svideo.Duration) }; } @@ -335,7 +335,7 @@ namespace NadekoBot.Modules.Music.Classes Uri = svideo.StreamLink, ProviderType = MusicType.Normal, Query = svideo.TrackLink, - AlbumArt = svideo.artwork_url, + AlbumArt = svideo.artwork_url, }) { TotalLength = TimeSpan.FromMilliseconds(svideo.Duration) }; } diff --git a/src/NadekoBot/Modules/Searches/Commands/OverwatchCommands.cs b/src/NadekoBot/Modules/Searches/Commands/OverwatchCommands.cs index 258bad9b..0b309e12 100644 --- a/src/NadekoBot/Modules/Searches/Commands/OverwatchCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/OverwatchCommands.cs @@ -23,6 +23,7 @@ namespace NadekoBot.Modules.Searches var battletag = query.Replace("#", "-"); try { + await Context.Channel.TriggerTypingAsync().ConfigureAwait(false); var model = await GetProfile(region, battletag); var rankimg = $"{model.Competitive.rank_img}"; diff --git a/src/NadekoBot/Modules/Utility/Commands/CalcCommand.cs b/src/NadekoBot/Modules/Utility/Commands/CalcCommand.cs index b0135fd0..b4327c85 100644 --- a/src/NadekoBot/Modules/Utility/Commands/CalcCommand.cs +++ b/src/NadekoBot/Modules/Utility/Commands/CalcCommand.cs @@ -50,7 +50,7 @@ namespace NadekoBot.Modules.Utility "Equals", "GetHashCode", "GetType"}); - await Context.Channel.SendConfirmAsync(string.Join(", ", selection)); + await Context.Channel.SendConfirmAsync("Available functions in calc", string.Join(", ", selection)); } } diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index d24d51a0..2b976ac6 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -125,11 +125,27 @@ namespace NadekoBot.Modules.Utility return; if (target != null) { - await channel.SendConfirmAsync($"⚔ **Page #{page} of roles for {target.Username}**", $"```css\n• " + string.Join("\n• ", target.GetRoles().Except(new[] { guild.EveryoneRole }).OrderBy(r => -r.Position).Skip((page - 1) * RolesPerPage).Take(RolesPerPage)).SanitizeMentions() + "\n```"); + var roles = target.GetRoles().Except(new[] { guild.EveryoneRole }).OrderBy(r => -r.Position).Skip((page - 1) * RolesPerPage).Take(RolesPerPage); + if (!roles.Any()) + { + await channel.SendErrorAsync("No roles on this page."); + } + else + { + await channel.SendConfirmAsync($"⚔ **Page #{page} of roles for {target.Username}**", $"```css\n• " + string.Join("\n• ", roles).SanitizeMentions() + "\n```"); + } } else { - await channel.SendConfirmAsync($"⚔ **Page #{page} of all roles on this server:**", $"```css\n• " + string.Join("\n• ", guild.Roles.Except(new[] { guild.EveryoneRole }).OrderBy(r => -r.Position).Skip((page - 1) * RolesPerPage).Take(RolesPerPage)).SanitizeMentions() + "\n```"); + var roles = guild.Roles.Except(new[] { guild.EveryoneRole }).OrderBy(r => -r.Position).Skip((page - 1) * RolesPerPage).Take(RolesPerPage); + if (!roles.Any()) + { + await channel.SendErrorAsync("No roles on this page."); + } + else + { + await channel.SendConfirmAsync($"⚔ **Page #{page} of all roles on this server:**", $"```css\n• " + string.Join("\n• ", roles).SanitizeMentions() + "\n```"); + } } } diff --git a/src/NadekoBot/Services/CommandHandler.cs b/src/NadekoBot/Services/CommandHandler.cs index d46f1a66..463d257e 100644 --- a/src/NadekoBot/Services/CommandHandler.cs +++ b/src/NadekoBot/Services/CommandHandler.cs @@ -135,15 +135,15 @@ namespace NadekoBot.Services catch { } string messageContent = usrMsg.Content; - foreach (var k in NadekoBot.ModulePrefixes.Values) - { - if (usrMsg.Content.ToLowerInvariant().StartsWith(k)) - { - messageContent = messageContent.Insert(k.Length, " "); - break; - } + //foreach (var k in NadekoBot.ModulePrefixes.Values) + //{ + // if (usrMsg.Content.ToLowerInvariant().StartsWith(k)) + // { + // messageContent = messageContent.Insert(k.Length, " "); + // break; + // } - } + //} var throwaway = Task.Run(async () => diff --git a/src/NadekoBot/Services/CurrencyHandler.cs b/src/NadekoBot/Services/CurrencyHandler.cs index 45383968..fb8d68a6 100644 --- a/src/NadekoBot/Services/CurrencyHandler.cs +++ b/src/NadekoBot/Services/CurrencyHandler.cs @@ -9,7 +9,7 @@ namespace NadekoBot.Services { public static class CurrencyHandler { - public static async Task RemoveCurrencyAsync(IGuildUser author, string reason, long amount, bool sendMessage) + public static async Task RemoveCurrencyAsync(IUser author, string reason, long amount, bool sendMessage) { var success = await RemoveCurrencyAsync(author.Id, reason, amount); diff --git a/src/NadekoBot/Services/Impl/GoogleApiService.cs b/src/NadekoBot/Services/Impl/GoogleApiService.cs index 6a18c686..6e5727f7 100644 --- a/src/NadekoBot/Services/Impl/GoogleApiService.cs +++ b/src/NadekoBot/Services/Impl/GoogleApiService.cs @@ -167,7 +167,8 @@ namespace NadekoBot.Services.Impl remaining -= toGet; var q = yt.Videos.List("contentDetails"); - q.Id = string.Join(",", videoIds); + q.Id = string.Join(",", videoIdsList.Take(toGet)); + videoIdsList = videoIdsList.Skip(toGet).ToList(); var items = (await q.ExecuteAsync().ConfigureAwait(false)).Items; foreach (var i in items) { diff --git a/src/NadekoBot/TypeReaders/ModuleTypeReader.cs b/src/NadekoBot/TypeReaders/ModuleTypeReader.cs index 1cfd4204..3363c83e 100644 --- a/src/NadekoBot/TypeReaders/ModuleTypeReader.cs +++ b/src/NadekoBot/TypeReaders/ModuleTypeReader.cs @@ -1,4 +1,5 @@ using Discord.Commands; +using NadekoBot.Extensions; using System.Linq; using System.Threading.Tasks; @@ -9,7 +10,7 @@ namespace NadekoBot.TypeReaders public override Task Read(CommandContext context, string input) { input = input.ToUpperInvariant(); - var module = NadekoBot.CommandService.Modules.FirstOrDefault(m => m.Name.ToUpperInvariant() == input); + var module = NadekoBot.CommandService.Modules.GroupBy(m => m.GetTopLevelModule()).FirstOrDefault(m => m.Key.Name.ToUpperInvariant() == input); if (module == null) return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "No such module found.")); diff --git a/src/NadekoBot/_Extensions/Extensions.cs b/src/NadekoBot/_Extensions/Extensions.cs index 97692a5d..284b72ba 100644 --- a/src/NadekoBot/_Extensions/Extensions.cs +++ b/src/NadekoBot/_Extensions/Extensions.cs @@ -79,34 +79,34 @@ namespace NadekoBot.Extensions public static double UnixTimestamp(this DateTime dt) => dt.ToUniversalTime().Subtract(new DateTime(1970, 1, 1)).TotalSeconds; - public static async Task SendMessageAsync(this IGuildUser user, string message, bool isTTS = false) => + public static async Task SendMessageAsync(this IUser user, string message, bool isTTS = false) => await (await user.CreateDMChannelAsync().ConfigureAwait(false)).SendMessageAsync(message, isTTS).ConfigureAwait(false); - public static async Task SendConfirmAsync(this IGuildUser user, string text) + public static async Task SendConfirmAsync(this IUser user, string text) => await (await user.CreateDMChannelAsync()).SendMessageAsync("", embed: new EmbedBuilder().WithColor(NadekoBot.OkColor).WithDescription(text)); - public static async Task SendConfirmAsync(this IGuildUser user, string title, string text, string url = null) + public static async Task SendConfirmAsync(this IUser user, string title, string text, string url = null) => await(await user.CreateDMChannelAsync()).SendMessageAsync("", embed: new EmbedBuilder().WithColor(NadekoBot.OkColor).WithDescription(text) .WithTitle(title).WithUrl(url)); - public static async Task SendErrorAsync(this IGuildUser user, string title, string error, string url = null) + public static async Task SendErrorAsync(this IUser user, string title, string error, string url = null) => await (await user.CreateDMChannelAsync()).SendMessageAsync("", embed: new EmbedBuilder().WithColor(NadekoBot.OkColor).WithDescription(error) .WithTitle(title).WithUrl(url)); - public static async Task SendErrorAsync(this IGuildUser user, string error) + public static async Task SendErrorAsync(this IUser user, string error) => await (await user.CreateDMChannelAsync()).SendMessageAsync("", embed: new EmbedBuilder().WithColor(NadekoBot.OkColor).WithDescription(error)); - public static async Task SendFileAsync(this IGuildUser user, string filePath, string caption = null, string text = null, bool isTTS = false) => + public static async Task SendFileAsync(this IUser user, string filePath, string caption = null, string text = null, bool isTTS = false) => await (await user.CreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(File.Open(filePath, FileMode.Open), caption ?? "x", text, isTTS).ConfigureAwait(false); - public static async Task SendFileAsync(this IGuildUser user, Stream fileStream, string fileName, string caption = null, bool isTTS = false) => + public static async Task SendFileAsync(this IUser 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 bool IsAuthor(this IUserMessage msg) => NadekoBot.Client.CurrentUser().Id == msg.Author.Id; public static IEnumerable Members(this IRole role) => - role.Guild.GetUsersAsync().GetAwaiter().GetResult() ?? Enumerable.Empty(); + role.Guild.GetUsersAsync().GetAwaiter().GetResult().Where(u => u.RoleIds.Contains(role.Id)) ?? Enumerable.Empty(); public static Task EmbedAsync(this IMessageChannel ch, EmbedBuilder embed, string msg = "") => ch.SendMessageAsync(msg, embed: embed);