mirror of
https://github.com/RPCS3/discord-bot.git
synced 2026-01-31 01:25:22 +01:00
use emojis instead of TriggerTyping()
This commit is contained in:
@@ -1,23 +1,16 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
|
||||
namespace CompatBot.Commands.Attributes
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)]
|
||||
internal class TriggersTyping: CheckBaseAttribute
|
||||
internal class TriggersTyping: Attribute
|
||||
{
|
||||
public bool InDmOnly { get; set; }
|
||||
|
||||
public override async Task<bool> ExecuteCheckAsync(CommandContext ctx, bool help)
|
||||
public bool ExecuteCheck(CommandContext ctx)
|
||||
{
|
||||
if (help)
|
||||
return true;
|
||||
|
||||
if (!InDmOnly || ctx.Channel.IsPrivate)
|
||||
await ctx.TriggerTypingAsync().ConfigureAwait(false);
|
||||
return true;
|
||||
return !InDmOnly || ctx.Channel.IsPrivate;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CompatBot.Commands.Attributes;
|
||||
using CompatBot.Database.Providers;
|
||||
using CompatBot.Utils;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.Entities;
|
||||
@@ -18,7 +20,23 @@ namespace CompatBot.Commands
|
||||
throw new DSharpPlus.CommandsNext.Exceptions.ChecksFailedException(ctx.Command, ctx, new CheckBaseAttribute[] {new RequiresDm()});
|
||||
}
|
||||
|
||||
if (TriggersTyping(ctx))
|
||||
await ctx.ReactWithAsync(Config.Reactions.PleaseWait).ConfigureAwait(false);
|
||||
|
||||
await base.BeforeExecutionAsync(ctx).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public override async Task AfterExecutionAsync(CommandContext ctx)
|
||||
{
|
||||
if (TriggersTyping(ctx))
|
||||
await ctx.RemoveReactionAsync(Config.Reactions.PleaseWait).ConfigureAwait(false);
|
||||
|
||||
await base.AfterExecutionAsync(ctx).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private static bool TriggersTyping(CommandContext ctx)
|
||||
{
|
||||
return ctx.Command.CustomAttributes.OfType<TriggersTyping>().FirstOrDefault() is TriggersTyping a && a.ExecuteCheck(ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AppveyorClient.POCOs;
|
||||
using CompatApiClient.Utils;
|
||||
using CompatBot.Commands.Attributes;
|
||||
using CompatBot.Utils;
|
||||
using CompatBot.Utils.ResultFormatters;
|
||||
using DSharpPlus.CommandsNext;
|
||||
@@ -12,7 +13,7 @@ using GithubClient.POCOs;
|
||||
|
||||
namespace CompatBot.Commands
|
||||
{
|
||||
[Group("pr")]
|
||||
[Group("pr"), TriggersTyping]
|
||||
[Description("Commands to list opened pull requests information")]
|
||||
internal sealed class Pr: BaseCommandModuleCustom
|
||||
{
|
||||
|
||||
@@ -73,6 +73,7 @@ namespace CompatBot
|
||||
public static readonly DiscordEmoji Starbucks = DiscordEmoji.FromUnicode("☕");
|
||||
public static readonly DiscordEmoji Moderated = DiscordEmoji.FromUnicode("🔨");
|
||||
public static readonly DiscordEmoji No = DiscordEmoji.FromUnicode("😐");
|
||||
public static readonly DiscordEmoji PleaseWait = DiscordEmoji.FromUnicode("👀");
|
||||
}
|
||||
|
||||
public static class Moderation
|
||||
|
||||
@@ -48,6 +48,18 @@ namespace CompatBot.Utils
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task RemoveReactionAsync(this DiscordMessage message, DiscordEmoji emoji)
|
||||
{
|
||||
try
|
||||
{
|
||||
await message.DeleteOwnReactionAsync(emoji).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Config.Log.Warn(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task ReactWithAsync(this DiscordMessage message, DiscordClient client, DiscordEmoji emoji, string fallbackMessage = null, bool showBoth = false)
|
||||
{
|
||||
try
|
||||
@@ -64,6 +76,11 @@ namespace CompatBot.Utils
|
||||
}
|
||||
}
|
||||
|
||||
public static Task RemoveReactionAsync(this CommandContext ctx, DiscordEmoji emoji)
|
||||
{
|
||||
return RemoveReactionAsync(ctx.Message, emoji);
|
||||
}
|
||||
|
||||
public static Task ReactWithAsync(this CommandContext ctx, DiscordEmoji emoji, string fallbackMessage = null, bool showBoth = false)
|
||||
{
|
||||
return ReactWithAsync(ctx.Message, ctx.Client, emoji, fallbackMessage, showBoth);
|
||||
|
||||
Reference in New Issue
Block a user