More work on moving to beta2, almost done

This commit is contained in:
Kwoth 2016-12-21 09:33:47 +01:00
parent caef908a0e
commit 5b55ab6775
27 changed files with 109 additions and 66 deletions

View File

@ -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; //AppendSpace = false;
} }

View File

@ -197,7 +197,7 @@ namespace NadekoBot.Modules.Administration
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
[RequireUserPermission(GuildPermission.Administrator)] [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) if (userThreshold < 2 || userThreshold > 30)
{ {
@ -239,7 +239,7 @@ namespace NadekoBot.Modules.Administration
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
[RequireUserPermission(GuildPermission.Administrator)] [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) if (messageCount < 2 || messageCount > 10)
return; return;

View File

@ -46,7 +46,7 @@ namespace NadekoBot.Modules.Administration
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
[RequireUserPermission(GuildPermission.ManageRoles)] [RequireUserPermission(GuildPermission.ManageRoles)]
public async Task AutoAssignRole(IUserMessage umsg, [Remainder] IRole role = null) public async Task AutoAssignRole([Remainder] IRole role = null)
{ {
GuildConfig conf; GuildConfig conf;
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())

View File

@ -73,7 +73,7 @@ namespace NadekoBot.Modules.Administration
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
[RequireUserPermission(GuildPermission.ManageGuild)] [RequireUserPermission(GuildPermission.ManageGuild)]
public async Task Jcsc(IUserMessage imsg, int token) public async Task Jcsc(int token)
{ {
ConcurrentHashSet<ITextChannel> set; ConcurrentHashSet<ITextChannel> set;
if (!Subscribers.TryGetValue(token, out set)) if (!Subscribers.TryGetValue(token, out set))

View File

@ -748,7 +748,7 @@ namespace NadekoBot.Modules.Administration
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias] //[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
//[RequireContext(ContextType.Guild)] //[RequireContext(ContextType.Guild)]
//public async Task VoiPresIgnore(IUserMessage imsg, IVoiceChannel voiceChannel) //public async Task VoiPresIgnore(IVoiceChannel voiceChannel)
//{ //{
// //var channel = (ITextChannel)Context.Channel; // //var channel = (ITextChannel)Context.Channel;
// int removed; // int removed;

View File

@ -116,7 +116,7 @@ namespace NadekoBot.Modules.Administration
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
[RequireUserPermission(GuildPermission.ManageMessages)] [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) if (minutes < 1 || minutes > 10080)
return; return;

View File

@ -136,7 +136,7 @@ namespace NadekoBot.Modules.Administration
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
[RequireUserPermission(GuildPermission.ManageRoles)] [RequireUserPermission(GuildPermission.ManageRoles)]
[Priority(1)] [Priority(1)]
public async Task SetMuteRole(IUserMessage imsg, [Remainder] string name) public async Task SetMuteRole([Remainder] string name)
{ {
//var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
name = name.Trim(); name = name.Trim();
@ -158,7 +158,7 @@ namespace NadekoBot.Modules.Administration
[RequireUserPermission(GuildPermission.ManageRoles)] [RequireUserPermission(GuildPermission.ManageRoles)]
[Priority(0)] [Priority(0)]
public Task SetMuteRole([Remainder] IRole role) public Task SetMuteRole([Remainder] IRole role)
=> SetMuteRole(Context.Message, role.Name); => SetMuteRole(role.Name);
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]

View File

@ -104,7 +104,7 @@ namespace NadekoBot.Modules.Administration
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[OwnerOnly] [OwnerOnly]
public async Task AddPlaying(IUserMessage umsg, [Remainder] string status) public async Task AddPlaying([Remainder] string status)
{ {
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {
@ -134,7 +134,7 @@ namespace NadekoBot.Modules.Administration
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[OwnerOnly] [OwnerOnly]
public async Task RemovePlaying(IUserMessage umsg, int index) public async Task RemovePlaying(int index)
{ {
index -= 1; index -= 1;

View File

@ -362,7 +362,7 @@ namespace NadekoBot.Modules.Administration
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
[RequireUserPermission(GuildPermission.ManageGuild)] [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); await ServerGreetCommands.SetByeDel(Context.Guild.Id, timer).ConfigureAwait(false);

View File

@ -58,7 +58,7 @@ namespace NadekoBot.Modules.ClashOfClans
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [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) if (!(Context.User as IGuildUser).GuildPermissions.ManageChannels)
return; return;
@ -88,12 +88,12 @@ namespace NadekoBot.Modules.ClashOfClans
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [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 num = 0;
int.TryParse(number, out num); int.TryParse(number, out num);
var warsInfo = GetWarInfo(umsg, Context.Guild, num); var warsInfo = GetWarInfo(Context.Guild, num);
if (warsInfo == null) if (warsInfo == null)
{ {
await Context.Channel.SendErrorAsync("🔰 **That war does not exist.**").ConfigureAwait(false); await Context.Channel.SendErrorAsync("🔰 **That war does not exist.**").ConfigureAwait(false);
@ -114,7 +114,7 @@ namespace NadekoBot.Modules.ClashOfClans
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [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 // if number is null, print all wars in a short way
@ -145,7 +145,7 @@ namespace NadekoBot.Modules.ClashOfClans
var num = 0; var num = 0;
int.TryParse(number, out num); int.TryParse(number, out num);
//if number is not null, print the war needed //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) if (warsInfo == null)
{ {
await Context.Channel.SendErrorAsync("🔰 **That war does not exist.**").ConfigureAwait(false); await Context.Channel.SendErrorAsync("🔰 **That war does not exist.**").ConfigureAwait(false);
@ -156,9 +156,9 @@ namespace NadekoBot.Modules.ClashOfClans
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [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) if (warsInfo == null || warsInfo.Item1.Count == 0)
{ {
await Context.Channel.SendErrorAsync("🔰 **That war does not exist.**").ConfigureAwait(false); await Context.Channel.SendErrorAsync("🔰 **That war does not exist.**").ConfigureAwait(false);
@ -206,7 +206,7 @@ namespace NadekoBot.Modules.ClashOfClans
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task EndWar(int number) public async Task EndWar(int number)
{ {
var warsInfo = GetWarInfo(Context.Message, Context.Guild, number); var warsInfo = GetWarInfo(Context.Guild, number);
if (warsInfo == null) if (warsInfo == null)
{ {
await Context.Channel.SendErrorAsync("🔰 That war does not exist.").ConfigureAwait(false); await Context.Channel.SendErrorAsync("🔰 That war does not exist.").ConfigureAwait(false);
@ -223,9 +223,9 @@ namespace NadekoBot.Modules.ClashOfClans
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [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) if (warsInfo == null || warsInfo.Item1.Count == 0)
{ {
await Context.Channel.SendErrorAsync("🔰 **That war does not exist.**").ConfigureAwait(false); 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) 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) if (warInfo == null || warInfo.Item1.Count == 0)
{ {
await Context.Channel.SendErrorAsync("🔰 **That war does not exist.**").ConfigureAwait(false); await Context.Channel.SendErrorAsync("🔰 **That war does not exist.**").ConfigureAwait(false);
@ -276,7 +276,7 @@ namespace NadekoBot.Modules.ClashOfClans
} }
} }
private static Tuple<List<ClashWar>, int> GetWarInfo(IUserMessage umsg, IGuild guild, int num) private static Tuple<List<ClashWar>, int> GetWarInfo(IGuild guild, int num)
{ {
List<ClashWar> wars = null; List<ClashWar> wars = null;
ClashWars.TryGetValue(guild.Id, out wars); ClashWars.TryGetValue(guild.Id, out wars);

View File

@ -206,7 +206,7 @@ namespace NadekoBot.Modules.CustomReactions
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
public async Task ShowCustReact(IUserMessage imsg, int id) public async Task ShowCustReact(int id)
{ {
ConcurrentHashSet<CustomReaction> customReactions; ConcurrentHashSet<CustomReaction> customReactions;
if (Context.Guild == null) if (Context.Guild == null)
@ -229,7 +229,7 @@ namespace NadekoBot.Modules.CustomReactions
} }
[NadekoCommand, Usage, Description, Aliases] [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)) 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] [NadekoCommand, Usage, Description, Aliases]
public async Task CrStatsClear(IUserMessage imsg, string trigger = null) public async Task CrStatsClear(string trigger = null)
{ {
if (string.IsNullOrWhiteSpace(trigger)) if (string.IsNullOrWhiteSpace(trigger))
{ {
@ -290,7 +290,7 @@ namespace NadekoBot.Modules.CustomReactions
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
public async Task CrStats(IUserMessage imsg, int page = 1) public async Task CrStats(int page = 1)
{ {
if (page < 1) if (page < 1)
return; return;

View File

@ -33,7 +33,7 @@ namespace NadekoBot.Modules.Gambling
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task JoinRace(IUserMessage umsg, int amount = 0) public async Task JoinRace(int amount = 0)
{ {
if (amount < 0) if (amount < 0)
amount = 0; amount = 0;

View File

@ -22,7 +22,7 @@ namespace NadekoBot.Modules.Gambling
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task Flip(IUserMessage imsg, int count = 1) public async Task Flip(int count = 1)
{ {
//var channel = (ITextChannel)Context.Channel; //var channel = (ITextChannel)Context.Channel;
if (count == 1) if (count == 1)
@ -50,7 +50,7 @@ namespace NadekoBot.Modules.Gambling
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [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 channel = (ITextChannel)Context.Channel;
var guildUser = (IGuildUser)Context.User; var guildUser = (IGuildUser)Context.User;

View File

@ -28,7 +28,7 @@ namespace NadekoBot.Modules.Games
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireUserPermission(GuildPermission.ManageMessages)] [RequireUserPermission(GuildPermission.ManageMessages)]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public Task PublicPoll(IUserMessage umsg, [Remainder] string arg = null) public Task PublicPoll([Remainder] string arg = null)
=> InternalStartPoll(arg, isPublic: true); => InternalStartPoll(arg, isPublic: true);
private async Task InternalStartPoll(string arg, bool isPublic = false) private async Task InternalStartPoll(string arg, bool isPublic = false)

View File

@ -38,12 +38,14 @@ namespace NadekoBot.Modules.Help
public async Task Modules() 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); .ConfigureAwait(false);
} }
[NadekoCommand, Usage, Description, Aliases] [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; var channel = Context.Channel;
@ -73,7 +75,7 @@ namespace NadekoBot.Modules.Help
} }
[NadekoCommand, Usage, Description, Aliases] [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; var channel = Context.Channel;
@ -142,7 +144,7 @@ namespace NadekoBot.Modules.Help
helpstr.AppendLine("----------------|--------------|-------"); helpstr.AppendLine("----------------|--------------|-------");
lastModule = com.Module.Name; 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"); helpstr = helpstr.Replace(NadekoBot.Client.CurrentUser().Username , "@BotName");
File.WriteAllText("../../docs/Commands List.md", helpstr.ToString()); File.WriteAllText("../../docs/Commands List.md", helpstr.ToString());

View File

@ -214,7 +214,7 @@ namespace NadekoBot.Modules.NSFW
if (matches.Count == 0) if (matches.Count == 0)
return null; return null;
return matches[rng.Next(0, matches.Count)].Groups["ll"].Value; return "http:" + matches[rng.Next(0, matches.Count)].Groups["ll"].Value;
} }
} }

View File

@ -36,7 +36,7 @@ namespace NadekoBot.Modules.Permissions
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [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; var channel = (ITextChannel)Context.Channel;
if (secs < 0 || secs > 3600) if (secs < 0 || secs > 3600)

View File

@ -180,7 +180,7 @@ namespace NadekoBot.Modules.Permissions
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task FilterWord(IUserMessage imsg, [Remainder] string word) public async Task FilterWord([Remainder] string word)
{ {
var channel = (ITextChannel)Context.Channel; var channel = (ITextChannel)Context.Channel;

View File

@ -53,7 +53,7 @@ namespace NadekoBot.Modules.Searches
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task Anime(IUserMessage umsg, [Remainder] string query) public async Task Anime([Remainder] string query)
{ {
var channel = (ITextChannel)Context.Channel; var channel = (ITextChannel)Context.Channel;
@ -80,7 +80,7 @@ namespace NadekoBot.Modules.Searches
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task Manga(IUserMessage umsg, [Remainder] string query) public async Task Manga([Remainder] string query)
{ {
var channel = (ITextChannel)Context.Channel; var channel = (ITextChannel)Context.Channel;

View File

@ -105,7 +105,7 @@ namespace NadekoBot.Modules.Searches
// public override void Init(CommandGroupBuilder cgb) // 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`") // .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("champ", ParameterType.Required)
// .Parameter("position", ParameterType.Unparsed) // .Parameter("position", ParameterType.Unparsed)

View File

@ -268,7 +268,7 @@ namespace NadekoBot.Modules.Searches
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [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(); var stream = username?.Trim();
if (string.IsNullOrWhiteSpace(stream)) if (string.IsNullOrWhiteSpace(stream))

View File

@ -67,7 +67,7 @@ namespace NadekoBot.Modules.Searches
} }
[NadekoCommand, Usage, Description, Aliases] [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 try
{ {

View File

@ -100,7 +100,7 @@ namespace NadekoBot.Modules.Utility
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
[Priority(1)] [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; IMessageChannel target;
if (meorhere == MeOrHere.Me) if (meorhere == MeOrHere.Me)
@ -111,13 +111,13 @@ namespace NadekoBot.Modules.Utility
{ {
target = Context.Channel; target = Context.Channel;
} }
await Remind(umsg, target, timeStr, message).ConfigureAwait(false); await Remind(target, timeStr, message).ConfigureAwait(false);
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
[Priority(0)] [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; var channel = (ITextChannel)Context.Channel;
@ -193,7 +193,7 @@ namespace NadekoBot.Modules.Utility
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
[OwnerOnly] [OwnerOnly]
public async Task RemindTemplate(IUserMessage umsg, [Remainder] string arg) public async Task RemindTemplate([Remainder] string arg)
{ {
var channel = (ITextChannel)Context.Channel; var channel = (ITextChannel)Context.Channel;

View File

@ -192,7 +192,7 @@ namespace NadekoBot.Modules.Utility
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
[OwnerOnly] [OwnerOnly]
public async Task ListServers(IUserMessage imsg, int page = 1) public async Task ListServers(int page = 1)
{ {
var channel = (ITextChannel)Context.Channel; var channel = (ITextChannel)Context.Channel;

View File

@ -28,7 +28,7 @@ namespace NadekoBot
public static CommandService CommandService { get; private set; } public static CommandService CommandService { get; private set; }
public static CommandHandler CommandHandler { 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 BotCredentials Credentials { get; private set; }
public static GoogleApiService Google { get; private set; } public static GoogleApiService Google { get; private set; }
@ -96,7 +96,7 @@ namespace NadekoBot
//load commands and prefixes //load commands and prefixes
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {
ModulePrefixes = new ConcurrentDictionary<string, string>(uow.BotConfig.GetOrCreate().ModulePrefixes.ToDictionary(m => m.ModuleName, m => m.Prefix)); ModulePrefixes = new ConcurrentDictionary<string, string>(uow.BotConfig.GetOrCreate().ModulePrefixes.OrderByDescending(mp => mp.Prefix.Length).ToDictionary(m => m.ModuleName, m => m.Prefix));
} }
// start handling messages received in commandhandler // start handling messages received in commandhandler
await CommandHandler.StartHandling().ConfigureAwait(false); await CommandHandler.StartHandling().ConfigureAwait(false);

View File

@ -71,6 +71,7 @@ namespace NadekoBot.Services
if (guild != null && guild.OwnerId != msg.Author.Id) if (guild != null && guild.OwnerId != msg.Author.Id)
{ {
//todo split checks into their own modules
if (Permissions.FilterCommands.InviteFilteringChannels.Contains(msg.Channel.Id) || if (Permissions.FilterCommands.InviteFilteringChannels.Contains(msg.Channel.Id) ||
Permissions.FilterCommands.InviteFilteringServers.Contains(guild.Id)) Permissions.FilterCommands.InviteFilteringServers.Contains(guild.Id))
{ {
@ -133,6 +134,18 @@ namespace NadekoBot.Services
} }
catch { } 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 throwaway = Task.Run(async () =>
{ {
var sw = new Stopwatch(); var sw = new Stopwatch();
@ -140,10 +153,10 @@ namespace NadekoBot.Services
try try
{ {
var t = await ExecuteCommand(new CommandContext(_client.MainClient, usrMsg), usrMsg.Content, DependencyMap.Empty, MultiMatchHandling.Best); var exec = await ExecuteCommand(new CommandContext(_client.MainClient, usrMsg), messageContent, DependencyMap.Empty, MultiMatchHandling.Best);
var command = t.Item1; var command = exec.CommandInfo;
var permCache = t.Item2; var permCache = exec.PermissionCache;
var result = t.Item3; var result = exec.Result;
sw.Stop(); sw.Stop();
var channel = (msg.Channel as ITextChannel); var channel = (msg.Channel as ITextChannel);
if (result.IsSuccess) if (result.IsSuccess)
@ -205,14 +218,17 @@ namespace NadekoBot.Services
}); });
return; return;
} }
public Task<ExecuteCommandResult> ExecuteCommandAsync(CommandContext context, int argPos, IDependencyMap dependencyMap = null, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception)
=> ExecuteCommand(context, context.Message.Content.Substring(argPos), dependencyMap, multiMatchHandling);
public async Task<Tuple<CommandInfo, PermissionCache, IResult>> ExecuteCommand(CommandContext context, string input, IDependencyMap dependencyMap = null, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception)
public async Task<ExecuteCommandResult> ExecuteCommand(CommandContext context, string input, IDependencyMap dependencyMap = null, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception)
{ {
dependencyMap = dependencyMap ?? DependencyMap.Empty; dependencyMap = dependencyMap ?? DependencyMap.Empty;
var searchResult = _commandService.Search(context, input); var searchResult = _commandService.Search(context, input);
if (!searchResult.IsSuccess) if (!searchResult.IsSuccess)
return new Tuple<CommandInfo, PermissionCache, IResult>(null, null, searchResult); return new ExecuteCommandResult(null, null, searchResult);
var commands = searchResult.Commands; var commands = searchResult.Commands;
for (int i = commands.Count - 1; i >= 0; i--) for (int i = commands.Count - 1; i >= 0; i--)
@ -221,7 +237,7 @@ namespace NadekoBot.Services
if (!preconditionResult.IsSuccess) if (!preconditionResult.IsSuccess)
{ {
if (commands.Count == 1) if (commands.Count == 1)
return new Tuple<CommandInfo, PermissionCache, IResult>(null, null, preconditionResult); return new ExecuteCommandResult(null, null, preconditionResult);
else else
continue; continue;
} }
@ -245,7 +261,7 @@ namespace NadekoBot.Services
if (!parseResult.IsSuccess) if (!parseResult.IsSuccess)
{ {
if (commands.Count == 1) if (commands.Count == 1)
return new Tuple<CommandInfo, PermissionCache, IResult>(null, null, parseResult); return new ExecuteCommandResult(null, null, parseResult);
else else
continue; continue;
} }
@ -273,7 +289,7 @@ namespace NadekoBot.Services
if (!resetCommand && !pc.RootPermission.AsEnumerable().CheckPermissions(context.Message, cmd.Aliases.First(), cmd.Module.Name, out index)) 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."; var returnMsg = $"Permission number #{index + 1} **{pc.RootPermission.GetAt(index).GetCommand((SocketGuild)context.Guild)}** is preventing this action.";
return new Tuple<CommandInfo, PermissionCache, IResult>(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())) if (!((IGuildUser)context.User).GetRoles().Any(r => r.Name.Trim().ToLowerInvariant() == pc.PermRole.Trim().ToLowerInvariant()))
{ {
return new Tuple<CommandInfo, PermissionCache, IResult>(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)) if (CmdCdsCommands.HasCooldown(cmd, context.Guild, context.User))
return new Tuple<CommandInfo, PermissionCache, IResult>(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<CommandInfo, PermissionCache, IResult>(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<CommandInfo, PermissionCache, IResult>(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;
}
} }
} }
} }

View File

@ -1,4 +1,5 @@
using Discord; using Discord;
using Discord.Commands;
using ImageSharp; using ImageSharp;
using Newtonsoft.Json; using Newtonsoft.Json;
using System; 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"); 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<IMessage> SendMessageToOwnerAsync(this IGuild guild, string message) public static async Task<IMessage> SendMessageToOwnerAsync(this IGuild guild, string message)
{ {
var ownerPrivate = await (await guild.GetOwnerAsync().ConfigureAwait(false)).CreateDMChannelAsync() var ownerPrivate = await (await guild.GetOwnerAsync().ConfigureAwait(false)).CreateDMChannelAsync()
@ -85,8 +96,8 @@ namespace NadekoBot.Extensions
public static async Task<IUserMessage> SendErrorAsync(this IGuildUser user, string error) public static async Task<IUserMessage> SendErrorAsync(this IGuildUser user, string error)
=> await (await user.CreateDMChannelAsync()).SendMessageAsync("", embed: new EmbedBuilder().WithColor(NadekoBot.OkColor).WithDescription(error)); => await (await user.CreateDMChannelAsync()).SendMessageAsync("", embed: new EmbedBuilder().WithColor(NadekoBot.OkColor).WithDescription(error));
public static async Task<IUserMessage> SendFileAsync(this IGuildUser user, string filePath, string caption = null, bool isTTS = false) => public static async Task<IUserMessage> SendFileAsync(this IGuildUser user, string filePath, string caption = null, string text = null, bool isTTS = false) =>
await (await user.CreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(filePath, caption, isTTS).ConfigureAwait(false); await (await user.CreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(File.Open(filePath, FileMode.Open), caption ?? "x", text, isTTS).ConfigureAwait(false);
public static async Task<IUserMessage> SendFileAsync(this IGuildUser user, Stream fileStream, string fileName, string caption = null, bool isTTS = false) => public static async Task<IUserMessage> 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); await (await user.CreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(fileStream, fileName, caption, isTTS).ConfigureAwait(false);