Skip to content

Commit

Permalink
Merge branch 'hotfix2022.2.1' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
tenhobi committed Feb 24, 2022
2 parents 9d1e490 + 60c3d9b commit 26d58c3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>2022.2</Version>
<Version>2022.2.1</Version>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,54 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using DSharpPlus.Entities;
using DSharpPlus.EventArgs;
using HonzaBotner.Discord.EventHandler;
using Microsoft.Extensions.Logging;

namespace HonzaBotner.Discord.Services.EventHandlers;

public class PollReactionsHandler : IEventHandler<MessageReactionAddEventArgs>
{
public async Task<EventHandlerResult> Handle(MessageReactionAddEventArgs args)

private readonly ILogger<PollReactionsHandler> _logger;

public PollReactionsHandler(ILogger<PollReactionsHandler> logger)
{
_logger = logger;
}

public Task<EventHandlerResult> Handle(MessageReactionAddEventArgs args)
{
if (args.User.IsBot) return EventHandlerResult.Continue;
if (args.User.IsBot) return Task.FromResult(EventHandlerResult.Continue);
_ = Task.Run(() => HandleAsync(args));
await Task.Delay(0);
return EventHandlerResult.Continue;
return Task.FromResult(EventHandlerResult.Continue);
}

private async Task HandleAsync(MessageReactionAddEventArgs args)
{
DiscordMessage message = args.Message.Content is null
? await args.Channel.GetMessageAsync(args.Message.Id)
: args.Message;
DiscordMessage message;
try
{
message = await args.Channel.GetMessageAsync(args.Message.Id);
}
catch (Exception e)
{
_logger.LogWarning(e,
"Failed while fetching message {MessageId} in channel {ChannelId} to check poll reactions",
args.Message.Id, args.Channel.Id
);
return;
}

if (!message.Author.IsCurrent
|| (message.Embeds?.Count.Equals(0) ?? true)
|| !(message.Embeds[0].Footer?.Text.EndsWith("Poll") ?? false))
{
return;
}

if (message.Reactions.Any(x => x.Emoji == args.Emoji && x.Count > 1)) return;
if (message.Reactions.FirstOrDefault(x => x.Emoji == args.Emoji)?.IsMe ?? false) return;

await args.Message.DeleteReactionAsync(args.Emoji, args.User);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public async Task<EventHandlerResult> Handle(ComponentInteractionCreateEventArgs

if (isAuthenticated)
{
builder.Content = _translation["UserAlreadyVerified"];
builder.Content = _translation["AlreadyVerified"];
builder.AddComponents(
new DiscordLinkButtonComponent(
link,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ private async Task SendReminderNotification(Reminder reminder)
// DM all users.
foreach (ulong user in receivers)
{
remindedUsers.Append("<@" + user + ">, ");
try
{
DiscordMember? member = await message.Channel.Guild.GetMemberAsync(user);
Expand All @@ -91,8 +92,6 @@ private async Task SendReminderNotification(Reminder reminder)
e.Message);
}
}

remindedUsers.Append("<@" + user + ">, ");
}

remindedUsers = remindedUsers.Remove(remindedUsers.Length - 2, 2);
Expand Down

0 comments on commit 26d58c3

Please sign in to comment.