diff --git a/src/NadekoBot/Attributes/NadekoModule.cs b/src/NadekoBot/Attributes/NadekoModule.cs index 832d7ad4..30ef1c51 100644 --- a/src/NadekoBot/Attributes/NadekoModule.cs +++ b/src/NadekoBot/Attributes/NadekoModule.cs @@ -26,7 +26,7 @@ namespace NadekoBot.Attributes } } - public NadekoModuleAttribute(string moduleName, string defaultPrefix) : base(GetModulePrefix(moduleName, defaultPrefix)) + public NadekoModuleAttribute(string moduleName, string defaultPrefix) : base(GetModulePrefix(moduleName, defaultPrefix), moduleName) { //AppendSpace = false; } diff --git a/src/NadekoBot/Modules/Administration/Commands/AntiRaidCommands.cs b/src/NadekoBot/Modules/Administration/Commands/AntiRaidCommands.cs index a220076d..2ef5dff0 100644 --- a/src/NadekoBot/Modules/Administration/Commands/AntiRaidCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/AntiRaidCommands.cs @@ -197,7 +197,7 @@ namespace NadekoBot.Modules.Administration [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] [RequireUserPermission(GuildPermission.Administrator)] - public async Task AntiRaid(IUserMessage imsg, int userThreshold, int seconds, PunishmentAction action) + public async Task AntiRaid(int userThreshold, int seconds, PunishmentAction action) { if (userThreshold < 2 || userThreshold > 30) { @@ -239,7 +239,7 @@ namespace NadekoBot.Modules.Administration [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] [RequireUserPermission(GuildPermission.Administrator)] - public async Task AntiSpam(IUserMessage imsg, int messageCount=3, PunishmentAction action = PunishmentAction.Mute) + public async Task AntiSpam(int messageCount=3, PunishmentAction action = PunishmentAction.Mute) { if (messageCount < 2 || messageCount > 10) return; diff --git a/src/NadekoBot/Modules/Administration/Commands/AutoAssignRoleCommands.cs b/src/NadekoBot/Modules/Administration/Commands/AutoAssignRoleCommands.cs index 902f4348..41c43c46 100644 --- a/src/NadekoBot/Modules/Administration/Commands/AutoAssignRoleCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/AutoAssignRoleCommands.cs @@ -46,7 +46,7 @@ namespace NadekoBot.Modules.Administration [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] [RequireUserPermission(GuildPermission.ManageRoles)] - public async Task AutoAssignRole(IUserMessage umsg, [Remainder] IRole role = null) + public async Task AutoAssignRole([Remainder] IRole role = null) { GuildConfig conf; using (var uow = DbHandler.UnitOfWork()) diff --git a/src/NadekoBot/Modules/Administration/Commands/CrossServerTextChannel.cs b/src/NadekoBot/Modules/Administration/Commands/CrossServerTextChannel.cs index 09335700..85847287 100644 --- a/src/NadekoBot/Modules/Administration/Commands/CrossServerTextChannel.cs +++ b/src/NadekoBot/Modules/Administration/Commands/CrossServerTextChannel.cs @@ -73,7 +73,7 @@ namespace NadekoBot.Modules.Administration [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] [RequireUserPermission(GuildPermission.ManageGuild)] - public async Task Jcsc(IUserMessage imsg, int token) + public async Task Jcsc(int token) { ConcurrentHashSet set; if (!Subscribers.TryGetValue(token, out set)) diff --git a/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs b/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs index ab358cb7..91a25b1b 100644 --- a/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs @@ -748,7 +748,7 @@ namespace NadekoBot.Modules.Administration //[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias] //[RequireContext(ContextType.Guild)] - //public async Task VoiPresIgnore(IUserMessage imsg, IVoiceChannel voiceChannel) + //public async Task VoiPresIgnore(IVoiceChannel voiceChannel) //{ // //var channel = (ITextChannel)Context.Channel; // int removed; diff --git a/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs b/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs index e470d4d1..c28f2700 100644 --- a/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs +++ b/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs @@ -116,7 +116,7 @@ namespace NadekoBot.Modules.Administration [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] [RequireUserPermission(GuildPermission.ManageMessages)] - public async Task Repeat(IUserMessage imsg, int minutes, [Remainder] string message) + public async Task Repeat(int minutes, [Remainder] string message) { if (minutes < 1 || minutes > 10080) return; diff --git a/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs b/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs index fbf443de..007ac331 100644 --- a/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs @@ -136,7 +136,7 @@ namespace NadekoBot.Modules.Administration [RequireContext(ContextType.Guild)] [RequireUserPermission(GuildPermission.ManageRoles)] [Priority(1)] - public async Task SetMuteRole(IUserMessage imsg, [Remainder] string name) + public async Task SetMuteRole([Remainder] string name) { //var channel = (ITextChannel)Context.Channel; name = name.Trim(); @@ -158,7 +158,7 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.ManageRoles)] [Priority(0)] public Task SetMuteRole([Remainder] IRole role) - => SetMuteRole(Context.Message, role.Name); + => SetMuteRole(role.Name); [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] diff --git a/src/NadekoBot/Modules/Administration/Commands/PlayingRotateCommands.cs b/src/NadekoBot/Modules/Administration/Commands/PlayingRotateCommands.cs index 0101e1c0..cd06fcff 100644 --- a/src/NadekoBot/Modules/Administration/Commands/PlayingRotateCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/PlayingRotateCommands.cs @@ -104,7 +104,7 @@ namespace NadekoBot.Modules.Administration [NadekoCommand, Usage, Description, Aliases] [OwnerOnly] - public async Task AddPlaying(IUserMessage umsg, [Remainder] string status) + public async Task AddPlaying([Remainder] string status) { using (var uow = DbHandler.UnitOfWork()) { @@ -134,7 +134,7 @@ namespace NadekoBot.Modules.Administration [NadekoCommand, Usage, Description, Aliases] [OwnerOnly] - public async Task RemovePlaying(IUserMessage umsg, int index) + public async Task RemovePlaying(int index) { index -= 1; diff --git a/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs b/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs index a663d120..44e8b37d 100644 --- a/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs @@ -362,7 +362,7 @@ namespace NadekoBot.Modules.Administration [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] [RequireUserPermission(GuildPermission.ManageGuild)] - public async Task ByeDel(IUserMessage umsg, int timer = 30) + public async Task ByeDel(int timer = 30) { await ServerGreetCommands.SetByeDel(Context.Guild.Id, timer).ConfigureAwait(false); diff --git a/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs b/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs index d5831e81..4ee08f4b 100644 --- a/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs +++ b/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs @@ -58,7 +58,7 @@ namespace NadekoBot.Modules.ClashOfClans [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] - public async Task CreateWar(IUserMessage umsg, int size, [Remainder] string enemyClan = null) + public async Task CreateWar(int size, [Remainder] string enemyClan = null) { if (!(Context.User as IGuildUser).GuildPermissions.ManageChannels) return; @@ -88,12 +88,12 @@ namespace NadekoBot.Modules.ClashOfClans [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] - public async Task StartWar(IUserMessage umsg, [Remainder] string number = null) + public async Task StartWar([Remainder] string number = null) { int num = 0; int.TryParse(number, out num); - var warsInfo = GetWarInfo(umsg, Context.Guild, num); + var warsInfo = GetWarInfo(Context.Guild, num); if (warsInfo == null) { await Context.Channel.SendErrorAsync("🔰 **That war does not exist.**").ConfigureAwait(false); @@ -114,7 +114,7 @@ namespace NadekoBot.Modules.ClashOfClans [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] - public async Task ListWar(IUserMessage umsg, [Remainder] string number = null) + public async Task ListWar([Remainder] string number = null) { // if number is null, print all wars in a short way @@ -145,7 +145,7 @@ namespace NadekoBot.Modules.ClashOfClans var num = 0; int.TryParse(number, out num); //if number is not null, print the war needed - var warsInfo = GetWarInfo(umsg, Context.Guild, num); + var warsInfo = GetWarInfo(Context.Guild, num); if (warsInfo == null) { await Context.Channel.SendErrorAsync("🔰 **That war does not exist.**").ConfigureAwait(false); @@ -156,9 +156,9 @@ namespace NadekoBot.Modules.ClashOfClans [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] - public async Task Claim(IUserMessage umsg, int number, int baseNumber, [Remainder] string other_name = null) + public async Task Claim(int number, int baseNumber, [Remainder] string other_name = null) { - var warsInfo = GetWarInfo(umsg, Context.Guild, number); + var warsInfo = GetWarInfo(Context.Guild, number); if (warsInfo == null || warsInfo.Item1.Count == 0) { await Context.Channel.SendErrorAsync("🔰 **That war does not exist.**").ConfigureAwait(false); @@ -206,7 +206,7 @@ namespace NadekoBot.Modules.ClashOfClans [RequireContext(ContextType.Guild)] public async Task EndWar(int number) { - var warsInfo = GetWarInfo(Context.Message, Context.Guild, number); + var warsInfo = GetWarInfo(Context.Guild, number); if (warsInfo == null) { await Context.Channel.SendErrorAsync("🔰 That war does not exist.").ConfigureAwait(false); @@ -223,9 +223,9 @@ namespace NadekoBot.Modules.ClashOfClans [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] - public async Task Unclaim(IUserMessage umsg, int number, [Remainder] string otherName = null) + public async Task Unclaim(int number, [Remainder] string otherName = null) { - var warsInfo = GetWarInfo(umsg, Context.Guild, number); + var warsInfo = GetWarInfo(Context.Guild, number); if (warsInfo == null || warsInfo.Item1.Count == 0) { await Context.Channel.SendErrorAsync("🔰 **That war does not exist.**").ConfigureAwait(false); @@ -250,7 +250,7 @@ namespace NadekoBot.Modules.ClashOfClans private async Task FinishClaim(int number, int baseNumber, int stars = 3) { - var warInfo = GetWarInfo(Context.Message, Context.Guild, number); + var warInfo = GetWarInfo(Context.Guild, number); if (warInfo == null || warInfo.Item1.Count == 0) { await Context.Channel.SendErrorAsync("🔰 **That war does not exist.**").ConfigureAwait(false); @@ -276,7 +276,7 @@ namespace NadekoBot.Modules.ClashOfClans } } - private static Tuple, int> GetWarInfo(IUserMessage umsg, IGuild guild, int num) + private static Tuple, int> GetWarInfo(IGuild guild, int num) { List wars = null; ClashWars.TryGetValue(guild.Id, out wars); diff --git a/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs b/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs index c16f7c91..4f99c99b 100644 --- a/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs +++ b/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs @@ -206,7 +206,7 @@ namespace NadekoBot.Modules.CustomReactions } [NadekoCommand, Usage, Description, Aliases] - public async Task ShowCustReact(IUserMessage imsg, int id) + public async Task ShowCustReact(int id) { ConcurrentHashSet customReactions; if (Context.Guild == null) @@ -229,7 +229,7 @@ namespace NadekoBot.Modules.CustomReactions } [NadekoCommand, Usage, Description, Aliases] - public async Task DelCustReact(IUserMessage imsg, int id) + public async Task DelCustReact(int id) { if ((Context.Guild == null && !NadekoBot.Credentials.IsOwner(Context.User)) || (Context.Guild != null && !((IGuildUser)Context.User).GuildPermissions.Administrator)) { @@ -268,7 +268,7 @@ namespace NadekoBot.Modules.CustomReactions } [NadekoCommand, Usage, Description, Aliases] - public async Task CrStatsClear(IUserMessage imsg, string trigger = null) + public async Task CrStatsClear(string trigger = null) { if (string.IsNullOrWhiteSpace(trigger)) { @@ -290,7 +290,7 @@ namespace NadekoBot.Modules.CustomReactions } [NadekoCommand, Usage, Description, Aliases] - public async Task CrStats(IUserMessage imsg, int page = 1) + public async Task CrStats(int page = 1) { if (page < 1) return; diff --git a/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs b/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs index 5751d1b2..50f4f450 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs @@ -33,7 +33,7 @@ namespace NadekoBot.Modules.Gambling [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] - public async Task JoinRace(IUserMessage umsg, int amount = 0) + public async Task JoinRace(int amount = 0) { if (amount < 0) amount = 0; diff --git a/src/NadekoBot/Modules/Gambling/Commands/FlipCoinCommand.cs b/src/NadekoBot/Modules/Gambling/Commands/FlipCoinCommand.cs index 5ea1c8a0..fc6c60a6 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/FlipCoinCommand.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/FlipCoinCommand.cs @@ -22,7 +22,7 @@ namespace NadekoBot.Modules.Gambling [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] - public async Task Flip(IUserMessage imsg, int count = 1) + public async Task Flip(int count = 1) { //var channel = (ITextChannel)Context.Channel; if (count == 1) @@ -50,7 +50,7 @@ namespace NadekoBot.Modules.Gambling [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] - public async Task Betflip(IUserMessage umsg, int amount, string guess) + public async Task Betflip(int amount, string guess) { //var channel = (ITextChannel)Context.Channel; var guildUser = (IGuildUser)Context.User; diff --git a/src/NadekoBot/Modules/Games/Commands/PollCommands.cs b/src/NadekoBot/Modules/Games/Commands/PollCommands.cs index 41ea2253..ad077586 100644 --- a/src/NadekoBot/Modules/Games/Commands/PollCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/PollCommands.cs @@ -28,7 +28,7 @@ namespace NadekoBot.Modules.Games [NadekoCommand, Usage, Description, Aliases] [RequireUserPermission(GuildPermission.ManageMessages)] [RequireContext(ContextType.Guild)] - public Task PublicPoll(IUserMessage umsg, [Remainder] string arg = null) + public Task PublicPoll([Remainder] string arg = null) => InternalStartPoll(arg, isPublic: true); private async Task InternalStartPoll(string arg, bool isPublic = false) diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index 165c6203..16fb59f3 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -38,12 +38,14 @@ namespace NadekoBot.Modules.Help public async Task Modules() { - await Context.Channel.SendMessageAsync("📜 **List of modules:** ```css\n• " + string.Join("\n• ", NadekoBot.CommandService.Modules.Select(m => m.Name)) + $"\n``` ℹ️ **Type** `-commands module_name` **to get a list of commands in that module.** ***e.g.*** `-commands games`") + 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`") .ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] - public async Task Commands(IUserMessage umsg, [Remainder] string module = null) + public async Task Commands([Remainder] string module = null) { var channel = Context.Channel; @@ -73,7 +75,7 @@ namespace NadekoBot.Modules.Help } [NadekoCommand, Usage, Description, Aliases] - public async Task H(IUserMessage umsg, [Remainder] string comToFind = null) + public async Task H([Remainder] string comToFind = null) { var channel = Context.Channel; @@ -142,7 +144,7 @@ namespace NadekoBot.Modules.Help helpstr.AppendLine("----------------|--------------|-------"); lastModule = com.Module.Name; } - helpstr.AppendLine($"{string.Join(" ", com.Aliases.Select(a => "`" + a + "`"))} | {string.Format(com.Summary, com.Module.Prefix)} {GetCommandRequirements(com)} | {string.Format(com.Remarks, com.Module.Prefix)}"); + helpstr.AppendLine($"{string.Join(" ", com.Aliases.Select(a => "`" + a + "`"))} | {string.Format(com.Summary, com.Module.GetPrefix())} {GetCommandRequirements(com)} | {string.Format(com.Remarks, com.Module.GetPrefix())}"); } helpstr = helpstr.Replace(NadekoBot.Client.CurrentUser().Username , "@BotName"); File.WriteAllText("../../docs/Commands List.md", helpstr.ToString()); diff --git a/src/NadekoBot/Modules/NSFW/NSFW.cs b/src/NadekoBot/Modules/NSFW/NSFW.cs index e4b0fa29..b01d9480 100644 --- a/src/NadekoBot/Modules/NSFW/NSFW.cs +++ b/src/NadekoBot/Modules/NSFW/NSFW.cs @@ -214,7 +214,7 @@ namespace NadekoBot.Modules.NSFW if (matches.Count == 0) return null; - return matches[rng.Next(0, matches.Count)].Groups["ll"].Value; + return "http:" + matches[rng.Next(0, matches.Count)].Groups["ll"].Value; } } diff --git a/src/NadekoBot/Modules/Permissions/Commands/CmdCdsCommands.cs b/src/NadekoBot/Modules/Permissions/Commands/CmdCdsCommands.cs index 4097783d..8ba1379a 100644 --- a/src/NadekoBot/Modules/Permissions/Commands/CmdCdsCommands.cs +++ b/src/NadekoBot/Modules/Permissions/Commands/CmdCdsCommands.cs @@ -36,7 +36,7 @@ namespace NadekoBot.Modules.Permissions } [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] - public async Task CmdCooldown(IUserMessage imsg, CommandInfo command, int secs) + public async Task CmdCooldown(CommandInfo command, int secs) { var channel = (ITextChannel)Context.Channel; if (secs < 0 || secs > 3600) diff --git a/src/NadekoBot/Modules/Permissions/Commands/FilterCommands.cs b/src/NadekoBot/Modules/Permissions/Commands/FilterCommands.cs index c6ca8919..c4711a7f 100644 --- a/src/NadekoBot/Modules/Permissions/Commands/FilterCommands.cs +++ b/src/NadekoBot/Modules/Permissions/Commands/FilterCommands.cs @@ -180,7 +180,7 @@ namespace NadekoBot.Modules.Permissions [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] - public async Task FilterWord(IUserMessage imsg, [Remainder] string word) + public async Task FilterWord([Remainder] string word) { var channel = (ITextChannel)Context.Channel; diff --git a/src/NadekoBot/Modules/Searches/Commands/AnimeSearchCommands.cs b/src/NadekoBot/Modules/Searches/Commands/AnimeSearchCommands.cs index 66402bb4..7508012d 100644 --- a/src/NadekoBot/Modules/Searches/Commands/AnimeSearchCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/AnimeSearchCommands.cs @@ -53,7 +53,7 @@ namespace NadekoBot.Modules.Searches [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] - public async Task Anime(IUserMessage umsg, [Remainder] string query) + public async Task Anime([Remainder] string query) { var channel = (ITextChannel)Context.Channel; @@ -80,7 +80,7 @@ namespace NadekoBot.Modules.Searches [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] - public async Task Manga(IUserMessage umsg, [Remainder] string query) + public async Task Manga([Remainder] string query) { var channel = (ITextChannel)Context.Channel; diff --git a/src/NadekoBot/Modules/Searches/Commands/LoLCommands.cs b/src/NadekoBot/Modules/Searches/Commands/LoLCommands.cs index d7b3a857..e0e95d97 100644 --- a/src/NadekoBot/Modules/Searches/Commands/LoLCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/LoLCommands.cs @@ -105,7 +105,7 @@ namespace NadekoBot.Modules.Searches // public override void Init(CommandGroupBuilder cgb) // { -// cgb.CreateCommand(Module.Prefix + "lolchamp") +// cgb.CreateCommand(Module.Name + "lolchamp") // .Description($"Shows League Of Legends champion statistics. If there are spaces/apostrophes or in the name - omit them. Optional second parameter is a role. |`{Prefix}lolchamp Riven` or `{Prefix}lolchamp Annie sup`") // .Parameter("champ", ParameterType.Required) // .Parameter("position", ParameterType.Unparsed) diff --git a/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs b/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs index 25433273..f607a5d9 100644 --- a/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs @@ -268,7 +268,7 @@ namespace NadekoBot.Modules.Searches [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] - public async Task CheckStream(IUserMessage imsg, FollowedStream.FollowedStreamType platform, [Remainder] string username) + public async Task CheckStream(FollowedStream.FollowedStreamType platform, [Remainder] string username) { var stream = username?.Trim(); if (string.IsNullOrWhiteSpace(stream)) diff --git a/src/NadekoBot/Modules/Searches/Commands/Translator.cs b/src/NadekoBot/Modules/Searches/Commands/Translator.cs index 121ff140..0222ba81 100644 --- a/src/NadekoBot/Modules/Searches/Commands/Translator.cs +++ b/src/NadekoBot/Modules/Searches/Commands/Translator.cs @@ -67,7 +67,7 @@ namespace NadekoBot.Modules.Searches } [NadekoCommand, Usage, Description, Aliases] - public async Task Translate(IUserMessage umsg, string langs, [Remainder] string text = null) + public async Task Translate(string langs, [Remainder] string text = null) { try { diff --git a/src/NadekoBot/Modules/Utility/Commands/Remind.cs b/src/NadekoBot/Modules/Utility/Commands/Remind.cs index ef6a92b2..92bbb3fb 100644 --- a/src/NadekoBot/Modules/Utility/Commands/Remind.cs +++ b/src/NadekoBot/Modules/Utility/Commands/Remind.cs @@ -100,7 +100,7 @@ namespace NadekoBot.Modules.Utility [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] [Priority(1)] - public async Task Remind(IUserMessage umsg, MeOrHere meorhere, string timeStr, [Remainder] string message) + public async Task Remind(MeOrHere meorhere, string timeStr, [Remainder] string message) { IMessageChannel target; if (meorhere == MeOrHere.Me) @@ -111,13 +111,13 @@ namespace NadekoBot.Modules.Utility { target = Context.Channel; } - await Remind(umsg, target, timeStr, message).ConfigureAwait(false); + await Remind(target, timeStr, message).ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] [Priority(0)] - public async Task Remind(IUserMessage umsg, IMessageChannel ch, string timeStr, [Remainder] string message) + public async Task Remind(IMessageChannel ch, string timeStr, [Remainder] string message) { var channel = (ITextChannel)Context.Channel; @@ -193,7 +193,7 @@ namespace NadekoBot.Modules.Utility [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] [OwnerOnly] - public async Task RemindTemplate(IUserMessage umsg, [Remainder] string arg) + public async Task RemindTemplate([Remainder] string arg) { var channel = (ITextChannel)Context.Channel; diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index cb87b710..d24d51a0 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -192,7 +192,7 @@ namespace NadekoBot.Modules.Utility [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] [OwnerOnly] - public async Task ListServers(IUserMessage imsg, int page = 1) + public async Task ListServers(int page = 1) { var channel = (ITextChannel)Context.Channel; diff --git a/src/NadekoBot/NadekoBot.cs b/src/NadekoBot/NadekoBot.cs index 1178508e..3ee8e2e5 100644 --- a/src/NadekoBot/NadekoBot.cs +++ b/src/NadekoBot/NadekoBot.cs @@ -28,7 +28,7 @@ namespace NadekoBot public static CommandService CommandService { get; private set; } public static CommandHandler CommandHandler { get; private set; } - public static ShardedDiscordClient Client { get; private set; } + public static ShardedDiscordClient Client { get; private set; } public static BotCredentials Credentials { get; private set; } public static GoogleApiService Google { get; private set; } @@ -96,7 +96,7 @@ namespace NadekoBot //load commands and prefixes using (var uow = DbHandler.UnitOfWork()) { - ModulePrefixes = new ConcurrentDictionary(uow.BotConfig.GetOrCreate().ModulePrefixes.ToDictionary(m => m.ModuleName, m => m.Prefix)); + ModulePrefixes = new ConcurrentDictionary(uow.BotConfig.GetOrCreate().ModulePrefixes.OrderByDescending(mp => mp.Prefix.Length).ToDictionary(m => m.ModuleName, m => m.Prefix)); } // start handling messages received in commandhandler await CommandHandler.StartHandling().ConfigureAwait(false); diff --git a/src/NadekoBot/Services/CommandHandler.cs b/src/NadekoBot/Services/CommandHandler.cs index 42d4e9d1..d46f1a66 100644 --- a/src/NadekoBot/Services/CommandHandler.cs +++ b/src/NadekoBot/Services/CommandHandler.cs @@ -71,6 +71,7 @@ namespace NadekoBot.Services if (guild != null && guild.OwnerId != msg.Author.Id) { + //todo split checks into their own modules if (Permissions.FilterCommands.InviteFilteringChannels.Contains(msg.Channel.Id) || Permissions.FilterCommands.InviteFilteringServers.Contains(guild.Id)) { @@ -133,6 +134,18 @@ 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; + } + + } + + var throwaway = Task.Run(async () => { var sw = new Stopwatch(); @@ -140,10 +153,10 @@ namespace NadekoBot.Services try { - var t = await ExecuteCommand(new CommandContext(_client.MainClient, usrMsg), usrMsg.Content, DependencyMap.Empty, MultiMatchHandling.Best); - var command = t.Item1; - var permCache = t.Item2; - var result = t.Item3; + var exec = await ExecuteCommand(new CommandContext(_client.MainClient, usrMsg), messageContent, DependencyMap.Empty, MultiMatchHandling.Best); + var command = exec.CommandInfo; + var permCache = exec.PermissionCache; + var result = exec.Result; sw.Stop(); var channel = (msg.Channel as ITextChannel); if (result.IsSuccess) @@ -205,14 +218,17 @@ namespace NadekoBot.Services }); return; } + public Task ExecuteCommandAsync(CommandContext context, int argPos, IDependencyMap dependencyMap = null, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception) + => ExecuteCommand(context, context.Message.Content.Substring(argPos), dependencyMap, multiMatchHandling); - public async Task> ExecuteCommand(CommandContext context, string input, IDependencyMap dependencyMap = null, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception) + + public async Task ExecuteCommand(CommandContext context, string input, IDependencyMap dependencyMap = null, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception) { dependencyMap = dependencyMap ?? DependencyMap.Empty; var searchResult = _commandService.Search(context, input); if (!searchResult.IsSuccess) - return new Tuple(null, null, searchResult); + return new ExecuteCommandResult(null, null, searchResult); var commands = searchResult.Commands; for (int i = commands.Count - 1; i >= 0; i--) @@ -221,7 +237,7 @@ namespace NadekoBot.Services if (!preconditionResult.IsSuccess) { if (commands.Count == 1) - return new Tuple(null, null, preconditionResult); + return new ExecuteCommandResult(null, null, preconditionResult); else continue; } @@ -245,7 +261,7 @@ namespace NadekoBot.Services if (!parseResult.IsSuccess) { if (commands.Count == 1) - return new Tuple(null, null, parseResult); + return new ExecuteCommandResult(null, null, parseResult); else continue; } @@ -273,7 +289,7 @@ namespace NadekoBot.Services if (!resetCommand && !pc.RootPermission.AsEnumerable().CheckPermissions(context.Message, cmd.Aliases.First(), cmd.Module.Name, out index)) { var returnMsg = $"Permission number #{index + 1} **{pc.RootPermission.GetAt(index).GetCommand((SocketGuild)context.Guild)}** is preventing this action."; - return new Tuple(cmd, pc, SearchResult.FromError(CommandError.Exception, returnMsg)); + return new ExecuteCommandResult(cmd, pc, SearchResult.FromError(CommandError.Exception, returnMsg)); } @@ -281,19 +297,33 @@ namespace NadekoBot.Services { if (!((IGuildUser)context.User).GetRoles().Any(r => r.Name.Trim().ToLowerInvariant() == pc.PermRole.Trim().ToLowerInvariant())) { - return new Tuple(cmd, pc, SearchResult.FromError(CommandError.Exception, $"You need the **{pc.PermRole}** role in order to use permission commands.")); + return new ExecuteCommandResult(cmd, pc, SearchResult.FromError(CommandError.Exception, $"You need the **{pc.PermRole}** role in order to use permission commands.")); } } } if (CmdCdsCommands.HasCooldown(cmd, context.Guild, context.User)) - return new Tuple(cmd, null, SearchResult.FromError(CommandError.Exception, $"That command is on cooldown for you.")); + return new ExecuteCommandResult(cmd, null, SearchResult.FromError(CommandError.Exception, $"That command is on cooldown for you.")); - return new Tuple(commands[i], null, await commands[i].Execute(context, parseResult, dependencyMap)); + return new ExecuteCommandResult(commands[i], null, await commands[i].Execute(context, parseResult, dependencyMap)); } - return new Tuple(null, null, SearchResult.FromError(CommandError.UnknownCommand, "This input does not match any overload.")); + return new ExecuteCommandResult(null, null, SearchResult.FromError(CommandError.UnknownCommand, "This input does not match any overload.")); + } + + public struct ExecuteCommandResult + { + public readonly CommandInfo CommandInfo; + public readonly PermissionCache PermissionCache; + public readonly IResult Result; + + public ExecuteCommandResult(CommandInfo commandInfo, PermissionCache cache, IResult result) + { + this.CommandInfo = commandInfo; + this.PermissionCache = cache; + this.Result = result; + } } } } diff --git a/src/NadekoBot/_Extensions/Extensions.cs b/src/NadekoBot/_Extensions/Extensions.cs index 37ddc535..97692a5d 100644 --- a/src/NadekoBot/_Extensions/Extensions.cs +++ b/src/NadekoBot/_Extensions/Extensions.cs @@ -1,4 +1,5 @@ using Discord; +using Discord.Commands; using ImageSharp; using Newtonsoft.Json; using System; @@ -22,6 +23,16 @@ namespace NadekoBot.Extensions http.DefaultRequestHeaders.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); } + public static string GetPrefix(this ModuleInfo module) => NadekoBot.ModulePrefixes[module.GetTopLevelModule().Name]; + + public static ModuleInfo GetTopLevelModule(this ModuleInfo module) { + while (module.Parent != null) + { + module = module.Parent; + } + return module; + } + public static async Task SendMessageToOwnerAsync(this IGuild guild, string message) { var ownerPrivate = await (await guild.GetOwnerAsync().ConfigureAwait(false)).CreateDMChannelAsync() @@ -85,8 +96,8 @@ namespace NadekoBot.Extensions public static async Task SendErrorAsync(this IGuildUser 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, bool isTTS = false) => - await (await user.CreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(filePath, caption, isTTS).ConfigureAwait(false); + public static async Task SendFileAsync(this IGuildUser 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) => await (await user.CreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(fileStream, fileName, caption, isTTS).ConfigureAwait(false);