Help command now in db, .showemojis added, permissions more optimal

This commit is contained in:
Kwoth
2016-10-06 19:19:42 +02:00
parent 4016974cef
commit 3136560f15
13 changed files with 1605 additions and 1650 deletions

View File

@@ -23,6 +23,9 @@ namespace NadekoBot.Modules.Administration
_log = LogManager.GetCurrentClassLogger();
NadekoBot.Client.MessageReceived += (imsg) =>
{
if (imsg.Author.IsBot)
return Task.CompletedTask;
var msg = imsg as IUserMessage;
if (msg == null)
return Task.CompletedTask;

View File

@@ -64,7 +64,7 @@ namespace NadekoBot.Modules.Games
private Task PotentialFlowerGeneration(IMessage imsg)
{
var msg = imsg as IUserMessage;
if (msg == null || msg.IsAuthor())
if (msg == null || msg.IsAuthor() || msg.Author.IsBot)
return Task.CompletedTask;
var channel = imsg.Channel as ITextChannel;

View File

@@ -111,7 +111,7 @@ namespace NadekoBot.Modules.Games
{
// has to be a user message
var msg = imsg as IUserMessage;
if (msg == null)
if (msg == null || msg.Author.IsBot)
return Task.CompletedTask;
// channel must be private
IPrivateChannel ch;

View File

@@ -101,6 +101,8 @@ namespace NadekoBot.Modules.Games
private Task AnswerReceived(IMessage imsg)
{
if (imsg.Author.IsBot)
return Task.CompletedTask;
var msg = imsg as IUserMessage;
if (msg == null)
return Task.CompletedTask;

View File

@@ -106,6 +106,8 @@ namespace NadekoBot.Modules.Games.Trivia
private Task PotentialGuess(IMessage imsg)
{
if (imsg.Author.IsBot)
return Task.CompletedTask;
var umsg = imsg as IUserMessage;
if (umsg == null)
return Task.CompletedTask;

View File

@@ -11,31 +11,40 @@ using System.Text;
using Discord.WebSocket;
using System.Collections;
using System.Collections.Generic;
using NadekoBot.Services.Database;
using System.Threading;
namespace NadekoBot.Modules.Help
{
[NadekoModule("Help", "-")]
public partial class Help : DiscordModule
{
public string HelpString {
get {
var str = @"To add me to your server, use this link -> <https://discordapp.com/oauth2/authorize?client_id={0}&scope=bot&permissions=66186303>
You can use `{1}modules` command to see a list of all modules.
You can use `{1}commands ModuleName`
(for example `{1}commands Administration`) to see a list of all of the commands in that module.
For a specific command help, use `{1}h CommandName` (for example {1}h !!q)
private static string helpString { get; }
public static string HelpString => String.Format(helpString, NadekoBot.Credentials.ClientId, NadekoBot.ModulePrefixes[typeof(Help).Name]);
public static string DMHelpString { get; }
**LIST OF COMMANDS CAN BE FOUND ON THIS LINK**
<https://github.com/Kwoth/NadekoBot/blob/master/commandlist.md>
Nadeko Support Server: https://discord.gg/0ehQwTK2RBjAxzEY";
return String.Format(str, NadekoBot.Credentials.ClientId, NadekoBot.ModulePrefixes[typeof(Help).Name]);
static Help()
{
using (var uow = DbHandler.UnitOfWork())
{
var config = uow.BotConfig.GetOrCreate();
helpString = config.HelpString;
DMHelpString = config.DMHelpString;
}
}
public Help(ILocalization loc, CommandService cmds, ShardedDiscordClient client) : base(loc, cmds, client)
{
client.MessageReceived += async (msg) =>
{
if (msg.Author.IsBot)
return;
if (msg.Channel is IPrivateChannel)
{
await msg.Channel.SendMessageAsync(DMHelpString).ConfigureAwait(false);
}
};
}
[NadekoCommand, Usage, Description, Aliases]
@@ -44,6 +53,30 @@ Nadeko Support Server: https://discord.gg/0ehQwTK2RBjAxzEY";
await umsg.Channel.SendMessageAsync("`List of modules:` ```xl\n• " + string.Join("\n• ", _commands.Modules.Select(m => m.Name)) + $"\n``` `Type \"-commands module_name\" to get a list of commands in that module.`")
.ConfigureAwait(false);
await RunWithTypingIntheBackgorund(async () =>
{
await Task.Delay(100000);
}, umsg);
}
private async Task RunWithTypingIntheBackgorund(Func<Task> someFUnc, IUserMessage ctx)
{
var cancelSource = new CancellationTokenSource();
var cancelToken = cancelSource.Token;
var t = Task.Run(async () =>
{
while (!cancelToken.IsCancellationRequested)
{
await Task.Delay(10000);
await ctx.Channel.TriggerTypingAsync();
}
}, cancelToken);
try
{
await someFUnc();
}
finally { cancelSource.Cancel(); }
}
[NadekoCommand, Usage, Description, Aliases]

View File

@@ -176,8 +176,7 @@ namespace NadekoBot.Modules.Permissions
SecondaryTargetName = command.Text.ToLowerInvariant(),
State = action.Value,
};
uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission.Prepend(newPerm);
uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission = newPerm;
uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
await uow.CompleteAsync().ConfigureAwait(false);
}
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{command.Text}` command on this server.").ConfigureAwait(false);
@@ -199,8 +198,7 @@ namespace NadekoBot.Modules.Permissions
SecondaryTargetName = module.Name.ToLowerInvariant(),
State = action.Value,
};
uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission.Prepend(newPerm);
uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission = newPerm;
uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
await uow.CompleteAsync().ConfigureAwait(false);
}
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{module.Name}` module on this server.").ConfigureAwait(false);
@@ -222,8 +220,7 @@ namespace NadekoBot.Modules.Permissions
SecondaryTargetName = command.Text.ToLowerInvariant(),
State = action.Value,
};
uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission.Prepend(newPerm);
uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission = newPerm;
uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
await uow.CompleteAsync().ConfigureAwait(false);
}
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{command.Text}` command for `{user}` user.").ConfigureAwait(false);
@@ -245,8 +242,7 @@ namespace NadekoBot.Modules.Permissions
SecondaryTargetName = module.Name.ToLowerInvariant(),
State = action.Value,
};
uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission.Prepend(newPerm);
uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission = newPerm;
uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
await uow.CompleteAsync().ConfigureAwait(false);
}
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{module.Name}` module for `{user}` user.").ConfigureAwait(false);
@@ -268,8 +264,7 @@ namespace NadekoBot.Modules.Permissions
SecondaryTargetName = command.Text.ToLowerInvariant(),
State = action.Value,
};
uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission.Prepend(newPerm);
uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission = newPerm;
uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
await uow.CompleteAsync().ConfigureAwait(false);
}
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{command.Text}` command for `{role}` role.").ConfigureAwait(false);
@@ -291,8 +286,7 @@ namespace NadekoBot.Modules.Permissions
SecondaryTargetName = module.Name.ToLowerInvariant(),
State = action.Value,
};
uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission.Prepend(newPerm);
uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission = newPerm;
uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
await uow.CompleteAsync().ConfigureAwait(false);
}
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{module.Name}` module for `{role}` role.").ConfigureAwait(false);
@@ -315,8 +309,7 @@ namespace NadekoBot.Modules.Permissions
SecondaryTargetName = command.Text.ToLowerInvariant(),
State = action.Value,
};
uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission.Prepend(newPerm);
uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission = newPerm;
uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
await uow.CompleteAsync().ConfigureAwait(false);
}
}
@@ -342,8 +335,7 @@ namespace NadekoBot.Modules.Permissions
SecondaryTargetName = module.Name.ToLowerInvariant(),
State = action.Value,
};
uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission.Prepend(newPerm);
uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission = newPerm;
uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
await uow.CompleteAsync().ConfigureAwait(false);
}
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{module.Name}` module for `{chnl}` channel.").ConfigureAwait(false);
@@ -365,8 +357,7 @@ namespace NadekoBot.Modules.Permissions
SecondaryTargetName = "*",
State = action.Value,
};
uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission.Prepend(newPerm);
uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission = newPerm;
uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
await uow.CompleteAsync().ConfigureAwait(false);
}
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `ALL MODULES` for `{chnl}` channel.").ConfigureAwait(false);
@@ -388,8 +379,7 @@ namespace NadekoBot.Modules.Permissions
SecondaryTargetName = "*",
State = action.Value,
};
uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission.Prepend(newPerm);
uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission = newPerm;
uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
await uow.CompleteAsync().ConfigureAwait(false);
}
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `ALL MODULES` for `{role}` role.").ConfigureAwait(false);
@@ -411,8 +401,7 @@ namespace NadekoBot.Modules.Permissions
SecondaryTargetName = "*",
State = action.Value,
};
uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission.Prepend(newPerm);
uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission = newPerm;
uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
await uow.CompleteAsync().ConfigureAwait(false);
}
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `ALL MODULES` for `{user}` user.").ConfigureAwait(false);
@@ -434,75 +423,10 @@ namespace NadekoBot.Modules.Permissions
SecondaryTargetName = "*",
State = action.Value,
};
uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission.Prepend(newPerm);
uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission = newPerm;
uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
await uow.CompleteAsync().ConfigureAwait(false);
}
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `ALL MODULES` on this server.").ConfigureAwait(false);
}
//[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
//[RequireContext(ContextType.Guild)]
//public async Task AllChnlCmds(IUserMessage imsg, Module module, PermissionAction action, ITextChannel chnl)
//{
// var channel = (ITextChannel)imsg.Channel;
// using (var uow = DbHandler.UnitOfWork())
// {
// uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission.Add(new Permission
// {
// PrimaryTarget = PrimaryPermissionType.Channel,
// PrimaryTargetId = chnl.Id,
// SecondaryTarget = SecondaryPermissionType.AllCommands,
// SecondaryTargetName = module.Name.ToLowerInvariant(),
// State = action.Value,
// });
// await uow.CompleteAsync().ConfigureAwait(false);
// }
// await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `ALL COMMANDS` from `{module.Name}` module for `{chnl}` channel.").ConfigureAwait(false);
//}
//[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
//[RequireContext(ContextType.Guild)]
//public async Task AllRoleCmds(IUserMessage imsg, Module module, PermissionAction action, IRole role)
//{
// var channel = (ITextChannel)imsg.Channel;
// using (var uow = DbHandler.UnitOfWork())
// {
// uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission.Add(new Permission
// {
// PrimaryTarget = PrimaryPermissionType.Role,
// PrimaryTargetId = role.Id,
// SecondaryTarget = SecondaryPermissionType.AllCommands,
// SecondaryTargetName = module.Name.ToLowerInvariant(),
// State = action.Value,
// });
// await uow.CompleteAsync().ConfigureAwait(false);
// }
// await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `ALL COMMANDS` from `{module.Name}` module for `{role}` role.").ConfigureAwait(false);
//}
//[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
//[RequireContext(ContextType.Guild)]
//public async Task AllUsrCmds(IUserMessage imsg, Module module, PermissionAction action, IUser user)
//{
// var channel = (ITextChannel)imsg.Channel;
// using (var uow = DbHandler.UnitOfWork())
// {
// uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission.Add(new Permission
// {
// PrimaryTarget = PrimaryPermissionType.User,
// PrimaryTargetId = user.Id,
// SecondaryTarget = SecondaryPermissionType.AllCommands,
// SecondaryTargetName = module.Name.ToLowerInvariant(),
// State = action.Value,
// });
// await uow.CompleteAsync().ConfigureAwait(false);
// }
// await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `ALL COMMANDS` from `{module.Name}` module for `{user}` user.").ConfigureAwait(false);
//}
}
}

View File

@@ -144,13 +144,26 @@ namespace NadekoBot.Modules.Utility
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Stats(IUserMessage umsg)
{
var channel = (ITextChannel)umsg.Channel;
var channel = umsg.Channel;
await channel.SendMessageAsync(await NadekoBot.Stats.Print());
}
private Regex emojiFinder { get; } = new Regex(@"<:(?<name>.+?):(?<id>\d*)>", RegexOptions.Compiled);
[NadekoCommand, Usage, Description, Aliases]
public async Task Showemojis(IUserMessage msg, [Remainder] string emojis)
{
var matches = emojiFinder.Matches(emojis);
var result = string.Join("\n", matches.Cast<Match>()
.Select(m => $"`Name:` {m.Groups["name"]} `Link:` http://discordapp.com/api/emojis/{m.Groups["id"]}.png"));
await msg.Channel.SendMessageAsync(result).ConfigureAwait(false);
}
}
}