From 38d0539a5fa87fad5ace6c77f938339a67381e67 Mon Sep 17 00:00:00 2001 From: Chris Plaatjes Date: Tue, 14 Feb 2023 13:59:20 -0500 Subject: [PATCH] Fixed method code (It works!) --- Program.cs | 10 +++------- TeleTok.csproj | 3 ++- TelegramListener.cs | 19 ++++--------------- VidDownload.cs | 3 +-- 4 files changed, 10 insertions(+), 25 deletions(-) diff --git a/Program.cs b/Program.cs index 7959a9f..f20a3d1 100644 --- a/Program.cs +++ b/Program.cs @@ -1,12 +1,5 @@ using Microsoft.Extensions.Configuration; using System; -using System.Web; -using System.Text.RegularExpressions; -using Telegram.Bot; -using Telegram.Bot.Exceptions; -using Telegram.Bot.Polling; -using Telegram.Bot.Types; -using Telegram.Bot.Types.Enums; namespace TeleTok { @@ -24,6 +17,9 @@ namespace TeleTok { TelegramListener listener = new TelegramListener(); + Console.WriteLine("Now listening..."); + + listener.RunListener(); } } diff --git a/TeleTok.csproj b/TeleTok.csproj index 42d88b4..9cd3d57 100644 --- a/TeleTok.csproj +++ b/TeleTok.csproj @@ -10,7 +10,8 @@ - + + diff --git a/TelegramListener.cs b/TelegramListener.cs index 4362731..3fb63f2 100644 --- a/TelegramListener.cs +++ b/TelegramListener.cs @@ -2,7 +2,7 @@ using System; using System.Configuration; using Telegram.Bot; using Telegram.Bot.Exceptions; -using Telegram.Bot.Polling; +using Telegram.Bot.Extensions.Polling; using Telegram.Bot.Types; using Telegram.Bot.Types.Enums; @@ -10,7 +10,7 @@ namespace TeleTok { public class TelegramListener { - public RunListener() + public void RunListener() { var botClient = new TelegramBotClient(TeleTok.token); using var cts = new CancellationTokenSource(); @@ -23,18 +23,15 @@ namespace TeleTok botClient.StartReceiving( updateHandler: HandleUpdateAsync, - pollingErrorHandler: HandlePollingErrorAsync, + errorHandler: HandlePollingErrorAsync, receiverOptions: receiverOptions, cancellationToken: cts.Token ); - var me = await botClient.GetMeAsync(); - - Console.WriteLine($"Start listening for @{me.Username}"); while (true) { // Do nothing until the stuff happens - } + }; cts.Cancel(); } @@ -69,14 +66,6 @@ namespace TeleTok ); } } - - Console.WriteLine($"Received a '{messageText}' message in chat {chatId}."); - - // Echo received message text - Message sentMessage = await botClient.SendTextMessageAsync( - chatId: chatId, - text: "You said:\n" + messageText, - cancellationToken: cancellationToken); } Task HandlePollingErrorAsync(ITelegramBotClient botClient, Exception exception, CancellationToken cancellationToken) diff --git a/VidDownload.cs b/VidDownload.cs index 01383d9..a040f55 100644 --- a/VidDownload.cs +++ b/VidDownload.cs @@ -7,7 +7,7 @@ namespace TeleTok public class VidDownload { // Takes the scraped TikTok URL and appends it to the proxy downloader link then returns it - public string TikTokURL(string videourl) + public static string TikTokURL(string videourl) { string url = videourl; string proxyUrl; @@ -24,7 +24,6 @@ namespace TeleTok } // Runs the URL through a web request then returns the full url - // If the URL is already the full one, it won't really do anything but will catch shortened ones static string UnshortenUrl(string videourl) { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(videourl);