mirror of
https://github.com/Jetsparrow/karmabot.git
synced 2026-01-21 00:56:09 +03:00
Update perfusion
This commit is contained in:
parent
9bf70017c8
commit
35dbb7fe78
@ -14,14 +14,14 @@ namespace JetKarmaBot
|
||||
{
|
||||
public class ChatCommandRouter
|
||||
{
|
||||
Telegram.Bot.Types.User BotUser { get; }
|
||||
public Telegram.Bot.Types.User Me { get; private set; }
|
||||
[Inject] private Logger log;
|
||||
[Inject] private KarmaContextFactory Db;
|
||||
[Inject] private TelegramBotClient Client { get; set; }
|
||||
|
||||
public ChatCommandRouter(Telegram.Bot.Types.User botUser)
|
||||
public async Task Start()
|
||||
{
|
||||
BotUser = botUser;
|
||||
Me = await Client.GetMeAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> Execute(object sender, MessageEventArgs args)
|
||||
@ -30,7 +30,7 @@ namespace JetKarmaBot
|
||||
var text = args.Message.Text;
|
||||
if (CommandString.TryParse(text, out var cmd))
|
||||
{
|
||||
if (cmd.UserName != null && cmd.UserName != BotUser.Username)
|
||||
if (cmd.UserName != null && cmd.UserName != Me.Username)
|
||||
{
|
||||
// directed not at us!
|
||||
log.Debug("Message not directed at us");
|
||||
|
||||
@ -43,7 +43,7 @@ namespace JetKarmaBot.Commands
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Me.Id == recipient.Id)
|
||||
if (CommandRouter.Me.Id == recipient.Id)
|
||||
{
|
||||
await Client.SendTextMessageAsync(
|
||||
args.Message.Chat.Id,
|
||||
@ -114,7 +114,7 @@ namespace JetKarmaBot.Commands
|
||||
[Inject] KarmaContextFactory Db { get; set; }
|
||||
[Inject] TelegramBotClient Client { get; set; }
|
||||
[Inject] Localization Locale { get; set; }
|
||||
User Me { get; }
|
||||
[Inject] ChatCommandRouter CommandRouter { get; set; }
|
||||
|
||||
public string Description => "Awards/revokes an award to a user.";
|
||||
public string DescriptionID => "jetkarmabot.award.help";
|
||||
@ -128,10 +128,5 @@ namespace JetKarmaBot.Commands
|
||||
DescriptionID="jetkarmabot.award.awardtypehelp"
|
||||
}
|
||||
};
|
||||
|
||||
public AwardCommand(User me)
|
||||
{
|
||||
Me = me;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ namespace JetKarmaBot.Commands
|
||||
[Inject] KarmaContextFactory Db;
|
||||
[Inject] TelegramBotClient Client { get; set; }
|
||||
[Inject] Localization Locale { get; set; }
|
||||
ChatCommandRouter Router;
|
||||
[Inject] ChatCommandRouter Router;
|
||||
public IReadOnlyCollection<string> Names => new[] { "help" };
|
||||
|
||||
public string Description => "Displays help text for all(one) command(s)";
|
||||
@ -54,9 +54,5 @@ namespace JetKarmaBot.Commands
|
||||
}
|
||||
}
|
||||
}
|
||||
public HelpCommand(ChatCommandRouter router)
|
||||
{
|
||||
Router = router;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,7 +22,6 @@ namespace JetKarmaBot
|
||||
|
||||
TelegramBotClient Client { get; set; }
|
||||
ChatCommandRouter Commands;
|
||||
Telegram.Bot.Types.User Me { get; set; }
|
||||
|
||||
public async Task Init()
|
||||
{
|
||||
@ -35,9 +34,8 @@ namespace JetKarmaBot
|
||||
|
||||
Client = new TelegramBotClient(Config.ApiKey, httpProxy);
|
||||
Container.AddInstance(Client);
|
||||
Me = await Client.GetMeAsync();
|
||||
|
||||
InitCommands(Container);
|
||||
await InitCommands(Container);
|
||||
|
||||
Client.OnMessage += BotOnMessageReceived;
|
||||
Client.StartReceiving();
|
||||
@ -84,15 +82,20 @@ namespace JetKarmaBot
|
||||
(await db.Users.FindAsync(u.Id)).Username = un;
|
||||
}
|
||||
|
||||
void InitCommands(IContainer c)
|
||||
async Task InitCommands(IContainer c)
|
||||
{
|
||||
Commands = c.ResolveObject(new ChatCommandRouter(Me));
|
||||
Commands.Add(c.ResolveObject(new HelpCommand(Commands)));
|
||||
Commands.Add(c.ResolveObject(new AwardCommand(Me)));
|
||||
Commands.Add(c.ResolveObject(new StatusCommand()));
|
||||
Commands.Add(c.ResolveObject(new LocaleCommand()));
|
||||
Commands.Add(c.ResolveObject(new CurrenciesCommand()));
|
||||
Commands.Add(c.ResolveObject(new LeaderboardCommand()));
|
||||
c.Add<HelpCommand>();
|
||||
c.Add<AwardCommand>();
|
||||
c.Add<StatusCommand>();
|
||||
c.Add<LocaleCommand>();
|
||||
c.Add<CurrenciesCommand>();
|
||||
c.Add<LeaderboardCommand>();
|
||||
Commands = c.GetInstance<ChatCommandRouter>();
|
||||
await Commands.Start();
|
||||
foreach (IChatCommand cmd in c.GetInstances<IChatCommand>())
|
||||
{
|
||||
Commands.Add(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -1 +1 @@
|
||||
Subproject commit 40e8f8871f42f1f32c29480505cf5ac6ba61c393
|
||||
Subproject commit 036e4c67275e859207feee215cf87d614e7198d2
|
||||
Loading…
Reference in New Issue
Block a user