.crad and .crdm added :O
This commit is contained in:
parent
0d1e870325
commit
7e6411e25b
1264
src/NadekoBot/Migrations/20170318190018_crad-and-crdm.Designer.cs
generated
Normal file
1264
src/NadekoBot/Migrations/20170318190018_crad-and-crdm.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
35
src/NadekoBot/Migrations/20170318190018_crad-and-crdm.cs
Normal file
35
src/NadekoBot/Migrations/20170318190018_crad-and-crdm.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
namespace NadekoBot.Migrations
|
||||||
|
{
|
||||||
|
public partial class cradandcrdm : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<bool>(
|
||||||
|
name: "AutoDeleteTrigger",
|
||||||
|
table: "CustomReactions",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: false);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<bool>(
|
||||||
|
name: "DmResponse",
|
||||||
|
table: "CustomReactions",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: false);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "AutoDeleteTrigger",
|
||||||
|
table: "CustomReactions");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "DmResponse",
|
||||||
|
table: "CustomReactions");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -310,8 +310,12 @@ namespace NadekoBot.Migrations
|
|||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd();
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<bool>("AutoDeleteTrigger");
|
||||||
|
|
||||||
b.Property<DateTime?>("DateAdded");
|
b.Property<DateTime?>("DateAdded");
|
||||||
|
|
||||||
|
b.Property<bool>("DmResponse");
|
||||||
|
|
||||||
b.Property<ulong?>("GuildId");
|
b.Property<ulong?>("GuildId");
|
||||||
|
|
||||||
b.Property<bool>("IsRegex");
|
b.Property<bool>("IsRegex");
|
||||||
|
@ -11,26 +11,24 @@ using NLog;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
using System;
|
using System;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using NadekoBot.DataStructures;
|
using NadekoBot.DataStructures;
|
||||||
using NLog.Fluent;
|
|
||||||
|
|
||||||
namespace NadekoBot.Modules.CustomReactions
|
namespace NadekoBot.Modules.CustomReactions
|
||||||
{
|
{
|
||||||
public static class CustomReactionExtensions
|
public static class CustomReactionExtensions
|
||||||
{
|
{
|
||||||
public static Task<IUserMessage> Send(this CustomReaction cr, IUserMessage context)
|
public static async Task<IUserMessage> Send(this CustomReaction cr, IUserMessage context)
|
||||||
{
|
{
|
||||||
var channel = context.Channel;
|
var channel = cr.DmResponse ? await context.Author.CreateDMChannelAsync() : context.Channel;
|
||||||
|
|
||||||
CustomReactions.ReactionStats.AddOrUpdate(cr.Trigger, 1, (k, old) => ++old);
|
CustomReactions.ReactionStats.AddOrUpdate(cr.Trigger, 1, (k, old) => ++old);
|
||||||
|
|
||||||
CREmbed crembed;
|
CREmbed crembed;
|
||||||
if (CREmbed.TryParse(cr.Response, out crembed))
|
if (CREmbed.TryParse(cr.Response, out crembed))
|
||||||
{
|
{
|
||||||
return channel.EmbedAsync(crembed.ToEmbed(), crembed.PlainText ?? "");
|
return await channel.EmbedAsync(crembed.ToEmbed(), crembed.PlainText ?? "");
|
||||||
}
|
}
|
||||||
return channel.SendMessageAsync(cr.ResponseWithContext(context));
|
return await channel.SendMessageAsync(cr.ResponseWithContext(context));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,6 +339,108 @@ namespace NadekoBot.Modules.CustomReactions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
|
public async Task CrDm(int id)
|
||||||
|
{
|
||||||
|
if ((Context.Guild == null && !NadekoBot.Credentials.IsOwner(Context.User)) ||
|
||||||
|
(Context.Guild != null && !((IGuildUser)Context.User).GuildPermissions.Administrator))
|
||||||
|
{
|
||||||
|
await ReplyErrorLocalized("insuff_perms").ConfigureAwait(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CustomReaction[] reactions = new CustomReaction[0];
|
||||||
|
|
||||||
|
if (Context.Guild == null)
|
||||||
|
reactions = GlobalReactions;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GuildReactions.TryGetValue(Context.Guild.Id, out reactions);
|
||||||
|
}
|
||||||
|
if (reactions.Any())
|
||||||
|
{
|
||||||
|
var reaction = reactions.FirstOrDefault(x => x.Id == id);
|
||||||
|
|
||||||
|
if (reaction == null)
|
||||||
|
{
|
||||||
|
await ReplyErrorLocalized("no_found_id").ConfigureAwait(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var setValue = reaction.DmResponse = !reaction.DmResponse;
|
||||||
|
|
||||||
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
|
{
|
||||||
|
uow.CustomReactions.Get(id).DmResponse = setValue;
|
||||||
|
uow.Complete();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (setValue)
|
||||||
|
{
|
||||||
|
await ReplyConfirmLocalized("crdm_enabled", Format.Code(reaction.Id.ToString())).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await ReplyConfirmLocalized("crdm_disabled", Format.Code(reaction.Id.ToString())).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await ReplyErrorLocalized("no_found").ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
|
public async Task CrAd(int id)
|
||||||
|
{
|
||||||
|
if ((Context.Guild == null && !NadekoBot.Credentials.IsOwner(Context.User)) ||
|
||||||
|
(Context.Guild != null && !((IGuildUser)Context.User).GuildPermissions.Administrator))
|
||||||
|
{
|
||||||
|
await ReplyErrorLocalized("insuff_perms").ConfigureAwait(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CustomReaction[] reactions = new CustomReaction[0];
|
||||||
|
|
||||||
|
if (Context.Guild == null)
|
||||||
|
reactions = GlobalReactions;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GuildReactions.TryGetValue(Context.Guild.Id, out reactions);
|
||||||
|
}
|
||||||
|
if (reactions.Any())
|
||||||
|
{
|
||||||
|
var reaction = reactions.FirstOrDefault(x => x.Id == id);
|
||||||
|
|
||||||
|
if (reaction == null)
|
||||||
|
{
|
||||||
|
await ReplyErrorLocalized("no_found_id").ConfigureAwait(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var setValue = reaction.AutoDeleteTrigger = !reaction.AutoDeleteTrigger;
|
||||||
|
|
||||||
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
|
{
|
||||||
|
uow.CustomReactions.Get(id).AutoDeleteTrigger = setValue;
|
||||||
|
uow.Complete();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (setValue)
|
||||||
|
{
|
||||||
|
await ReplyConfirmLocalized("crad_enabled", Format.Code(reaction.Id.ToString())).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await ReplyConfirmLocalized("crad_disabled", Format.Code(reaction.Id.ToString())).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await ReplyErrorLocalized("no_found").ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
[OwnerOnly]
|
[OwnerOnly]
|
||||||
public async Task CrStatsClear(string trigger = null)
|
public async Task CrStatsClear(string trigger = null)
|
||||||
|
56
src/NadekoBot/Resources/CommandStrings.Designer.cs
generated
56
src/NadekoBot/Resources/CommandStrings.Designer.cs
generated
@ -1976,6 +1976,60 @@ namespace NadekoBot.Resources {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to crad.
|
||||||
|
/// </summary>
|
||||||
|
public static string crad_cmd {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("crad_cmd", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Toggles whether the message triggering the custom reaction will be automatically deleted..
|
||||||
|
/// </summary>
|
||||||
|
public static string crad_desc {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("crad_desc", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to `{0}crad 59`.
|
||||||
|
/// </summary>
|
||||||
|
public static string crad_usage {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("crad_usage", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to crdm.
|
||||||
|
/// </summary>
|
||||||
|
public static string crdm_cmd {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("crdm_cmd", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Toggles whether the response message of the custom reaction will be sent as a direct message..
|
||||||
|
/// </summary>
|
||||||
|
public static string crdm_desc {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("crdm_desc", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to `{0}crad 44`.
|
||||||
|
/// </summary>
|
||||||
|
public static string crdm_usage {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("crdm_usage", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to createinvite crinv.
|
/// Looks up a localized string similar to createinvite crinv.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -2373,7 +2427,7 @@ namespace NadekoBot.Resources {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to `{0}delq abc`.
|
/// Looks up a localized string similar to `{0}delq 123456`.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string deletequote_usage {
|
public static string deletequote_usage {
|
||||||
get {
|
get {
|
||||||
|
@ -3186,4 +3186,22 @@
|
|||||||
<data name="vcrole_usage" xml:space="preserve">
|
<data name="vcrole_usage" xml:space="preserve">
|
||||||
<value>`{0}vcrole SomeRole` or `{0}vcrole`</value>
|
<value>`{0}vcrole SomeRole` or `{0}vcrole`</value>
|
||||||
</data>
|
</data>
|
||||||
</root>
|
<data name="crad_cmd" xml:space="preserve">
|
||||||
|
<value>crad</value>
|
||||||
|
</data>
|
||||||
|
<data name="crad_desc" xml:space="preserve">
|
||||||
|
<value>Toggles whether the message triggering the custom reaction will be automatically deleted.</value>
|
||||||
|
</data>
|
||||||
|
<data name="crad_usage" xml:space="preserve">
|
||||||
|
<value>`{0}crad 59`</value>
|
||||||
|
</data>
|
||||||
|
<data name="crdm_cmd" xml:space="preserve">
|
||||||
|
<value>crdm</value>
|
||||||
|
</data>
|
||||||
|
<data name="crdm_desc" xml:space="preserve">
|
||||||
|
<value>Toggles whether the response message of the custom reaction will be sent as a direct message.</value>
|
||||||
|
</data>
|
||||||
|
<data name="crdm_usage" xml:space="preserve">
|
||||||
|
<value>`{0}crad 44`</value>
|
||||||
|
</data>
|
||||||
|
</root>
|
36
src/NadekoBot/Resources/ResponseStrings.Designer.cs
generated
36
src/NadekoBot/Resources/ResponseStrings.Designer.cs
generated
@ -2017,6 +2017,42 @@ namespace NadekoBot.Resources {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Message triggering the custom reaction with id {0} won't get automatically deleted..
|
||||||
|
/// </summary>
|
||||||
|
public static string customreactions_crad_disabled {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("customreactions_crad_disabled", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Message triggering the custom reaction with id {0} will get automatically deleted..
|
||||||
|
/// </summary>
|
||||||
|
public static string customreactions_crad_enabled {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("customreactions_crad_enabled", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Response message for the custom reaction with id {0} won't be sent as a DM..
|
||||||
|
/// </summary>
|
||||||
|
public static string customreactions_crdm_disabled {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("customreactions_crdm_disabled", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Response message for the custom reaction with id {0} will be sent as a DM..
|
||||||
|
/// </summary>
|
||||||
|
public static string customreactions_crdm_enabled {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("customreactions_crdm_enabled", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Custom Reaction deleted.
|
/// Looks up a localized string similar to Custom Reaction deleted.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -2248,4 +2248,16 @@ Owner ID: {2}</value>
|
|||||||
<data name="administration_vc_role_list" xml:space="preserve">
|
<data name="administration_vc_role_list" xml:space="preserve">
|
||||||
<value>Voice channel roles</value>
|
<value>Voice channel roles</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="customreactions_crad_disabled" xml:space="preserve">
|
||||||
|
<value>Message triggering the custom reaction with id {0} won't get automatically deleted.</value>
|
||||||
|
</data>
|
||||||
|
<data name="customreactions_crad_enabled" xml:space="preserve">
|
||||||
|
<value>Message triggering the custom reaction with id {0} will get automatically deleted.</value>
|
||||||
|
</data>
|
||||||
|
<data name="customreactions_crdm_disabled" xml:space="preserve">
|
||||||
|
<value>Response message for the custom reaction with id {0} won't be sent as a DM.</value>
|
||||||
|
</data>
|
||||||
|
<data name="customreactions_crdm_enabled" xml:space="preserve">
|
||||||
|
<value>Response message for the custom reaction with id {0} will be sent as a DM.</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
@ -303,6 +303,11 @@ namespace NadekoBot.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
await cr.Send(usrMsg).ConfigureAwait(false);
|
await cr.Send(usrMsg).ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (cr.AutoDeleteTrigger)
|
||||||
|
{
|
||||||
|
try { await msg.DeleteAsync().ConfigureAwait(false); } catch { }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -10,8 +10,11 @@ namespace NadekoBot.Services.Database.Models
|
|||||||
public Regex Regex { get; set; }
|
public Regex Regex { get; set; }
|
||||||
public string Response { get; set; }
|
public string Response { get; set; }
|
||||||
public string Trigger { get; set; }
|
public string Trigger { get; set; }
|
||||||
|
|
||||||
public bool IsRegex { get; set; }
|
public bool IsRegex { get; set; }
|
||||||
public bool OwnerOnly { get; set; }
|
public bool OwnerOnly { get; set; }
|
||||||
|
public bool AutoDeleteTrigger { get; set; }
|
||||||
|
public bool DmResponse { get; set; }
|
||||||
|
|
||||||
public bool IsGlobal => !GuildId.HasValue;
|
public bool IsGlobal => !GuildId.HasValue;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user