some small fixes, .time added, closes #989

This commit is contained in:
Kwoth
2017-04-03 23:18:18 +02:00
parent aa6f700d0b
commit 3e1b5d7e57
10 changed files with 134 additions and 19 deletions

View File

@@ -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
{

View File

@@ -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);

View File

@@ -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())
{

View 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;
}
}

View File

@@ -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}&timestamp={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)
{