mirror of
https://github.com/Jetsparrow/karmabot.git
synced 2026-01-21 09:06:09 +03:00
Add /locale list and /locale all
This commit is contained in:
parent
08ebdbaa37
commit
98361572dc
@ -4,6 +4,7 @@ using Telegram.Bot.Args;
|
||||
using Perfusion;
|
||||
using JetKarmaBot.Services;
|
||||
using NLog;
|
||||
using System.Linq;
|
||||
|
||||
namespace JetKarmaBot.Commands
|
||||
{
|
||||
@ -26,6 +27,23 @@ namespace JetKarmaBot.Commands
|
||||
replyToMessageId: args.Message.MessageId);
|
||||
return true;
|
||||
}
|
||||
else if (cmd.Parameters[0] == "list")
|
||||
{
|
||||
Client.SendTextMessageAsync(
|
||||
args.Message.Chat.Id,
|
||||
currentLocale["jetkarmabot.changelocale.listalltext"] + "\n"
|
||||
+ string.Join("\n", Locale.Select(a => a.Key)),
|
||||
replyToMessageId: args.Message.MessageId);
|
||||
return true;
|
||||
}
|
||||
else if (cmd.Parameters[0] == "all")
|
||||
{
|
||||
Client.SendTextMessageAsync(
|
||||
args.Message.Chat.Id,
|
||||
currentLocale["jetkarmabot.changelocale.errorall"],
|
||||
replyToMessageId: args.Message.MessageId);
|
||||
return true;
|
||||
}
|
||||
string localeId;
|
||||
if (Locale.ContainsLocale(cmd.Parameters[0]))
|
||||
localeId = cmd.Parameters[0];
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@ -8,7 +9,7 @@ using Perfusion;
|
||||
|
||||
namespace JetKarmaBot
|
||||
{
|
||||
public class Localization
|
||||
public class Localization : IReadOnlyDictionary<string, Locale>
|
||||
{
|
||||
private Dictionary<string, Locale> locales = new Dictionary<string, Locale>();
|
||||
|
||||
@ -77,21 +78,42 @@ namespace JetKarmaBot
|
||||
|
||||
void Log(Exception e) => Console.WriteLine(e);
|
||||
|
||||
public class Locale
|
||||
{
|
||||
private Dictionary<string, string> locale;
|
||||
private string localeName;
|
||||
private string[] commonNames;
|
||||
public IEnumerable<string> Keys => locales.Keys;
|
||||
|
||||
public Locale(JObject locale, string localeName)
|
||||
{
|
||||
this.locale = locale.Property("strings").Value.ToObject<Dictionary<string, string>>();
|
||||
this.localeName = localeName;
|
||||
this.commonNames = locale.Property("names").Value.ToObject<string[]>();
|
||||
}
|
||||
public string[] CommonNames => commonNames;
|
||||
public string Name => localeName;
|
||||
public string this[string name] => locale.ContainsKey(name) ? locale[name] : "unknown";
|
||||
public IEnumerable<Locale> Values => locales.Values;
|
||||
|
||||
public int Count => locales.Count;
|
||||
|
||||
public bool ContainsKey(string key) => locales.ContainsKey(key.ToLower());
|
||||
|
||||
public bool TryGetValue(string key, out Locale value)
|
||||
{
|
||||
return locales.TryGetValue(key.ToLower(), out value);
|
||||
}
|
||||
|
||||
public IEnumerator<KeyValuePair<string, Locale>> GetEnumerator()
|
||||
{
|
||||
return locales.GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
|
||||
|
||||
}
|
||||
public class Locale
|
||||
{
|
||||
private Dictionary<string, string> locale;
|
||||
private string localeName;
|
||||
private string[] commonNames;
|
||||
|
||||
public Locale(JObject locale, string localeName)
|
||||
{
|
||||
this.locale = locale.Property("strings").Value.ToObject<Dictionary<string, string>>();
|
||||
this.localeName = localeName;
|
||||
this.commonNames = locale.Property("names").Value.ToObject<string[]>();
|
||||
}
|
||||
public string[] CommonNames => commonNames;
|
||||
public string Name => localeName;
|
||||
public string this[string name] => locale.ContainsKey(name) ? locale[name] : "unknown";
|
||||
}
|
||||
}
|
||||
@ -14,6 +14,8 @@
|
||||
"jetkarmabot.status.listspecifictext": "You are at {0}{1} now.",
|
||||
"jetkarmabot.status.havenothing": "You don't have anything yet.",
|
||||
"jetkarmabot.changelocale.justchanged": "Roger that.",
|
||||
"jetkarmabot.changelocale.getlocale": "I'm currently speaking English."
|
||||
"jetkarmabot.changelocale.getlocale": "I'm currently speaking English.",
|
||||
"jetkarmabot.changelocale.listalltext": "I know:",
|
||||
"jetkarmabot.changelocale.errorall": "I would like to speak all languages at once, but because of the rules of the universe, I am not allowed to do that."
|
||||
}
|
||||
}
|
||||
@ -15,6 +15,8 @@
|
||||
"jetkarmabot.status.listspecifictext": "У вас сейчас {0}{1}.",
|
||||
"jetkarmabot.status.havenothing": "У вас пока ничего нет.",
|
||||
"jetkarmabot.changelocale.justchanged": "Так точно.",
|
||||
"jetkarmabot.changelocale.getlocale": "Я сейчас говорю по-русски."
|
||||
"jetkarmabot.changelocale.getlocale": "Я сейчас говорю по-русски.",
|
||||
"jetkarmabot.changelocale.listalltext": "Я знаю:",
|
||||
"jetkarmabot.changelocale.errorall": "Мне бы хотелось говорить на всех языках в то же самое время, но из-за ограничений вселенной, мне это не позволяется."
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user