public static (string display, int index) GetStatus(IEmote emote) { // Attending if (Emotes.IsEmote(emote, Emotes.Maybe)) { return("Maybe", 0); } if (Emotes.IsEmote(emote, Emotes.Yes)) { return("Attending", 1); } if (Emotes.IsEmote(emote, Emotes.No)) { return("Not Attending", 2); } // Roles if (Emotes.IsEmote(emote, Emotes.Tank)) { return("Tank", 3); } if (Emotes.IsEmote(emote, Emotes.Healer)) { return("Healer", 4); } if (Emotes.IsEmote(emote, Emotes.DPS)) { return("DPS", 5); } return("Invalid", -1); }
private async Task ReactionAdded(Cacheable <IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction) { try { if (!this.messageEventLookup.ContainsKey(message.Id.ToString())) { return; } // don't mark yourself as attending! if (reaction.UserId == Program.DiscordClient.CurrentUser.Id) { return; } string eventId = this.messageEventLookup[message.Id.ToString()]; Event? evt = await EventsDatabase.Load(eventId); if (evt is null) { // this event was deleted while the notification was up. // we need to detect this case in the 'Update' loop to clear old notifications. // but for now, we'll handle it when someone reacts. this.messageEventLookup.Remove(message.Id.ToString()); await channel.DeleteMessageAsync(message.Value); return; } if (evt.Notify == null) { return; } Event.Instance.Attendee?attendee = evt.GetAttendee(reaction.UserId); if (attendee == null) { attendee = new Event.Instance.Attendee(); attendee.UserId = reaction.UserId.ToString(); evt.Notify.Attendees.Add(attendee); await EventsDatabase.Save(evt); } if (Emotes.IsEmote(reaction.Emote, Emotes.Bell)) { ////ReminderService.SetReminder(evt, attendee); evt.ToggleAttendeeReminder(reaction.UserId); await EventsDatabase.Save(evt); } else { (string display, int index) = GetStatus(reaction.Emote); if (index < 0) { return; } evt.SetAttendeeStatus(reaction.UserId, index); await EventsDatabase.Save(evt); } await evt.Notify.Post(evt); RestUserMessage userMessage = (RestUserMessage)await channel.GetMessageAsync(message.Id); SocketUser user = Program.DiscordClient.GetUser(reaction.UserId); await userMessage.RemoveReactionAsync(reaction.Emote, user); } catch (Exception ex) { Log.Write(ex); } }