Exemplo n.º 1
0
        public async Task checkWord(Discord.Commands.SocketCommandContext context, string word)
        {
            if (foundWords.Contains(word))
            {
                await context.Message.AddReactionAsync(new Emoji("🔁"));

                return;
            }
            foreach (char item in word)
            {
                if (!letters.Contains(item))
                {
                    await context.Message.AddReactionAsync(new Emoji("❌"));

                    return;
                }
            }
            using (StreamReader sr = new StreamReader("sowpods.txt"))
            {
                string line = "";
                while ((line = sr.ReadLine()) != null)
                {
                    if (line == word)
                    {
                        if (word.Length >= 7)
                        {
                            await context.Channel.SendMessageAsync($"7+ letter word was found, game over!");

                            addPoints(context.Message.Author.Id, word.Length);
                            string scoreboard = "**Scores:**\n";
                            foreach (KeyValuePair <ulong, int> item in Global.wordGameDic[context.Channel.Id].scoreCard)
                            {
                                scoreboard = scoreboard + Commands.DBTransaction.getUserFromID(item.Key) + ": " + item.Value + "\n";
                            }
                            await context.Channel.SendMessageAsync(scoreboard);

                            Global.wordGameDic.Remove(context.Channel.Id);
                            return;
                        }
                        foundWords.Add(word);
                        addPoints(context.Message.Author.Id, word.Length);
                        string newMessage = message.Content + " " + word;
                        await message.ModifyAsync(msg => msg.Content = newMessage);

                        await context.Message.DeleteAsync();

                        return;
                    }
                }
                await context.Message.AddReactionAsync(new Emoji("❌"));
            }
        }
Exemplo n.º 2
0
        async Task PreGame()
        {
            var messages = await channel.GetMessagesAsync().FlattenAsync();

            await channel.DeleteMessagesAsync(messages);

            int preGameMinutes = 3;
            int preGameSeconds = 0;

            const string messageContent = "**DM to join bideo gam**";

            message = await channel.SendMessageAsync(messageContent, false, new EmbedBuilder().WithFooter("Created by Jeff and .jpg.\nView our code here: https://github.com/drB-dotjpg/DiscordUnoBot").Build());

            do
            {
                bool twoOrMore = players.Count >= 2;

                string time = twoOrMore ? $"`{preGameMinutes.ToString("00")}:{preGameSeconds.ToString("00")}`" : "`Waiting for two or more players`";

                string playersDisplay = "";
                foreach (Player player in players)
                {
                    playersDisplay += "`" + player.name + "` ";
                }
                playersDisplay = players.Count != 0 ? playersDisplay.Trim() : "`No players`";

                await message.ModifyAsync(x => x.Content = $"{messageContent}\n" +
                                          $"> Time remaining: {time}\n" +
                                          $"> Players: {playersDisplay}");

                if (twoOrMore)
                {
                    preGameSeconds--;
                }
                if (preGameSeconds < 0 && preGameMinutes > 0)
                {
                    preGameMinutes--;
                    preGameSeconds += 59;
                }
                await Task.Delay(1000);
            } while (preGameSeconds > 0 || preGameMinutes > 0);

            foreach (Player player in players)
            {
                for (int i = 0; i < 6; i++)
                {
                    player.Cards.Add(GenerateCard());
                }
            }
            Shuffle(players);
            await InGame();
        }
Exemplo n.º 3
0
            public async Task mySR()
            {
                Discord.Rest.RestUserMessage msg = await Context.Channel.SendMessageAsync("Hold please...");

                Person person = Data.Data.GetUser(Context.User.Id);

                if (person.BattleTag == String.Empty)
                {
                    await msg.ModifyAsync(con => con.Content = "I'm afraid I do not know your battle tag!");
                }
                else
                {
                    Player player = await Utilities.Overwatch.GetPlayer(person.BattleTag);

                    if (player.IsProfilePrivate)
                    {
                        await msg.ModifyAsync(con => con.Content = "Your profile seems to be private. Change it to public and then close the game to use this command.");
                    }
                    else
                    {
                        await msg.ModifyAsync(con => con.Content = "Your SR is: " + player.CompetitiveRank);
                    }
                }
            }
Exemplo n.º 4
0
        async Task InGame()
        {
            phase    = Phase.Ingame;
            lastCard = GenerateCard(true);

            while (true)
            {
                await SendTurnsToPlayersAsync();

                await message.ModifyAsync(x => x.Content = "Current Game");

                await message.ModifyAsync(x => x.Embed = GetTurnBriefing(null, true, true, false).Build());

                string drawNotif = drawMultiplier > 0 ? $"\nYou will draw {drawMultiplier} at the end of the turn, unless you stack." : "";

                await AlertPlayerAsync(GetCurrentTurnOrderPlayer(), "Its your turn! Select a card to play or draw a card.", $"You have {timeForTurn} seconds to play a card.{drawNotif}");

                int turnTimer = 0;
                while (!nextTurnFlag && turnTimer < timeForTurn)
                {
                    await Task.Delay(1000);

                    turnTimer++;

                    if (timeForTurn - turnTimer == (int)(timeForTurn / 3))
                    {
                        await AlertPlayerAsync(GetCurrentTurnOrderPlayer(), $"You have {timeForTurn - turnTimer} seconds to play a card!");
                    }
                }

                if (!nextTurnFlag)
                {
                    GetCurrentTurnOrderPlayer().afkSkips++;
                    if (GetCurrentTurnOrderPlayer().afkSkips >= afkSkipsAllowed)
                    {
                        await AlertPlayerAsync(GetCurrentTurnOrderPlayer(), "You ran out of time! You have been kicked due to inactivity.");
                        await HandleLeave(GetCurrentTurnOrderPlayer().thisUser);
                    }
                    else
                    {
                        await AlertPlayerAsync(GetCurrentTurnOrderPlayer(), "You ran out of time!", "Starting next turn" +
                                               "\nContinue running out of time and you'll be kick from the game.");
                        await HandleCardDraw(GetCurrentTurnOrderPlayer().thisUser, await GetCurrentTurnOrderPlayer().thisUser.GetOrCreateDMChannelAsync() as SocketDMChannel);
                    }
                }

                if (nextTurnFlag && GetCurrentTurnOrderPlayer().Cards.Count == 0) //if the player has 0 cards
                {
                    winningPlayer = GetCurrentTurnOrderPlayer();
                    await PostGame();

                    break;
                }
                if (players.Count < 2) //if there are less than 2 players (ie: someone left the game)
                {
                    winningPlayer = players.FirstOrDefault();
                    await PostGame();

                    break;
                }

                StartNextTurn();

                turnMultiplier = 1;
                turn++;
                nextTurnFlag = false;
            }
        }
Exemplo n.º 5
0
        public async Task <string> GetYtURL(SocketCommandContext Context, string name, InteractiveService interactive, Discord.Rest.RestUserMessage msg)
        {
            try
            {
                var youtubeService = new YouTubeService(new BaseClientService.Initializer()
                {
                    ApiKey          = ytApiKey,
                    ApplicationName = "RankoKanzaki"
                });

                List <string> videos = new List <string>();

                int i     = 1;
                var items = new VideoSearch();

                List <string> urls = new List <string>();
                foreach (var item in items.SearchQuery(name, 1))
                {
                    byte[] bytes = System.Text.Encoding.Default.GetBytes(item.Title);
                    string value = System.Text.Encoding.UTF8.GetString(bytes);

                    videos.Add(string.Format("{0})", value));
                    urls.Add(string.Format("{0})", item.Url));

                    i++;
                }
                int index;
                if (videos.Count > 1)
                {
                    var eb = new EmbedBuilder()
                    {
                        Color = new Color(4, 97, 247),
                        Title = "Enter the Index of the YT video you want to add.",
                    };
                    string vids  = "";
                    int    count = 1;
                    foreach (var v in videos)
                    {
                        vids += $"**{count}.** {v}\n";
                        count++;
                    }
                    eb.Description = vids;
                    var del = await Context.Channel.SendMessageAsync("", false, eb.Build());

                    var response = await interactive.WaitForMessage(Context.User, Context.Channel, TimeSpan.FromSeconds(20));

                    await del.DeleteAsync();

                    if (response == null)
                    {
                        await msg.ModifyAsync(x =>
                        {
                            x.Content = $":no_entry_sign: Answer timed out {Context.User.Mention} (≧д≦ヾ)";
                        });

                        return("f2");
                    }
                    if (!Int32.TryParse(response.Content, out index))
                    {
                        await msg.ModifyAsync(x =>
                        {
                            x.Content = $":no_entry_sign: Only add the Index";
                        });

                        return("f2");
                    }
                    if (index > (videos.Count) || index < 1)
                    {
                        await msg.ModifyAsync(x =>
                        {
                            x.Content = $":no_entry_sign: Invalid Number";
                        });

                        return("f2");
                    }
                }
                else
                {
                    index = 1;
                }
                return(urls[index - 1]);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            return("f");
        }
Exemplo n.º 6
0
        private async Task <string> AniInfo([Remainder] string text, Discord.Rest.RestUserMessage msg, AnilistType type)
        {
            var client          = new GraphQLClient("https://graphql.anilist.co");
            List <animeinfo> ch = new List <animeinfo>();
            var    info         = new animeinfo();
            string stype        = "";

            if (type == AnilistType.ANIME)
            {
                stype = "ANIME";
            }
            else
            {
                stype = "MANGA";
            }
            var request = new GraphQLRequest
            {
                Query     = @"
query($id: Int, $page: Int, $perPage: Int, $search: String) {
                    Page(page: $page, perPage: $perPage) {
                        pageInfo {
                          total
                          currentPage
                          lastPage
                          hasNextPage
                          perPage
                        }
                        media(type: " + stype + @", id: $id, search: $search, isAdult: false) {
                            id
                            title {
                                romaji
                            }
                            siteUrl 
                        }
                    }
                }
",
                Variables = new
                {
                    search  = text,
                    page    = 1,
                    perPage = 20
                }
            };

            var response = await client.PostAsync(request);

            if (response.Data.Page.pageInfo.total.ToObject <int>() > 0)
            {
                if (response.Data.Page.pageInfo.total.ToObject <int>() > response.Data.Page.pageInfo.perPage.ToObject <int>())
                {
                    for (int i = 0; i < 20; i++)
                    {
                        info.id      = response.Data.Page.media[i].id;
                        info.romaji  = response.Data.Page.media[i].title.romaji;
                        info.siteURL = response.Data.Page.media[i].siteUrl;
                        ch.Add(info);
                    }
                }
                else
                {
                    for (int i = 0; i < response.Data.Page.pageInfo.total.ToObject <int>(); i++)
                    {
                        info.id      = response.Data.Page.media[i].id;
                        info.romaji  = response.Data.Page.media[i].title.romaji;
                        info.siteURL = response.Data.Page.media[i].siteUrl;
                        ch.Add(info);
                    }
                }
            }
            else
            {
                return("f");
            }

            int index;

            if (ch.Count > 1 && ch != null)
            {
                var eb = new EmbedBuilder()
                {
                    Color = new Color(4, 97, 247),
                    Title = "Enter the index of character u wanna see.",
                };
                string vids  = "";
                int    count = 1;
                foreach (var v in ch)
                {
                    vids += $"**{count}.** {v.romaji}\n";
                    count++;
                }
                eb.Description = vids;
                var del = await Context.Channel.SendMessageAsync("", false, eb.Build());

                var response2 = await _interactive.WaitForMessage(Context.User, Context.Channel, TimeSpan.FromSeconds(20));

                await del.DeleteAsync();

                if (response2 == null)
                {
                    await msg.ModifyAsync(x =>
                    {
                        x.Content = $":no_entry_sign: Answer timed out {Context.User.Mention} (≧д≦ヾ)";
                    });

                    return("f2");
                }
                if (!Int32.TryParse(response2.Content, out index))
                {
                    await msg.ModifyAsync(x =>
                    {
                        x.Content = $":no_entry_sign: Only add the Index";
                    });

                    return("f2");
                }
                if (index > (ch.Count) || index < 1)
                {
                    await msg.ModifyAsync(x =>
                    {
                        x.Content = $":no_entry_sign: Invalid Number";
                    });

                    return("f2");
                }
            }
            else
            {
                index = 1;
            }
            return(ch[index - 1].siteURL);
        }
Exemplo n.º 7
0
        public async Task FlipAsync([Remainder] string input)
        {
            int    delay    = 15;
            string emote    = null;
            int    bet      = 0;
            string side     = null;
            var    userInfo = (IGuildUser)Context.User;
            string userName = null;

            Discord.Rest.RestUserMessage mainMessage = null;
            Embed embedBuilt = null;

            if (userInfo.Nickname != null)
            {
                userName = userInfo.Nickname;
            }
            else
            {
                userName = Context.User.Username;
            }

            var footer = new EmbedFooterBuilder
            {
                Text = "Cody by Ayla / Alsekwolf#0001"
            };
            var author = new EmbedAuthorBuilder
            {
                IconUrl = Context.User.GetAvatarUrl(),
                Name    = $"{userName} entered a game of coin flip."
            };
            var embed = new EmbedBuilder
            {
                Author    = author,
                Color     = Color.Magenta,
                Footer    = footer,
                Timestamp = DateTimeOffset.Now
            };

            if (!Services.CommandDelay.IncomingRequest(Context.User.Id.ToString(), delay))
            {
                string activeUser = _activeUsers.FirstOrDefault(s => s == Context.User.Id.ToString());
                if (activeUser == null)
                {
                    _activeUsers.Add(Context.User.Id.ToString());
                }
                if (activeUser != null)
                {
                    await Context.Message.DeleteAsync();

                    return;
                }

                embed.WithDescription(
                    $"please wait longer between *investing*. \nYour bet will be sent when the delay is up. \nReact with the stop emote to cancel.");
                embedBuilt  = embed.Build();
                mainMessage = await Context.Channel.SendMessageAsync(embed : embedBuilt);

                if (Emote.TryParse(StopEmote, out var stopEmoteParsed))
                {
                    await mainMessage.AddReactionAsync(stopEmoteParsed);
                }

                Services.CommandDelay.User tempUser = Services.CommandDelay.Users.FirstOrDefault(User => User.Username == Context.User.Id.ToString());
                try
                {
                    while ((DateTime.Now - tempUser.LastRequest).TotalSeconds <= delay)
                    {
                        await Task.Delay(1000);
                    }

                    int count = 0;
                    foreach (string y in _activeUsers.FindAll(x => x == Context.User.Id.ToString()))  // returns the value of all hits}
                    {
                        _activeUsers.Remove(y);
                        count++;
                    }

                    var userList = await mainMessage.GetReactionUsersAsync(stopEmoteParsed, int.MaxValue).FlattenAsync();

                    if (userList.Any(u => u.Id == Context.User.Id))
                    {
                        return;
                    }
                    await mainMessage.RemoveAllReactionsAsync();
                }
                catch (Exception e)
                {
                    Console.WriteLine("DelayCommand error: " + e.Message);
                    throw;
                }
            }

            var SQL      = new SQLFunctions.Main();
            var userData = SQL.LoadUserData(Context.User);

            if (input.ContainsAny(" "))
            {
                var splitInput = input.Split(' ');
                if (splitInput[0].All(char.IsDigit))
                {
                    bet  = Int32.Parse(splitInput[0]);
                    side = splitInput[1];
                }
                if (splitInput[1].All(char.IsDigit))
                {
                    bet  = Int32.Parse(splitInput[1]);
                    side = splitInput[0];
                }
                if (splitInput[0].ContainsAny("all"))
                {
                    bet  = userData.cash;
                    side = splitInput[1];
                }
                if (splitInput[1].ContainsAny("all"))
                {
                    bet  = userData.cash;
                    side = splitInput[0];
                }
                if (side.ContainsAny("head", "heads", "h"))
                {
                    side = "heads";
                }
                if (side.ContainsAny("tail", "tailss", "t"))
                {
                    side = "tails";
                }
            }
            else
            {
                if (input.All(char.IsDigit))
                {
                    bet  = Int32.Parse(input);
                    side = "heads";
                }

                if (input.ContainsAny("all"))
                {
                    bet  = userData.cash;
                    side = "heads";
                }
            }

            if (bet == 0)
            {
                embed.WithDescription($"You can't bet 0, that's not how this works!!'");
                embedBuilt = embed.Build();

                if (mainMessage != null)
                {
                    await mainMessage.ModifyAsync(msg => msg.Embed = embedBuilt);
                }
                else
                {
                    await Context.Channel.SendMessageAsync(embed : embedBuilt);
                }
                return;
            }
            if (side == null)
            {
                embed.WithDescription($"something went wrong, please try again.");
                embedBuilt = embed.Build();

                if (mainMessage != null)
                {
                    await mainMessage.ModifyAsync(msg => msg.Embed = embedBuilt);
                }
                else
                {
                    await Context.Channel.SendMessageAsync(embed : embedBuilt);
                }
                return;
            }

            if (userData.cash >= bet)
            {
                embed.WithAuthor($"{userName} spent ${bet} and chose {side}", Context.User.GetAvatarUrl());
                embed.WithDescription($"The coin spins.... {FlipEmote}");
                embedBuilt = embed.Build();

                if (mainMessage != null)
                {
                    await mainMessage.ModifyAsync(msg => msg.Embed = embedBuilt);
                }
                else
                {
                    mainMessage = await Context.Channel.SendMessageAsync(embed : embedBuilt);
                }

                await Task.Delay(2250);

                int randomNumber = RandomNumber.Between(0, 100);
                if (randomNumber > 50)
                {
                    if (side == "heads")
                    {
                        emote = TailsEmote;
                    }
                    else
                    {
                        emote = HeadsEmote;
                    }

                    embed.WithDescription($"The coin spins.... {emote} and **{userName}** lost it all... :c");
                    embedBuilt = embed.Build();

                    await mainMessage.ModifyAsync(msg => msg.Embed = embedBuilt);

                    userData.cash = userData.cash - bet;
                    SQL.SaveUserData(Context.User, userData);
                }

                if (randomNumber < 50)
                {
                    if (side == "heads")
                    {
                        emote = HeadsEmote;
                    }
                    else
                    {
                        emote = TailsEmote;
                    }
                    embed.WithDescription($"The coin spins.... {emote} and **{userName}** won **${bet}** c:");
                    embedBuilt = embed.Build();

                    await mainMessage.ModifyAsync(msg => msg.Embed = embedBuilt);

                    userData.cash = userData.cash + bet;
                    SQL.SaveUserData(Context.User, userData);
                }
            }
            else
            {
                embed.WithDescription($"you probably don't have enough cash. \nYou currently have **${userData.cash}**");
                embedBuilt = embed.Build();

                if (mainMessage != null)
                {
                    await mainMessage.ModifyAsync(msg => msg.Embed = embedBuilt);
                }
                else
                {
                    await Context.Channel.SendMessageAsync(embed : embedBuilt);
                }
            }
        }
Exemplo n.º 8
0
        public async Task HandleReact(Cacheable <IUserMessage, ulong> cache, ISocketMessageChannel channel, SocketReaction react)
        {
            if ((react.UserId != client.CurrentUser.Id))
            {
                string tag = null;
                Discord.Rest.RestUserMessage message = null;
                foreach (IMessage msg in Var.awaitingHelp)
                {
                    if (msg.Id == cache.Value.Id)
                    {
                        if (react.Emote.Name == Constants.Emotes.HAMMER.Name)
                        {
                            tag = "[MOD]";
                        }
                        else if (react.Emote.Name == Constants.Emotes.DIE.Name)
                        {
                            tag = "[FUN]";
                        }
                        else if (react.Emote.Name == Constants.Emotes.QUESTION.Name)
                        {
                            tag = "[OTHER]";
                        }
                        else if (react.Emote.Name == Constants.Emotes.BRADY.Name)
                        {
                            tag = "[BRADY]";
                        }
                        message = msg as Discord.Rest.RestUserMessage;
                        Var.awaitingHelp.Remove(msg);
                        break;
                    }
                }

                if (tag != null)
                {
                    JEmbed emb = new JEmbed();

                    emb.Author.Name = "ForkBot Commands";
                    emb.ColorStripe = Constants.Colours.DEFAULT_COLOUR;

                    foreach (CommandInfo c in commands.Commands)
                    {
                        string cTag = null;
                        if (c.Summary != null)
                        {
                            if (c.Summary.StartsWith("["))
                            {
                                int index;
                                index = c.Summary.IndexOf(']') + 1;
                                cTag  = c.Summary.Substring(0, index);
                            }
                            else
                            {
                                cTag = "[OTHER]";
                            }
                        }


                        if (cTag != null && cTag == tag)
                        {
                            emb.Fields.Add(new JEmbedField(x =>
                            {
                                string header = c.Name;
                                foreach (String alias in c.Aliases)
                                {
                                    if (alias != c.Name)
                                    {
                                        header += " (;" + alias + ") ";
                                    }
                                }
                                foreach (Discord.Commands.ParameterInfo parameter in c.Parameters)
                                {
                                    header += " [" + parameter.Name + "]";
                                }
                                x.Header = header;
                                x.Text   = c.Summary.Replace(tag + " ", "");
                            }));
                        }
                    }
                    await message.ModifyAsync(x => x.Embed = emb.Build());

                    await message.RemoveAllReactionsAsync();
                }
            }
        }
Exemplo n.º 9
0
        public async Task <string> GetYtURL(SocketCommandContext Context, string name, InteractiveService interactive, Discord.Rest.RestUserMessage msg)
        {
            try
            {
                var youtubeService = new YouTubeService(new BaseClientService.Initializer()
                {
                    ApiKey          = ytApiKey,
                    ApplicationName = "SoraBot" //this.GetType().ToString()
                });

                var searchListRequest = youtubeService.Search.List("snippet");
                var search            = System.Net.WebUtility.UrlEncode(name);
                searchListRequest.Q          = search;
                searchListRequest.MaxResults = 10;

                var searchListResponse = await searchListRequest.ExecuteAsync();

                List <string> videos = new List <string>();
                List <Google.Apis.YouTube.v3.Data.SearchResult> videosR = new List <Google.Apis.YouTube.v3.Data.SearchResult>();

                foreach (var searchResult in searchListResponse.Items)
                {
                    switch (searchResult.Id.Kind)
                    {
                    case "youtube#video":
                        videos.Add(String.Format("{0}", searchResult.Snippet.Title));
                        videosR.Add(searchResult);
                        break;
                    }
                }
                int index;
                if (videos.Count > 1)
                {
                    var eb = new EmbedBuilder()
                    {
                        Color = new Color(4, 97, 247),
                        Title = "Enter the Index of the YT video you want to add.",
                    };
                    string vids  = "";
                    int    count = 1;
                    foreach (var v in videos)
                    {
                        vids += $"**{count}.** {v}\n";
                        count++;
                    }
                    eb.Description = vids;
                    var del = await Context.Channel.SendMessageAsync("", embed : eb);

                    var response = await interactive.WaitForMessage(Context.User, Context.Channel, TimeSpan.FromSeconds(20));

                    await del.DeleteAsync();

                    if (response == null)
                    {
                        await msg.ModifyAsync(x =>
                        {
                            x.Content = $":no_entry_sign: Answer timed out {Context.User.Mention} (≧д≦ヾ)";
                        });

                        return("f2");
                    }
                    if (!Int32.TryParse(response.Content, out index))
                    {
                        await msg.ModifyAsync(x =>
                        {
                            x.Content = $":no_entry_sign: Only add the Index";
                        });

                        return("f2");
                    }
                    if (index > (videos.Count) || index < 1)
                    {
                        await msg.ModifyAsync(x =>
                        {
                            x.Content = $":no_entry_sign: Invalid Number";
                        });

                        return("f2");
                    }
                }
                else
                {
                    index = 1;
                }
                return($"https://www.youtube.com/watch?v={videosR[index-1].Id.VideoId}");
                //await Context.Channel.SendMessageAsync(String.Format("Videos: \n{0}\n", String.Join("\n", videos)));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                await SentryService.SendError(e, Context);
            }
            return("f");
        }
Exemplo n.º 10
0
        public async Task <string> GetYtURLAsync(SocketCommandContext Context, string name, InteractiveService interactive, Discord.Rest.RestUserMessage msg)
        {
            // this.GetType().ToString()
            var youtubeService = new YouTubeService(new BaseClientService.Initializer()
            {
                ApiKey          = "AIzaSyCBXGF_M-o0HYYPYTh8LZWCPGAZfp97j4o",
                ApplicationName = "SoraBot"
            });

            var searchListRequest = youtubeService.Search.List("snippet");
            var search            = System.Net.WebUtility.UrlEncode(name);

            searchListRequest.Q          = search;
            searchListRequest.MaxResults = 10;

            var searchListResponse = await searchListRequest.ExecuteAsync();

            List <string> videos = new List <string>();
            List <Google.Apis.YouTube.v3.Data.SearchResult> videosR = new List <Google.Apis.YouTube.v3.Data.SearchResult>();

            foreach (var searchResult in searchListResponse.Items)
            {
                switch (searchResult.Id.Kind)
                {
                case "youtube#video":
                {
                    videos.Add(String.Format("{0}", searchResult.Snippet.Title));
                    videosR.Add(searchResult);
                    break;
                }
                }
            }
            int indexx = 0;

            if (videos.Count > 1)
            {
                var eb = new EmbedBuilder()
                {
                    Color = new Color(4, 97, 247),
                    Title = "Enter the Index of the YT video you want to add."
                };
                string vids  = "";
                int    count = 1;
                foreach (var v in videos)
                {
                    vids  += "**{count}.** {v}" + Constants.vbLf;
                    count += 1;
                }
                eb.Description = vids;
                var del = await Context.Channel.SendMessageAsync("", embed : eb);

                await del.DeleteAsync();

                if (indexx > (videos.Count) || indexx < 1)
                {
                    await msg.ModifyAsync(x =>
                    {
                        x.Content = ":no_entry_sign: Invalid Number";
                    });

                    return("f2");
                }
            }
            else
            {
                indexx = 1;
            }
            // await Context.Channel.SendMessageAsync(String.Format("Videos: \n{0}\n", String.Join("\n", videos)));

            return("https://www.youtube.com/watch?v={videosR[index-1].Id.VideoId}");
        }
Exemplo n.º 11
0
        private async Task <string> ChInfo([Remainder] string text, Discord.Rest.RestUserMessage msg)
        {
            List <ch_info> ch     = new List <ch_info>();
            var            info   = new ch_info();
            var            client = new WebClient();

            string pageSourceCode = client.DownloadString(string.Format("https://gbf.wiki/index.php?title=Special:Search&profile=default&fulltext=Search&search={0}", text));

            System.Text.RegularExpressions.MatchCollection mc = System.Text.RegularExpressions.Regex.Matches(pageSourceCode, "<div class=(.*?)><a href=\"(.*?)\" title=\"(.*?)\" data-serp-pos=\"(.*?)\">");
            if (mc.Count > 0)
            {
                foreach (System.Text.RegularExpressions.Match match in mc)
                {
                    info.name = match.Groups[3].Value;
                    info.page = match.Groups[2].Value;
                    ch.Add(info);
                }
            }
            else
            {
                return("f");
            }

            int index;

            if (ch.Count > 1 && ch != null)
            {
                var eb = new EmbedBuilder()
                {
                    Color = new Color(4, 97, 247),
                    Title = "Enter the index of character u wanna see.",
                };
                string vids  = "";
                int    count = 1;
                foreach (var v in ch)
                {
                    vids += $"**{count}.** {v.name}\n";
                    count++;
                }
                eb.Description = vids;
                var del = await Context.Channel.SendMessageAsync("", false, eb.Build());

                var response = await _interactive.WaitForMessage(Context.User, Context.Channel, TimeSpan.FromSeconds(20));

                await del.DeleteAsync();

                if (response == null)
                {
                    await msg.ModifyAsync(x =>
                    {
                        x.Content = $":no_entry_sign: Answer timed out {Context.User.Mention} (≧д≦ヾ)";
                    });

                    return("f2");
                }
                if (!Int32.TryParse(response.Content, out index))
                {
                    await msg.ModifyAsync(x =>
                    {
                        x.Content = $":no_entry_sign: Only add the Index";
                    });

                    return("f2");
                }
                if (index > (ch.Count) || index < 1)
                {
                    await msg.ModifyAsync(x =>
                    {
                        x.Content = $":no_entry_sign: Invalid Number";
                    });

                    return("f2");
                }
            }
            else
            {
                index = 1;
            }
            return($"https://gbf.wiki" + ch[index - 1].page);
        }