.ecr Command added, edits the custom reaction's response given the id

This commit is contained in:
Master Kwoth 2017-09-27 16:22:42 +02:00
parent 99ec9e1bb4
commit 748072aa8e
6 changed files with 89 additions and 4 deletions

View File

@ -37,7 +37,10 @@ namespace NadekoBot.Modules.Administration
.AddField(efb => efb.WithName(GetText("reason")).WithValue(reason ?? "-"))) .AddField(efb => efb.WithName(GetText("reason")).WithValue(reason ?? "-")))
.ConfigureAwait(false); .ConfigureAwait(false);
} }
catch { } catch
{
}
var punishment = await _service.Warn(Context.Guild, user.Id, Context.User.ToString(), reason).ConfigureAwait(false); var punishment = await _service.Warn(Context.Guild, user.Id, Context.User.ToString(), reason).ConfigureAwait(false);
if (punishment == null) if (punishment == null)

View File

@ -80,6 +80,60 @@ namespace NadekoBot.Modules.CustomReactions
).ConfigureAwait(false); ).ConfigureAwait(false);
} }
[NadekoCommand, Usage, Description, Aliases]
public async Task EditCustReact(int id, [Remainder] string message)
{
var channel = Context.Channel as ITextChannel;
if (string.IsNullOrWhiteSpace(message) || id < 0)
return;
if ((channel == null && !_creds.IsOwner(Context.User)) || (channel != null && !((IGuildUser)Context.User).GuildPermissions.Administrator))
{
await ReplyErrorLocalized("insuff_perms").ConfigureAwait(false);
return;
}
CustomReaction cr;
using (var uow = _db.UnitOfWork)
{
cr = uow.CustomReactions.Get(id);
if (cr != null)
{
cr.Response = message;
await uow.CompleteAsync().ConfigureAwait(false);
}
}
if (cr != null)
{
if (channel == null)
{
await _service.EditGcr(id, message).ConfigureAwait(false);
}
else
{
if (_service.GuildReactions.TryGetValue(Context.Guild.Id, out var crs))
{
var oldCr = crs.FirstOrDefault(x => x.Id == id);
if (oldCr != null)
oldCr.Response = message;
}
}
await Context.Channel.EmbedAsync(new EmbedBuilder().WithOkColor()
.WithTitle(GetText("edited_cust_react"))
.WithDescription($"#{cr.Id}")
.AddField(efb => efb.WithName(GetText("trigger")).WithValue(cr.Trigger))
.AddField(efb => efb.WithName(GetText("response")).WithValue(message.Length > 1024 ? GetText("redacted_too_long") : message))
).ConfigureAwait(false);
}
else
{
await ReplyErrorLocalized("edit_fail").ConfigureAwait(false);
}
}
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[Priority(1)] [Priority(1)]
public async Task ListCustReact(int page = 1) public async Task ListCustReact(int page = 1)

View File

@ -59,6 +59,14 @@ namespace NadekoBot.Modules.CustomReactions.Services
var id = int.Parse(msg); var id = int.Parse(msg);
GlobalReactions = GlobalReactions.Where(cr => cr?.Id != id).ToArray(); GlobalReactions = GlobalReactions.Where(cr => cr?.Id != id).ToArray();
}, StackExchange.Redis.CommandFlags.FireAndForget); }, StackExchange.Redis.CommandFlags.FireAndForget);
sub.Subscribe(_client.CurrentUser.Id + "_gcr.edited", (ch, msg) =>
{
var obj = new { Id = 0, Message = "" };
obj = JsonConvert.DeserializeAnonymousType(msg, obj);
var gcr = GlobalReactions.FirstOrDefault(x => x.Id == obj.Id);
if (gcr != null)
gcr.Response = obj.Message;
}, StackExchange.Redis.CommandFlags.FireAndForget);
sub.Subscribe(_client.CurrentUser.Id + "_crad.toggle", (ch, msg) => sub.Subscribe(_client.CurrentUser.Id + "_crad.toggle", (ch, msg) =>
{ {
var obj = new { Id = 0, Value = false }; var obj = new { Id = 0, Value = false };
@ -91,6 +99,17 @@ namespace NadekoBot.Modules.CustomReactions.Services
GlobalReactions = items.Where(g => g.GuildId == null || g.GuildId == 0).ToArray(); GlobalReactions = items.Where(g => g.GuildId == null || g.GuildId == 0).ToArray();
} }
public Task EditGcr(int id, string message)
{
var sub = _cache.Redis.GetSubscriber();
return sub.PublishAsync(_client.CurrentUser.Id + "_gcr.edited", JsonConvert.SerializeObject(new
{
Id = id,
Message = message,
}));
}
public Task AddGcr(CustomReaction cr) public Task AddGcr(CustomReaction cr)
{ {
var sub = _cache.Redis.GetSubscriber(); var sub = _cache.Redis.GetSubscriber();

View File

@ -20,7 +20,7 @@ namespace NadekoBot.Services.Impl
private readonly IBotCredentials _creds; private readonly IBotCredentials _creds;
private readonly DateTime _started; private readonly DateTime _started;
public const string BotVersion = "1.9.1"; public const string BotVersion = "1.9.2";
public string Author => "Kwoth#2560"; public string Author => "Kwoth#2560";
public string Library => "Discord.Net"; public string Library => "Discord.Net";

View File

@ -4,7 +4,8 @@
"customreactions_insuff_perms": "Insufficient permissions. Requires Bot ownership for global custom reactions, and Administrator for server custom reactions.", "customreactions_insuff_perms": "Insufficient permissions. Requires Bot ownership for global custom reactions, and Administrator for server custom reactions.",
"customreactions_list_all": "List of all custom reactions", "customreactions_list_all": "List of all custom reactions",
"customreactions_name": "Custom Reactions", "customreactions_name": "Custom Reactions",
"customreactions_new_cust_react": "New Custom Reaction", "customreactions_new_cust_react": "\"New Custom Reaction",
"customreactions_edited_cust_react": "Custom Reaction Edited",
"customreactions_no_found": "No custom reaction found.", "customreactions_no_found": "No custom reaction found.",
"customreactions_no_found_id": "No custom reaction found with that id.", "customreactions_no_found_id": "No custom reaction found with that id.",
"customreactions_response": "Response", "customreactions_response": "Response",
@ -880,5 +881,6 @@
"searches_feed_removed": "Feed removed.", "searches_feed_removed": "Feed removed.",
"searches_feed_no_feed": "You haven't subscribed to any feeds on this server.", "searches_feed_no_feed": "You haven't subscribed to any feeds on this server.",
"administration_restart_fail": "You must setup RestartCommand in your credentials.json", "administration_restart_fail": "You must setup RestartCommand in your credentials.json",
"administration_restarting": "Restarting." "administration_restarting": "Restarting.",
"customreactions_edit_fail": "Custom reaction with that ID does not exist."
} }

View File

@ -2988,5 +2988,12 @@
"usage": [ "usage": [
"{0}feeds" "{0}feeds"
] ]
},
"editcustreact": {
"cmd": "editcustreact ecr",
"desc": "Edits the custom reaction's response given it's ID.",
"usage": [
"{0}ecr 123 I'm a magical girl"
]
} }
} }