Compare commits

...

3 Commits

4 changed files with 26 additions and 26 deletions

View File

@@ -1,6 +1,3 @@
stages:
- build
variables: variables:
DOTNET_CLI_TELEMETRY_OPTOUT: "1" DOTNET_CLI_TELEMETRY_OPTOUT: "1"
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: "1" DOTNET_SKIP_FIRST_TIME_EXPERIENCE: "1"
@@ -8,14 +5,15 @@ variables:
before_script: before_script:
- apt-get update && apt-get install -y tar - apt-get update && apt-get install -y tar
build: jobs:
stage: build build:
image: mcr.microsoft.com/dotnet/sdk:8.0 stage: build
script: image: mcr.microsoft.com/dotnet/sdk:8.0
- dotnet nuget add source https://pkgs.dev.azure.com/tgbots/Telegram.Bot/_packaging/release/nuget/v3/index.json -n Telegram.Bot script:
- dotnet restore --no-cache - dotnet nuget add source https://pkgs.dev.azure.com/tgbots/Telegram.Bot/_packaging/release/nuget/v3/index.json -n Telegram.Bot
- dotnet publish -c Release -r linux-x64 --self-contained true /p:PublishSingleFile=true /p:PublishTrimmed=false /p:EnableCompressionInSingleFile=true - dotnet restore --no-cache
- tar -czvf publish.tar.gz -C bin/Release/net8.0/linux-x64/publish/ . - dotnet publish -c Release -r linux-x64 --self-contained true /p:PublishSingleFile=true /p:PublishTrimmed=false /p:EnableCompressionInSingleFile=true
artifacts: - tar -czvf publish.tar.gz -C bin/Release/net8.0/linux-x64/publish/ .
paths: artifacts:
- publish.tar.gz paths:
- publish.tar.gz

View File

@@ -55,7 +55,7 @@ public class MastodonBot
} }
// Set a timer to fetch and process posts every 15 minutes // Set a timer to fetch and process posts every 15 minutes
_timer = new Timer(async _ => await RunCheck.runAsync(db, bot, DotNetEnv.Env.GetString("TAG"), logger, DotNetEnv.Env.GetString("CUSTOM_INSTANCE") ?? default), null, TimeSpan.Zero, TimeSpan.FromMinutes(15)); _timer = new Timer(async _ => await RunCheck.runAsync(db, bot, DotNetEnv.Env.GetString("TAG"), logger, DotNetEnv.Env.GetString("CUSTOM_INSTANCE")), null, TimeSpan.Zero, TimeSpan.FromMinutes(15));
Console.ReadLine(); Console.ReadLine();

View File

@@ -7,12 +7,13 @@ namespace mstdnCats.Services
public sealed class PostResolver public sealed class PostResolver
{ {
public static async Task<List<Post>?> GetPostsAsync(string tag, ILogger<MastodonBot>? logger, string instance = "https://haminoa.net") public static async Task<List<Post>?> GetPostsAsync(string tag, ILogger<MastodonBot>? logger, string instance)
{ {
// Get posts // Get posts
HttpClient _httpClient = new HttpClient(); HttpClient _httpClient = new HttpClient();
// Get posts from mastodon api (40 latest posts) // Get posts from mastodon api (40 latest posts)
var response = await _httpClient.GetAsync($"{instance}/api/v1/timelines/tag/{tag}?limit=40"); string requestUrl = $"{instance}/api/v1/timelines/tag/{tag}?limit=40";
var response = await _httpClient.GetAsync(requestUrl);
// Print out ratelimit info // Print out ratelimit info
logger?.LogInformation("Remaining requests: " + response.Headers.GetValues("X-RateLimit-Remaining").First() + "time to reset: " + response.Headers.GetValues("X-RateLimit-Reset").First()); logger?.LogInformation("Remaining requests: " + response.Headers.GetValues("X-RateLimit-Remaining").First() + "time to reset: " + response.Headers.GetValues("X-RateLimit-Reset").First());

View File

@@ -7,13 +7,13 @@ namespace mstdnCats.Services
{ {
public class RunCheck public class RunCheck
{ {
public static async Task<bool> runAsync(IDocumentCollection<Post> _db, TelegramBotClient _bot, string _tag, ILogger<MastodonBot>? logger, string _instance = "https://haminoa.net") public static async Task<bool> runAsync(IDocumentCollection<Post> _db, TelegramBotClient _bot, string _tag, ILogger<MastodonBot>? logger, string _instance)
{ {
// Run check // Run check
try //try
{ //{
// First get posts // First get posts
var posts = await PostResolver.GetPostsAsync(_tag, logger, _instance); var posts = await PostResolver.GetPostsAsync(_tag, logger, _instance??"https://haminoa.net");
if (posts == null) if (posts == null)
{ {
@@ -22,11 +22,12 @@ namespace mstdnCats.Services
// Then process them // Then process them
await ProcessPosts.checkAndInsertPostsAsync(_db, _bot, posts, logger); await ProcessPosts.checkAndInsertPostsAsync(_db, _bot, posts, logger);
} //}
catch (Exception ex) //catch (Exception ex)
{ //{
logger?.LogCritical("Error while running check: " + ex.Message); // logger?.LogCritical("Error while running check: " + ex.Message);
} // throw new Exception("Error while running check: " + ex.Message);
//}
return true; return true;
} }
} }