mirror of
https://github.com/appinfosapienza/so-un-bot.git
synced 2025-03-13 16:05:22 +01:00
Switch from webserver to telegram inputfile
This commit is contained in:
parent
ea3ff8aba8
commit
a38357d7e7
3 changed files with 46 additions and 32 deletions
|
@ -5,7 +5,9 @@ using SoUnBot.ModuleLoader;
|
||||||
using Telegram.Bot;
|
using Telegram.Bot;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
|
using Telegram.Bot.Types.InputFiles;
|
||||||
using Telegram.Bot.Types.ReplyMarkups;
|
using Telegram.Bot.Types.ReplyMarkups;
|
||||||
|
using File = System.IO.File;
|
||||||
|
|
||||||
namespace SoUnBot.Modules.OttoLinux
|
namespace SoUnBot.Modules.OttoLinux
|
||||||
{
|
{
|
||||||
|
@ -16,7 +18,7 @@ namespace SoUnBot.Modules.OttoLinux
|
||||||
private string _questionsPath;
|
private string _questionsPath;
|
||||||
private string _name;
|
private string _name;
|
||||||
private bool _lock;
|
private bool _lock;
|
||||||
private string _webBaseURL;
|
private string _imgBaseDir;
|
||||||
|
|
||||||
private Dictionary<long, OttoScore> _scores;
|
private Dictionary<long, OttoScore> _scores;
|
||||||
private Dictionary<long, Question> _playingQuestions;
|
private Dictionary<long, Question> _playingQuestions;
|
||||||
|
@ -25,13 +27,13 @@ namespace SoUnBot.Modules.OttoLinux
|
||||||
|
|
||||||
private static Random _rng = new Random();
|
private static Random _rng = new Random();
|
||||||
|
|
||||||
public BotGame(AccessManager accessManager, string name, string path, bool locke, string webBaseUrl, int version = 1)
|
public BotGame(AccessManager accessManager, string name, string path, bool locke, string imgBaseDir, int version = 1)
|
||||||
{
|
{
|
||||||
_accessManager = accessManager;
|
_accessManager = accessManager;
|
||||||
_questionsPath = path;
|
_questionsPath = path;
|
||||||
_name = name;
|
_name = name;
|
||||||
_lock = locke;
|
_lock = locke;
|
||||||
_webBaseURL = webBaseUrl;
|
_imgBaseDir = imgBaseDir;
|
||||||
|
|
||||||
_questions = new List<Question>();
|
_questions = new List<Question>();
|
||||||
_scores = new Dictionary<long, OttoScore>();
|
_scores = new Dictionary<long, OttoScore>();
|
||||||
|
@ -422,9 +424,18 @@ namespace SoUnBot.Modules.OttoLinux
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await botClient.SendPhotoAsync(
|
if (qst.Image.Contains("http"))
|
||||||
chatId: uid,
|
{
|
||||||
photo: qst.Image.Contains("http") ? qst.Image : _webBaseURL + "/" + qst.Image);
|
await botClient.SendPhotoAsync(
|
||||||
|
chatId: uid,
|
||||||
|
photo: qst.Image);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await botClient.SendPhotoAsync(
|
||||||
|
chatId: uid,
|
||||||
|
photo: File.OpenRead(_imgBaseDir + "/" + qst.Image));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
|
@ -435,9 +446,18 @@ namespace SoUnBot.Modules.OttoLinux
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await botClient.SendPhotoAsync(
|
if (qst.Image.Contains("http"))
|
||||||
chatId: uid,
|
{
|
||||||
photo: quest.Substring(4).Split('\n')[0].Contains("http") ? quest.Substring(4).Split('\n')[0] : _webBaseURL + "/" + quest.Substring(4).Split('\n')[0]);
|
await botClient.SendPhotoAsync(
|
||||||
|
chatId: uid,
|
||||||
|
photo: quest.Substring(4).Split('\n')[0]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await botClient.SendPhotoAsync(
|
||||||
|
chatId: uid,
|
||||||
|
photo: File.OpenRead(_imgBaseDir + "/" + quest.Substring(4).Split('\n')[0]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
|
@ -466,11 +486,18 @@ namespace SoUnBot.Modules.OttoLinux
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await botClient.SendPhotoAsync(
|
if (qst.Image.Contains("http"))
|
||||||
chatId: uid,
|
{
|
||||||
photo: qst.Answers[i].Split('\n')[0].Substring(4).Contains("http") ? qst.Answers[i].Split('\n')[0].Substring(4) : _webBaseURL + "/" + qst.Answers[i].Split('\n')[0].Substring(4),
|
await botClient.SendPhotoAsync(
|
||||||
caption: "✏️ Risposta " + (i + 1) + ": " + qst.Answers[i].Substring(qst.Answers[i].Split('\n')[0].Length)
|
chatId: uid,
|
||||||
);
|
photo: qst.Answers[i].Split('\n')[0].Substring(4));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await botClient.SendPhotoAsync(
|
||||||
|
chatId: uid,
|
||||||
|
photo: File.OpenRead(_imgBaseDir + "/" + qst.Answers[i].Split('\n')[0].Substring(4)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,6 +9,7 @@ string aclPath = Environment.GetEnvironmentVariable("ACL_PATH") ?? "BotData/ACL"
|
||||||
string tgToken = Environment.GetEnvironmentVariable("TELEGRAM_TOKEN") ?? "this-string-is-not-a-token";
|
string tgToken = Environment.GetEnvironmentVariable("TELEGRAM_TOKEN") ?? "this-string-is-not-a-token";
|
||||||
string tgAdminId = Environment.GetEnvironmentVariable("TELEGRAM_ADMIN_ID") ?? "000000";
|
string tgAdminId = Environment.GetEnvironmentVariable("TELEGRAM_ADMIN_ID") ?? "000000";
|
||||||
string webBaseURL = Environment.GetEnvironmentVariable("WEB_BASE_URL") ?? "http://localhost:8001";
|
string webBaseURL = Environment.GetEnvironmentVariable("WEB_BASE_URL") ?? "http://localhost:8001";
|
||||||
|
string imagesPath = dataPath + "/Images";
|
||||||
|
|
||||||
Console.WriteLine("Welcome to SO un bot!");
|
Console.WriteLine("Welcome to SO un bot!");
|
||||||
|
|
||||||
|
@ -29,12 +30,12 @@ try
|
||||||
if (f.EndsWith("txt"))
|
if (f.EndsWith("txt"))
|
||||||
{
|
{
|
||||||
Console.WriteLine("Loading module " + Path.GetFileNameWithoutExtension(f));
|
Console.WriteLine("Loading module " + Path.GetFileNameWithoutExtension(f));
|
||||||
moduleLoader.LoadModule(new BotGame(acl, Path.GetFileNameWithoutExtension(f), f, false, webBaseURL));
|
moduleLoader.LoadModule(new BotGame(acl, Path.GetFileNameWithoutExtension(f), f, false, imagesPath));
|
||||||
}
|
}
|
||||||
else if (f.EndsWith("json"))
|
else if (f.EndsWith("json"))
|
||||||
{
|
{
|
||||||
Console.WriteLine("Loading module " + Path.GetFileNameWithoutExtension(f));
|
Console.WriteLine("Loading module " + Path.GetFileNameWithoutExtension(f));
|
||||||
moduleLoader.LoadModule(new BotGame(acl, Path.GetFileNameWithoutExtension(f), f, false, webBaseURL, 3));
|
moduleLoader.LoadModule(new BotGame(acl, Path.GetFileNameWithoutExtension(f), f, false, imagesPath, 3));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -44,7 +45,7 @@ try
|
||||||
foreach (string d in Directory.GetDirectories(dataPath + "/Questions"))
|
foreach (string d in Directory.GetDirectories(dataPath + "/Questions"))
|
||||||
{
|
{
|
||||||
Console.WriteLine("Loading module " + Path.GetFileName(d));
|
Console.WriteLine("Loading module " + Path.GetFileName(d));
|
||||||
moduleLoader.LoadModule(new BotGame(acl, Path.GetFileName(d), d, false, webBaseURL, 2));
|
moduleLoader.LoadModule(new BotGame(acl, Path.GetFileName(d), d, false, imagesPath, 2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (System.Exception ex)
|
catch (System.Exception ex)
|
||||||
|
@ -56,8 +57,6 @@ catch (System.Exception ex)
|
||||||
Console.WriteLine("Starting Telegram bot listener...");
|
Console.WriteLine("Starting Telegram bot listener...");
|
||||||
new TelegramBot(tgToken, acl, dataPath + "/motd.txt", moduleLoader.Modules);
|
new TelegramBot(tgToken, acl, dataPath + "/motd.txt", moduleLoader.Modules);
|
||||||
|
|
||||||
new PhotoServer(dataPath + "/Images");
|
|
||||||
|
|
||||||
// worst way ever to keep the main thread running, I know
|
// worst way ever to keep the main thread running, I know
|
||||||
while (true)
|
while (true)
|
||||||
Thread.Sleep(10000);
|
Thread.Sleep(10000);
|
|
@ -21,17 +21,5 @@ services:
|
||||||
- TELEGRAM_TOKEN=${TELEGRAM_TOKEN}
|
- TELEGRAM_TOKEN=${TELEGRAM_TOKEN}
|
||||||
# User id of the administrator user (will receive logs for errors)
|
# User id of the administrator user (will receive logs for errors)
|
||||||
- TELEGRAM_ADMIN_ID=${TELEGRAM_ADMIN_ID}
|
- TELEGRAM_ADMIN_ID=${TELEGRAM_ADMIN_ID}
|
||||||
- WEB_BASE_URL=https://so-un-bot.srv.mrlc.cc
|
|
||||||
volumes:
|
volumes:
|
||||||
- ${ACL_DIR}:/acl
|
- ${ACL_DIR}:/acl
|
||||||
labels:
|
|
||||||
- "traefik.enable=true"
|
|
||||||
- "traefik.http.routers.so-un-bot.entrypoints=web, websecure"
|
|
||||||
- "traefik.http.routers.so-un-bot.rule=Host(`so-un-bot.srv.mrlc.cc`)"
|
|
||||||
- "traefik.http.routers.so-un-bot.tls=true"
|
|
||||||
- "traefik.http.routers.so-un-bot.tls.certresolver=production"
|
|
||||||
- "traefik.http.services.so-un-bot.loadbalancer.server.port=8001"
|
|
||||||
|
|
||||||
networks:
|
|
||||||
proxynet:
|
|
||||||
external: true
|
|
Loading…
Reference in a new issue