Skip to content

Commit

Permalink
🪄 Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
database64128 committed Dec 9, 2021
1 parent e6273e1 commit 3041f99
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 28 deletions.
4 changes: 2 additions & 2 deletions CubicBot.Telegram/CLI/BotRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ public static class BotRunner
{
public static async Task<int> RunBot(string? botToken, CancellationToken cancellationToken = default)
{
(var config, var loadConfigErrMsg) = await Config.LoadConfigAsync(cancellationToken);
var (config, loadConfigErrMsg) = await Config.LoadConfigAsync(cancellationToken);
if (loadConfigErrMsg is not null)
{
Console.WriteLine(loadConfigErrMsg);
return 1;
}

(var data, var loadDataErrMsg) = await Data.LoadDataAsync(cancellationToken);
var (data, loadDataErrMsg) = await Data.LoadDataAsync(cancellationToken);
if (loadDataErrMsg is not null)
{
Console.WriteLine(loadDataErrMsg);
Expand Down
4 changes: 2 additions & 2 deletions CubicBot.Telegram/CLI/ConfigCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static class ConfigCommand
{
public static async Task<int> Get(CancellationToken cancellationToken = default)
{
(var config, var loadConfigErrMsg) = await Config.LoadConfigAsync(cancellationToken);
var (config, loadConfigErrMsg) = await Config.LoadConfigAsync(cancellationToken);
if (loadConfigErrMsg is not null)
{
Console.WriteLine(loadConfigErrMsg);
Expand Down Expand Up @@ -57,7 +57,7 @@ public static async Task<int> Set(
bool? enableMessageCounter,
CancellationToken cancellationToken = default)
{
(var config, var loadConfigErrMsg) = await Config.LoadConfigAsync(cancellationToken);
var (config, loadConfigErrMsg) = await Config.LoadConfigAsync(cancellationToken);
if (loadConfigErrMsg is not null)
{
Console.WriteLine(loadConfigErrMsg);
Expand Down
2 changes: 1 addition & 1 deletion CubicBot.Telegram/Commands/CommandsDispatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public CommandsDispatch(Config config, Data data, string botUsername)

public Task HandleAsync(ITelegramBotClient botClient, Message message, CancellationToken cancellationToken = default)
{
(var command, var argument) = ChatHelper.ParseMessageIntoCommandAndArgument(message.Text, _botUsername);
var (command, argument) = ChatHelper.ParseMessageIntoCommandAndArgument(message.Text, _botUsername);
if (command is null)
{
return Task.CompletedTask;
Expand Down
22 changes: 0 additions & 22 deletions CubicBot.Telegram/Commands/QueryStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ private static Task SendUserStats(ITelegramBotClient botClient, Message message,
public static Task SendApologeticLeaderboardAsync(ITelegramBotClient botClient, Message message, string? argument, Config config, Data data, CancellationToken cancellationToken = default)
=> SendLeaderboardAsync(botClient,
message,
argument,
data,
"🙏 Who's the most apologetic person in this chat?",
null,
Expand All @@ -236,7 +235,6 @@ public static Task SendApologeticLeaderboardAsync(ITelegramBotClient botClient,
public static Task SendApologiesAcceptedLeaderboardAsync(ITelegramBotClient botClient, Message message, string? argument, Config config, Data data, CancellationToken cancellationToken = default)
=> SendLeaderboardAsync(botClient,
message,
argument,
data,
"😭 Apologies Accepted",
null,
Expand All @@ -246,7 +244,6 @@ public static Task SendApologiesAcceptedLeaderboardAsync(ITelegramBotClient botC
public static Task SendChantsLeaderboardAsync(ITelegramBotClient botClient, Message message, string? argument, Config config, Data data, CancellationToken cancellationToken = default)
=> SendLeaderboardAsync(botClient,
message,
argument,
data,
"📢 Who chants the most in this chat?",
null,
Expand All @@ -256,7 +253,6 @@ public static Task SendChantsLeaderboardAsync(ITelegramBotClient botClient, Mess
public static Task SendDrinkLeaderboardAsync(ITelegramBotClient botClient, Message message, string? argument, Config config, Data data, CancellationToken cancellationToken = default)
=> SendLeaderboardAsync(botClient,
message,
argument,
data,
"🍺 Who drinks the most in this chat?",
null,
Expand All @@ -266,7 +262,6 @@ public static Task SendDrinkLeaderboardAsync(ITelegramBotClient botClient, Messa
public static Task SendLoveThemselvesLeaderboardAsync(ITelegramBotClient botClient, Message message, string? argument, Config config, Data data, CancellationToken cancellationToken = default)
=> SendLeaderboardAsync(botClient,
message,
argument,
data,
"🤳 Who loves themselves the most in this chat?",
null,
Expand All @@ -276,7 +271,6 @@ public static Task SendLoveThemselvesLeaderboardAsync(ITelegramBotClient botClie
public static Task SendThankfulLeaderboardAsync(ITelegramBotClient botClient, Message message, string? argument, Config config, Data data, CancellationToken cancellationToken = default)
=> SendLeaderboardAsync(botClient,
message,
argument,
data,
"😊 Who's the most thankful person in this chat?",
null,
Expand All @@ -286,7 +280,6 @@ public static Task SendThankfulLeaderboardAsync(ITelegramBotClient botClient, Me
public static Task SendAppreciatedLeaderboardAsync(ITelegramBotClient botClient, Message message, string? argument, Config config, Data data, CancellationToken cancellationToken = default)
=> SendLeaderboardAsync(botClient,
message,
argument,
data,
"💖 Who's the most appreciated person in this chat?",
null,
Expand All @@ -298,7 +291,6 @@ public static Task SendAppreciatedLeaderboardAsync(ITelegramBotClient botClient,
public static Task SendDicesLeaderboardAsync(ITelegramBotClient botClient, Message message, string? argument, Config config, Data data, CancellationToken cancellationToken = default)
=> SendLeaderboardAsync(botClient,
message,
argument,
data,
"🎲 Dices Thrown",
x => x.DicesThrown,
Expand All @@ -308,7 +300,6 @@ public static Task SendDicesLeaderboardAsync(ITelegramBotClient botClient, Messa
public static Task SendDartsLeaderboardAsync(ITelegramBotClient botClient, Message message, string? argument, Config config, Data data, CancellationToken cancellationToken = default)
=> SendLeaderboardAsync(botClient,
message,
argument,
data,
"🎯 Darts Thrown",
x => x.DartsThrown,
Expand All @@ -318,7 +309,6 @@ public static Task SendDartsLeaderboardAsync(ITelegramBotClient botClient, Messa
public static Task SendBasketballsLeaderboardAsync(ITelegramBotClient botClient, Message message, string? argument, Config config, Data data, CancellationToken cancellationToken = default)
=> SendLeaderboardAsync(botClient,
message,
argument,
data,
"🏀 Basketballs Thrown",
x => x.BasketballsThrown,
Expand All @@ -328,7 +318,6 @@ public static Task SendBasketballsLeaderboardAsync(ITelegramBotClient botClient,
public static Task SendSoccerGoalsLeaderboardAsync(ITelegramBotClient botClient, Message message, string? argument, Config config, Data data, CancellationToken cancellationToken = default)
=> SendLeaderboardAsync(botClient,
message,
argument,
data,
"⚽ Soccer Goals",
x => x.SoccerGoals,
Expand All @@ -338,7 +327,6 @@ public static Task SendSoccerGoalsLeaderboardAsync(ITelegramBotClient botClient,
public static Task SendSlotsRolledLeaderboardAsync(ITelegramBotClient botClient, Message message, string? argument, Config config, Data data, CancellationToken cancellationToken = default)
=> SendLeaderboardAsync(botClient,
message,
argument,
data,
"🎰 Slots Rolled",
x => x.SlotMachineRolled,
Expand All @@ -348,7 +336,6 @@ public static Task SendSlotsRolledLeaderboardAsync(ITelegramBotClient botClient,
public static Task SendPinsKnockedLeaderboardAsync(ITelegramBotClient botClient, Message message, string? argument, Config config, Data data, CancellationToken cancellationToken = default)
=> SendLeaderboardAsync(botClient,
message,
argument,
data,
"🎳 Pins Knocked",
x => x.PinsKnocked,
Expand All @@ -360,7 +347,6 @@ public static Task SendPinsKnockedLeaderboardAsync(ITelegramBotClient botClient,
public static Task SendSexualLeaderboardAsync(ITelegramBotClient botClient, Message message, string? argument, Config config, Data data, CancellationToken cancellationToken = default)
=> SendLeaderboardAsync(botClient,
message,
argument,
data,
"💋 Who's the most sexual person in this chat?",
x => x.SexInitiated,
Expand All @@ -372,7 +358,6 @@ public static Task SendSexualLeaderboardAsync(ITelegramBotClient botClient, Mess
public static Task SendCriminalLeaderboardAsync(ITelegramBotClient botClient, Message message, string? argument, Config config, Data data, CancellationToken cancellationToken = default)
=> SendLeaderboardAsync(botClient,
message,
argument,
data,
"🦹 Criminals",
x => x.ArrestsMade,
Expand All @@ -384,7 +369,6 @@ public static Task SendCriminalLeaderboardAsync(ITelegramBotClient botClient, Me
public static Task SendInterrogationsInitiatedLeaderboardAsync(ITelegramBotClient botClient, Message message, string? argument, Config config, Data data, CancellationToken cancellationToken = default)
=> SendLeaderboardAsync(botClient,
message,
argument,
data,
"发起喝茶排行榜",
x => x.InterrogationsInitiated,
Expand All @@ -394,7 +378,6 @@ public static Task SendInterrogationsInitiatedLeaderboardAsync(ITelegramBotClien
public static Task SendInterrogatedLeaderboardAsync(ITelegramBotClient botClient, Message message, string? argument, Config config, Data data, CancellationToken cancellationToken = default)
=> SendLeaderboardAsync(botClient,
message,
argument,
data,
"被请喝茶排行榜",
x => x.Members.Select(x => x.Value.InterrogatedByOthers)
Expand All @@ -407,7 +390,6 @@ public static Task SendInterrogatedLeaderboardAsync(ITelegramBotClient botClient
public static Task SendSystemdFandomLeaderboardAsync(ITelegramBotClient botClient, Message message, string? argument, Config config, Data data, CancellationToken cancellationToken = default)
=> SendLeaderboardAsync(botClient,
message,
argument,
data,
"🐧 Who's the biggest systemd fan in this chat?",
null,
Expand All @@ -418,7 +400,6 @@ public static Task SendSystemdFandomLeaderboardAsync(ITelegramBotClient botClien
public static Task SendGrassGrownLeaderboardAsync(ITelegramBotClient botClient, Message message, string? argument, Config config, Data data, CancellationToken cancellationToken = default)
=> SendLeaderboardAsync(botClient,
message,
argument,
data,
"🌿 生草排行榜",
x => x.Members.Select(x => x.Value.GrassGrown)
Expand All @@ -429,7 +410,6 @@ public static Task SendGrassGrownLeaderboardAsync(ITelegramBotClient botClient,
public static Task SendDemandingLeaderboardAsync(ITelegramBotClient botClient, Message message, string? argument, Config config, Data data, CancellationToken cancellationToken = default)
=> SendLeaderboardAsync(botClient,
message,
argument,
data,
"👉 Who's the most demanding person in this chat?",
x => x.CommandsHandled,
Expand All @@ -439,7 +419,6 @@ public static Task SendDemandingLeaderboardAsync(ITelegramBotClient botClient, M
public static Task SendTalkativeLeaderboardAsync(ITelegramBotClient botClient, Message message, string? argument, Config config, Data data, CancellationToken cancellationToken = default)
=> SendLeaderboardAsync(botClient,
message,
argument,
data,
"🗣️ Who's the most talkative person in this chat?",
x => x.MessagesProcessed,
Expand All @@ -449,7 +428,6 @@ public static Task SendTalkativeLeaderboardAsync(ITelegramBotClient botClient, M
private static async Task SendLeaderboardAsync(
ITelegramBotClient botClient,
Message message,
string? argument,
Data data,
string? title,
Func<GroupData, ulong>? getTotal,
Expand Down
2 changes: 1 addition & 1 deletion CubicBot.Telegram/Utils/ChatHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public static int GetRetryWaitTimeMs(ApiRequestException apiRequestException)
try
{
_ = Encoding.UTF8.GetBytes(apiRequestException.Message, timeString);
timeString = timeString[31..length];
timeString = timeString[31..];
if (Utf8Parser.TryParse(timeString, out int timeSec, out _))
{
var extra = Random.Shared.Next(1, 6);
Expand Down

0 comments on commit 3041f99

Please sign in to comment.