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); } }
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); } }
public async Task CrAd(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.AutoDeleteTrigger = !reaction.AutoDeleteTrigger; await _service.SetCrAdAsync(reaction.Id, setValue).ConfigureAwait(false); 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); } }