public List <string> RunCommand(ChannelMessageEventDataModel messageEvent, GroupCollection arguments = null, bool useCache = true) { WeatherApiConfigModel weatherApiConfig = ConfigHelpers.LoadConfig <WeatherApiConfigModel>(ConfigHelpers.ConfigPaths.WeatherApiConfig); if (!weatherApiConfig.UserDefaultLocale.ContainsKey(messageEvent.Nick)) { return($"User has no default locale set, use '{messageEvent.MessageWithPrefix[0]}{arguments[0].Value} set <locale>' command to set a locale.".SplitInParts(430).ToList()); } CurrentWeatherModel.CurrentWeather currentWeather; bool shortQuery = arguments[0].Value == "ws"; try { currentWeather = Weather.GetCurrentWeatherAsync(weatherApiConfig.UserDefaultLocale[messageEvent.Nick], weatherApiConfig.ApiKey).Result; } catch (Exception e) { if (e.InnerException is QueryNotFoundException) { return("Could not find given location.".SplitInParts(430).ToList()); } throw; } return(FormatResponse.FormatWeatherResponse(currentWeather.Current, currentWeather.Location, shortWeather: shortQuery) .SplitInParts(430) //.Concat(FormatResponse.FormatForecastResponse(forecastWeather.Forecast, forecastWeather.Location, shortWeather: shortQuery)) .ToList()); }
public List <string> RunCommand(ChannelMessageEventDataModel messageEvent, GroupCollection arguments = null, bool useCache = true) { if (arguments == null || arguments.Count == 1) { throw new ArgumentException("Not enough arguments"); } WeatherApiConfigModel weatherApiConfig = ConfigHelpers.LoadConfig <WeatherApiConfigModel>(ConfigHelpers.ConfigPaths.WeatherApiConfig); weatherApiConfig.UserDefaultLocale[messageEvent.Nick] = arguments[1].Value; ConfigHelpers.SaveConfig(weatherApiConfig, ConfigHelpers.ConfigPaths.WeatherApiConfig); return($"Successfully updated default user locale for {messageEvent.Nick} to {arguments[1].Value}".SplitInParts(430) .ToList()); }
public List <string> RunCommand(ChannelMessageEventDataModel messageEvent, GroupCollection arguments = null, bool useCache = true) { if (arguments == null || arguments.Count == 1) { throw new ArgumentException("Not enough arguments"); } bool shortQuery = arguments[0].Value.Substring(0, 2) == "ws"; string query = arguments[1].Value; if (query.ToLower() == "goonyland") { query = "Goteborg, Sweden"; } WeatherApiConfigModel weatherApiConfig = ConfigHelpers.LoadConfig <WeatherApiConfigModel>(ConfigHelpers.ConfigPaths.WeatherApiConfig); CurrentWeatherModel.CurrentWeather currentWeather; try { currentWeather = Weather.GetCurrentWeatherAsync(query, weatherApiConfig.ApiKey) .Result; } catch (Exception e) { if (e.InnerException is QueryNotFoundException) { return("Could not find given location.".SplitInParts(430).ToList()); } throw; } return(FormatResponse.FormatWeatherResponse(currentWeather.Current, currentWeather.Location, shortWeather: shortQuery) .SplitInParts(430) //.Concat(FormatResponse.FormatForecastResponse(forecastWeather.Forecast, forecastWeather.Location, shortWeather: shortQuery)) .ToList()); }