mirror of
https://github.com/Jetsparrow/karmabot.git
synced 2026-01-21 00:56:09 +03:00
Make locale a feature
This commit is contained in:
parent
a6426d1b8d
commit
77735d8108
@ -18,7 +18,7 @@ namespace JetKarmaBot.Commands
|
||||
public async Task<bool> Execute(RequestContext ctx)
|
||||
{
|
||||
var db = ctx.GetFeature<KarmaContext>();
|
||||
var currentLocale = Locale[(await db.Chats.FindAsync(ctx.EventArgs.Message.Chat.Id)).Locale];
|
||||
var currentLocale = ctx.GetFeature<Locale>();
|
||||
|
||||
var awarder = ctx.EventArgs.Message.From;
|
||||
string awardTypeText = null;
|
||||
|
||||
@ -16,10 +16,10 @@ namespace JetKarmaBot.Commands
|
||||
public async Task<bool> Execute(RequestContext ctx)
|
||||
{
|
||||
var db = ctx.GetFeature<KarmaContext>();
|
||||
var currentLocale = ctx.GetFeature<Locale>();
|
||||
var cmd = ctx.Command;
|
||||
var args = ctx.EventArgs;
|
||||
|
||||
var currentLocale = Locale[(await db.Chats.FindAsync(ctx.EventArgs.Message.Chat.Id)).Locale];
|
||||
if (cmd.Parameters.Length < 1)
|
||||
{
|
||||
await ctx.SendMessage(currentLocale["jetkarmabot.changelocale.getlocale"]);
|
||||
|
||||
@ -22,7 +22,7 @@ namespace JetKarmaBot.Commands
|
||||
public async Task<bool> Execute(RequestContext ctx)
|
||||
{
|
||||
var db = ctx.GetFeature<KarmaContext>();
|
||||
var currentLocale = Locale[(await db.Chats.FindAsync(ctx.EventArgs.Message.Chat.Id)).Locale];
|
||||
var currentLocale = ctx.GetFeature<Locale>();
|
||||
await ctx.SendMessage(
|
||||
currentLocale["jetkarmabot.currencies.listtext"] + "\n" + string.Join("\n",
|
||||
(await db.AwardTypes.ToListAsync())
|
||||
|
||||
@ -27,8 +27,7 @@ namespace JetKarmaBot.Commands
|
||||
|
||||
public async Task<bool> Execute(RequestContext ctx)
|
||||
{
|
||||
var db = ctx.GetFeature<KarmaContext>();
|
||||
var currentLocale = Locale[(await db.Chats.FindAsync(ctx.EventArgs.Message.Chat.Id)).Locale];
|
||||
var currentLocale = ctx.GetFeature<Locale>();
|
||||
var router = ctx.GetFeature<ChatCommandRouter.Feature>().Router;
|
||||
if (ctx.Command.Parameters.Length < 1)
|
||||
{
|
||||
|
||||
@ -15,7 +15,7 @@ namespace JetKarmaBot.Commands
|
||||
public async Task<bool> Execute(RequestContext ctx)
|
||||
{
|
||||
var db = ctx.GetFeature<KarmaContext>();
|
||||
var currentLocale = Locale[(await db.Chats.FindAsync(ctx.EventArgs.Message.Chat.Id)).Locale];
|
||||
var currentLocale = ctx.GetFeature<Locale>();
|
||||
var asker = ctx.EventArgs.Message.From;
|
||||
var awardTypeName = ctx.Command.Parameters.FirstOrDefault();
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@ namespace JetKarmaBot.Commands
|
||||
public async Task<bool> Execute(RequestContext ctx)
|
||||
{
|
||||
var db = ctx.GetFeature<KarmaContext>();
|
||||
var currentLocale = Locale[(await db.Chats.FindAsync(ctx.EventArgs.Message.Chat.Id)).Locale];
|
||||
var currentLocale = ctx.GetFeature<Locale>();
|
||||
var asker = ctx.EventArgs.Message.From;
|
||||
var awardTypeName = ctx.Command.Parameters.FirstOrDefault();
|
||||
bool isPrivate = ctx.EventArgs.Message.Chat.Type == Telegram.Bot.Types.Enums.ChatType.Private;
|
||||
|
||||
@ -7,11 +7,13 @@ namespace JetKarmaBot.Services.Handling
|
||||
public class DatabaseHandler : IRequestHandler
|
||||
{
|
||||
[Inject] private KarmaContextFactory Db;
|
||||
[Inject] private Localization Locale;
|
||||
public async Task Handle(RequestContext ctx, Func<RequestContext, Task> next)
|
||||
{
|
||||
using (var db = Db.GetContext())
|
||||
{
|
||||
ctx.Features.Add(db);
|
||||
ctx.Features.Add(db); // KarmaContext
|
||||
ctx.Features.Add(Locale[(await db.Chats.FindAsync(ctx.EventArgs.Message.Chat.Id)).Locale]); // Locale
|
||||
await next(ctx);
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
@ -101,7 +101,7 @@ namespace JetKarmaBot.Services.Handling
|
||||
{
|
||||
if (!TimeoutCache[uid].TimeoutMessaged)
|
||||
{
|
||||
Locale currentLocale = Locale[(await db.Chats.FindAsync(ctx.EventArgs.Message.Chat.Id)).Locale];
|
||||
Locale currentLocale = ctx.GetFeature<Locale>();
|
||||
await ctx.SendMessage(currentLocale["jetkarmabot.ratelimit"]);
|
||||
TimeoutCache[uid] = new TimeoutStats() { TimeoutMessaged = true, CooldownDate = TimeoutCache[uid].CooldownDate };
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user