Exemple #1
0
        public async Task StartAsync([Remainder] string adventurename)
        {
            if (!AdventureService.messageMarkers.ContainsKey(Context.Channel.Id))
            {
                Dictionary <string, AdventureSegment> segments = AdventureService.adventures[adventurename].segments;
                string       segIndex = "Start";
                IUserMessage msg      = await AdventureService.SendSegmentMessage(Context.Channel, adventurename, segIndex);

                messageMarker messageMarker = new messageMarker(msg.Id, adventurename, segIndex);
                AdventureService.messageMarkers.Add(msg.Channel.Id, messageMarker);
            }
            else
            {
                await ReplyAsync("Sorry but only one adventure is allowed in a channel at once");
            }
        }
Exemple #2
0
        public static async Task <IUserMessage> SendSegmentMessage(ISocketMessageChannel channel, string adventurename, string segIndex)
        {
            AdventureSegment segment = adventures[adventurename].segments[segIndex];
            await channel.SendMessageAsync(string.Format("**{0}**", segment.maintext));

            Embed embed = GetChoiceEmbed(adventurename, segIndex);
            await Task.Delay(Convert.ToInt32(segment.maintext.Length / charPerSec * 1000));

            IUserMessage msg = await channel.SendMessageAsync(null, embed : embed);

            messageMarker messageMarker = new messageMarker(msg.Id, adventurename, segIndex);

            foreach (Emoji emote in GetChoiceEmotes(adventurename, segIndex))
            {
                await msg.AddReactionAsync(emote);
            }
            return(msg);
        }
Exemple #3
0
        private async Task OnReactionAdded(Discord.Cacheable <Discord.IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction)
        {
            string        segIndex      = "";
            messageMarker messageMarker = messageMarkers[channel.Id];

            if (reaction.User.Value.IsBot || message.Id != messageMarker.messageId)
            {
                return;
            }

            Adventure        adventure = adventures[messageMarker.adventureName];
            AdventureSegment segment   = adventure.segments[messageMarker.segIndex];

            foreach (AdventureChoice choice in segment.choices)
            {
                Emoji        emoji = new Emoji(choice.emote);
                IUserMessage msg   = await message.GetOrDownloadAsync();

                if ((await msg.GetReactionUsersAsync(emoji, 5).FlattenAsync()).Count() > 1)
                {
                    segIndex = choice.target;
                }
            }

            if (adventure.segments[segIndex].choices.Count() > 0)
            {
                IUserMessage newmsg = await SendSegmentMessage(channel, messageMarker.adventureName, segIndex);

                messageMarkers[channel.Id] = new messageMarker(newmsg.Id, messageMarker.adventureName, segIndex);
            }
            else
            {
                IncrementPlays(messageMarker.adventureName);
                await SendEndingMessage(channel, messageMarker.adventureName, segIndex);

                messageMarkers.Remove(channel.Id);
            }
        }