-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(stickercounter): Add sticker counter
- Loading branch information
Showing
4 changed files
with
105 additions
and
2 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
40 changes: 40 additions & 0 deletions
40
src/HonzaBotner.Discord.Services/EventHandlers/StickerCounterService.cs
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,40 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using DSharpPlus.Entities; | ||
using DSharpPlus.EventArgs; | ||
using HonzaBotner.Discord.EventHandler; | ||
using HonzaBotner.Discord.Services.Options; | ||
using HonzaBotner.Services.Contract; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace HonzaBotner.Discord.Services.EventHandlers; | ||
|
||
public class StickerCounterService : IEventHandler<MessageCreateEventArgs> | ||
{ | ||
private readonly IEmojiCounterService _emojiCounterService; | ||
private readonly ulong[] _ignoreChannels; | ||
|
||
public StickerCounterService(IEmojiCounterService emojiCounterService, IOptions<CommonCommandOptions> options) | ||
{ | ||
_emojiCounterService = emojiCounterService; | ||
_ignoreChannels = options.Value.ReactionIgnoreChannels ?? Array.Empty<ulong>(); | ||
} | ||
|
||
public async Task<EventHandlerResult> Handle(MessageCreateEventArgs args) | ||
{ | ||
if (args.Message.Stickers.Count == 0 || _ignoreChannels.Contains(args.Channel.Id)) | ||
{ | ||
return EventHandlerResult.Continue; | ||
} | ||
|
||
DiscordMessageSticker sticker = args.Message.Stickers[0]; | ||
|
||
if (sticker.Type == StickerType.Guild && args.Guild.Stickers.Keys.Contains(sticker.Id)) | ||
{ | ||
await _emojiCounterService.IncrementAsync(sticker.Id); | ||
} | ||
|
||
return EventHandlerResult.Continue; | ||
} | ||
} |
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