add more awaits and update !roll

This commit is contained in:
runebaas 2018-07-28 16:31:18 +02:00
parent 95618b1f8b
commit 18b3436d66
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6
12 changed files with 60 additions and 47 deletions

View file

@ -0,0 +1,11 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_ACCESSORHOLDER_ATTRIBUTE_ON_SAME_LINE_EX/@EntryValue">NEVER</s:String>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LIMIT/@EntryValue">200</s:Int64>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpAttributeForSingleLineMethodUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpRenamePlacementToArrangementMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002ECSharpPlaceAttributeOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View file

@ -37,7 +37,7 @@ namespace Geekbot.net.Commands.Audio
} }
catch (Exception e) catch (Exception e)
{ {
_errorHandler.HandleCommandException(e, Context); await _errorHandler.HandleCommandException(e, Context);
} }
} }

View file

@ -33,15 +33,18 @@ namespace Geekbot.net.Commands.Games
var transDict = await _translation.GetDict(Context); var transDict = await _translation.GetDict(Context);
if (guess <= 100 && guess > 0) if (guess <= 100 && guess > 0)
{ {
var prevRoll = _redis.Db.HashGet($"{Context.Guild.Id}:RollsPrevious", Context.Message.Author.Id); var prevRoll = _redis.Db.HashGet($"{Context.Guild.Id}:RollsPrevious2", Context.Message.Author.Id).ToString()?.Split('|');
if (!prevRoll.IsNullOrEmpty && prevRoll.ToString() == guess.ToString()) if (prevRoll?.Length == 2)
{ {
await ReplyAsync(string.Format(transDict["NoPrevGuess"], Context.Message.Author.Mention)); if (prevRoll[0] == guess.ToString() && DateTime.Parse(prevRoll[1]) > DateTime.Now.AddDays(-1))
return; {
await ReplyAsync(string.Format(transDict["NoPrevGuess"], Context.Message.Author.Mention));
return;
}
} }
_redis.Db.HashSet($"{Context.Guild.Id}:RollsPrevious", _redis.Db.HashSet($"{Context.Guild.Id}:RollsPrevious2", new[] {new HashEntry(Context.Message.Author.Id, $"{guess}|{DateTime.Now}")});
new[] {new HashEntry(Context.Message.Author.Id, guess)});
await ReplyAsync(string.Format(transDict["Rolled"], Context.Message.Author.Mention, number, guess)); await ReplyAsync(string.Format(transDict["Rolled"], Context.Message.Author.Mention, number, guess));
if (guess == number) if (guess == number)
{ {
@ -56,7 +59,7 @@ namespace Geekbot.net.Commands.Games
} }
catch (Exception e) catch (Exception e)
{ {
_errorHandler.HandleCommandException(e, Context); await _errorHandler.HandleCommandException(e, Context);
} }
} }
} }

View file

@ -112,7 +112,7 @@ namespace Geekbot.net.Commands.Integrations
} }
catch (Exception e) catch (Exception e)
{ {
_errorHandler.HandleCommandException(e, Context); await _errorHandler.HandleCommandException(e, Context);
} }
} }
} }

View file

@ -87,7 +87,7 @@ namespace Geekbot.net.Commands.Randomness
} }
catch (Exception e) catch (Exception e)
{ {
_errorHandler.HandleCommandException(e, Context); await _errorHandler.HandleCommandException(e, Context);
} }
} }

View file

@ -67,7 +67,7 @@ namespace Geekbot.net.Commands.User
} }
catch (Exception e) catch (Exception e)
{ {
_errorHandler.HandleCommandException(e, Context); await _errorHandler.HandleCommandException(e, Context);
} }
} }
@ -114,7 +114,7 @@ namespace Geekbot.net.Commands.User
} }
catch (Exception e) catch (Exception e)
{ {
_errorHandler.HandleCommandException(e, Context); await _errorHandler.HandleCommandException(e, Context);
} }
} }

View file

@ -80,7 +80,7 @@ namespace Geekbot.net.Commands.User
} }
catch (Exception e) catch (Exception e)
{ {
_errorHandler.HandleCommandException(e, Context); await _errorHandler.HandleCommandException(e, Context);
} }
} }
} }

View file

@ -38,7 +38,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.0" /> <PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.1.0" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="2.1.0" /> <PackageReference Include="Microsoft.Extensions.Options" Version="2.1.0" />
<PackageReference Include="MtgApiManager.Lib" Version="1.1.0" /> <PackageReference Include="MtgApiManager.Lib" Version="1.1.1" />
<PackageReference Include="MyAnimeListSharp" Version="1.3.4" /> <PackageReference Include="MyAnimeListSharp" Version="1.3.4" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" /> <PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="NLog" Version="4.5.6" /> <PackageReference Include="NLog" Version="4.5.6" />

View file

@ -26,7 +26,7 @@ namespace Geekbot.net
private readonly IUserRepository _userRepository; private readonly IUserRepository _userRepository;
private readonly IReactionListener _reactionListener; private readonly IReactionListener _reactionListener;
public Handlers(DatabaseContext database, IDiscordClient client, IGeekbotLogger logger, IAlmostRedis redis, public Handlers(DatabaseContext database, IDiscordClient client, IGeekbotLogger logger, IAlmostRedis redis,
IServiceProvider servicesProvider, CommandService commands, IUserRepository userRepository, IServiceProvider servicesProvider, CommandService commands, IUserRepository userRepository,
IReactionListener reactionListener) IReactionListener reactionListener)
{ {
@ -58,26 +58,24 @@ namespace Geekbot.net
var lowCaseMsg = message.ToString().ToLower(); var lowCaseMsg = message.ToString().ToLower();
if (lowCaseMsg.StartsWith("hui")) if (lowCaseMsg.StartsWith("hui"))
{ {
var hasPing = _database.GuildSettings.FirstOrDefault(guild => var hasPing = _database.GuildSettings.FirstOrDefault(guild => guild.GuildId.Equals(((SocketGuildChannel) message.Channel).Guild.Id.AsLong()))?.Hui ?? false;
guild.GuildId.Equals(((SocketGuildChannel) message.Channel).Guild.Id.AsLong()))
?.Hui ?? false;
if (hasPing) if (hasPing)
{ {
message.Channel.SendMessageAsync("hui!!!"); message.Channel.SendMessageAsync("hui!!!");
return Task.CompletedTask; return Task.CompletedTask;
} }
} }
if (lowCaseMsg.StartsWith("ping ") || lowCaseMsg.Equals("ping")) if (lowCaseMsg.StartsWith("ping ") || lowCaseMsg.Equals("ping"))
{ {
var hasPing = _database.GuildSettings.FirstOrDefault(guild => var hasPing = _database.GuildSettings.FirstOrDefault(guild => guild.GuildId.Equals(((SocketGuildChannel) message.Channel).Guild.Id.AsLong()))?.Ping ?? false;
guild.GuildId.Equals(((SocketGuildChannel) message.Channel).Guild.Id.AsLong()))
?.Ping ?? false;
if (hasPing) if (hasPing)
{ {
message.Channel.SendMessageAsync("pong"); message.Channel.SendMessageAsync("pong");
return Task.CompletedTask; return Task.CompletedTask;
} }
} }
if (!(message.HasCharPrefix('!', ref argPos) || if (!(message.HasCharPrefix('!', ref argPos) ||
message.HasMentionPrefix(_client.CurrentUser, ref argPos))) return Task.CompletedTask; message.HasMentionPrefix(_client.CurrentUser, ref argPos))) return Task.CompletedTask;
var context = new CommandContext(_client, message); var context = new CommandContext(_client, message);
@ -104,6 +102,7 @@ namespace Geekbot.net
_logger.Information(LogSource.Message, $"[DM-Channel] {message.Content}", SimpleConextConverter.ConvertSocketMessage(message)); _logger.Information(LogSource.Message, $"[DM-Channel] {message.Content}", SimpleConextConverter.ConvertSocketMessage(message));
return; return;
} }
var channel = (SocketGuildChannel) message.Channel; var channel = (SocketGuildChannel) message.Channel;
// await _database.Database.ExecuteSqlCommandAsync("UPDATE \"Messages\" " + // await _database.Database.ExecuteSqlCommandAsync("UPDATE \"Messages\" " +
@ -133,15 +132,14 @@ namespace Geekbot.net
{ {
if (!user.IsBot) if (!user.IsBot)
{ {
var message = _database.GuildSettings.FirstOrDefault(guild => var message = _database.GuildSettings.FirstOrDefault(guild => guild.GuildId.Equals(user.Guild.Id.AsLong()))?.WelcomeMessage;
guild.GuildId.Equals(user.Guild.Id.AsLong()))
?.WelcomeMessage;
if (!string.IsNullOrEmpty(message)) if (!string.IsNullOrEmpty(message))
{ {
message = message.Replace("$user", user.Mention); message = message.Replace("$user", user.Mention);
await user.Guild.DefaultChannel.SendMessageAsync(message); await user.Guild.DefaultChannel.SendMessageAsync(message);
} }
} }
await _userRepository.Update(user); await _userRepository.Update(user);
_logger.Information(LogSource.Geekbot, $"{user.Username} ({user.Id}) joined {user.Guild.Name} ({user.Guild.Id})"); _logger.Information(LogSource.Geekbot, $"{user.Username} ({user.Id}) joined {user.Guild.Name} ({user.Guild.Id})");
} }
@ -172,6 +170,7 @@ namespace Geekbot.net
{ {
_logger.Error(LogSource.Geekbot, "Failed to send leave message", e); _logger.Error(LogSource.Geekbot, "Failed to send leave message", e);
} }
_logger.Information(LogSource.Geekbot, $"{user.Username} ({user.Id}) joined {user.Guild.Name} ({user.Guild.Id})"); _logger.Information(LogSource.Geekbot, $"{user.Username} ({user.Id}) joined {user.Guild.Name} ({user.Guild.Id})");
} }
@ -192,14 +191,14 @@ namespace Geekbot.net
var sb = new StringBuilder(); var sb = new StringBuilder();
if (message.Value != null) if (message.Value != null)
{ {
sb.AppendLine( sb.AppendLine($"The following message from {message.Value.Author.Username}#{message.Value.Author.Discriminator} was deleted in <#{channel.Id}>");
$"The following message from {message.Value.Author.Username}#{message.Value.Author.Discriminator} was deleted in <#{channel.Id}>");
sb.AppendLine(message.Value.Content); sb.AppendLine(message.Value.Content);
} }
else else
{ {
sb.AppendLine("Someone deleted a message, the message was not cached..."); sb.AppendLine("Someone deleted a message, the message was not cached...");
} }
await modChannelSocket.SendMessageAsync(sb.ToString()); await modChannelSocket.SendMessageAsync(sb.ToString());
} }
} }

View file

@ -52,16 +52,16 @@ namespace Geekbot.net.Lib.ErrorHandling
if (!string.IsNullOrEmpty(resStackTrace)) if (!string.IsNullOrEmpty(resStackTrace))
{ {
var maxLen = Math.Min(resStackTrace.Length, 1850); var maxLen = Math.Min(resStackTrace.Length, 1850);
context.Channel.SendMessageAsync($"{e.Message}\r\n```\r\n{resStackTrace.Substring(0, maxLen)}\r\n```"); await context.Channel.SendMessageAsync($"{e.Message}\r\n```\r\n{resStackTrace.Substring(0, maxLen)}\r\n```");
} }
else else
{ {
context.Channel.SendMessageAsync(e.Message); await context.Channel.SendMessageAsync(e.Message);
} }
} }
else else
{ {
context.Channel.SendMessageAsync(errorString); await context.Channel.SendMessageAsync(errorString);
} }
} }
@ -82,7 +82,7 @@ namespace Geekbot.net.Lib.ErrorHandling
} }
catch (Exception ex) catch (Exception ex)
{ {
context.Channel.SendMessageAsync("Something went really really wrong here"); await context.Channel.SendMessageAsync("Something went really really wrong here");
_logger.Error(LogSource.Geekbot, "Errorception", ex); _logger.Error(LogSource.Geekbot, "Errorception", ex);
} }
} }

View file

@ -101,8 +101,8 @@ namespace Geekbot.net
{ {
Console.Write("Your bot Token: "); Console.Write("Your bot Token: ");
var newToken = Console.ReadLine(); var newToken = Console.ReadLine();
_globalSettings.SetKey("DiscordToken", newToken); await _globalSettings.SetKey("DiscordToken", newToken);
_globalSettings.SetKey("Game", "Ping Pong"); await _globalSettings.SetKey("Game", "Ping Pong");
_token = newToken; _token = newToken;
} }

View file

@ -7,7 +7,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
<PackageReference Include="xunit" Version="2.3.1" /> <PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" /> <PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" /> <DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>