Custom reaction trigger fix, translate moved to searches module, removed translator module

This commit is contained in:
Kwoth 2016-10-10 05:04:50 +02:00
parent fae2829a68
commit bd1efc6f75
3 changed files with 9 additions and 11 deletions

View File

@ -42,18 +42,19 @@ namespace NadekoBot.Modules.CustomReactions
var t = Task.Run(async () => var t = Task.Run(async () =>
{ {
var content = umsg.Content.ToLowerInvariant();
HashSet<CustomReaction> reactions; HashSet<CustomReaction> reactions;
GuildReactions.TryGetValue(channel.Guild.Id, out reactions); GuildReactions.TryGetValue(channel.Guild.Id, out reactions);
if (reactions != null && reactions.Any()) if (reactions != null && reactions.Any())
{ {
var reaction = reactions.Where(cr => cr.TriggerWithContext(umsg) == umsg.Content).Shuffle().FirstOrDefault(); var reaction = reactions.Where(cr => cr.TriggerWithContext(umsg) == content).Shuffle().FirstOrDefault();
if (reaction != null) if (reaction != null)
{ {
try { await channel.SendMessageAsync(reaction.ResponseWithContext(umsg)).ConfigureAwait(false); } catch { } try { await channel.SendMessageAsync(reaction.ResponseWithContext(umsg)).ConfigureAwait(false); } catch { }
return; return;
} }
} }
var greaction = GlobalReactions.Where(cr => cr.TriggerWithContext(umsg) == umsg.Content).Shuffle().FirstOrDefault(); var greaction = GlobalReactions.Where(cr => cr.TriggerWithContext(umsg) == content).Shuffle().FirstOrDefault();
if (greaction != null) if (greaction != null)
{ {
try { await channel.SendMessageAsync(greaction.ResponseWithContext(umsg)).ConfigureAwait(false); } catch { } try { await channel.SendMessageAsync(greaction.ResponseWithContext(umsg)).ConfigureAwait(false); } catch { }
@ -71,6 +72,8 @@ namespace NadekoBot.Modules.CustomReactions
if (string.IsNullOrWhiteSpace(message) || string.IsNullOrWhiteSpace(key)) if (string.IsNullOrWhiteSpace(message) || string.IsNullOrWhiteSpace(key))
return; return;
key = key.ToLowerInvariant();
if ((channel == null && !NadekoBot.Credentials.IsOwner(imsg.Author)) || (channel != null && !((IGuildUser)imsg.Author).GuildPermissions.Administrator)) if ((channel == null && !NadekoBot.Credentials.IsOwner(imsg.Author)) || (channel != null && !((IGuildUser)imsg.Author).GuildPermissions.Administrator))
{ {
try { await imsg.Channel.SendMessageAsync("Insufficient permissions. Requires Bot ownership for global custom reactions, and Administrator for guild custom reactions."); } catch { } try { await imsg.Channel.SendMessageAsync("Insufficient permissions. Requires Bot ownership for global custom reactions, and Administrator for guild custom reactions."); } catch { }
@ -81,7 +84,7 @@ namespace NadekoBot.Modules.CustomReactions
{ {
GuildId = channel?.Guild.Id, GuildId = channel?.Guild.Id,
IsRegex = false, IsRegex = false,
Trigger = key.ToLowerInvariant(), Trigger = key,
Response = message, Response = message,
}; };

View File

@ -5,7 +5,7 @@ using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace NadekoBot.Modules.Translator namespace NadekoBot.Modules.Searches
{ {
public class GoogleTranslator public class GoogleTranslator
{ {

View File

@ -7,15 +7,10 @@ using System.Threading.Tasks;
using NadekoBot.Services; using NadekoBot.Services;
using Discord.WebSocket; using Discord.WebSocket;
namespace NadekoBot.Modules.Translator namespace NadekoBot.Modules.Searches
{ {
[NadekoModule("Translator", "~")] public partial class Searches
public class Translator : DiscordModule
{ {
public Translator(ILocalization loc, CommandService cmds, ShardedDiscordClient client) : base(loc, cmds, client)
{
}
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task Translate(IUserMessage umsg, string langs, [Remainder] string text = null) public async Task Translate(IUserMessage umsg, string langs, [Remainder] string text = null)