Bug fix
This commit is contained in:
@@ -3,7 +3,7 @@ namespace CatsOfMastodonBot.Models
|
|||||||
public class configData
|
public class configData
|
||||||
{
|
{
|
||||||
|
|
||||||
public static Boolean fetchData()
|
public static config fetchData()
|
||||||
{
|
{
|
||||||
// Load from .env file first
|
// Load from .env file first
|
||||||
DotNetEnv.Env.Load();
|
DotNetEnv.Env.Load();
|
||||||
@@ -20,7 +20,7 @@ namespace CatsOfMastodonBot.Models
|
|||||||
if (string.IsNullOrEmpty(dbName) || string.IsNullOrEmpty(botToken) || string.IsNullOrEmpty(tag)
|
if (string.IsNullOrEmpty(dbName) || string.IsNullOrEmpty(botToken) || string.IsNullOrEmpty(tag)
|
||||||
|| string.IsNullOrEmpty(channelNumId) || string.IsNullOrEmpty(adminNumId))
|
|| string.IsNullOrEmpty(channelNumId) || string.IsNullOrEmpty(adminNumId))
|
||||||
{
|
{
|
||||||
return false; // Failure if any are missing
|
return null; // Failure if any are missing
|
||||||
}
|
}
|
||||||
|
|
||||||
// If all required variables are present, assign to the config
|
// If all required variables are present, assign to the config
|
||||||
@@ -33,7 +33,7 @@ namespace CatsOfMastodonBot.Models
|
|||||||
ADMIN_NUMID = adminNumId
|
ADMIN_NUMID = adminNumId
|
||||||
};
|
};
|
||||||
|
|
||||||
return true; // Success
|
return config; // Success
|
||||||
}
|
}
|
||||||
|
|
||||||
public class config
|
public class config
|
||||||
|
@@ -8,8 +8,6 @@ using Telegram.Bot.Types.Enums;
|
|||||||
|
|
||||||
public class MastodonBot
|
public class MastodonBot
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
private static Timer _timer;
|
private static Timer _timer;
|
||||||
|
|
||||||
private static async Task Main()
|
private static async Task Main()
|
||||||
@@ -23,13 +21,15 @@ public class MastodonBot
|
|||||||
});
|
});
|
||||||
var logger = loggerFactory.CreateLogger<MastodonBot>();
|
var logger = loggerFactory.CreateLogger<MastodonBot>();
|
||||||
|
|
||||||
if (!configData.fetchData())
|
var config = configData.fetchData();
|
||||||
|
if (config==null)
|
||||||
{
|
{
|
||||||
logger.LogCritical("Error reading envinonment variables, either some values are missing or no .env file was found");
|
logger.LogCritical("Error reading envinonment variables, either some values are missing or no .env file was found");
|
||||||
throw new Exception("Error reading envinonment variables, either some values are missing or no .env file was found");
|
throw new Exception("Error reading envinonment variables, either some values are missing or no .env file was found");
|
||||||
}
|
}
|
||||||
var config = new configData.config();
|
|
||||||
// Setup DB
|
// Setup DB
|
||||||
|
Console.WriteLine("DB name: " + config.DB_NAME);
|
||||||
var db = await DbInitializer.SetupDb(config.DB_NAME);
|
var db = await DbInitializer.SetupDb(config.DB_NAME);
|
||||||
if (db == null)
|
if (db == null)
|
||||||
{
|
{
|
||||||
|
@@ -13,7 +13,7 @@ namespace mstdnCats.Services
|
|||||||
{
|
{
|
||||||
public static async Task HandleCallbackQuery(CallbackQuery callbackQuery, IDocumentCollection<Post> _db, TelegramBotClient _bot, ILogger<MastodonBot>? logger)
|
public static async Task HandleCallbackQuery(CallbackQuery callbackQuery, IDocumentCollection<Post> _db, TelegramBotClient _bot, ILogger<MastodonBot>? logger)
|
||||||
{
|
{
|
||||||
var config = new configData.config();
|
var config = configData.fetchData();
|
||||||
|
|
||||||
// Extract media ID from callback query data
|
// Extract media ID from callback query data
|
||||||
string[] parts = callbackQuery.Data.Split('-');
|
string[] parts = callbackQuery.Data.Split('-');
|
||||||
|
@@ -12,7 +12,7 @@ namespace mstdnCats.Services
|
|||||||
{
|
{
|
||||||
public static async Task<List<MediaAttachment>> checkAndInsertPostsAsync(IDocumentCollection<Post> _db, TelegramBotClient _bot, List<Post> fetchedPosts, ILogger<MastodonBot>? logger)
|
public static async Task<List<MediaAttachment>> checkAndInsertPostsAsync(IDocumentCollection<Post> _db, TelegramBotClient _bot, List<Post> fetchedPosts, ILogger<MastodonBot>? logger)
|
||||||
{
|
{
|
||||||
var config = new configData.config();
|
var config = configData.fetchData();
|
||||||
|
|
||||||
// Get existing posts
|
// Get existing posts
|
||||||
var existingPosts = _db.AsQueryable().Select(x => x.mstdnPostId).ToArray();
|
var existingPosts = _db.AsQueryable().Select(x => x.mstdnPostId).ToArray();
|
||||||
|
Reference in New Issue
Block a user