Skip to content

Commit

Permalink
Added TemperatureScale to settings
Browse files Browse the repository at this point in the history
Improved AntiSwear
  • Loading branch information
Bond-009 committed Feb 22, 2017
1 parent 247eda0 commit e71c368
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
1 change: 0 additions & 1 deletion iTool.DiscordBot/Modules/Random.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Discord;
using Discord.Commands;
using Newtonsoft.Json.Linq;
using System;
using System.Net.Http;
using System.Threading.Tasks;

Expand Down
14 changes: 13 additions & 1 deletion iTool.DiscordBot/Modules/Weather.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
26 changes: 10 additions & 16 deletions iTool.DiscordBot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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");
}
}

Expand Down
2 changes: 2 additions & 0 deletions iTool.DiscordBot/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Discord;
using OpenWeather;

namespace iTool.DiscordBot
{
Expand All @@ -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; }
}
}
4 changes: 2 additions & 2 deletions iTool.DiscordBot/iTool.DiscordBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Discord.Net.Commands" Version="1.0.0-rc-00598" />
<PackageReference Include="Discord.Net.WebSocket" Version="1.0.0-rc-00598" />
<PackageReference Include="Discord.Net.Commands" Version="1.0.0-rc-00604" />
<PackageReference Include="Discord.Net.WebSocket" Version="1.0.0-rc-00604" />
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<PackageReference Include="OpenWeather.Net" Version="0.5.1" />
<PackageReference Include="System.Xml.XmlSerializer" Version="4.3.0" />
Expand Down

0 comments on commit e71c368

Please sign in to comment.