some small fixes, .time added, closes #989
This commit is contained in:
parent
aa6f700d0b
commit
3e1b5d7e57
@ -169,7 +169,8 @@ namespace NadekoBot.Modules.Administration
|
||||
var guser = (IGuildUser)Context.User;
|
||||
|
||||
var userRoles = user.GetRoles();
|
||||
if (guser.Id != Context.Guild.OwnerId && (user.Id == Context.Guild.OwnerId || guser.GetRoles().Max(x => x.Position) <= userRoles.Max(x => x.Position)))
|
||||
if (guser.Id != Context.Guild.OwnerId &&
|
||||
(user.Id == Context.Guild.OwnerId || guser.GetRoles().Max(x => x.Position) <= userRoles.Max(x => x.Position)))
|
||||
return;
|
||||
try
|
||||
{
|
||||
|
@ -1,6 +1,7 @@
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Attributes;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using NLog;
|
||||
using System;
|
||||
@ -48,6 +49,11 @@ namespace NadekoBot.Modules.Administration
|
||||
[RequireUserPermission(GuildPermission.ManageRoles)]
|
||||
public async Task AutoAssignRole([Remainder] IRole role = null)
|
||||
{
|
||||
var guser = (IGuildUser)Context.User;
|
||||
if (role != null)
|
||||
if (Context.User.Id != guser.Guild.OwnerId && guser.GetRoles().Max(x => x.Position) <= role.Position)
|
||||
return;
|
||||
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
var conf = uow.GuildConfigs.For(Context.Guild.Id, set => set);
|
||||
|
@ -43,6 +43,10 @@ namespace NadekoBot.Modules.Administration
|
||||
{
|
||||
IEnumerable<SelfAssignedRole> roles;
|
||||
|
||||
var guser = (IGuildUser)Context.User;
|
||||
if (Context.User.Id != guser.Guild.OwnerId && guser.GetRoles().Max(x => x.Position) <= role.Position)
|
||||
return;
|
||||
|
||||
string msg;
|
||||
var error = false;
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
@ -75,6 +79,10 @@ namespace NadekoBot.Modules.Administration
|
||||
[RequireUserPermission(GuildPermission.ManageRoles)]
|
||||
public async Task Rsar([Remainder] IRole role)
|
||||
{
|
||||
var guser = (IGuildUser)Context.User;
|
||||
if (Context.User.Id != guser.Guild.OwnerId && guser.GetRoles().Max(x => x.Position) <= role.Position)
|
||||
return;
|
||||
|
||||
bool success;
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
|
42
src/NadekoBot/Modules/Searches/Commands/Models/TimeModels.cs
Normal file
42
src/NadekoBot/Modules/Searches/Commands/Models/TimeModels.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Modules.Searches.Commands.Models
|
||||
{
|
||||
public class TimeZoneResult
|
||||
{
|
||||
public double DstOffset { get; set; }
|
||||
public double RawOffset { get; set; }
|
||||
|
||||
//public string TimeZoneId { get; set; }
|
||||
public string TimeZoneName { get; set; }
|
||||
}
|
||||
|
||||
public class GeolocationResult
|
||||
{
|
||||
|
||||
public class GeolocationModel
|
||||
{
|
||||
public class GeometryModel
|
||||
{
|
||||
public class LocationModel
|
||||
{
|
||||
public float Lat { get; set; }
|
||||
public float Lng { get; set; }
|
||||
}
|
||||
|
||||
public LocationModel Location { get; set; }
|
||||
}
|
||||
|
||||
[JsonProperty("formatted_address")]
|
||||
public string FormattedAddress { get; set; }
|
||||
public GeometryModel Geometry { get; set; }
|
||||
}
|
||||
|
||||
public GeolocationModel[] results;
|
||||
}
|
||||
}
|
@ -56,6 +56,27 @@ namespace NadekoBot.Modules.Searches
|
||||
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
public async Task Time([Remainder] string arg)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(arg) || string.IsNullOrWhiteSpace(NadekoBot.Credentials.GoogleApiKey))
|
||||
return;
|
||||
|
||||
using (var http = new HttpClient())
|
||||
{
|
||||
var res = await http.GetStringAsync($"https://maps.googleapis.com/maps/api/geocode/json?address={arg}&key={NadekoBot.Credentials.GoogleApiKey}").ConfigureAwait(false);
|
||||
var obj = JsonConvert.DeserializeObject<GeolocationResult>(res);
|
||||
|
||||
var currentSeconds = DateTime.UtcNow.UnixTimestamp();
|
||||
var timeRes = await http.GetStringAsync($"https://maps.googleapis.com/maps/api/timezone/json?location={obj.results[0].Geometry.Location.Lat},{obj.results[0].Geometry.Location.Lng}×tamp={currentSeconds}&key={NadekoBot.Credentials.GoogleApiKey}").ConfigureAwait(false);
|
||||
var timeObj = JsonConvert.DeserializeObject<TimeZoneResult>(timeRes);
|
||||
|
||||
var time = DateTime.UtcNow.AddSeconds(timeObj.DstOffset + timeObj.RawOffset);
|
||||
|
||||
await ReplyConfirmLocalized("time", Format.Bold(obj.results[0].FormattedAddress), Format.Code(time.ToString("HH:mm")), timeObj.TimeZoneName).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
public async Task Youtube([Remainder] string query = null)
|
||||
{
|
||||
|
29
src/NadekoBot/Resources/CommandStrings.Designer.cs
generated
29
src/NadekoBot/Resources/CommandStrings.Designer.cs
generated
@ -5757,7 +5757,7 @@ namespace NadekoBot.Resources {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar quoteid qid.
|
||||
/// Looks up a localized string similar to quoteid qid.
|
||||
/// </summary>
|
||||
public static string quoteid_cmd {
|
||||
get {
|
||||
@ -8267,6 +8267,33 @@ namespace NadekoBot.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to time.
|
||||
/// </summary>
|
||||
public static string time_cmd {
|
||||
get {
|
||||
return ResourceManager.GetString("time_cmd", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Shows the current time and timezone in the specified location..
|
||||
/// </summary>
|
||||
public static string time_desc {
|
||||
get {
|
||||
return ResourceManager.GetString("time_desc", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to `{0}time London, UK`.
|
||||
/// </summary>
|
||||
public static string time_usage {
|
||||
get {
|
||||
return ResourceManager.GetString("time_usage", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to timezone.
|
||||
/// </summary>
|
||||
|
@ -3357,4 +3357,13 @@
|
||||
<data name="slowmodewhitelist_usage" xml:space="preserve">
|
||||
<value>`{0}slowmodewl SomeRole` or `{0}slowmodewl AdminDude`</value>
|
||||
</data>
|
||||
<data name="time_cmd" xml:space="preserve">
|
||||
<value>time</value>
|
||||
</data>
|
||||
<data name="time_desc" xml:space="preserve">
|
||||
<value>Shows the current time and timezone in the specified location.</value>
|
||||
</data>
|
||||
<data name="time_usage" xml:space="preserve">
|
||||
<value>`{0}time London, UK`</value>
|
||||
</data>
|
||||
</root>
|
20
src/NadekoBot/Resources/ResponseStrings.Designer.cs
generated
20
src/NadekoBot/Resources/ResponseStrings.Designer.cs
generated
@ -5773,6 +5773,15 @@ namespace NadekoBot.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Time in {0} is {1} - {2}.
|
||||
/// </summary>
|
||||
public static string searches_time {
|
||||
get {
|
||||
return ResourceManager.GetString("searches_time", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Title:.
|
||||
/// </summary>
|
||||
@ -6498,7 +6507,7 @@ namespace NadekoBot.Resources {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to No quotes on this page..
|
||||
/// Looks up a localized string similar to No quotes found matching the quote ID specified..
|
||||
/// </summary>
|
||||
public static string utility_quotes_page_none {
|
||||
get {
|
||||
@ -6506,15 +6515,6 @@ namespace NadekoBot.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to No quotes found matching the quote ID specified..
|
||||
/// </summary>
|
||||
public static string utility_quotes_notfound {
|
||||
get {
|
||||
return ResourceManager.GetString("utility_quotes_notfound", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to No quotes found which you can remove..
|
||||
/// </summary>
|
||||
|
@ -2082,11 +2082,8 @@ Owner ID: {2}</value>
|
||||
<value>Page {0} of quotes</value>
|
||||
</data>
|
||||
<data name="utility_quotes_page_none" xml:space="preserve">
|
||||
<value>No quotes on this page.</value>
|
||||
<data name="utility_quotes_notfound" xml:space="preserve">
|
||||
<value>No quotes found matching the quote ID specified.</value>
|
||||
</data>
|
||||
</data>
|
||||
<data name="utility_quotes_remove_none" xml:space="preserve">
|
||||
<value>No quotes found which you can remove.</value>
|
||||
</data>
|
||||
@ -2405,4 +2402,8 @@ Owner ID: {2}</value>
|
||||
<data name="utility_clpa_too_early" xml:space="preserve">
|
||||
<value>Rewards can be claimed on or after 5th of each month.</value>
|
||||
</data>
|
||||
<data name="searches_time" xml:space="preserve">
|
||||
<value>Time in {0} is {1} - {2}</value>
|
||||
<comment>Time in London, UK is 15:30 - Time Zone Name</comment>
|
||||
</data>
|
||||
</root>
|
@ -193,7 +193,7 @@ namespace NadekoBot.Extensions
|
||||
public static string SanitizeMentions(this string str) =>
|
||||
str.Replace("@everyone", "@everyοne").Replace("@here", "@һere");
|
||||
|
||||
public static double UnixTimestamp(this DateTime dt) => dt.ToUniversalTime().Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
|
||||
public static double UnixTimestamp(this DateTime dt) => dt.ToUniversalTime().Subtract(new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds;
|
||||
|
||||
public static async Task<IUserMessage> SendMessageAsync(this IUser user, string message, bool isTTS = false) =>
|
||||
await (await user.CreateDMChannelAsync().ConfigureAwait(false)).SendMessageAsync(message, isTTS).ConfigureAwait(false);
|
||||
|
Loading…
Reference in New Issue
Block a user