Skip to content

Commit

Permalink
Add cooldown to reaction create
Browse files Browse the repository at this point in the history
  • Loading branch information
marens101 authored and KarlOfDuty committed Jul 15, 2020
1 parent ceeb3e1 commit a317e9a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions SupportBoi/EventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ namespace SupportBoi
internal class EventHandler
{
private DiscordClient discordClient;

//DateTime for the end of the cooldown
private static Dictionary<ulong, DateTime> reactionTicketCooldowns = new Dictionary<ulong, DateTime>();

public EventHandler(DiscordClient client)
{
this.discordClient = client;
Expand Down Expand Up @@ -133,6 +137,12 @@ internal async Task OnReactionAdded(MessageReactionAddEventArgs e)
DiscordMember member = await guild.GetMemberAsync(e.User.Id);

if (!Config.HasPermission(member, "new") || Database.IsBlacklisted(member.Id)) return;
if (reactionTicketCooldowns.ContainsKey(member.Id))
{
if (reactionTicketCooldowns[member.Id] > DateTime.Now) return; // cooldown has not expired
else reactionTicketCooldowns.Remove(member.Id); // cooldown exists but has expired, delete it
}


DiscordChannel category = guild.GetChannel(Config.ticketCategory);
DiscordChannel ticketChannel = await guild.CreateChannelAsync("ticket", ChannelType.Text, category);
Expand All @@ -146,6 +156,7 @@ internal async Task OnReactionAdded(MessageReactionAddEventArgs e)
}

long id = Database.NewTicket(member.Id, staffID, ticketChannel.Id);
reactionTicketCooldowns.Add(member.Id, DateTime.Now.AddSeconds(10)); // add a cooldown which expires in 10 seconds
string ticketID = id.ToString("00000");
await ticketChannel.ModifyAsync("ticket-" + ticketID);
await ticketChannel.AddOverwriteAsync(member, Permissions.AccessChannels, Permissions.None);
Expand Down

0 comments on commit a317e9a

Please sign in to comment.