placeholder methods for time and weather commands
This commit is contained in:
parent
07eb3ef475
commit
5d94a5d5f3
|
@ -12,13 +12,13 @@ namespace dotbot.Commands
|
||||||
{
|
{
|
||||||
private readonly IConfigurationRoot _config;
|
private readonly IConfigurationRoot _config;
|
||||||
private Dictionary<ulong, string> _cache;
|
private Dictionary<ulong, string> _cache;
|
||||||
private string CleverBotAPIURL = "https://www.cleverbot.com/getreply";
|
private string CleverBotApiUrl = "https://www.cleverbot.com/getreply";
|
||||||
|
|
||||||
public CleverBot(IConfigurationRoot config, CleverBotCacheService cache)
|
public CleverBot(IConfigurationRoot config, CleverBotCacheService cache)
|
||||||
{
|
{
|
||||||
_config = config;
|
_config = config;
|
||||||
_cache = cache.Cache;
|
_cache = cache.Cache;
|
||||||
CleverBotAPIURL += $"?key={_config["tokens:cleverbot"]}&input=";
|
CleverBotApiUrl += $"?key={_config["tokens:cleverbot"]}&input=";
|
||||||
}
|
}
|
||||||
|
|
||||||
class CleverBotResponse
|
class CleverBotResponse
|
||||||
|
@ -33,7 +33,7 @@ namespace dotbot.Commands
|
||||||
[Summary("talk to benbot")]
|
[Summary("talk to benbot")]
|
||||||
public async Task ChatWithCleverBot([Remainder] [Summary("what you want to say to benbot")] string message)
|
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))
|
if (_cache.ContainsKey(Context.Channel.Id))
|
||||||
url += $"&cs={_cache[Context.Channel.Id]}";
|
url += $"&cs={_cache[Context.Channel.Id]}";
|
||||||
var json = (new WebClient { Proxy = null }).DownloadString(url);
|
var json = (new WebClient { Proxy = null }).DownloadString(url);
|
||||||
|
|
|
@ -4,17 +4,39 @@ using dotbot.Core;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
namespace dotbot.Commands
|
namespace dotbot.Commands
|
||||||
{
|
{
|
||||||
[Group("time")]
|
[Group("time")]
|
||||||
public class Time : ModuleBase<SocketCommandContext>
|
public class Time : ModuleBase<SocketCommandContext>
|
||||||
{
|
{
|
||||||
|
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]
|
[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()
|
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")]
|
[Command("save")]
|
||||||
[Summary("save your location")]
|
[Summary("save your location")]
|
||||||
public async Task SaveUserLocation([Remainder] [Summary("the location")] string location)
|
public async Task SaveUserLocation([Remainder] [Summary("the location")] string location)
|
||||||
|
@ -44,12 +75,13 @@ namespace dotbot.Commands
|
||||||
using (var db = new DotbotDbContext())
|
using (var db = new DotbotDbContext())
|
||||||
{
|
{
|
||||||
if (db.UserLocations.Any(u => u.Id == Context.User.Id))
|
if (db.UserLocations.Any(u => u.Id == Context.User.Id))
|
||||||
{
|
{ // update existing
|
||||||
var loc = db.UserLocations.Find(Context.User.Id);
|
var loc = db.UserLocations.Find(Context.User.Id);
|
||||||
// TODO: update location for user
|
// TODO: update location for user
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{ // save new record
|
||||||
|
|
||||||
// TODO: lookup location and save
|
// TODO: lookup location and save
|
||||||
db.UserLocations.Add(new UserLocation
|
db.UserLocations.Add(new UserLocation
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,9 +1,60 @@
|
||||||
using Discord.Commands;
|
using System.Threading.Tasks;
|
||||||
|
using Discord.Commands;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
namespace dotbot.Commands
|
namespace dotbot.Commands
|
||||||
{
|
{
|
||||||
|
[Group("weather")]
|
||||||
public class Weather : ModuleBase<SocketCommandContext>
|
public class Weather : ModuleBase<SocketCommandContext>
|
||||||
{
|
{
|
||||||
|
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}");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
{
|
{
|
||||||
"prefix": "!",
|
"prefix": "!",
|
||||||
"gmail_login": "",
|
"gmail_login": "user@gmail.com",
|
||||||
"tokens": {
|
"tokens": {
|
||||||
"discord": "",
|
"discord": "",
|
||||||
"cleverbot": "",
|
"cleverbot": "",
|
||||||
"gmail": ""
|
"gmail": "", // password here
|
||||||
|
"owm": "",
|
||||||
|
"geonames": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue