mirror of
https://github.com/Jetsparrow/karmabot.git
synced 2026-01-21 09:06:09 +03:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
a55f7a1d97
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
[submodule "perfusion"]
|
||||
path = perfusion
|
||||
url = http://192.168.1.65/git/perfusion.git
|
||||
@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.28010.2036
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JetKarmaBot", "JetKarmaBot\JetKarmaBot.csproj", "{729E88EE-BE5E-4D12-B83F-EDC5FC5E2D07}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JetKarmaBot", "JetKarmaBot\JetKarmaBot.csproj", "{729E88EE-BE5E-4D12-B83F-EDC5FC5E2D07}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
||||
@ -6,6 +6,7 @@ using Telegram.Bot;
|
||||
using Telegram.Bot.Args;
|
||||
using Telegram.Bot.Types;
|
||||
using Telegram.Bot.Types.Enums;
|
||||
using Perfusion;
|
||||
|
||||
namespace JetKarmaBot.Commands
|
||||
{
|
||||
@ -59,14 +60,12 @@ namespace JetKarmaBot.Commands
|
||||
}
|
||||
|
||||
|
||||
Db Db { get; }
|
||||
TelegramBotClient Client { get; }
|
||||
[Inject(true)]Db Db { get; set; }
|
||||
[Inject(true)] TelegramBotClient Client { get; set; }
|
||||
User Me { get; }
|
||||
|
||||
public AwardCommand(Db db, TelegramBotClient client, User me)
|
||||
public AwardCommand(User me)
|
||||
{
|
||||
Db = db;
|
||||
Client = client;
|
||||
Me = me;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,16 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using Telegram.Bot.Args;
|
||||
using Perfusion;
|
||||
|
||||
namespace JetKarmaBot.Commands
|
||||
{
|
||||
public class StartCommand : IChatCommand
|
||||
{
|
||||
Db Db;
|
||||
|
||||
public StartCommand(Db db)
|
||||
{
|
||||
Db = db;
|
||||
}
|
||||
[Inject(true)]Db Db;
|
||||
|
||||
public IReadOnlyCollection<string> Names => new[] { "start" };
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using JetKarmaBot.Commands;
|
||||
using Perfusion;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -21,19 +22,19 @@ namespace JetKarmaBot
|
||||
foreach (var u in db.Chats)
|
||||
client.SendTextMessageAsync(u.Value.ChatId, message);
|
||||
}
|
||||
|
||||
public JetKarmaBot(Config cfg, Db db)
|
||||
|
||||
public JetKarmaBot([Inject(true)]Config cfg, [Inject(true)] Container container)
|
||||
{
|
||||
this.db = db;
|
||||
var httpProxy = new WebProxy($"{cfg.ProxyUrl}:{cfg.ProxyPort}")
|
||||
{
|
||||
Credentials = new NetworkCredential(cfg.ProxyLogin, cfg.ProxyPassword)
|
||||
};
|
||||
var botClient = new TelegramBotClient(cfg.ApiKey, httpProxy);
|
||||
container.AddInstance(botClient);
|
||||
var cred = new NetworkCredential(cfg.ProxyLogin, cfg.ProxyPassword);
|
||||
client = new TelegramBotClient(cfg.ApiKey, httpProxy);
|
||||
me = client.GetMeAsync().Result;
|
||||
InitCommands();
|
||||
InitCommands(container);
|
||||
client.OnMessage += BotOnMessageReceived;
|
||||
client.StartReceiving();
|
||||
}
|
||||
@ -46,7 +47,7 @@ namespace JetKarmaBot
|
||||
#endregion
|
||||
|
||||
#region service
|
||||
Db db { get; }
|
||||
[Inject(true)] Db db { get; set; }
|
||||
TelegramBotClient client { get; }
|
||||
User me { get; }
|
||||
|
||||
@ -62,11 +63,11 @@ namespace JetKarmaBot
|
||||
long from = message.From.Id;
|
||||
Task.Run(() => commands.Execute(sender, messageEventArgs));
|
||||
}
|
||||
void InitCommands()
|
||||
void InitCommands(Container c)
|
||||
{
|
||||
commands = new ChatCommandRouter();
|
||||
commands.Add(new StartCommand(db));
|
||||
commands.Add(new AwardCommand(db, client, me));
|
||||
commands.Add(c.ResolveObject(new StartCommand()));
|
||||
commands.Add(c.ResolveObject(new AwardCommand(me)));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
<PackageReference Include="MySql.Data" Version="8.0.13" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
|
||||
<PackageReference Include="Telegram.Bot" Version="14.10.0" />
|
||||
<ProjectReference Include="..\perfusion\Perfusion\Perfusion.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Perfusion;
|
||||
|
||||
namespace JetKarmaBot
|
||||
{
|
||||
@ -6,23 +7,20 @@ namespace JetKarmaBot
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Current = new App(new Config("karma.cfg.json"));
|
||||
|
||||
Container c = new Container();
|
||||
c.AddInstance(new Config("karma.cfg.json"));
|
||||
Current = c.GetInstance(typeof(App)) as App;
|
||||
Console.ReadKey();
|
||||
}
|
||||
|
||||
public static App Current { get; private set; }
|
||||
|
||||
public App(Config cfg)
|
||||
[Inject(true)]
|
||||
public void Run(Container c)
|
||||
{
|
||||
Config = cfg;
|
||||
Db = new Db(Config);
|
||||
Watcher = new JetKarmaBot(Config, Db);
|
||||
Watcher = c.GetInstance<JetKarmaBot>();
|
||||
Console.WriteLine("JetKarmaBot started!");
|
||||
}
|
||||
|
||||
Config Config { get; }
|
||||
Db Db { get; }
|
||||
JetKarmaBot Watcher { get; }
|
||||
JetKarmaBot Watcher { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using Dapper;
|
||||
using MySql.Data.MySqlClient;
|
||||
using Perfusion;
|
||||
|
||||
namespace JetKarmaBot
|
||||
{
|
||||
@ -105,7 +106,7 @@ namespace JetKarmaBot
|
||||
#endregion
|
||||
|
||||
#region service
|
||||
public Db(Config cfg)
|
||||
public Db([Inject(true)]Config cfg)
|
||||
{
|
||||
Log("Initializing...");
|
||||
Conn = new MySqlConnection(cfg.ConnectionString);
|
||||
|
||||
1
perfusion
Submodule
1
perfusion
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 470af231e3f7cf6942907d3b50473fa04dc04caf
|
||||
Loading…
Reference in New Issue
Block a user