Fixed method code (It works!)
This commit is contained in:
parent
31733aa673
commit
38d0539a5f
10
Program.cs
10
Program.cs
@ -1,12 +1,5 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using System;
|
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
|
namespace TeleTok
|
||||||
{
|
{
|
||||||
@ -24,6 +17,9 @@ namespace TeleTok
|
|||||||
{
|
{
|
||||||
|
|
||||||
TelegramListener listener = new TelegramListener();
|
TelegramListener listener = new TelegramListener();
|
||||||
|
Console.WriteLine("Now listening...");
|
||||||
|
|
||||||
|
listener.RunListener();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,8 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.2" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.2" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
<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>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -2,7 +2,7 @@ using System;
|
|||||||
using System.Configuration;
|
using System.Configuration;
|
||||||
using Telegram.Bot;
|
using Telegram.Bot;
|
||||||
using Telegram.Bot.Exceptions;
|
using Telegram.Bot.Exceptions;
|
||||||
using Telegram.Bot.Polling;
|
using Telegram.Bot.Extensions.Polling;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
|
|
||||||
@ -10,7 +10,7 @@ namespace TeleTok
|
|||||||
{
|
{
|
||||||
public class TelegramListener
|
public class TelegramListener
|
||||||
{
|
{
|
||||||
public RunListener()
|
public void RunListener()
|
||||||
{
|
{
|
||||||
var botClient = new TelegramBotClient(TeleTok.token);
|
var botClient = new TelegramBotClient(TeleTok.token);
|
||||||
using var cts = new CancellationTokenSource();
|
using var cts = new CancellationTokenSource();
|
||||||
@ -23,18 +23,15 @@ namespace TeleTok
|
|||||||
|
|
||||||
botClient.StartReceiving(
|
botClient.StartReceiving(
|
||||||
updateHandler: HandleUpdateAsync,
|
updateHandler: HandleUpdateAsync,
|
||||||
pollingErrorHandler: HandlePollingErrorAsync,
|
errorHandler: HandlePollingErrorAsync,
|
||||||
receiverOptions: receiverOptions,
|
receiverOptions: receiverOptions,
|
||||||
cancellationToken: cts.Token
|
cancellationToken: cts.Token
|
||||||
);
|
);
|
||||||
|
|
||||||
var me = await botClient.GetMeAsync();
|
|
||||||
|
|
||||||
Console.WriteLine($"Start listening for @{me.Username}");
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
// Do nothing until the stuff happens
|
// Do nothing until the stuff happens
|
||||||
}
|
};
|
||||||
|
|
||||||
cts.Cancel();
|
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)
|
Task HandlePollingErrorAsync(ITelegramBotClient botClient, Exception exception, CancellationToken cancellationToken)
|
||||||
|
@ -7,7 +7,7 @@ namespace TeleTok
|
|||||||
public class VidDownload
|
public class VidDownload
|
||||||
{
|
{
|
||||||
// Takes the scraped TikTok URL and appends it to the proxy downloader link then returns it
|
// 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 url = videourl;
|
||||||
string proxyUrl;
|
string proxyUrl;
|
||||||
@ -24,7 +24,6 @@ namespace TeleTok
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Runs the URL through a web request then returns the full url
|
// 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)
|
static string UnshortenUrl(string videourl)
|
||||||
{
|
{
|
||||||
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(videourl);
|
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(videourl);
|
||||||
|
Loading…
Reference in New Issue
Block a user