Compare commits

..

No commits in common. "main" and "bugfixes/crash-handler" have entirely different histories.

8 changed files with 37 additions and 134 deletions

View File

@ -4,6 +4,11 @@ type: docker
name: publish-bot
steps:
- name: build-dotnet
image: mcr.microsoft.com/dotnet/sdk:6.0
commands:
- dotnet publish
- name: build-image
image: plugins/docker
settings:
@ -12,8 +17,10 @@ steps:
from_secret: DOCKER_USER
password:
from_secret: DOCKER_PASS
repo: git.kizaing.ca/kizaing/teletok
repo: git.kizaing.ca/kizaing/TeleTok
tags: latest
platform: linux/amd64,linux/arm64
# Commented out until stuff actually works
trigger:

View File

@ -1,36 +0,0 @@
# .gitea/workflows/build.yaml
name: Publish Docker image
on:
push:
branches: [main]
jobs:
push_to_registry:
name: Push Docker image to registries
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3
with:
token: ${{ secrets.GITEA_TOKEN }}
- name: Login to DockerHub
uses: https://github.com/docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Login to Gitea registry
uses: https://github.com/docker/login-action@v2
with:
registry: git.kizaing.ca
username: ${{ gitea.actor }}
password: ${{ secrets.GITEA_TOKEN }}
- name: Build and push Docker image
uses: https://github.com/docker/build-push-action@v4
with:
context: .
push: true
tags: git.kizaing.ca/kizaing/teletok:latest, kizaing

4
.gitignore vendored
View File

@ -1,4 +1,2 @@
bin
obj
.vscode
config.Dev.json
obj

View File

@ -1,14 +1,7 @@
#Builds the bot from source
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-task
COPY . /build
RUN cd /build && dotnet publish
# Actually runs the bot
FROM mcr.microsoft.com/dotnet/runtime:6.0
FROM mcr.microsoft.com/dotnet/runtime:6.0-alpine3
WORKDIR /app/teletok
COPY --from=build-task /build/bin/Debug/net6.0/publish/* /app/teletok/
COPY bin/Debug/net6.0/publish/* /app/teletok/
CMD [ "./TeleTok" ]
CMD [ "TeleTok" ]

View File

@ -15,29 +15,12 @@ namespace TeleTok
static async Task Main(string[] args)
{
//Checks if the config json data is valid
if(token == "" || token == null || token == "INSERT TOKEN HERE")
{
LogMessage("Telegram bot token is invalid! Exiting...");
}
else if(ptInstance == "" || ptInstance == null || ptInstance == "PROXITOK INSTANCE URL")
{
LogMessage("Proxitok instance is invalid! Exiting...");
}
else
{
TelegramListener listener = new TelegramListener();
LogMessage("Now listening...");
TelegramListener listener = new TelegramListener();
Console.WriteLine("Now listening...");
listener.RunListener();
}
}
public static void LogMessage(string text)
{
DateTime now =DateTime.Now;
Console.WriteLine("[" + now.ToString() + "] " + text);
listener.RunListener();
}
}
}

View File

@ -1,31 +1,5 @@
[![Build Status](https://ci.kizaing.ca/api/badges/kizaing/TeleTok/status.svg)](https://ci.kizaing.ca/kizaing/TeleTok)
# TeleTok Telegram Bot
This bot will monitor any chats for TikTok links that are posted, and then will run the link through a [ProxiTok](https://github.com/pablouser1/ProxiTok) instance to generate a download link. The resulting video file will then get directly uploaded directly to your chat.
## Building
Requirements: Dotnet SDK 6.0
Run `dotnet build` for a Debug instance
Run `dotnet publish` for a full release
## Installation
### Requirements
* A telegram bot token
* A working [ProxiTok](https://github.com/pablouser1/ProxiTok) instance, either public or hosted yourself. (Please be kind and take bandwidth into account when using a public instance)
### Binary
1. Either build the application or download a release zip for your OS/architecture
2. Edit the config.json and put your telegram bot token in the "token" field, and your chosen ProxiTok instance in the "ptInstance" field
3. Run the TeleTok.exe/TeleTok executable
### Docker
1. You can build an image for yourself with `docker build teletok .` or you can pull a prebuilt image with `docker pull kizaing/teletok:latest`
2. Copy the placeholder config.json from the repo to a location of your choosing
3. Edit the config.json and put your telegram bot token in the "token" field, and your chosen ProxiTok instance in the "ptInstance" field
4. Run the container with `docker run -v ${PWD}/config.json:/app/teletok/config.json -d kizaing/teletok:latest`
## To Do
- [x] Add better error and link handling
- [x] Process videos into telegram
- [ ] Add [Matrix](https://matrix.org) support
- [ ] Automate binary release publishing
This bot is in early development, but the end goal is to have this bot automatically convert all tiktok links in a chat into a videofile that can be re-uploaded to the telegram chat

View File

@ -55,15 +55,22 @@ namespace TeleTok
// Passes the url along to the video downloader if it is valid AND a tiktok link
if (isUri)
{
if(messageText.Contains("tiktok.com"))
try
{
proxyUrl = VidDownload.TikTokURL(messageText);
if(messageText.Contains("tiktok.com"))
{
proxyUrl = VidDownload.TikTokURL(messageText);
Message ttVideo = await botClient.SendVideoAsync(
chatId: chatId,
video: proxyUrl,
cancellationToken: cancellationToken
);
Message ttVideo = await botClient.SendVideoAsync(
chatId: chatId,
video: proxyUrl,
cancellationToken: cancellationToken
);
}
}
catch
{
Console.WriteLine("Valid TikTok URI was sent, but was not a video!");
}
}
}
@ -77,7 +84,7 @@ namespace TeleTok
_ => exception.ToString()
};
TeleTok.LogMessage(ErrorMessage);
Console.WriteLine(ErrorMessage);
return Task.CompletedTask;
}
}

View File

@ -12,16 +12,13 @@ namespace TeleTok
string url = videourl;
string proxyUrl;
TeleTok.LogMessage("Video for " + videourl + " processing..");
if(url.Contains("vm.tiktok.com"))
{
url = UnshortenUrl(url);
}
proxyUrl = CreateDownloadLink(url);
TeleTok.LogMessage("Sending video link for " + proxyUrl);
proxyUrl = TeleTok.ptInstance + "/download?url=" + url;
Console.WriteLine("Video for " + url + " has been sent..");
return proxyUrl;
}
@ -36,25 +33,5 @@ namespace TeleTok
return realUrl;
}
//Breaks apart the URL and extracts the User and Video ID to be processed into a working download link
static string CreateDownloadLink(string videourl)
{
Uri segmentedUri = new Uri(videourl);
segmentedUri = new Uri(segmentedUri.AbsoluteUri.Replace(segmentedUri.Query, string.Empty));
string videoUser = segmentedUri.Segments[1];
videoUser = videoUser.Replace(@"/", "");
string videoID = segmentedUri.Segments[3];
string fixedUrl = "https://www.tiktok.com/" + videoUser + "/video/" + videoID + @"&id=" + videoID + @"&user=" + videoUser.Remove(0, 1);
string proxyLink = TeleTok.ptInstance + "/download?url=" + fixedUrl;
TeleTok.LogMessage("Input User ID is: " + videoUser);
TeleTok.LogMessage("Input video ID is: " + videoID);
return proxyLink;
}
}
}