Ejemplo n.º 1
0
        public async Task ProgressInteractiveReactions(IUserMessage message, ISocketMessageChannel channel, SocketReaction reaction, IUser user)
        {
            if (!ProgressTracker.IsProgressTrackerMessage(message))
            {
                return;
            }

            if (reaction.Emote.Name == DecreaseEmoji)
            {
                DecreaseProgress(message);
                await message.RemoveReactionAsync(reaction.Emote, user).ConfigureAwait(false);
            }
            if (reaction.Emote.Name == IncreaseEmoji)
            {
                IncreaseProgress(message);
                await message.RemoveReactionAsync(reaction.Emote, user).ConfigureAwait(false);
            }
            if (reaction.Emote.Name == FullEmoji)
            {
                IncreaseProgressFullCheck(message);
                await message.RemoveReactionAsync(reaction.Emote, user).ConfigureAwait(false);
            }
            if (reaction.Emote.Name == RollEmoji)
            {
                var tracker = new ProgressTracker(message);
                var roll    = new ActionRoll(0, tracker.ActionDie, $"{ProgressResources.ProgressRollFor}{tracker.Title}");
                await channel.SendMessageAsync(roll.ToString()).ConfigureAwait(false);

                await message.RemoveReactionAsync(reaction.Emote, user).ConfigureAwait(false);
            }

            return;
        }
Ejemplo n.º 2
0
        private async Task CloserLook(IUserMessage message, ISocketMessageChannel channel, SocketReaction reaction, IUser user)
        {
            var oldEmbed = message.Embeds.FirstOrDefault();
            var planet   = Planet.GeneratePlanetFromEmbed(oldEmbed, Services);

            if (planet.RevealedLooks >= 3)
            {
                await message.RemoveReactionAsync(reaction.Emote, user).ConfigureAwait(false);

                return;
            }

            planet.RevealedLooks++;

            await message.ModifyAsync(msg =>
            {
                msg.Content = string.Empty;
                msg.Embed   = planet.GetEmbedBuilder().Build();
            }).ConfigureAwait(false);

            await message.RemoveReactionAsync(reaction.Emote, user).ConfigureAwait(false);

            if (planet.RevealedLooks >= 3)
            {
                await message.RemoveReactionAsync(reaction.Emote, message.Author).ConfigureAwait(false);
            }
        }
Ejemplo n.º 3
0
        public async Task ProgressInteractiveReactions(IUserMessage message, ISocketMessageChannel channel, SocketReaction reaction, IUser user)
        {
            if (!ProgressTrackerInfo.IsProgressTrackerMessage(message))
            {
                return;
            }

            if (reaction.Emote.IsSameAs(DecreaseEmoji))
            {
                DecreaseProgress(message);
                await message.RemoveReactionAsync(reaction.Emote, user).ConfigureAwait(false);
            }
            if (reaction.Emote.IsSameAs(IncreaseEmoji))
            {
                IncreaseProgress(message);
                await message.RemoveReactionAsync(reaction.Emote, user).ConfigureAwait(false);
            }
            if (reaction.Emote.IsSameAs(oldFullEmoji) || reaction.Emote.IsSameAs(FullEmoji))
            {
                IncreaseProgressFullCheck(message);
                await message.RemoveReactionAsync(reaction.Emote, user).ConfigureAwait(false);
            }
            if (reaction.Emote.IsSameAs(RollEmoji))
            {
                var tracker = new ProgressTrackerInfo().PopulateFromMessage(message);
                var roll    = new ActionRoll(0, tracker.ActionDie, $"{ProgressResources.ProgressRollFor}{tracker.Description}");
                await channel.SendMessageAsync(roll.ToString()).ConfigureAwait(false);

                await message.RemoveReactionAsync(reaction.Emote, user).ConfigureAwait(false);
            }

            return;
        }
Ejemplo n.º 4
0
        public async Task <bool> HandleReactionChangedAsync(IUserMessage message, IEmote reaction, IUser user, ReactionEvent eventType)
        {
            if (user.IsBot)
            {
                return(false);
            }

            if (await VoteService.ParseVoteCommand(message) is not VoteDefinition voteDefinition)
            {
                return(false);
            }

            if (voteDefinition.IsPastDeadline())
            {
                // vote already finished
                await message.RemoveReactionAsync(reaction, user);

                return(true);
            }

            if (!voteDefinition.Options.ContainsKey(reaction))
            {
                // not a vote option
                await message.RemoveReactionAsync(reaction, user);

                return(true);
            }

            var newText = VoteService.ComposeSummary(message, voteDefinition);
            await VoteService.UpdateVoteReplyAsync(message, newText);

            return(true);
        }
Ejemplo n.º 5
0
        public static async Task HandleReactionMessage(ISocketMessageChannel channel, SocketSelfUser botUser, SocketReaction reaction, IUserMessage message)
        {
            if (message.Author.Id == botUser.Id && reaction.UserId != botUser.Id)
            {
                var reactionMessage = GetReactionMessageById(message.Id);
                if (reactionMessage != null && reaction.UserId == reactionMessage.Context.User.Id && (reactionMessage.AcceptsAllReactions || reactionMessage.AcceptedReactions.Contains(reaction.Emote.ToString())))
                {
                    try
                    {
                        await reactionMessage.RunAction(reaction.Emote);
                    }
                    catch (Exception ex)
                    {
                        await ExceptionMessageHelper.HandleException(ex, channel);
                    }

                    if (reactionMessage.AllowMultipleReactions)
                    {
                        await message.RemoveReactionAsync(reaction.Emote, reactionMessage.Context.User);
                    }
                    else
                    {
                        await message.RemoveAllReactionsAsync();

                        DeleteReactionMessage(reactionMessage);
                    }
                }
                else if (reactionMessage != null && reaction.User.IsSpecified)
                {
                    await message.RemoveReactionAsync(reaction.Emote, reaction.User.Value);
                }
            }
        }
Ejemplo n.º 6
0
        public async Task First()
        {
            await _msg.RemoveReactionAsync(new Emoji(SFirst), _user);

            if (_currentPage == 0)
            {
                return;
            }

            await _msg.ModifyAsync(m => m.Embed = GetPage((int)(_currentPage = 0)));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gives the user reacting to the message in info the mapped role (devices/helper/news)
        /// </summary>
        /// <param name="message">The <see cref="Discord.IUserMessage"> object containing the info message reponsible for handling the info post</param>
        /// <param name="channel">The <see cref="Discord.WebSocket.ISocketMessageChannel"> info context channel</param>
        /// <param name="reaction">The <see cref="Discord.WebSocket.SocketReaction"> object containing the added reaction</param>
        /// <returns>task</returns>
        public async Task Execute(IUserMessage message, ISocketMessageChannel channel, SocketReaction reaction)
        {
            if (!(channel is IGuildChannel))
            {
                return;
            }
            var guildChannel = (IGuildChannel)channel;
            var isCustom     = !(reaction.Emote is Emoji);

            using (var db = new Database())
            {
                IQueryable <ReactionRole> appropriateRole;
                if (isCustom)
                {
                    var emote = reaction.Emote as Emote;
                    appropriateRole = db.ReactionRoles.Include(ro => ro.EmoteReference).Where(ro => ro.EmoteReference.EmoteId == emote.Id);
                }
                else
                {
                    var emoji = reaction.Emote as Emoji;
                    appropriateRole = db.ReactionRoles.Include(ro => ro.EmoteReference).Where(ro => ro.EmoteReference.Name == emoji.Name);
                }
                if (appropriateRole.Any())
                {
                    var user       = (IGuildUser)reaction.User.Value;
                    var roleToGive = appropriateRole.First();
                    if (roleToGive.MinLevel > 0)
                    {
                        var userInDb = db.Users.Include(u => u.CurrentLevel).AsQueryable().Where(dbU => dbU.Id == user.Id);
                        if (userInDb.Any())
                        {
                            var userFromDB = userInDb.FirstOrDefault();
                            if (userFromDB == null || userFromDB.CurrentLevel == null || userFromDB.CurrentLevel.Level < roleToGive.MinLevel)
                            {
                                await message.RemoveReactionAsync(reaction.Emote, reaction.User.Value);

                                return;
                            }
                        }
                        else
                        {
                            await message.RemoveReactionAsync(reaction.Emote, reaction.User.Value);

                            return;
                        }
                    }
                    var role = guildChannel.Guild.GetRole(roleToGive.RoleID);
                    await user.AddRoleAsync(role);
                }
            }
        }
Ejemplo n.º 8
0
        private async Task ReactionLocateObjectiveEvent(IUserMessage message, ISocketMessageChannel channel, SocketReaction reaction, IUser user)
        {
            if (!IsDelveMessage(message))
            {
                return;
            }
            await message.RemoveReactionAsync(reaction.Emote, user).ConfigureAwait(false);

            DelveInfo delve = new DelveInfo().FromMessage(DelveService, message);
            var       roll  = new ActionRoll(0, delve.ActionDie, String.Format(DelveResources.LocateObjectiveRoll, delve.SiteName));
            await channel.SendMessageAsync(roll.ToString()).ConfigureAwait(false);

            await message.RemoveReactionAsync(reaction.Emote, user).ConfigureAwait(false);
        }
Ejemplo n.º 9
0
        private async Task ShipReactionHandler(IUserMessage message, ISocketMessageChannel channel, SocketReaction reaction, IUser user)
        {
            var starshipHelperEmbed = message.Embeds.FirstOrDefault(embed => embed?.Title?.Contains(StarShipResources.StarshipHelperTitle) ?? false);

            if (starshipHelperEmbed != null)
            {
                var region = StarforgedUtilites.SpaceRegionFromEmote(reaction.Emote.Name);
                if (region == SpaceRegion.None)
                {
                    return;
                }

                string name = starshipHelperEmbed.Fields.FirstOrDefault(fld => fld.Name == StarShipResources.StarshipName).Value ?? string.Empty;

                Starship newShip = Starship.GenerateShip(Services, region, name);
                Task.WaitAll(message.RemoveAllReactionsAsync());

                await message.ModifyAsync(msg =>
                {
                    msg.Content = string.Empty;
                    msg.Embed   = newShip.GetEmbedBuilder().Build();
                }).ConfigureAwait(false);

                await message.AddReactionAsync(missionEmoji).ConfigureAwait(false);

                return;
            }

            var shipEmbed = message.Embeds.FirstOrDefault(embed => embed?.Description?.Contains(StarShipResources.Starship, StringComparison.OrdinalIgnoreCase) ?? false);

            if (shipEmbed == null)
            {
                return;
            }

            Starship ship = Starship.FromEmbed(Services, shipEmbed);

            if (reaction.Emote.Name == missionEmoji.Name)
            {
                ship.MissionRevealed = true;
                await message.RemoveReactionAsync(reaction.Emote, message.Author).ConfigureAwait(false);
            }

            await message.ModifyAsync(msg => msg.Embed = ship.GetEmbedBuilder().Build()).ConfigureAwait(false);

            await message.RemoveReactionAsync(reaction.Emote, user).ConfigureAwait(false);

            return;
        }
Ejemplo n.º 10
0
        async Task GrantUserRoleBasedOnReaction(IEmote emote, IUserMessage message, SocketGuild guild, TownGuild guildSettings, IGuildUser guildUser)
        {
            GrantingRoleSettings roleSettings = guildSettings.RoleGrantingSettings.MessagesMap[message.Id].ReactionsToRoles[emote.Name];

            SocketRole role = guild.GetRole(roleSettings.RoleToGrant);

            Console.WriteLine($"{guildUser} reacted with: {emote.Name} and is being given role: " + role);

            await guildUser.AddRoleAsync(role);

            if (guildSettings.RoleGrantingSettings.RemoveReactOnSuccess)
            {
                await message.RemoveReactionAsync(emote, guildUser);
            }

            string welcomeMessage = guildSettings.FormatMessage(roleSettings.GrantedMessage, guildUser, client);

            await(guild.GetChannel(roleSettings.MessageChannel) as SocketTextChannel).SendMessageAsync(welcomeMessage);

            if (roleSettings.DirectMessageOnGrant)
            {
                string directMessage = guildSettings.FormatMessage(roleSettings.DirectMessage, guildUser, client);

                await guildUser.SendMessageAsync(roleSettings.DirectMessage);
            }
        }
Ejemplo n.º 11
0
        public async Task OnReactionAddedAsync(Cacheable <IUserMessage, ulong> cache, ISocketMessageChannel chan, SocketReaction reaction)
        {
            if (!IsValidReaction(chan, reaction))
            {
                return;
            }
            IUserMessage msg = await cache.GetOrDownloadAsync();

            if (!this.IsValidMessage(msg))
            {
                return;
            }
            SocketGuildChannel reactionChan = (SocketGuildChannel)chan;
            SocketGuildUser    botUser      = reactionChan.Guild.CurrentUser;

            if (!botUser.GetPermissions(reactionChan).AddReactions)
            {
                return;
            }

            List <Embed> embeds = new List <Embed>();

            foreach (BaseProvider provider in this.ExtendableMessageProviders)
            {
                await provider.BuildEmbedsAsync(embeds, msg, reaction);
            }

            foreach (Embed embed in embeds)
            {
                await this.MessageSender.SendAsync(chan, embed);
            }

            await msg.RemoveReactionAsync(EmoteExtend, botUser);
        }
Ejemplo n.º 12
0
            public async Task <bool> HandleCallbackAsync(SocketReaction reaction)
            {
                // Remove the reaction so the button can be pressed again
                await _message.RemoveReactionAsync(reaction.Emote, reaction.UserId);

                var redraw = false;

                if (reaction.Emote.Name == SkipBackward)
                {
                    await _items.GotoStart();

                    redraw = true;
                }
                else if (reaction.Emote.Name == MoveBackward)
                {
                    redraw = await _items.MoveBackward();
                }
                else if (reaction.Emote.Name == MoveForward)
                {
                    redraw = await _items.MoveForward();
                }

                if (redraw)
                {
                    await Draw();
                }

                return(false);
            }
Ejemplo n.º 13
0
        private async Task CreatureReactionHandler(IUserMessage message, ISocketMessageChannel channel, SocketReaction reaction, IUser user)
        {
            var CreatureHelperEmbed = message.Embeds.FirstOrDefault(embed => embed?.Title?.Contains(CreatureResources.CreatureHelper) ?? false);

            if (CreatureHelperEmbed != null)
            {
                CreatureEnvironment environment = StarforgedUtilites.CreatureEnvironmentFromEmote(reaction.Emote.Name);
                if (reaction.Emote.IsSameAs(randomEmoji))
                {
                    string lookupValue = Services.GetRequiredService <OracleService>().RandomRow("Creature Environment").Description;
                    environment = StarforgedUtilites.GetAnyEnvironment(lookupValue);
                }
                if (environment == CreatureEnvironment.None)
                {
                    return;
                }

                var newCreature = Creature.GenerateNewCreature(Services, channel.Id, environment);
                Task.WaitAll(message.RemoveAllReactionsAsync());

                await message.ModifyAsync(msg =>
                {
                    msg.Content = string.Empty;
                    msg.Embed   = newCreature.GetEmbedBuilder().Build();
                }).ConfigureAwait(false);

                await Task.Run(async() =>
                {
                    if (message.Reactions.Count > 0)
                    {
                        await Task.Delay(1500); //wait just in case we are still adding more reactions. Impatient users deserve to wait!!!
                        await message.RemoveAllReactionsAsync();
                    }

                    await message.AddReactionAsync(revealAspectEmoji).ConfigureAwait(false);
                }).ConfigureAwait(false);

                return;
            }

            var creatureEmbed = message.Embeds.FirstOrDefault(embed => embed?.Title?.Contains(CreatureResources.CreatureTitle) ?? false);

            if (creatureEmbed == null)
            {
                return;
            }

            var creature = Creature.FromEmbed(creatureEmbed, Services, channel.Id);

            if (reaction.Emote.IsSameAs(revealAspectEmoji))
            {
                creature.AddRandomAspect();
            }

            await message.ModifyAsync(msg => msg.Embed = creature.GetEmbedBuilder().Build()).ConfigureAwait(false);

            await message.RemoveReactionAsync(reaction.Emote, user).ConfigureAwait(false);

            return;
        }
Ejemplo n.º 14
0
 /// <summary>
 ///     Remove multiple reactions from a message.
 /// </summary>
 /// <remarks>
 ///     This method does not bulk remove reactions! If you want to clear reactions from a message,
 ///     <see cref="IMessage.RemoveAllReactionsAsync(RequestOptions)"/>
 /// </remarks>
 /// <example>
 /// <code language="cs">
 /// await msg.RemoveReactionsAsync(currentUser, new[] { A, B });
 /// </code>
 /// </example>
 /// <param name="msg">The message to remove reactions from.</param>
 /// <param name="user">The user who removed the reaction.</param>
 /// <param name="reactions">An array of reactions to remove from the message.</param>
 /// <param name="options">The options to be used when sending the request.</param>
 /// <returns>
 ///     A task that represents the asynchronous operation for removing a reaction to this message.
 /// </returns>
 /// <seealso cref="IMessage.RemoveReactionAsync(IEmote, IUser, RequestOptions)"/>
 /// <seealso cref="IEmote"/>
 public static async Task RemoveReactionsAsync(this IUserMessage msg, IUser user, IEnumerable <IEmote> reactions, RequestOptions options = null)
 {
     foreach (var rxn in reactions)
     {
         await msg.RemoveReactionAsync(rxn, user, options).ConfigureAwait(false);
     }
 }
Ejemplo n.º 15
0
        public static void WaitForReaction(this IUserMessage message, SocketCommandContext context, IEmote emote, Func <Task> action)
        {
            async Task handler(Cacheable <IUserMessage, ulong> reactionMessage, ISocketMessageChannel channel, SocketReaction reaction)
            {
                var user = reaction.User.GetValueOrDefault() ?? context.Client.GetUser(reaction.UserId);

                if (user.IsBot || reactionMessage.Id != message.Id)
                {
                    return;
                }

                if (reaction.Emote.Name != emote.Name)
                {
                    await message.RemoveReactionAsync(reaction.Emote, user);
                }
                else
                {
                    await action();

                    context.Client.ReactionAdded -= handler;
                }
            }

            context.Client.ReactionAdded += handler;
        }
Ejemplo n.º 16
0
        [NotNull, ItemCanBeNull] private async Task <Task> EnqueueYoutubeClip(string vid, IUserMessage message)
        {
            var url = $"https://www.youtube.com/watch?v={vid}";

            //Try to get the audio from the cache
            var cached = _youtube.TryGetCachedYoutubeAudio(url);

            if (cached != null)
            {
                Console.WriteLine($"Retrieved {vid} from cache");
                return(await EnqueueMusicClip(() => new FileAudio(cached)));
            }
            else
            {
                //Add reaction indicating download
                var addEmoji = message.AddReactionAsync(EmojiLookup.Loading);

                //Start downloading the video
                var download = Task.Factory.StartNew(async() => {
                    var yt = await _youtube.GetYoutubeAudio(url);
                    Console.WriteLine("Download complete");
                    return(yt);
                }).Unwrap();

                //Wait for download to complete
                await addEmoji;
                await download;

                //Remove emoji indicating download
                await message.RemoveReactionAsync(EmojiLookup.Loading, Context.Client.CurrentUser);

                //Enqueue the track
                return(await EnqueueMusicClip(() => new YoutubeAsyncFileAudio(vid, download)));
            }
        }
Ejemplo n.º 17
0
        public static async Task ReactionAdded(Cacheable <IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction)
        {
            if (reaction.Emote.Name == "commend")
            {
                IUserMessage msg = (IUserMessage)channel.GetMessageAsync(message.Id).Result;

                IUser author = msg.Author;

                if (author.IsBot)
                {
                    return;
                }

                IUser sender = reaction.User.Value;

                using (VooperContext context = new VooperContext(VoopAI.DBOptions))
                {
                    User senderData = context.Users.FirstOrDefault(u => u.discord_id == sender.Id);

                    if (senderData == null || author.Id == sender.Id || senderData.discord_last_commend_hour == DateTime.Now.Hour)
                    {
                        await msg.RemoveReactionAsync(reaction.Emote, sender);
                    }
                    else
                    {
                        await AddCommend(author, sender, message.Id);
                    }
                }
            }
        }
Ejemplo n.º 18
0
        async Task <bool> FixRaidMessageAfterLoad(SocketGuild guild, IUserMessage message)
        {
            var raidInfo = ParseRaidInfo(message);

            if (raidInfo == null)
            {
                return(false);
            }

            logger.LogInformation($"Updating raid message '{message.Id}'");

            raidStorageService.AddRaid(guild.Id, message.Channel.Id, message.Id, raidInfo);
            // Adjust user count
            var allUsersWithThumbsUp = await message.GetReactionUsersAsync(Emojis.ThumbsUp, ReactionUsersLimit).FlattenAsync();

            var usersWithThumbsUp = allUsersWithThumbsUp
                                    .Where(t => !t.IsBot)
                                    .Select(t => guild.GetUser(t.Id))
                                    .Where(t => t != null);

            foreach (var user in usersWithThumbsUp)
            {
                raidInfo.Players[user.Id] = userService.GetPlayer(guild.GetUser(user.Id));
            }

            // Extra players
            for (int i = 0; i < Emojis.KeycapDigits.Length; i++)
            {
                var emoji = Emojis.KeycapDigits[i];
                var usersWithKeycapReaction = await message.GetReactionUsersAsync(emoji, ReactionUsersLimit).FlattenAsync();

                foreach (var user in usersWithKeycapReaction.Where(t => !t.IsBot))
                {
                    raidInfo.ExtraPlayers.Add((user.Id, ExtraPlayerKeycapDigitToCount(emoji.Name)));
                }
            }

            await message.ModifyAsync(t =>
            {
                t.Content = string.Empty;
                t.Embed   = ToEmbed(raidInfo);
            });

            var allReactions     = message.Reactions;
            var invalidReactions = allReactions.Where(t => !IsValidReactionEmote(t.Key.Name)).ToList();

            // Remove invalid reactions
            foreach (var react in invalidReactions)
            {
                var users = await message.GetReactionUsersAsync(react.Key, ReactionUsersLimit, retryOptions).FlattenAsync();

                foreach (var user in users)
                {
                    await message.RemoveReactionAsync(react.Key, user, retryOptions);
                }
            }

            return(true);
        }
Ejemplo n.º 19
0
        private async Task TryPlayUrlAsync(IMusicPlayerService music, ITextChannel textChan, IUserMessage msg, IGuildUser guser, string url)
        {
            if (string.IsNullOrWhiteSpace(url))
            {
                return;                                 // can be null or empty apparently
            }
            IGuildUser botUser = await guser.Guild.GetCurrentUserAsync();

            await msg.RemoveReactionAsync(Emote, botUser);

            bool played = await this.TryPlaySpotifyAsync(music, textChan, guser, url);

            if (played)
            {
                return;
            }

            SearchResult result = await music.LavaRestClient.SearchTracksAsync(url);

            List <ILavaTrack> tracks = result.Tracks.ToList();

            switch (result.LoadType)
            {
            case LoadType.SearchResult:
            case LoadType.TrackLoaded:
                if (tracks.Count > 0)
                {
                    await music.AddTrackAsync(guser.VoiceChannel, textChan, tracks[0]);
                }
                break;

            case LoadType.PlaylistLoaded:
                if (tracks.Count > 0)
                {
                    await music.AddPlaylistAsync(guser.VoiceChannel, textChan, result.PlaylistInfo.Name, tracks);
                }
                break;

            case LoadType.LoadFailed:
                await this.SendNonPlayableContentAsync(guser, msg, textChan, url, "File is corrupted or does not have audio");

                this.Logger.Nice("music player", ConsoleColor.Yellow, $"Could add/play track from playable content ({url})");
                break;

            case LoadType.NoMatches:
                await this.SendNonPlayableContentAsync(guser, msg, textChan, url, "Could not find the track to be added/played");

                this.Logger.Nice("music player", ConsoleColor.Yellow, $"Could not find match for playable content ({url})");
                break;

            default:
                await this.SendNonPlayableContentAsync(guser, msg, textChan, url, "Unkown error");

                this.Logger.Nice("music player", ConsoleColor.Yellow, $"Unknown error ({url})");
                break;
            }
        }
Ejemplo n.º 20
0
        internal async Task RemoveReaction(IEmote e, IUserMessage msg = null,
                                           SocketSelfUser bot         = null)
        {
            options.Remove(e.ToString());
            msg ??= await GetUiMessage();

            _ = msg.RemoveReactionAsync(e,
                                        bot ?? Handlers.DiscordBotHandler.Client.CurrentUser);
        }
Ejemplo n.º 21
0
        public async Task GoBack(SocketReaction reaction, SocketCommandContext context, IUserMessage msg)
        {
            if (index == 0)
            {
                await msg.RemoveReactionAsync(reaction.Emote, reaction.User.Value);

                return;
            }
            else
            {
                index--;
                await msg.ModifyAsync(x => x.Embed = PokemonEntry(results.ElementAt(index)));

                await msg.RemoveReactionAsync(reaction.Emote, reaction.User.Value);

                return;
            }
        }
Ejemplo n.º 22
0
        private async Task Life(IUserMessage message, ISocketMessageChannel channel, SocketReaction reaction, IUser user)
        {
            var oldEmbed = message.Embeds.FirstOrDefault();
            var planet   = Planet.GeneratePlanetFromEmbed(oldEmbed, Services);

            planet.LifeRevealed = true;

            await Task.Run(async() =>
            {
                await message.ModifyAsync(msg =>
                {
                    msg.Content = string.Empty;
                    msg.Embed   = planet.GetEmbedBuilder().Build();
                });
                await message.RemoveReactionAsync(reaction.Emote, user);
                await message.RemoveReactionAsync(reaction.Emote, message.Author);
            }).ConfigureAwait(false);
        }
Ejemplo n.º 23
0
        private async Task HandleReactionAdded(Cacheable <IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction)
        {
            if (reaction.User.IsSpecified && reaction.User.Value.IsBot)
            {
                return;
            }

            string reactionEmote = reaction.Emote.Name;

            // if an Eye emoji was added, let's process it
            if ((reactionEmote == "👁" || reactionEmote == "🖼") &&
                reaction.Message.IsSpecified &&
                (IsAuthorPatron(reaction.UserId) || BotConfig.Instance.OcrAutoIds.Contains(channel.Id)) &&
                reaction.Message.Value.ParseImageUrl() != null)
            {
                if (reaction.Message.Value.Reactions.Any(r => (r.Key.Name == "👁" || r.Key.Name == "🖼") && r.Value.ReactionCount > 1))
                {
                    return;
                }

                await this.HandleMessageReceivedAsync(reaction.Message.Value, reactionEmote);
            }

            var guildChannel = channel as SocketTextChannel;
            var settings     = SettingsConfig.GetSettings(guildChannel.Guild.Id);
            var customEmote  = reaction.Emote as Emote;

            if ((reactionEmote == "💬" || reactionEmote == "🗨️" || reactionEmote == "❓" || reactionEmote == "🤖") && reaction.Message.IsSpecified && !string.IsNullOrEmpty(reaction.Message.Value?.Content))
            {
                // if the reaction already exists, don't re-process.
                if (reaction.Message.Value.Reactions.Any(r => (r.Key.Name == "💬" || r.Key.Name == "🗨️" || r.Key.Name == "❓" || r.Key.Name == "🤖") && r.Value.ReactionCount > 1))
                {
                    return;
                }

                await this.HandleMessageReceivedAsync(reaction.Message.Value, reactionEmote, reaction.User.Value);
            }
            else if (reactionEmote == "➕" || reactionEmote == "➖" || customEmote?.Id == settings.RoleAddEmoteId || customEmote?.Id == settings.RoleRemoveEmoteId)
            {
                // handle possible role adds/removes
                IUserMessage reactionMessage = null;
                if (reaction.Message.IsSpecified)
                {
                    reactionMessage = reaction.Message.Value;
                }
                else
                {
                    reactionMessage = await reaction.Channel.GetMessageAsync(reaction.MessageId) as IUserMessage;
                }

                if (await RoleCommand.AddRoleViaReaction(reactionMessage, reaction))
                {
                    await reactionMessage.RemoveReactionAsync(reaction.Emote, reaction.User.Value);
                }
            }
        }
Ejemplo n.º 24
0
        private async Task MultiTrackLeft(IUserMessage message, ISocketMessageChannel channel, SocketReaction reaction, IUser user)
        {
            var asset = Asset.FromEmbed(Services, message.Embeds.First());

            //TODO

            await message.RemoveReactionAsync(reaction.Emote, user).ConfigureAwait(false);

            await message.ModifyAsync(msg => msg.Embed = asset.GetEmbed(asset.arguments.ToArray())).ConfigureAwait(false);
        }
Ejemplo n.º 25
0
        private async Task CountingTrackUp(IUserMessage message, ISocketMessageChannel channel, SocketReaction reaction, IUser user)
        {
            var asset = Asset.FromEmbed(Services, message.Embeds.First());

            asset.CountingAssetTrack.StartingValue++;

            await message.RemoveReactionAsync(reaction.Emote, user).ConfigureAwait(false);

            await message.ModifyAsync(msg => msg.Embed = asset.GetEmbed(asset.arguments.ToArray())).ConfigureAwait(false);
        }
        private async Task ContactReactionHandler(IUserMessage message, ISocketMessageChannel channel, SocketReaction reaction, IUser user)
        {
            var settlmentEmbed = message.Embeds.FirstOrDefault(embed => embed?.Description?.Contains(SettlementResources.Settlement) ?? false);

            if (settlmentEmbed == null)
            {
                return;
            }

            var settlement = new Settlement(Services, channel.Id).FromEmbed(settlmentEmbed);

            settlement.RevealInitialContact();

            await message.ModifyAsync(msg => msg.Embed = settlement.GetEmbedBuilder().Build()).ConfigureAwait(false);

            await message.RemoveReactionAsync(reaction.Emote, message.Author).ConfigureAwait(false);

            await message.RemoveReactionAsync(reaction.Emote, user).ConfigureAwait(false);
        }
Ejemplo n.º 27
0
        private async Task PairedTableReactionHandler(IUserMessage message, ISocketMessageChannel channel, SocketReaction reaction, IUser user)
        {
            if (message.Author.Id != _client.CurrentUser.Id)
            {
                return;
            }

            var pairEmoji = new Emoji("\uD83E\uDDE6");

            if (reaction.Emote.IsSameAs(pairEmoji))
            {
                await message.ModifyAsync(msg => msg.Embed = AddRollToExisting(message)).ConfigureAwait(false);

                await message.RemoveReactionAsync(pairEmoji, user).ConfigureAwait(false);

                await message.RemoveReactionAsync(pairEmoji, message.Author).ConfigureAwait(false);
            }

            return;
        }
Ejemplo n.º 28
0
            public async Task Unload(string role)
            {
                RoleSetting       roleSetting = Methods.Data.GetRoleSetting(role);
                SocketTextChannel channel     = Constants.IGuilds.Jordan(Context).Channels.Where(x => x.Id == Methods.Data.GetChnlId("role-selection")).FirstOrDefault() as SocketTextChannel;
                IUserMessage      msg         = channel.GetMessageAsync(roleSetting.id).Result as IUserMessage;
                Embed             embed       = msg.Embeds.FirstOrDefault() as Embed;

                if (embed.Fields.FirstOrDefault().Name == $"There are no {roleSetting.group.ToLower()} roles available at the moment.")
                {
                    //Message is empty
                    await ReplyAsync(":x: Role is not loaded.");
                }

                string rolename = Constants.IGuilds.Jordan(Context).Roles.Where(x => x.Id == roleSetting.roleid).FirstOrDefault().Name;

                foreach (EmbedField field in embed.Fields)
                {
                    if (field.Name == rolename)
                    {
                        //Role is loaded
                        EmbedBuilder embedBuilder = new EmbedBuilder();
                        embedBuilder.WithTitle(embed.Title);
                        embedBuilder.WithColor(embed.Color.Value);
                        if (embed.Fields.Count() == 1)
                        {
                            embedBuilder.AddField($"There are no {roleSetting.group.ToLower()} roles available at the moment.", "Check back later for another event.");
                        }
                        else
                        {
                            foreach (EmbedField field_ in embed.Fields)
                            {
                                if (field_.Name != rolename)
                                {
                                    embedBuilder.AddField(field_.Name, field_.Value);
                                }
                            }
                        }
                        if (embed.Footer != null)
                        {
                            embedBuilder.WithFooter(embed.Footer.Value.Text);
                        }

                        await msg.ModifyAsync(x => x.Embed = embedBuilder.Build());
                        await ReplyAsync(":white_check_mark: Role unloaded.");

                        IEmote emote = new Emoji("");
                        emote = new Emoji(Methods.Data.GetRoleSetting(role).emoji);
                        await msg.RemoveReactionAsync(emote, Context.Client.CurrentUser);

                        return;
                    }
                }
            }
Ejemplo n.º 29
0
        private async Task ReactionFeatureEvent(IUserMessage message, ISocketMessageChannel channel, SocketReaction reaction, IUser user)
        {
            if (!IsDelveMessage(message))
            {
                return;
            }
            await message.RemoveReactionAsync(reaction.Emote, user).ConfigureAwait(false);

            var delve = new DelveInfo().FromMessage(DelveService, message);

            await channel.SendMessageAsync(String.Format(DelveResources.RevealFeatureRoll, delve.SiteName), false, delve.RevealFeatureRoller().GetEmbed()).ConfigureAwait(false);
        }
Ejemplo n.º 30
0
        private async Task TradeConfirmation(Cacheable <IUserMessage, ulong> message, ISocketMessageChannel channel,
                                             SocketReaction reaction)
        {
            if (reaction.User.Value.IsBot || message.Id != _tradeMessage.Id)
            {
                return;
            }

            if (reaction.UserId != _tradeUserTwo || (!reaction.Emote.Name.Equals(Y) && !reaction.Emote.Name.Equals(N)))
            {
                await _tradeMessage.RemoveReactionAsync(reaction.Emote, reaction.User.Value);

                return;
            }

            Context.Client.ReactionAdded -= TradeConfirmation;
            await _tradeMessage.DeleteAsync();

            var playerOne = Program.PlayerList[_tradeUserOne];
            var playerTwo = Program.PlayerList[_tradeUserTwo];

            if (reaction.Emote.Name.Equals(Y))
            {
                if (_tradeYourItemID == uint.MaxValue)
                {
                    playerOne.TakeMoney(_tradeYourAmount);
                    playerTwo.GiveMoney(_tradeYourAmount);
                }
                else
                {
                    playerOne.TakeItem(_tradeYourItemID, _tradeYourAmount);
                    playerTwo.GiveItem(_tradeYourItemID, _tradeYourAmount);
                }

                if (_tradeTheirItemId == uint.MaxValue)
                {
                    playerTwo.TakeMoney(_tradeTheirAmount);
                    playerOne.GiveMoney(_tradeTheirAmount);
                }
                else
                {
                    playerTwo.TakeItem(_tradeTheirItemId, _tradeTheirAmount);
                    playerOne.GiveItem(_tradeTheirItemId, _tradeTheirAmount);
                }

                await ReplyAsync("Trade accepted!");
            }
            else
            {
                await ReplyAsync("Trade declined");
            }
            _sqlService.UpdateDatabase();
        }