Added many more braces for multiline if's, Improved .crypto command quite a bit and applied locale-specific format

This commit is contained in:
Kwoth
2022-02-04 06:00:17 +01:00
parent f77f2f433f
commit eda38e64d1
129 changed files with 635 additions and 233 deletions

View File

@@ -25,6 +25,7 @@ public partial class Games
var game = new AcrophobiaGame(options);
if (_service.AcrophobiaGames.TryAdd(channel.Id, game))
{
try
{
game.OnStarted += Game_OnStarted;
@@ -40,6 +41,7 @@ public partial class Games
_service.AcrophobiaGames.TryRemove(channel.Id, out game);
game?.Dispose();
}
}
else
await ReplyErrorLocalizedAsync(strs.acro_running);

View File

@@ -35,6 +35,7 @@ public sealed class GamesConfigService : ConfigServiceBase<GamesConfig>
private void Migrate()
{
if (data.Version < 1)
{
ModifyConfig(c =>
{
c.Version = 1;
@@ -43,5 +44,6 @@ public sealed class GamesConfigService : ConfigServiceBase<GamesConfig>
CurrencyReward = 0
};
});
}
}
}

View File

@@ -62,9 +62,7 @@ public class GamesService : INService, IReadyExecutor
// reset rating once a day
using var timer = new PeriodicTimer(TimeSpan.FromDays(1));
while (await timer.WaitForNextTickAsync())
{
GirlRatings.Clear();
}
}
private async Task<RatingTexts> GetRatingTexts()

View File

@@ -24,18 +24,23 @@ public partial class Games
public static IEmbedBuilder GetEmbed(IEmbedBuilderService eb, HangmanGame.State state)
{
if (state.Phase == HangmanGame.Phase.Running)
{
return eb.Create()
.WithOkColor()
.AddField("Hangman", Draw(state))
.AddField("Guess", Format.Code(state.Word))
.WithFooter(state.MissedLetters.Join(' '));
}
if (state.Phase == HangmanGame.Phase.Ended && state.Failed)
{
return eb.Create()
.WithErrorColor()
.AddField("Hangman", Draw(state))
.AddField("Guess", Format.Code(state.Word))
.WithFooter(state.MissedLetters.Join(' '));
}
return eb.Create()
.WithOkColor()
.AddField("Hangman", Draw(state))

View File

@@ -87,16 +87,20 @@ public sealed class HangmanService : IHangmanService, ILateExecutor
return;
if (state.GuessResult is HangmanGame.GuessResult.Incorrect or HangmanGame.GuessResult.AlreadyTried)
{
_cdCache.Set(msg.Author.Id,
string.Empty,
new MemoryCacheEntryOptions
{
AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(3)
});
}
if (state.Phase == HangmanGame.Phase.Ended)
{
if (_hangmanGames.TryRemove(msg.Channel.Id, out _))
rew = _gcs.Data.Hangman.CurrencyReward;
}
}
if (rew > 0)

View File

@@ -31,6 +31,7 @@ public partial class Games
}
if (_service.StartPoll(poll))
{
await ctx.Channel.EmbedAsync(_eb.Create()
.WithOkColor()
.WithTitle(GetText(strs.poll_created(ctx.User.ToString())))
@@ -39,6 +40,7 @@ public partial class Games
+ string.Join("\n",
poll.Answers.Select(x
=> $"`{x.Index + 1}.` {Format.Bold(x.Text)}"))));
}
else
await ReplyErrorLocalizedAsync(strs.poll_already_running);
}

View File

@@ -116,11 +116,13 @@ public class PollService : IEarlyBehavior
var voted = await poll.TryVote(msg);
if (voted)
{
Log.Information("User {UserName} [{UserId}] voted in a poll on {GuildName} [{GuildId}] server",
msg.Author.ToString(),
msg.Author.Id,
guild.Name,
guild.Id);
}
return voted;
}

View File

@@ -151,9 +151,11 @@ public class TypingGame
.AddField("Errors", distance.ToString(), true));
if (_finishedUserIds.Count % 4 == 0)
{
await Channel.SendConfirmAsync(_eb,
":exclamation: A lot of people finished, here is the text for those still typing:"
+ $"\n\n**{Format.Sanitize(CurrentSentence.Replace(" ", " \x200B", StringComparison.InvariantCulture)).SanitizeMentions(true)}**");
}
}
}
catch (Exception ex)

View File

@@ -89,9 +89,7 @@ public class TicTacToe
embed.WithFooter(GetText(strs.ttt_users_move(_users[curUserIndex])));
}
else
{
embed.WithFooter(GetText(strs.ttt_has_won(winner)));
}
return embed;
}

View File

@@ -123,6 +123,7 @@ public class TriviaGame
//hint
await Task.Delay(_options.QuestionTimer * 1000 / 2, triviaCancelSource.Token);
if (!_options.NoHint)
{
try
{
await questionMessage.ModifyAsync(m
@@ -134,6 +135,7 @@ public class TriviaGame
break;
}
catch (Exception ex) { Log.Warning(ex, "Error editing triva message"); }
}
//timeout
await Task.Delay(_options.QuestionTimer * 1000 / 2, triviaCancelSource.Token);
@@ -147,6 +149,7 @@ public class TriviaGame
}
if (!triviaCancelSource.IsCancellationRequested)
{
try
{
var embed = _eb.Create()
@@ -165,6 +168,7 @@ public class TriviaGame
{
Log.Warning(ex, "Error sending trivia time's up message");
}
}
await Task.Delay(5000);
}
@@ -186,6 +190,7 @@ public class TriviaGame
var old = ShouldStopGame;
ShouldStopGame = true;
if (!old)
{
try
{
await Channel.SendConfirmAsync(_eb, GetText(strs.trivia_game), GetText(strs.trivia_stopping));
@@ -194,6 +199,7 @@ public class TriviaGame
{
Log.Warning(ex, "Error sending trivia stopping message");
}
}
}
private Task PotentialGuess(SocketMessage imsg)