mirror of
https://github.com/Jetsparrow/antiantiswearingbot.git
synced 2026-01-20 23:16:08 +03:00
fixed main to die on ctrl-c, added logs
This commit is contained in:
parent
a4e7b836b8
commit
453bbdf9e4
@ -27,7 +27,7 @@ namespace AntiAntiSwearingBot
|
||||
|
||||
TelegramBotClient Client { get; set; }
|
||||
ChatCommandRouter Router { get; set; }
|
||||
User Me { get; set; }
|
||||
public User Me { get; private set; }
|
||||
|
||||
public async Task Init()
|
||||
{
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace AntiAntiSwearingBot
|
||||
{
|
||||
@ -13,17 +14,36 @@ namespace AntiAntiSwearingBot
|
||||
ErrorInvalidCommandLine = 0x100
|
||||
};
|
||||
|
||||
static void Log(string m) => Console.WriteLine($"{DateTime.Now:HH:mm:ss.fff}|{m}");
|
||||
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
Log("AntiAntiSwearBot starting....");
|
||||
|
||||
var cfg = Config.Load<Config>("aasb.cfg.json", "aasb.cfg.secret.json");
|
||||
var dict = new SearchDictionary(cfg);
|
||||
Log($"{dict.Count} words loaded.");
|
||||
var bot = new AntiAntiSwearingBot(cfg, dict);
|
||||
bot.Init().Wait();
|
||||
Console.WriteLine("AntiAntiSwear started. Press any key to exit...");
|
||||
Log($"Connected to Telegram as @{bot.Me.Username}");
|
||||
Log("AntiAntiSwearBot started! Press Ctrl-C to exit.");
|
||||
Environment.ExitCode = (int)ExitCode.ErrorRunning;
|
||||
Console.ReadKey();
|
||||
|
||||
ManualResetEvent quitEvent = new ManualResetEvent(false);
|
||||
try
|
||||
{
|
||||
Console.CancelKeyPress += (sender, eArgs) => // ctrl-c
|
||||
{
|
||||
eArgs.Cancel = true;
|
||||
quitEvent.Set();
|
||||
};
|
||||
}
|
||||
catch { }
|
||||
|
||||
quitEvent.WaitOne(Timeout.Infinite);
|
||||
|
||||
Console.WriteLine("Waiting for exit...");
|
||||
bot.Stop().Wait();
|
||||
dict.Save();
|
||||
|
||||
@ -21,6 +21,8 @@ namespace AntiAntiSwearingBot
|
||||
words = File.ReadAllLines(path).ToList();
|
||||
}
|
||||
|
||||
public int Count => words.Count;
|
||||
|
||||
public void Save()
|
||||
{
|
||||
if (File.Exists(tmppath))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user