mirror of
https://github.com/appinfosapienza/so-un-bot.git
synced 2025-05-07 06:59:37 +02:00
Refactor repo structure
This commit is contained in:
parent
36ac339086
commit
8fc89fbc03
1732 changed files with 3812 additions and 67 deletions
53
Bot/Program.cs
Normal file
53
Bot/Program.cs
Normal file
|
@ -0,0 +1,53 @@
|
|||
using HomeBot.ACL;
|
||||
using HomeBot.ModuleLoader;
|
||||
using HomeBot.Modules.OttoLinux;
|
||||
using HomeBot.Telegram;
|
||||
using Telegram.Bot.Types;
|
||||
|
||||
string dataPath = Environment.GetEnvironmentVariable("DATA_PATH") ?? "BotData";
|
||||
string aclPath = Environment.GetEnvironmentVariable("ACL_PATH") ?? "BotData";
|
||||
string tgToken = Environment.GetEnvironmentVariable("TELEGRAM_TOKEN") ?? "this-string-is-not-a-token";
|
||||
string tgAdminId = Environment.GetEnvironmentVariable("TELEGRAM_ADMIN_ID") ?? "000000";
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
var acl = new ACM(aclPath, tgAdminLong);
|
||||
var moduleLoader = new ModuleLoader();
|
||||
|
||||
try
|
||||
{
|
||||
foreach (string f in Directory.GetFiles(dataPath + "/Questions"))
|
||||
{
|
||||
if (!f.EndsWith("txt"))
|
||||
{
|
||||
Console.WriteLine("Skipping " + Path.GetFileName(f) + " as the file extension is not supported");
|
||||
continue;
|
||||
}
|
||||
Console.WriteLine("Loading module " + Path.GetFileNameWithoutExtension(f));
|
||||
moduleLoader.LoadModule(new BotGame(acl, Path.GetFileNameWithoutExtension(f), f, false));
|
||||
}
|
||||
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, 2));
|
||||
}
|
||||
}
|
||||
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);
|
Loading…
Add table
Add a link
Reference in a new issue