Merge remote-tracking branch 'origin/main'
This commit is contained in:
		@@ -12,6 +12,7 @@ build:
 | 
			
		||||
  stage: build
 | 
			
		||||
  image: mcr.microsoft.com/dotnet/sdk:8.0
 | 
			
		||||
  script:
 | 
			
		||||
    - dotnet nuget add source https://pkgs.dev.azure.com/tgbots/Telegram.Bot/_packaging/release/nuget/v3/index.json -n Telegram.Bot
 | 
			
		||||
    - dotnet restore --no-cache
 | 
			
		||||
    - dotnet publish -c Release -r linux-x64 --self-contained true /p:PublishSingleFile=true /p:PublishTrimmed=false /p:EnableCompressionInSingleFile=true
 | 
			
		||||
    - tar -czvf publish.tar.gz -C bin/Release/net8.0/linux-x64/publish/ .
 | 
			
		||||
 
 | 
			
		||||
@@ -55,7 +55,7 @@ public class MastodonBot
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // 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();
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -7,12 +7,13 @@ namespace mstdnCats.Services
 | 
			
		||||
    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
 | 
			
		||||
            HttpClient _httpClient = new HttpClient();
 | 
			
		||||
            // 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
 | 
			
		||||
            logger?.LogInformation("Remaining requests: " + response.Headers.GetValues("X-RateLimit-Remaining").First() + "time to reset: " + response.Headers.GetValues("X-RateLimit-Reset").First());
 | 
			
		||||
 
 | 
			
		||||
@@ -7,13 +7,13 @@ namespace mstdnCats.Services
 | 
			
		||||
{
 | 
			
		||||
    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
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
            //try
 | 
			
		||||
            //{
 | 
			
		||||
                // 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)
 | 
			
		||||
                {
 | 
			
		||||
@@ -22,11 +22,12 @@ namespace mstdnCats.Services
 | 
			
		||||
 | 
			
		||||
                // Then process them
 | 
			
		||||
                await ProcessPosts.checkAndInsertPostsAsync(_db, _bot, posts, logger);
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception ex)
 | 
			
		||||
            {
 | 
			
		||||
                logger?.LogCritical("Error while running check: " + ex.Message);
 | 
			
		||||
            }
 | 
			
		||||
            //}
 | 
			
		||||
            //catch (Exception ex)
 | 
			
		||||
            //{
 | 
			
		||||
             //   logger?.LogCritical("Error while running check: " + ex.Message);
 | 
			
		||||
             //   throw new Exception("Error while running check: " + ex.Message);
 | 
			
		||||
            //}
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user