.crca added. If you enable it on a custom reation, you can use the trigger word anywhere in the sentence in order to trigger that custom reaction.

This commit is contained in:
Master Kwoth 2017-07-22 18:12:08 +02:00
parent 1aa86937c8
commit f773b0c6b6
8 changed files with 1734 additions and 6 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Migrations;
namespace NadekoBot.Migrations
{
public partial class crca : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "ContainsAnywhere",
table: "CustomReactions",
nullable: false,
defaultValue: false);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "ContainsAnywhere",
table: "CustomReactions");
}
}
}

View File

@ -361,6 +361,8 @@ namespace NadekoBot.Migrations
b.Property<bool>("AutoDeleteTrigger"); b.Property<bool>("AutoDeleteTrigger");
b.Property<bool>("ContainsAnywhere");
b.Property<DateTime?>("DateAdded"); b.Property<DateTime?>("DateAdded");
b.Property<bool>("DmResponse"); b.Property<bool>("DmResponse");

View File

@ -270,7 +270,7 @@ namespace NadekoBot.Modules.CustomReactions
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
public async Task CrDm(int id) public async Task CrCa(int id)
{ {
if ((Context.Guild == null && !_creds.IsOwner(Context.User)) || if ((Context.Guild == null && !_creds.IsOwner(Context.User)) ||
(Context.Guild != null && !((IGuildUser)Context.User).GuildPermissions.Administrator)) (Context.Guild != null && !((IGuildUser)Context.User).GuildPermissions.Administrator))
@ -297,21 +297,21 @@ namespace NadekoBot.Modules.CustomReactions
return; return;
} }
var setValue = reaction.DmResponse = !reaction.DmResponse; var setValue = reaction.ContainsAnywhere = !reaction.ContainsAnywhere;
using (var uow = _db.UnitOfWork) using (var uow = _db.UnitOfWork)
{ {
uow.CustomReactions.Get(id).DmResponse = setValue; uow.CustomReactions.Get(id).ContainsAnywhere = setValue;
uow.Complete(); uow.Complete();
} }
if (setValue) if (setValue)
{ {
await ReplyConfirmLocalized("crdm_enabled", Format.Code(reaction.Id.ToString())).ConfigureAwait(false); await ReplyConfirmLocalized("crca_enabled", Format.Code(reaction.Id.ToString())).ConfigureAwait(false);
} }
else else
{ {
await ReplyConfirmLocalized("crdm_disabled", Format.Code(reaction.Id.ToString())).ConfigureAwait(false); await ReplyConfirmLocalized("crca_disabled", Format.Code(reaction.Id.ToString())).ConfigureAwait(false);
} }
} }
else else

View File

@ -69,7 +69,13 @@ namespace NadekoBot.Modules.CustomReactions.Services
var hasTarget = cr.Response.ToLowerInvariant().Contains("%target%"); var hasTarget = cr.Response.ToLowerInvariant().Contains("%target%");
var trigger = cr.TriggerWithContext(umsg, _client).Trim().ToLowerInvariant(); var trigger = cr.TriggerWithContext(umsg, _client).Trim().ToLowerInvariant();
return ((hasTarget && content.StartsWith(trigger + " ")) || (_bc.BotConfig.CustomReactionsStartWith && content.StartsWith(trigger + " ")) || content == trigger); return ((cr.ContainsAnywhere &&
(content.StartsWith(trigger + " ")
|| content.EndsWith(" " + trigger)
|| content.Contains(" " + trigger + " ")))
|| (hasTarget && content.StartsWith(trigger + " "))
|| (_bc.BotConfig.CustomReactionsStartWith && content.StartsWith(trigger + " "))
|| content == trigger);
}).ToArray(); }).ToArray();
if (rs.Length != 0) if (rs.Length != 0)

View File

@ -3249,6 +3249,15 @@
<data name="crdm_usage" xml:space="preserve"> <data name="crdm_usage" xml:space="preserve">
<value>`{0}crdm 44`</value> <value>`{0}crdm 44`</value>
</data> </data>
<data name="crca_cmd" xml:space="preserve">
<value>crca</value>
</data>
<data name="crca_desc" xml:space="preserve">
<value>Toggles whether the custom reaction will trigger if the triggering message contains the keyword (instead of only starting with it).</value>
</data>
<data name="crca_usage" xml:space="preserve">
<value>`{0}crca 44`</value>
</data>
<data name="aliaslist_cmd" xml:space="preserve"> <data name="aliaslist_cmd" xml:space="preserve">
<value>aliaslist cmdmaplist aliases</value> <value>aliaslist cmdmaplist aliases</value>
</data> </data>

View File

@ -17,6 +17,8 @@ namespace NadekoBot.Services.Database.Models
public bool DmResponse { get; set; } public bool DmResponse { get; set; }
public bool IsGlobal => !GuildId.HasValue; public bool IsGlobal => !GuildId.HasValue;
public bool ContainsAnywhere { get; set; }
} }
public class ReactionResponse : DbEntity public class ReactionResponse : DbEntity

View File

@ -734,6 +734,8 @@
"customreactions_crad_enabled": "Message triggering the custom reaction with id {0} will get automatically deleted.", "customreactions_crad_enabled": "Message triggering the custom reaction with id {0} will get automatically deleted.",
"customreactions_crdm_disabled": "Response message for the custom reaction with id {0} won't be sent as a DM.", "customreactions_crdm_disabled": "Response message for the custom reaction with id {0} won't be sent as a DM.",
"customreactions_crdm_enabled": "Response message for the custom reaction with id {0} will be sent as a DM.", "customreactions_crdm_enabled": "Response message for the custom reaction with id {0} will be sent as a DM.",
"customreactions_crca_disabled": "Custom reaction with id {0} will no longer trigger unless it's trigger word is at the beggining of the sentence.",
"customreactions_crca_enabled": "Custom reaction with id {0} will now trigger if it's contained anywhere in the sentence.",
"utility_aliases_none": "No alias found", "utility_aliases_none": "No alias found",
"utility_alias_added": "Typing {0} will now be an alias of {1}.", "utility_alias_added": "Typing {0} will now be an alias of {1}.",
"utility_alias_list": "List of aliases", "utility_alias_list": "List of aliases",