From 948c48909e5b1395451ca85bdef07e3937c3de88 Mon Sep 17 00:00:00 2001 From: runebaas Date: Sun, 22 Jul 2018 15:02:53 +0200 Subject: [PATCH 1/2] Allow the same guess after 24h again with !roll --- Geekbot.net/Commands/Games/Roll.cs | 15 +++++++++------ Geekbot.net/Lib/Localization/Translations.json | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Geekbot.net/Commands/Games/Roll.cs b/Geekbot.net/Commands/Games/Roll.cs index 30697df..e8a89c0 100644 --- a/Geekbot.net/Commands/Games/Roll.cs +++ b/Geekbot.net/Commands/Games/Roll.cs @@ -34,15 +34,18 @@ namespace Geekbot.net.Commands.Games var transDict = _translation.GetDict(Context); if (guess <= 100 && guess > 0) { - var prevRoll = _redis.HashGet($"{Context.Guild.Id}:RollsPrevious", Context.Message.Author.Id); - if (!prevRoll.IsNullOrEmpty && prevRoll.ToString() == guess.ToString()) + var prevRoll = _redis.HashGet($"{Context.Guild.Id}:RollsPrevious2", Context.Message.Author.Id).ToString()?.Split('|'); + if (prevRoll?.Length == 2) { - await ReplyAsync(string.Format(transDict["NoPrevGuess"], Context.Message.Author.Mention)); - return; + if (prevRoll[0] == guess.ToString() && DateTime.Parse(prevRoll[1]) > DateTime.Now.AddDays(-1)) + { + await ReplyAsync(string.Format(transDict["NoPrevGuess"], Context.Message.Author.Mention)); + return; + } } - _redis.HashSet($"{Context.Guild.Id}:RollsPrevious", - new[] {new HashEntry(Context.Message.Author.Id, guess)}); + _redis.HashSet($"{Context.Guild.Id}:RollsPrevious2", + new[] {new HashEntry(Context.Message.Author.Id, $"{guess}|{DateTime.Now}")}); await ReplyAsync(string.Format(transDict["Rolled"], Context.Message.Author.Mention, number, guess)); if (guess == number) { diff --git a/Geekbot.net/Lib/Localization/Translations.json b/Geekbot.net/Lib/Localization/Translations.json index 2d3414e..fab8b94 100644 --- a/Geekbot.net/Lib/Localization/Translations.json +++ b/Geekbot.net/Lib/Localization/Translations.json @@ -93,8 +93,8 @@ "CHDE": "{0}, du hesch {1} grollt" }, "NoPrevGuess": { - "EN": ":red_circle: {0}, you can't guess the same number again", - "CHDE": ":red_circle: {0}, du chasch nid nomol es gliche rate" + "EN": ":red_circle: {0}, you can't guess the same number again within 24 hours", + "CHDE": ":red_circle: {0}, du chasch nid nomol es gliche rate innerhalb vo 24 stund" } } } \ No newline at end of file From 8cff234bc640adc10fedfea95e33d0ce7b254985 Mon Sep 17 00:00:00 2001 From: runebaas Date: Sat, 25 Aug 2018 21:40:04 +0200 Subject: [PATCH 2/2] Upgrade to discord.net 2.0-beta --- Geekbot.net/Commands/Admin/Mod.cs | 1 + Geekbot.net/Commands/Games/Overwatch.cs | 1 + Geekbot.net/Commands/Games/Pokedex.cs | 1 + .../Commands/Integrations/MagicTheGathering.cs | 1 + Geekbot.net/Commands/Integrations/Mal.cs | 1 + .../Integrations/UbranDictionary/UrbanDictionary.cs | 1 + Geekbot.net/Commands/Randomness/RandomAnimals.cs | 6 ++---- Geekbot.net/Commands/User/GuildInfo.cs | 1 + Geekbot.net/Commands/User/Karma.cs | 1 + Geekbot.net/Commands/User/Stats.cs | 1 + Geekbot.net/Commands/Utils/Info.cs | 1 + Geekbot.net/Commands/Utils/Poll/Poll.cs | 1 + Geekbot.net/Commands/Utils/Quote/Quote.cs | 11 +++++------ Geekbot.net/Geekbot.net.csproj | 2 +- Geekbot.net/Lib/Extensions/EmbedBuilderExtensions.cs | 12 ++++++++++++ Geekbot.net/Lib/Polyfills/UserPolyfillDto.cs | 2 +- 16 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 Geekbot.net/Lib/Extensions/EmbedBuilderExtensions.cs diff --git a/Geekbot.net/Commands/Admin/Mod.cs b/Geekbot.net/Commands/Admin/Mod.cs index 6f79157..7551a47 100644 --- a/Geekbot.net/Commands/Admin/Mod.cs +++ b/Geekbot.net/Commands/Admin/Mod.cs @@ -6,6 +6,7 @@ using Discord.Commands; using Discord.WebSocket; using Geekbot.net.Lib; using Geekbot.net.Lib.ErrorHandling; +using Geekbot.net.Lib.Extensions; using Geekbot.net.Lib.UserRepository; using StackExchange.Redis; diff --git a/Geekbot.net/Commands/Games/Overwatch.cs b/Geekbot.net/Commands/Games/Overwatch.cs index 73e5858..bda75b3 100644 --- a/Geekbot.net/Commands/Games/Overwatch.cs +++ b/Geekbot.net/Commands/Games/Overwatch.cs @@ -4,6 +4,7 @@ using Discord; using Discord.Commands; using Geekbot.net.Lib; using Geekbot.net.Lib.ErrorHandling; +using Geekbot.net.Lib.Extensions; using Geekbot.net.Lib.UserRepository; using OverwatchAPI; using OverwatchAPI.Config; diff --git a/Geekbot.net/Commands/Games/Pokedex.cs b/Geekbot.net/Commands/Games/Pokedex.cs index 57f842a..780c564 100644 --- a/Geekbot.net/Commands/Games/Pokedex.cs +++ b/Geekbot.net/Commands/Games/Pokedex.cs @@ -5,6 +5,7 @@ using Discord; using Discord.Commands; using Geekbot.net.Lib; using Geekbot.net.Lib.ErrorHandling; +using Geekbot.net.Lib.Extensions; using PokeAPI; namespace Geekbot.net.Commands.Games diff --git a/Geekbot.net/Commands/Integrations/MagicTheGathering.cs b/Geekbot.net/Commands/Integrations/MagicTheGathering.cs index 3074803..8ecefd2 100644 --- a/Geekbot.net/Commands/Integrations/MagicTheGathering.cs +++ b/Geekbot.net/Commands/Integrations/MagicTheGathering.cs @@ -7,6 +7,7 @@ using Discord.Commands; using Geekbot.net.Lib; using Geekbot.net.Lib.Converters; using Geekbot.net.Lib.ErrorHandling; +using Geekbot.net.Lib.Extensions; using MtgApiManager.Lib.Service; namespace Geekbot.net.Commands.Integrations diff --git a/Geekbot.net/Commands/Integrations/Mal.cs b/Geekbot.net/Commands/Integrations/Mal.cs index d70949a..eee5782 100644 --- a/Geekbot.net/Commands/Integrations/Mal.cs +++ b/Geekbot.net/Commands/Integrations/Mal.cs @@ -6,6 +6,7 @@ using Discord.Commands; using Geekbot.net.Lib; using Geekbot.net.Lib.Clients; using Geekbot.net.Lib.ErrorHandling; +using Geekbot.net.Lib.Extensions; namespace Geekbot.net.Commands.Integrations { diff --git a/Geekbot.net/Commands/Integrations/UbranDictionary/UrbanDictionary.cs b/Geekbot.net/Commands/Integrations/UbranDictionary/UrbanDictionary.cs index 44402d0..9d99885 100644 --- a/Geekbot.net/Commands/Integrations/UbranDictionary/UrbanDictionary.cs +++ b/Geekbot.net/Commands/Integrations/UbranDictionary/UrbanDictionary.cs @@ -6,6 +6,7 @@ using Discord; using Discord.Commands; using Geekbot.net.Lib; using Geekbot.net.Lib.ErrorHandling; +using Geekbot.net.Lib.Extensions; using Newtonsoft.Json; namespace Geekbot.net.Commands.Integrations.UbranDictionary diff --git a/Geekbot.net/Commands/Randomness/RandomAnimals.cs b/Geekbot.net/Commands/Randomness/RandomAnimals.cs index a96aea8..0e3b81d 100644 --- a/Geekbot.net/Commands/Randomness/RandomAnimals.cs +++ b/Geekbot.net/Commands/Randomness/RandomAnimals.cs @@ -73,11 +73,9 @@ namespace Geekbot.net.Commands.Randomness await ReplyAsync("", false, Eb(_mediaProvider.GetFox())); } - private EmbedBuilder Eb(string image) + private Embed Eb(string image) { - var eb = new EmbedBuilder(); - eb.ImageUrl = image; - return eb; + return new EmbedBuilder {ImageUrl = image}.Build(); } } } \ No newline at end of file diff --git a/Geekbot.net/Commands/User/GuildInfo.cs b/Geekbot.net/Commands/User/GuildInfo.cs index 6306a76..18618d7 100644 --- a/Geekbot.net/Commands/User/GuildInfo.cs +++ b/Geekbot.net/Commands/User/GuildInfo.cs @@ -5,6 +5,7 @@ using Discord; using Discord.Commands; using Geekbot.net.Lib; using Geekbot.net.Lib.ErrorHandling; +using Geekbot.net.Lib.Extensions; using Geekbot.net.Lib.Levels; using StackExchange.Redis; diff --git a/Geekbot.net/Commands/User/Karma.cs b/Geekbot.net/Commands/User/Karma.cs index d6244a8..6290dc4 100644 --- a/Geekbot.net/Commands/User/Karma.cs +++ b/Geekbot.net/Commands/User/Karma.cs @@ -4,6 +4,7 @@ using Discord; using Discord.Commands; using Geekbot.net.Lib; using Geekbot.net.Lib.ErrorHandling; +using Geekbot.net.Lib.Extensions; using Geekbot.net.Lib.Localization; using StackExchange.Redis; diff --git a/Geekbot.net/Commands/User/Stats.cs b/Geekbot.net/Commands/User/Stats.cs index 19a6aa8..476d643 100644 --- a/Geekbot.net/Commands/User/Stats.cs +++ b/Geekbot.net/Commands/User/Stats.cs @@ -4,6 +4,7 @@ using Discord; using Discord.Commands; using Geekbot.net.Lib; using Geekbot.net.Lib.ErrorHandling; +using Geekbot.net.Lib.Extensions; using Geekbot.net.Lib.Levels; using StackExchange.Redis; diff --git a/Geekbot.net/Commands/Utils/Info.cs b/Geekbot.net/Commands/Utils/Info.cs index de34e89..467b9d3 100644 --- a/Geekbot.net/Commands/Utils/Info.cs +++ b/Geekbot.net/Commands/Utils/Info.cs @@ -7,6 +7,7 @@ using Discord.Commands; using Discord.WebSocket; using Geekbot.net.Lib; using Geekbot.net.Lib.ErrorHandling; +using Geekbot.net.Lib.Extensions; using StackExchange.Redis; namespace Geekbot.net.Commands.Utils diff --git a/Geekbot.net/Commands/Utils/Poll/Poll.cs b/Geekbot.net/Commands/Utils/Poll/Poll.cs index 5d18a0f..b32a7c9 100644 --- a/Geekbot.net/Commands/Utils/Poll/Poll.cs +++ b/Geekbot.net/Commands/Utils/Poll/Poll.cs @@ -8,6 +8,7 @@ using Discord.Commands; using Geekbot.net.Lib; using Geekbot.net.Lib.Converters; using Geekbot.net.Lib.ErrorHandling; +using Geekbot.net.Lib.Extensions; using Geekbot.net.Lib.UserRepository; using Newtonsoft.Json; using StackExchange.Redis; diff --git a/Geekbot.net/Commands/Utils/Quote/Quote.cs b/Geekbot.net/Commands/Utils/Quote/Quote.cs index 7a25b50..84eec26 100644 --- a/Geekbot.net/Commands/Utils/Quote/Quote.cs +++ b/Geekbot.net/Commands/Utils/Quote/Quote.cs @@ -189,12 +189,11 @@ namespace Geekbot.net.Commands.Utils.Quote try { var list = Context.Channel.GetMessagesAsync().Flatten(); - await list; - return list.Result - .First(msg => msg.Author.Id == user.Id - && msg.Embeds.Count == 0 - && msg.Id != Context.Message.Id - && !msg.Content.ToLower().StartsWith("!")); + return await list.FirstOrDefault(msg => + msg.Author.Id == user.Id && + msg.Embeds.Count == 0 && + msg.Id != Context.Message.Id && + !msg.Content.ToLower().StartsWith("!")); } catch { diff --git a/Geekbot.net/Geekbot.net.csproj b/Geekbot.net/Geekbot.net.csproj index 90ff896..81f3a6c 100755 --- a/Geekbot.net/Geekbot.net.csproj +++ b/Geekbot.net/Geekbot.net.csproj @@ -15,7 +15,7 @@ - 1.0.2 + 2.0.0-beta diff --git a/Geekbot.net/Lib/Extensions/EmbedBuilderExtensions.cs b/Geekbot.net/Lib/Extensions/EmbedBuilderExtensions.cs new file mode 100644 index 0000000..2a84622 --- /dev/null +++ b/Geekbot.net/Lib/Extensions/EmbedBuilderExtensions.cs @@ -0,0 +1,12 @@ +using Discord; + +namespace Geekbot.net.Lib.Extensions +{ + public static class EmbedBuilderExtensions + { + public static EmbedBuilder AddInlineField(this EmbedBuilder builder, string name, object value) + { + return builder.AddField(new EmbedFieldBuilder().WithIsInline(true).WithName(name).WithValue(value)); + } + } +} diff --git a/Geekbot.net/Lib/Polyfills/UserPolyfillDto.cs b/Geekbot.net/Lib/Polyfills/UserPolyfillDto.cs index 407ae36..568bdd7 100644 --- a/Geekbot.net/Lib/Polyfills/UserPolyfillDto.cs +++ b/Geekbot.net/Lib/Polyfills/UserPolyfillDto.cs @@ -9,7 +9,7 @@ namespace Geekbot.net.Lib.Polyfills public ulong Id { get; set; } public DateTimeOffset CreatedAt { get; set; } public string Mention { get; set; } - public Game? Game { get; set; } + public IActivity Activity { get; } public UserStatus Status { get; set; } public string AvatarId { get; set; } public string Discriminator { get; set; }