-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
50e81b1
commit 04c1efc
Showing
5 changed files
with
74 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using DSharpPlus.CommandsNext; | ||
using DSharpPlus.Entities; | ||
using Kattbot.Helpers; | ||
using MediatR; | ||
|
||
namespace Kattbot.CommandHandlers.Random; | ||
|
||
public class ClapTextRequest : CommandRequest | ||
{ | ||
public ClapTextRequest(CommandContext ctx, string text) | ||
: base(ctx) | ||
{ | ||
Text = text; | ||
} | ||
|
||
public string Text { get; } | ||
} | ||
|
||
public class ClapTextRequestHandler : IRequestHandler<ClapTextRequest> | ||
{ | ||
public async Task Handle(ClapTextRequest request, CancellationToken cancellationToken) | ||
{ | ||
CommandContext ctx = request.Ctx; | ||
string text = request.Text; | ||
DiscordMessage? reply = ctx.Message.ReferencedMessage; | ||
|
||
if (reply is not null) | ||
{ | ||
text = reply.Content; | ||
} | ||
|
||
if (string.IsNullOrEmpty(text)) | ||
{ | ||
await ctx.RespondAsync("What am I supposed to clap?"); | ||
return; | ||
} | ||
|
||
DiscordEmoji clapEmoji = DiscordEmoji.FromUnicode(EmojiMap.Clap); | ||
|
||
string[] textParts = text.Split(' '); | ||
|
||
string innerClappedMessage = string.Join($" {clapEmoji} ", textParts.Select(x => x.ToUpper())); | ||
|
||
var clappedMessage = $"{clapEmoji} {innerClappedMessage} {clapEmoji}"; | ||
|
||
if (clappedMessage.Length > DiscordConstants.MaxMessageLength) | ||
{ | ||
await ctx.RespondAsync("I can't clap that much!"); | ||
return; | ||
} | ||
|
||
await ctx.RespondAsync(clappedMessage); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters