mirror of
https://github.com/Jetsparrow/karmabot.git
synced 2026-01-21 00:56:09 +03:00
46 lines
1.6 KiB
C#
46 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Telegram.Bot;
|
|
using Telegram.Bot.Args;
|
|
using Telegram.Bot.Types;
|
|
using Perfusion;
|
|
using JetKarmaBot.Models;
|
|
using JetKarmaBot.Services;
|
|
|
|
namespace JetKarmaBot.Commands
|
|
{
|
|
class ChangeLocaleCommand : IChatCommand
|
|
{
|
|
public IReadOnlyCollection<string> Names => new[] { "changelocale", "locale" };
|
|
|
|
public bool Execute(CommandString cmd, MessageEventArgs args)
|
|
{
|
|
using (var db = Db.GetContext())
|
|
{
|
|
var currentLocale = Locale[db.Chats.Find(args.Message.Chat.Id).Locale];
|
|
if (cmd.Parameters.Length < 1)
|
|
{
|
|
Client.SendTextMessageAsync(
|
|
args.Message.Chat.Id,
|
|
currentLocale["jetkarmabot.changelocale.getlocale"],
|
|
replyToMessageId: args.Message.MessageId);
|
|
return true;
|
|
}
|
|
db.Chats.Find(args.Message.Chat.Id).Locale = cmd.Parameters[0];
|
|
currentLocale = Locale[db.Chats.Find(args.Message.Chat.Id).Locale];
|
|
Client.SendTextMessageAsync(
|
|
args.Message.Chat.Id,
|
|
currentLocale["jetkarmabot.changelocale.justchanged"],
|
|
replyToMessageId: args.Message.MessageId);
|
|
db.SaveChanges();
|
|
return true;
|
|
}
|
|
}
|
|
|
|
[Inject] KarmaContextFactory Db { get; set; }
|
|
[Inject] TelegramBotClient Client { get; set; }
|
|
[Inject] Localization Locale { get; set; }
|
|
}
|
|
}
|