diff --git a/Commands/CleverBot.cs b/Commands/CleverBot.cs index 190f026..aea8f55 100644 --- a/Commands/CleverBot.cs +++ b/Commands/CleverBot.cs @@ -12,13 +12,13 @@ namespace dotbot.Commands { private readonly IConfigurationRoot _config; private Dictionary _cache; - private string CleverBotAPIURL = "https://www.cleverbot.com/getreply"; + private string CleverBotApiUrl = "https://www.cleverbot.com/getreply"; public CleverBot(IConfigurationRoot config, CleverBotCacheService cache) { _config = config; _cache = cache.Cache; - CleverBotAPIURL += $"?key={_config["tokens:cleverbot"]}&input="; + CleverBotApiUrl += $"?key={_config["tokens:cleverbot"]}&input="; } class CleverBotResponse @@ -33,7 +33,7 @@ namespace dotbot.Commands [Summary("talk to benbot")] public async Task ChatWithCleverBot([Remainder] [Summary("what you want to say to benbot")] string message) { - var url = $"{CleverBotAPIURL}{message}"; + var url = $"{CleverBotApiUrl}{message}"; if (_cache.ContainsKey(Context.Channel.Id)) url += $"&cs={_cache[Context.Channel.Id]}"; var json = (new WebClient { Proxy = null }).DownloadString(url); diff --git a/Commands/Time.cs b/Commands/Time.cs index e840aad..695cd4b 100644 --- a/Commands/Time.cs +++ b/Commands/Time.cs @@ -4,17 +4,39 @@ using dotbot.Core; using System; using System.Linq; using System.Threading.Tasks; +using Microsoft.Extensions.Configuration; namespace dotbot.Commands { [Group("time")] public class Time : ModuleBase { + private readonly IConfigurationRoot _config; + private string OwmApiUrl = "http://api.openweathermap.org/data/2.5/weather"; + private string GeoNamesUrl = "http://api.geonames.org/timezoneJSON"; + + public Time(IConfigurationRoot config) + { + _config = config; + OwmApiUrl += $"?APPID={_config["tokens:owm"]}&units=metric"; + GeoNamesUrl += $"?username={_config["tokens:geonames"]}"; + } + [Command] - [Summary("get the time at the bot's location")] + [Summary("get the time at your location (or bot's location if you don't have one saved)")] public async Task GetTime() { - await ReplyAsync($"{DateTime.Now:g}"); + using (var db = new DotbotDbContext()) + { + if (db.UserLocations.Any(u => u.Id == Context.User.Id)) + { + var ul = db.UserLocations.Find(Context.User.Id); + var dt = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTime.UtcNow, ul.TimeZone); + await ReplyAsync($"it's {dt:g} in {ul.City}"); + } + else + await ReplyAsync($"it's {DateTime.Now:g} Eastern Time (where the bot is hosted)"); + } } @@ -37,6 +59,15 @@ namespace dotbot.Commands } } + + [Command] + [Summary("check the time in an arbitrary location")] + public async Task LookupTime([Remainder] [Summary("location")] string location) + { + // TODO: api lookup + await ReplyAsync($"it is __ o'clock in {location}"); + } + [Command("save")] [Summary("save your location")] public async Task SaveUserLocation([Remainder] [Summary("the location")] string location) @@ -44,12 +75,13 @@ namespace dotbot.Commands using (var db = new DotbotDbContext()) { if (db.UserLocations.Any(u => u.Id == Context.User.Id)) - { + { // update existing var loc = db.UserLocations.Find(Context.User.Id); // TODO: update location for user } else - { + { // save new record + // TODO: lookup location and save db.UserLocations.Add(new UserLocation { diff --git a/Commands/Weather.cs b/Commands/Weather.cs index a0f223e..7f36a4c 100644 --- a/Commands/Weather.cs +++ b/Commands/Weather.cs @@ -1,9 +1,60 @@ -using Discord.Commands; +using System.Threading.Tasks; +using Discord.Commands; +using Microsoft.Extensions.Configuration; namespace dotbot.Commands { + [Group("weather")] public class Weather : ModuleBase { + private IConfigurationRoot _config; + private string OwmApiUrl = "http://api.openweathermap.org/data/2.5/weather"; + private string GeoNamesUrl = "http://api.geonames.org/timezoneJSON"; + + public Weather(IConfigurationRoot config) + { + _config = config; + OwmApiUrl += $"?APPID={_config["tokens:owm"]}&units=metric"; + GeoNamesUrl += $"?username={_config["tokens:geonames"]}"; + } + + + [Command] + [Summary("gets the weather for your location")] + public async Task GetWeather() + { + // TODO: check if user has saved location and do API lookup + await ReplyAsync("good weather"); + } + + + [Command] + [Summary("look up the weather at a mentioned user's saved location")] + public async Task LookupWeatherForUser([Summary("user to check time for")] IUser user) + { + // TODO: check if they're in DB + // TODO: convert to tz + await ReplyAsync($"it's __ weather for {user.Mention}"); + } + + + [Command] + [Summary("look up the weather at a specified location")] + public async Task LookupWeather([Remainder] [Summary("location")] string location) + { + // TODO: API lookup + await ReplyAsync($"the weather in {location} is crap"); + } + + + [Command("save")] + [Summary("save a location for timezone and weather")] + public async Task SaveUserLocation([Remainder] [Summary("location")] string location) + { + // TODO: lookup location detail + // TODO: save to db + await ReplyAsync($"you location has been saved as {location}"); + } } } diff --git a/_config.example.json b/_config.example.json index 02d6311..ad0c5c2 100644 --- a/_config.example.json +++ b/_config.example.json @@ -1,9 +1,11 @@ { "prefix": "!", - "gmail_login": "", + "gmail_login": "user@gmail.com", "tokens": { "discord": "", "cleverbot": "", - "gmail": "" + "gmail": "", // password here + "owm": "", + "geonames": "" } }