.langset and .langsetd can now be used with no arguments to show the currently set language

This commit is contained in:
Kwoth 2017-02-13 17:56:06 +01:00
parent 08c96385ea
commit 8ed7a4c5d8
4 changed files with 26 additions and 9 deletions

View File

@ -28,6 +28,13 @@ namespace NadekoBot.Modules.Administration
[RequireUserPermission(GuildPermission.Administrator)] [RequireUserPermission(GuildPermission.Administrator)]
public async Task LanguageSet([Remainder] string name = null) public async Task LanguageSet([Remainder] string name = null)
{ {
if (string.IsNullOrWhiteSpace(name))
{
var cul = NadekoBot.Localization.GetCultureInfo(Context.Guild);
await Context.Channel.SendConfirmAsync("This server's language is set to " + cul + " - " + cul.NativeName).ConfigureAwait(false);
return;
}
CultureInfo ci = null; CultureInfo ci = null;
try try
{ {
@ -53,8 +60,14 @@ namespace NadekoBot.Modules.Administration
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[OwnerOnly] [OwnerOnly]
public async Task LanguageSetDefault(string name) public async Task LanguageSetDefault([Remainder]string name = null)
{ {
if (string.IsNullOrWhiteSpace(name))
{
var cul = NadekoBot.Localization.GetCultureInfo(Context.Guild);
await Context.Channel.SendConfirmAsync("Bot's language is set to " + cul + " - " + cul.NativeName).ConfigureAwait(false);
return;
}
CultureInfo ci = null; CultureInfo ci = null;
try try
{ {

View File

@ -3687,7 +3687,7 @@ namespace NadekoBot.Resources {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to Sets this server&apos;s response language If bot&apos;s response strings have been translated to that language, bot will use that language in this server. Reset by using `default` as the locale name.. /// Looks up a localized string similar to Sets this server&apos;s response language If bot&apos;s response strings have been translated to that language, bot will use that language in this server. Reset by using `default` as the locale name. Provide no arguments to see currently set language..
/// </summary> /// </summary>
public static string languageset_desc { public static string languageset_desc {
get { get {
@ -3714,7 +3714,7 @@ namespace NadekoBot.Resources {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to Sets the bot&apos;s default response language. All servers which use a default locale will use this one. Setting to `default` will use the host&apos;s current culture.. /// Looks up a localized string similar to Sets the bot&apos;s default response language. All servers which use a default locale will use this one. Setting to `default` will use the host&apos;s current culture. Provide no arguments to see currently set language..
/// </summary> /// </summary>
public static string languagesetdefault_desc { public static string languagesetdefault_desc {
get { get {

View File

@ -3109,7 +3109,7 @@
<value>langsetdefault langsetd</value> <value>langsetdefault langsetd</value>
</data> </data>
<data name="languagesetdefault_desc" xml:space="preserve"> <data name="languagesetdefault_desc" xml:space="preserve">
<value>Sets the bot's default response language. All servers which use a default locale will use this one. Setting to `default` will use the host's current culture.</value> <value>Sets the bot's default response language. All servers which use a default locale will use this one. Setting to `default` will use the host's current culture. Provide no arguments to see currently set language.</value>
</data> </data>
<data name="languagesetdefault_usage" xml:space="preserve"> <data name="languagesetdefault_usage" xml:space="preserve">
<value>`{0}langsetd en-US` or `{0}langsetd default`</value> <value>`{0}langsetd en-US` or `{0}langsetd default`</value>
@ -3118,7 +3118,7 @@
<value>languageset langset</value> <value>languageset langset</value>
</data> </data>
<data name="languageset_desc" xml:space="preserve"> <data name="languageset_desc" xml:space="preserve">
<value>Sets this server's response language If bot's response strings have been translated to that language, bot will use that language in this server. Reset by using `default` as the locale name.</value> <value>Sets this server's response language If bot's response strings have been translated to that language, bot will use that language in this server. Reset by using `default` as the locale name. Provide no arguments to see currently set language.</value>
</data> </data>
<data name="languageset_usage" xml:space="preserve"> <data name="languageset_usage" xml:space="preserve">
<value>`{0}langset de-DE ` or `{0}langset default`</value> <value>`{0}langset de-DE ` or `{0}langset default`</value>

View File

@ -89,13 +89,17 @@ namespace NadekoBot.Services
public void SetDefaultCulture(CultureInfo ci) public void SetDefaultCulture(CultureInfo ci)
{ {
using (var uow = DbHandler.UnitOfWork())
{
var bc = uow.BotConfig.GetOrCreate();
bc.Locale = ci.Name;
uow.Complete();
}
DefaultCultureInfo = ci; DefaultCultureInfo = ci;
} }
public void ResetDefaultCulture() public void ResetDefaultCulture() =>
{ SetDefaultCulture(CultureInfo.CurrentCulture);
DefaultCultureInfo = CultureInfo.CurrentCulture;
}
public CultureInfo GetCultureInfo(IGuild guild) => public CultureInfo GetCultureInfo(IGuild guild) =>
GetCultureInfo(guild.Id); GetCultureInfo(guild.Id);