From e71c3683c6240081eab0fad8cfc8dfbe3d7bdd12 Mon Sep 17 00:00:00 2001 From: Bond-009 Date: Wed, 22 Feb 2017 20:37:13 +0100 Subject: [PATCH] Added TemperatureScale to settings Improved AntiSwear --- iTool.DiscordBot/Modules/Random.cs | 1 - iTool.DiscordBot/Modules/Weather.cs | 14 ++++++++++++- iTool.DiscordBot/Program.cs | 26 +++++++++--------------- iTool.DiscordBot/Settings.cs | 2 ++ iTool.DiscordBot/iTool.DiscordBot.csproj | 4 ++-- 5 files changed, 27 insertions(+), 20 deletions(-) diff --git a/iTool.DiscordBot/Modules/Random.cs b/iTool.DiscordBot/Modules/Random.cs index 4dc0621..8345f7c 100644 --- a/iTool.DiscordBot/Modules/Random.cs +++ b/iTool.DiscordBot/Modules/Random.cs @@ -1,7 +1,6 @@ using Discord; using Discord.Commands; using Newtonsoft.Json.Linq; -using System; using System.Net.Http; using System.Threading.Tasks; diff --git a/iTool.DiscordBot/Modules/Weather.cs b/iTool.DiscordBot/Modules/Weather.cs index c338663..5f70b3c 100644 --- a/iTool.DiscordBot/Modules/Weather.cs +++ b/iTool.DiscordBot/Modules/Weather.cs @@ -20,7 +20,19 @@ public async Task GetWeather(string input) OpenWeatherClient client = new OpenWeatherClient(Program.Settings.OpenWeatherMapKey); WeatherInfo weather = await client.GetCurrentAsync(input); - weather.Temperature = weather.Temperature.ToCelsius(); //TODO: Add temperaturescale setting + switch (Program.Settings.TemperatureScale) + { + case TemperatureScale.Kelvin: + weather.Temperature = weather.Temperature.ToKelvin(); + break; + case TemperatureScale.Fahrenheit: + weather.Temperature = weather.Temperature.ToFahrenheit(); + break; + case TemperatureScale.Celsius: + default: + weather.Temperature = weather.Temperature.ToCelsius(); + break; + } EmbedBuilder b = new EmbedBuilder() { diff --git a/iTool.DiscordBot/Program.cs b/iTool.DiscordBot/Program.cs index b2cde16..f9fa327 100644 --- a/iTool.DiscordBot/Program.cs +++ b/iTool.DiscordBot/Program.cs @@ -38,12 +38,12 @@ public static async Task Start() Environment.Exit(0); } - DiscordSocketConfig config = new DiscordSocketConfig(); - config.AlwaysDownloadUsers = Settings.AlwaysDownloadUsers; - config.LogLevel = Settings.LogLevel; - config.MessageCacheSize = Settings.MessageCacheSize; - - discordClient = new DiscordSocketClient(config); + discordClient = new DiscordSocketClient(new DiscordSocketConfig() + { + AlwaysDownloadUsers = Settings.AlwaysDownloadUsers, + LogLevel = Settings.LogLevel, + MessageCacheSize = Settings.MessageCacheSize + }); await discordClient.LoginAsync(TokenType.Bot, Settings.DiscordToken); await discordClient.ConnectAsync(); @@ -90,17 +90,11 @@ private async static Task DiscordClient_MessageReceived(SocketMessage arg) Console.WriteLine("[" + arg.Timestamp.UtcDateTime.ToString("dd/MM/yyyy HH:mm:ss") + "]" + arg.Author.Username + ": " + arg.Content); #endif - if (!badWords.IsNullOrEmpty() && Settings.AntiSwear) + if (Settings.AntiSwear && !badWords.IsNullOrEmpty() + && badWords.Any(Regex.Replace(arg.Content.ToLower(), "[^A-Za-z0-9]", "").Contains)) { - foreach (string badWord in badWords) - { - if (Regex.Replace(arg.Content.ToLower(), "[^A-Za-z0-9]", "").Contains(badWord)) - { - await arg.DeleteAsync(); - await arg.Channel.SendMessageAsync(arg.Author.Mention + ", please don't put such things in chat"); - break; - } - } + await arg.DeleteAsync(); + await arg.Channel.SendMessageAsync(arg.Author.Mention + ", please don't put such things in chat"); } } diff --git a/iTool.DiscordBot/Settings.cs b/iTool.DiscordBot/Settings.cs index 7649283..8de8d6a 100644 --- a/iTool.DiscordBot/Settings.cs +++ b/iTool.DiscordBot/Settings.cs @@ -1,4 +1,5 @@ using Discord; +using OpenWeather; namespace iTool.DiscordBot { @@ -13,5 +14,6 @@ public class Settings public string SteamKey { get; set; } = string.Empty; public string OpenWeatherMapKey { get; set; } = string.Empty; public string DiscordToken { get; set; } = string.Empty; + public TemperatureScale TemperatureScale { get; set; } } } diff --git a/iTool.DiscordBot/iTool.DiscordBot.csproj b/iTool.DiscordBot/iTool.DiscordBot.csproj index fac3a45..a6e5bde 100644 --- a/iTool.DiscordBot/iTool.DiscordBot.csproj +++ b/iTool.DiscordBot/iTool.DiscordBot.csproj @@ -8,8 +8,8 @@ - - + +