示例#1
0
      public IMessageActivity createEpisodeMessage(IDialogContext context, Declarations.Episodes.Rootobject episode)
      {
          IMessageActivity message = context.MakeMessage();
          HtmlDocument     doc     = new HtmlDocument();

          doc.LoadHtml(episode.summary);
          if (episode.image == null)
          {
              episode.image          = new Declarations.Episodes.Image();
              episode.image.medium   = "http://www.herniamovers.com/assets/boxes_packages/large/image_not_available.gif";
              episode.image.original = "http://www.herniamovers.com/assets/boxes_packages/large/image_not_available.gif";
          }


          /*message.Attachments.Add(new Attachment() {
           *  ContentType="image/jpg",
           *  ContentUrl=episode.image.medium,
           * });*/
          string summary = "";

          if (episode.summary == "" || episode.summary == null)
          {
              summary = "Not Available";
          }
          else
          {
              HtmlNodeCollection l = doc.DocumentNode.SelectNodes("//p");
              foreach (HtmlNode nodes in l)
              {
                  summary += nodes.InnerText;
              }
          }
          StringBuilder res = new StringBuilder();


          res.Append("# " + episode.name).AppendLine().AppendLine();
          res.Append($"![]({episode.image.medium})");
          res.AppendLine().AppendLine().Append(" **airdate:** " + episode.airdate).AppendLine().AppendLine();
          res.Append("**Time:** " + episode.airtime).AppendLine().AppendLine();
          res.Append("**Episode Runtime:** " + episode.runtime.ToString() + " mins").AppendLine().AppendLine();
          res.Append($"**Summary:** {summary}");

          message.Text = res.ToString();
          return(message);
      }
示例#2
0
      public async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> result)
      {
          var    message = await result;
          string data    = message.Text;

          char[]        delimiter = { ' ' };
          string[]      command   = data.Split(delimiter);
          StringBuilder sb        = new StringBuilder();

          //if (command.Length > 1)
          //{


          if (trigger == 0)
          {
              for (int i = 1; i < command.Length; i++)
              {
                  if (command.Length > 1)
                  {
                      sb.Append(command[i] + " ");
                  }
              }

              switch (command[0].ToLower())
              {
              case "search":
                  await createSearchResponse(context, sb);

                  break;

              case "showid":
                  url = "http://api.tvmaze.com/shows/" + HttpUtility.UrlEncode(sb.ToString().Trim());
                  await createShowResponse(context, url);
                  await sendOptions(context);

                  break;

              case "cast":
                  if (url != "")
                  {
                      string casturl = url + "/cast";
                      await createCastResponse(context, casturl);
                      await sendOptions(context);
                  }
                  break;

              case "epbn":
                  if (url != "")
                  {
                      trigger = 1;
                      await context.PostAsync("Enter Season number and Episode number separated by space");
                  }
                  break;

              case "clear":
                  url = "";
                  break;

              case "season":
                  if (url != "")
                  {
                      string seasonurl = url + "/seasons";
                      s_url = seasonurl;
                      await createSeasonResponse(context, seasonurl);
                  }
                  break;

              case "selectseason":
                  if (s_url != "")
                  {
                      s_num   = int.Parse(command[1]);
                      trigger = 2;
                      await context.PostAsync("Enter the episode number for this season");
                  }
                  break;

              default:
                  await context.PostAsync("I dont understand this");

                  break;
              }
          }
          else if (trigger == 1)
          {
              trigger = 0;
              int season = int.Parse(command[0]);
              int ep     = int.Parse(command[1]);

              string          epurl    = url + $"/episodebynumber?season={season}&number={ep}";
              HttpWebRequest  request  = WebRequest.Create(epurl) as HttpWebRequest;
              HttpWebResponse response = request.GetResponse() as HttpWebResponse;
              StreamReader    reader   = new StreamReader(response.GetResponseStream());
              string          s        = reader.ReadToEnd();
              Declarations.Episodes.Rootobject episode = JsonConvert.DeserializeObject <Declarations.Episodes.Rootobject>(s);

              await context.PostAsync(createEpisodeMessage(context, episode));
              await sendOptions(context);
          }
          else if (trigger == 2)
          {
              trigger = 0;
              int epno = int.Parse(command[0]);

              string          epurl    = url + $"/episodebynumber?season={s_num}&number={epno}";
              HttpWebRequest  request  = WebRequest.Create(epurl) as HttpWebRequest;
              HttpWebResponse response = request.GetResponse() as HttpWebResponse;
              StreamReader    reader   = new StreamReader(response.GetResponseStream());
              string          s        = reader.ReadToEnd();
              Declarations.Episodes.Rootobject episode = JsonConvert.DeserializeObject <Declarations.Episodes.Rootobject>(s);

              await context.PostAsync(createEpisodeMessage(context, episode));
              await sendOptions(context);
          }

          context.Wait(MessageReceivedAsync);
      }