diff --git a/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs b/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs index a9311d55..ffead6e5 100644 --- a/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs +++ b/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs @@ -272,7 +272,7 @@ namespace NadekoBot.Modules.CustomReactions [NadekoCommand, Usage, Description, Aliases] 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)) { await ReplyErrorLocalized("insuff_perms").ConfigureAwait(false); @@ -320,6 +320,57 @@ namespace NadekoBot.Modules.CustomReactions } } + [NadekoCommand, Usage, Description, Aliases] + public async Task CrDm(int id) + { + if ((Context.Guild == null && !_creds.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 = _service.GlobalReactions; + else + { + _service.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 = _db.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) {