Ejemplo n.º 1
0
 public static void SendWall(Chat chat, string category)
 {
     // Getting ranges of wallpapers
     var randrange = GetRange(category, GetRandomBoolean());
     if (randrange.Length == 0)
     {
         Bot.Methods.SendMessage(chat, "⚠️ Sorry, unable to connect with LIKE5.");
         return;
     }
     // Sending preview:
     SendPreviewWall(chat, (new Random()).Next(randrange[0], randrange[1]), category);
 }
Ejemplo n.º 2
0
		/// <summary>
		///	 Message constructor
		/// </summary>
		/// <param name="id">ID of message</param>
		/// <param name="text">Text</param>
		/// <param name="chat">Chat</param>
		public Message(int id, string text, Chat chat)
		{
			MessageId = id;
			Text = text;
			Chat = chat;
		}
Ejemplo n.º 3
0
        public static void SendPreviewWall(Chat chat, int id, string category)
        {
            Bot.Methods.SendChatAction(chat, "upload_photo");
            Task.Factory.StartNew(delegate
            {
                var filename = _cacheDirectory + "s_" + id + ".jpg";
                var readyId = '_' + category.ToLower() + '_' +
                              Path.GetFileName(filename).Replace(".jpg", "").Replace("s_", "");
                if (!File.Exists(filename))
                {
                    var uri = $"http://hao.newtabplus.com/cloudWallpaper/{category}/s_{id}.jpg";
                    try
                    {
                        var wc = new WebClient();
                        wc.DownloadFile(uri, filename);
                    }
                    catch (WebException exc)
                    {
                        var errorResponse = exc.Response as HttpWebResponse;
                        if (errorResponse == null) return;
                        switch (errorResponse.StatusCode)
                        {
                            case HttpStatusCode.NotFound:
                                Bot.Methods.SendMessage(chat, "⚠️ This wallpaper not found.");
                                break;
                            default:
                                Bot.Methods.SendMessage(chat, "⚠️ Error, when get image. Try again in 5 seconds:\n"
                                                              + "/fullsize" + readyId);
                                break;
                        }
                        return;
                    }
                }
                var fileInfo = new FileInfo(filename);
                if (IsFileLocked(fileInfo))
                {
                    Bot.Methods.SendMessage(chat, "Please wait...");
                    while (IsFileLocked(fileInfo))
                    {
                        Thread.Sleep(1000);
                    }
                }
                // + "\n/wallpaper_" + category.ToLower() + " - next wallpaper from this category",
                var markup = new ReplyKeyboardMarkup()
                {
                    Keyboard = new[]
                    {
                        new[] {$"/wallpaper_{category.ToLower()}"},
                        new[] {$"/fullsize{readyId}"},
                        new[] { "🔠 Menu", "✌️ Ok, it's all" }
                    },
                    ResizeKeyboard = true,
                    OneTimeKeyboard = false
                };
                Bot.Methods.SendPhotoFile(chat, filename, $"/fullsize{readyId}", markup);

                GC.Collect();
            });
        }