Exemplo n.º 1
0
        public static async Task Start(string ApiKey)
        {
            try
            {
                Api = new Client(ApiKey);
                Me  = await Api.GetMe();
            }
            catch (Exception Ex)
            {
                Ex.Log();
                "Telegram integration could not be loaded".Log();
                return;
            }

            Commands.Add("add", async(s, e) =>
            {
                var Music = GetMusic(e);
                if (Music != null && (string)s != string.Empty)
                {
                    string[] Data = await ParseInlineId((string)s);
                    if (Data[0] == null)
                    {
                        return;
                    }

                    await Respond(Data[0], e, "Resolving song..");

                    var Files = Directory.GetFiles(SongData.MusicDir).Where(x => x.EndsWith(".mp3") && x.ToLower().Contains(Data[1].ToLower())).ToArray();
                    string Song;
                    if (Files.Length == 0)
                    {
                        Song = Music.Enqueue(Data[1]);
                    }
                    else
                    {
                        Song = Music.Enqueue(Files[0], true);
                    }

                    await Respond(Data[0], e, Song);
                }
            });

            Commands.Add("song", async(s, e) =>
            {
                var Music = GetMusic(e);
                if (Music != null)
                {
                    string[] Data = await ParseInlineId((string)s);
                    string Song   = Music.GetCurrentSong()?.FullName;
                    if (Song == null)
                    {
                        await Respond(Data[0], e, "Nothing is playing right now");
                    }
                    else
                    {
                        await Respond(Data[0], e, "I'm playing " + Song);
                    }
                }
            });

            Commands.Add("queue", async(s, e) =>
            {
                var Music = GetMusic(e);
                if (Music != null)
                {
                    string[] Data   = await ParseInlineId((string)s);
                    string Playlist = Music.GetCurrentPlaylist();
                    if (Playlist == string.Empty)
                    {
                        await Respond(Data[0], e, "The queue is empty");
                    }
                    else
                    {
                        await Respond(Data[0], e, Playlist);
                    }
                }
            });

            Commands.Add("skip", async(s, e) =>
            {
                var Music = GetMusic(e);
                if (Music != null)
                {
                    string[] Data = await ParseInlineId((string)s);
                    if (Music.Playing)
                    {
                        string NextTitle = Music.PeekNextName();
                        if (NextTitle == null)
                        {
                            await Respond(Data[0], e, "Skipped, no more songs left");
                        }
                        else
                        {
                            await Respond(Data[0], e, "Skipped to " + NextTitle.Compact(100));
                        }

                        Music.Skip();
                    }
                    else
                    {
                        await Respond(Data[0], e, "I'm not playing any music at the moment");
                    }
                }
            });

            Commands.Add("remove", async(s, e) =>
            {
                var Music = GetMusic(e);
                if (Music != null)
                {
                    string[] Data = await ParseInlineId((string)s);
                    var Removed   = Music.Remove(Data[1].ParseInts());

                    if (Removed.Count > 0)
                    {
                        await Respond(Data[0], e, "Removed " + Removed.Join(", "));
                    }
                    else
                    {
                        await Respond(Data[0], e, "I couldn't remove that song");
                    }

                    /*else
                     * {
                     *  int Count = Music.SongCount;
                     *  if (Count == 0)
                     *  {
                     *      await Respond(Data[0], e, "There is nothing I can remove");
                     *  }
                     *  else
                     *  {
                     *      var KeyboardMarkup = new ReplyKeyboardMarkup();
                     *      int Row = -1;
                     *
                     *      KeyboardMarkup.Keyboard = new KeyboardButton[(int)Math.Ceiling((double)Count / 2)][];
                     *      for (int i = 0; i < (2 * KeyboardMarkup.Keyboard.Length); i++)
                     *      {
                     *          if (i % 2 == 0)
                     *          {
                     *              KeyboardMarkup.Keyboard[++Row] = new KeyboardButton[2];
                     *          }
                     *
                     *          if (i < Count)
                     *          {
                     *              KeyboardMarkup.Keyboard[Row][i % 2] = "/remove " + (i + 1).ToString();
                     *          }
                     *          else
                     *          {
                     *              KeyboardMarkup.Keyboard[Row][i % 2] = string.Empty;
                     *          }
                     *      }
                     *
                     *      KeyboardMarkup.OneTimeKeyboard = true;
                     *      KeyboardMarkup.ResizeKeyboard = true;
                     *      KeyboardMarkup.Selective = true;
                     *
                     *      await Respond(Data[0], e, Music.GetCurrentPlaylist() + "\nWhich song should I remove?", Markup: KeyboardMarkup);
                     *  }
                     * }*/
                }
            });

            Commands.Add("pair", async(s, e) =>
            {
                if (NextPairChannel != null)
                {
                    Db.SetDiscordServerId(e.Chat.Id, NextPairChannel.Server.Id);
                    Respond(e, "This chat has now been succesfully paired with " + NextPairChannel.Server.Name).Forget();
                    await Bot.SendAsync(NextPairChannel, "This server has been paired with " + ((e.Chat.Type == ChatType.Private) ? "" : e.Chat.Title + " by ") + e.From.Username);

                    NextPairChannel = null;
                }
            });

            Commands.Add("hrc", (s, e) =>
            {
                try
                {
                    if (e.Chat.Type == ChatType.Private || e.Chat.Title.StartsWith("H"))
                    {
                        Respond(e, Lewd.GetRandomLewd(s, (e.From.Username != "Akkey" && e.Chat.Type != ChatType.Private)), false).Forget();
                    }
                }
                catch (Exception Ex)
                {
                    $"HRC {Ex}".Log();
                }
            });

            $"Logged into Telegram as {Me.Username}".Log();

            Api.MessageReceived            += Api_MessageReceived;
            Api.InlineQueryReceived        += Api_InlineQueryReceived;
            Api.ChosenInlineResultReceived += Api_ChosenInlineResultReceived;
            Api.CallbackQueryReceived      += Api_CallbackQueryReceived;
            Api.StartReceiving();
        }