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 content = umsg.Content.ToLowerInvariant();
HashSet<CustomReaction> reactions;
GuildReactions.TryGetValue(channel.Guild.Id, out reactions);
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)
{
try { await channel.SendMessageAsync(reaction.ResponseWithContext(umsg)).ConfigureAwait(false); } catch { }
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)
{
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))
return;
key = key.ToLowerInvariant();
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 { }
@ -81,7 +84,7 @@ namespace NadekoBot.Modules.CustomReactions
{
GuildId = channel?.Guild.Id,
IsRegex = false,
Trigger = key.ToLowerInvariant(),
Trigger = key,
Response = message,
};

View File

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

View File

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