public static string GetMention(this Event.Instance.Attendee self, Event evt) { if (self.UserId == null) { throw new ArgumentNullException("Id"); } SocketUser user = Program.DiscordClient.GetUser(ulong.Parse(self.UserId)); if (user == null) { return("Unknown"); } SocketGuild guild = Program.DiscordClient.GetGuild(evt.ServerIdStr); if (guild != null) { SocketGuildUser guildUser = guild.GetUser(ulong.Parse(self.UserId)); if (guildUser != null) { return(guildUser.Mention); } } return(user.Username); }
public static bool Is(this Event.Instance.Attendee self, ulong userId) { if (self.UserId == null) { return(false); } return(ulong.Parse(self.UserId) == userId); }
public static Event.Instance.Attendee GetOrCreateAttendee(this Event self, ulong userId) { Event.Instance.Attendee?attendee = self.GetAttendee(userId); if (attendee == null) { attendee = new Event.Instance.Attendee(); attendee.UserId = userId.ToString(); } return(attendee); }
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); } }
public static void SetAttendeeStatus(this Event self, ulong userId, int index) { Event.Instance.Attendee attendee = self.GetOrCreateAttendee(userId); attendee.Status = index; }
public static void ToggleAttendeeReminder(this Event self, ulong userId) { Event.Instance.Attendee attendee = self.GetOrCreateAttendee(userId); attendee.Notify = !attendee.Notify; }