Пример #1
0
        private async Task CheckReactions(RestUserMessage sm, RoleSelector rsm, bool dupchecker = false)
        {
            for (int i = 0; i < sm.Reactions.Count; i++)
            {
                var rd = sm.Reactions.ElementAt(i);

                var t = await sm.GetReactionUsersAsync(rd.Key, 100).FlattenAsync();

                if (!rd.Value.IsMe)
                {
                    foreach (var bb in t)
                    {
                        await sm.RemoveReactionAsync(rd.Key, bb);
                    }
                }
                else if (!dupchecker)
                {
                    var p = rsm.roles.Where(s => s.EmoteCheckCompare(rd.Key.Name)).ToList();
                    if (p.Count == 0)
                    {
                        foreach (var bb in t)
                        {
                            await sm.RemoveReactionAsync(rd.Key, bb);
                        }
                    }
                }
            }

            if (!dupchecker)
            {
                await GetEmotes(sm, rsm);
            }
        }
Пример #2
0
        private static async Task CheckReactions(this Event.Instance self, Event evt, RestUserMessage message, IEmote emote, int index)
        {
            IEnumerable <IUser> checkedUsers = await message.GetReactionUsersAsync(emote, 99).FlattenAsync();

            if (!checkedUsers.Contains(Program.DiscordClient.CurrentUser))
            {
                await message.AddReactionAsync(emote);
            }

            foreach (IUser user in checkedUsers)
            {
                if (user.Id == Program.DiscordClient.CurrentUser.Id)
                {
                    continue;
                }

                evt.SetAttendeeStatus(user.Id, index);

                SocketUser socketUser = Program.DiscordClient.GetUser(user.Id);
                await message.RemoveReactionAsync(emote, socketUser);
            }
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
        private async Task ReactionAwait(RestUserMessage msg, string nameMsg, List <string> pageContent)
        {
            int    page            = 0;
            var    userId          = Context.User.Id;
            IEmote reactionBack    = new Emoji("⬅️");
            IEmote reactionForward = new Emoji("➡️");
            await msg.AddReactionAsync(reactionBack).ConfigureAwait(false);

            System.Threading.Thread.Sleep(300);
            await msg.AddReactionAsync(reactionForward).ConfigureAwait(false);

            var sw = new Stopwatch();

            sw.Start();

            while (sw.ElapsedMilliseconds < 30_000)
            {
                var collectorBack = await msg.GetReactionUsersAsync(reactionBack, 100).FlattenAsync().ConfigureAwait(false);

                var collectorForward = await msg.GetReactionUsersAsync(reactionForward, 100).FlattenAsync().ConfigureAwait(false);

                IUser?UserReactionBack    = collectorBack.FirstOrDefault(x => x.Id == userId && !x.IsBot);
                IUser?UserReactionForward = collectorForward.FirstOrDefault(x => x.Id == userId && !x.IsBot);

                if (UserReactionBack != null && page > 0)
                {
                    page--;
                    var embedBack = new EmbedBuilder {
                        Color = Color.DarkBlue
                    }.AddField(x =>
                    {
                        x.Name     = nameMsg;
                        x.Value    = pageContent[page];
                        x.IsInline = false;
                    }).WithFooter(x =>
                    {
                        x.IconUrl = "https://i.imgur.com/nXNBrlr.png";
                        x.Text    = $"Page {page + 1 } of {pageContent.Count}";
                    }).Build();

                    await msg.RemoveReactionAsync(reactionBack, UserReactionBack);

                    await msg.ModifyAsync(msg => msg.Embed = embedBack).ConfigureAwait(false);

                    sw.Restart();
                }
                else if (UserReactionForward != null && page < pageContent.Count - 1)
                {
                    page++;
                    var embedForward = new EmbedBuilder {
                        Color = Color.DarkBlue
                    }.AddField(x =>
                    {
                        x.Name     = nameMsg;
                        x.Value    = pageContent[page];
                        x.IsInline = false;
                    }).WithFooter(x =>
                    {
                        x.IconUrl = "https://i.imgur.com/nXNBrlr.png";
                        x.Text    = $"Page {page + 1} of {pageContent.Count}";
                    }).Build();

                    await msg.RemoveReactionAsync(reactionForward, UserReactionForward);

                    await msg.ModifyAsync(msg => msg.Embed = embedForward).ConfigureAwait(false);

                    sw.Restart();
                }
            }
            await msg.DeleteAsync().ConfigureAwait(false);
        }
Пример #5
0
        public async Task Play(SocketReaction reaction, ISocketMessageChannel channel, Optional <IUser> user)
        {
            if (user.ToString() == "Gideon#8386")
            {
                return;
            }
            if (currentTurnUser.ToString() != user.ToString())
            {
                await m.RemoveReactionAsync(reaction.Emote, reaction.User.Value);

                return;
            }

            string emote = reaction.Emote.ToString();

            if (emote == "↖")
            {
                boardSlots[0] = EmojiToPlace(0);
            }
            else if (emote == "⬆")
            {
                boardSlots[1] = EmojiToPlace(1);
            }
            else if (emote == "↗")
            {
                boardSlots[2] = EmojiToPlace(2);
            }
            else if (emote == "⬅")
            {
                boardSlots[3] = EmojiToPlace(3);
            }
            else if (emote == "⏺")
            {
                boardSlots[4] = EmojiToPlace(4);
            }
            else if (emote == "➡")
            {
                boardSlots[5] = EmojiToPlace(5);
            }
            else if (emote == "↙")
            {
                boardSlots[6] = EmojiToPlace(6);
            }
            else if (emote == "⬇")
            {
                boardSlots[7] = EmojiToPlace(7);
            }
            else if (emote == "↘")
            {
                boardSlots[8] = EmojiToPlace(8);
            }

            if (canPlaySlot)
            {
                await CheckForWin(channel, ":x:");
                await CheckForWin(channel, ":o:");
                await CheckForDraw();
                await IncrementTurn();
            }

            await m.RemoveReactionAsync(reaction.Emote, reaction.User.Value);
        }
Пример #6
0
        private async Task HandleEventAsync(Cacheable <IUserMessage, ulong> cache, ISocketMessageChannel channel, SocketReaction reaction, RestUserMessage message, bool reactionAdded)
        {
            var           em     = message.Embeds.First();
            var           fields = em.Fields;
            List <string> att    = new List <string>();
            List <string> nAtt   = new List <string>();

            // Iterate over fields and grab data needed
            int    maxParticipants = 0;
            string dateTime        = "";

            for (int i = 0; i < fields.Count(); i++)
            {
                if (fields[i].Name == "When?")
                {
                    dateTime = fields[i].Value;
                }
                if (fields[i].Name == "Max Participants")
                {
                    maxParticipants = Int32.Parse(fields[i].Value);
                }
            }

            // Refresh both 'Attending' and 'Not attending' lists
            var attending = message.GetReactionUsersAsync(new Emoji("\u2705"), 100);

            attending.ForEach(users => {
                for (int i = 0; i < users.Count(); i++)
                {
                    if (!users.ElementAt(i).IsBot)
                    {
                        att.Add(users.ElementAt(i).Mention);
                    }
                }
            });
            var notAttending = message.GetReactionUsersAsync(new Emoji("\u274C"), 100);

            notAttending.ForEach(users => {
                for (int i = 0; i < users.Count(); i++)
                {
                    if (!users.ElementAt(i).IsBot)
                    {
                        nAtt.Add(users.ElementAt(i).Mention);
                    }
                }
            });

            // If reaction was added
            if (reactionAdded)
            {
                // Check if max participants have been reached
                if (att.Count > maxParticipants && maxParticipants != 0)
                {
                    await message.RemoveReactionAsync(new Emoji("\u2705"), reaction.User.Value);

                    return;
                }

                // Check for and handle double reactions
                if (reaction.Emote.Equals(new Emoji("\u2705")))
                {
                    foreach (string n in nAtt)
                    {
                        if (n == reaction.User.Value.Mention)
                        {
                            await message.RemoveReactionAsync(new Emoji("\u274C"), reaction.User.Value);

                            return;
                        }
                    }
                }
                if (reaction.Emote.Equals(new Emoji("\u274C")))
                {
                    foreach (string n in att)
                    {
                        if (n == reaction.User.Value.Mention)
                        {
                            await message.RemoveReactionAsync(new Emoji("\u2705"), reaction.User.Value);

                            return;
                        }
                    }
                }
            }

            var embed = await EmbedHandler.UpdateEventEmbed(em.Title, em.Description, maxParticipants, dateTime, em.Footer.Value.ToString(), att, nAtt);

            await message.ModifyAsync(q => {
                q.Embed = embed;
            });
        }