.crad and .crdm added :O
This commit is contained in:
@@ -11,26 +11,24 @@ using NLog;
|
||||
using System.Diagnostics;
|
||||
using Discord.WebSocket;
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using NadekoBot.DataStructures;
|
||||
using NLog.Fluent;
|
||||
|
||||
namespace NadekoBot.Modules.CustomReactions
|
||||
{
|
||||
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);
|
||||
|
||||
CREmbed 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]
|
||||
[OwnerOnly]
|
||||
public async Task CrStatsClear(string trigger = null)
|
||||
|
Reference in New Issue
Block a user