so-un-bot/Bot/Program.cs

60 lines
2.1 KiB
C#
Raw Normal View History

2024-01-19 19:06:53 +01:00
using SoUnBot.AccessControl;
using SoUnBot.ModuleLoader;
using SoUnBot.Modules.OttoLinux;
using SoUnBot.Telegram;
2024-01-19 03:29:39 +01:00
string dataPath = Environment.GetEnvironmentVariable("DATA_PATH") ?? "BotData";
2024-01-31 04:56:23 +01:00
string aclPath = Environment.GetEnvironmentVariable("ACL_PATH") ?? "BotData/ACL";
2024-01-19 03:29:39 +01:00
string tgToken = Environment.GetEnvironmentVariable("TELEGRAM_TOKEN") ?? "this-string-is-not-a-token";
string tgAdminId = Environment.GetEnvironmentVariable("TELEGRAM_ADMIN_ID") ?? "000000";
string imagesPath = dataPath + "/Images";
2024-01-19 03:29:39 +01:00
Console.WriteLine("Welcome to SO un bot!");
long tgAdminLong;
if (!long.TryParse(tgAdminId, out tgAdminLong))
{
Console.WriteLine("Telegram Admin ID is invalid or unset");
return;
}
2024-01-19 19:06:53 +01:00
var acl = new AccessManager(aclPath, tgAdminLong);
2024-01-19 03:29:39 +01:00
var moduleLoader = new ModuleLoader();
try
{
foreach (string f in Directory.GetFiles(dataPath + "/Questions"))
{
2024-01-31 03:24:59 +01:00
if (f.EndsWith("txt"))
{
Console.WriteLine("Loading module " + Path.GetFileNameWithoutExtension(f));
moduleLoader.LoadModule(new BotGame(acl, Path.GetFileNameWithoutExtension(f), f, false, imagesPath));
2024-01-31 03:24:59 +01:00
}
else if (f.EndsWith("json"))
{
Console.WriteLine("Loading module " + Path.GetFileNameWithoutExtension(f));
moduleLoader.LoadModule(new BotGame(acl, Path.GetFileNameWithoutExtension(f), f, false, imagesPath, 3));
2024-01-31 03:24:59 +01:00
}
else
2024-01-19 03:29:39 +01:00
{
Console.WriteLine("Skipping " + Path.GetFileName(f) + " as the file extension is not supported");
}
}
foreach (string d in Directory.GetDirectories(dataPath + "/Questions"))
{
Console.WriteLine("Loading module " + Path.GetFileName(d));
moduleLoader.LoadModule(new BotGame(acl, Path.GetFileName(d), d, false, imagesPath, 2));
2024-01-19 03:29:39 +01:00
}
}
catch (System.Exception ex)
{
Console.WriteLine("There was an issue loading the module: " + ex.Message);
return;
}
Console.WriteLine("Starting Telegram bot listener...");
new TelegramBot(tgToken, acl, dataPath + "/motd.txt", moduleLoader.Modules);
// worst way ever to keep the main thread running, I know
while (true)
Thread.Sleep(10000);