Preliminary work on tiktok url regex
Some checks reported errors
continuous-integration/drone/push Build was killed
Some checks reported errors
continuous-integration/drone/push Build was killed
This commit is contained in:
parent
1f15b65bf5
commit
27a480d2b0
70
Program.cs
70
Program.cs
@ -1,6 +1,12 @@
|
|||||||
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;
|
||||||
|
using Telegram.Bot.Exceptions;
|
||||||
|
using Telegram.Bot.Polling;
|
||||||
|
using Telegram.Bot.Types;
|
||||||
|
using Telegram.Bot.Types.Enums;
|
||||||
|
|
||||||
namespace TeleTok
|
namespace TeleTok
|
||||||
{
|
{
|
||||||
@ -16,10 +22,72 @@ namespace TeleTok
|
|||||||
var token = config.GetSection("TeleTokConf:token").Value;
|
var token = config.GetSection("TeleTokConf:token").Value;
|
||||||
|
|
||||||
var botClient = new TelegramBotClient(token);
|
var botClient = new TelegramBotClient(token);
|
||||||
|
using var cts = new CancellationTokenSource();
|
||||||
|
|
||||||
|
// StartReceiving does not block the caller thread. Receiving is done on the ThreadPool.
|
||||||
|
ReceiverOptions receiverOptions = new ()
|
||||||
|
{
|
||||||
|
AllowedUpdates = Array.Empty<UpdateType>() // receive all update types
|
||||||
|
};
|
||||||
|
|
||||||
|
// HandleUpdateAsync and HandlePollingErrorAsync no worky Tyler help
|
||||||
|
botClient.StartReceiving(
|
||||||
|
updateHandler: HandleUpdateAsync,
|
||||||
|
pollingErrorHandler: HandlePollingErrorAsync,
|
||||||
|
receiverOptions: receiverOptions,
|
||||||
|
cancellationToken: cts.Token
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
var me = await botClient.GetMeAsync();
|
var me = await botClient.GetMeAsync();
|
||||||
|
|
||||||
Console.WriteLine($"Hello world! I am user {me.Id} and my name is {me.FirstName}.");
|
Console.WriteLine($"Start listening for @{me.Username}");
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
// Do nothing until the stuff happens
|
||||||
|
}
|
||||||
|
|
||||||
|
cts.Cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
async Task HandleUpdateAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
// Only process Message updates: https://core.telegram.org/bots/api#message
|
||||||
|
if (update.Message is not { } message)
|
||||||
|
return;
|
||||||
|
// Only process text messages
|
||||||
|
if (message.Text is not { } messageText)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var chatId = message.Chat.Id;
|
||||||
|
|
||||||
|
bool isUri = Uri.IsWellFormedUriString(message.ToString(), UriKind.RelativeOrAbsolute);
|
||||||
|
|
||||||
|
if (isUri)
|
||||||
|
{
|
||||||
|
Regex isTikTok = new Regex(@"(?x)(http(s)?:\/\/)?(?:www|m)\.(?:tiktok.com)\/(?:v|embed|trending)(?:\/)?(?:\?shareId=)?(?P<id>[\da-z]+)", RegexOptions.Singleline);
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
var ErrorMessage = exception switch
|
||||||
|
{
|
||||||
|
ApiRequestException apiRequestException
|
||||||
|
=> $"Telegram API Error:\n[{apiRequestException.ErrorCode}]\n{apiRequestException.Message}",
|
||||||
|
_ => exception.ToString()
|
||||||
|
};
|
||||||
|
|
||||||
|
Console.WriteLine(ErrorMessage);
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
10
VidDownload.cs
Normal file
10
VidDownload.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
namespace TeleTok
|
||||||
|
{
|
||||||
|
public class VidDownload
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user