Fixed method code (It works!)

This commit is contained in:
Chris Plaatjes 2023-02-14 13:59:20 -05:00
parent 31733aa673
commit 38d0539a5f
4 changed files with 10 additions and 25 deletions

View File

@ -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();
}
}

View File

@ -10,7 +10,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Telegram.Bot" Version="18.0.0" />
<PackageReference Include="Telegram.Bot" Version="17.0.0" />
<PackageReference Include="Telegram.Bot.Extensions.Polling" Version="1.0.2" />
</ItemGroup>
</Project>

View File

@ -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)

View File

@ -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);