mirror of
https://github.com/JustArchiNET/ArchiSteamFarm
synced 2024-09-20 14:32:05 +00:00
Add !level command (#946)
* add !level command * Added blank lines * Fix https://github.com/JustArchiNET/ArchiSteamFarm/pull/946 * Fix №2 https://github.com/JustArchiNET/ArchiSteamFarm/pull/946
This commit is contained in:
parent
c6ad260e81
commit
ab6ce7c7e5
4 changed files with 256 additions and 171 deletions
|
@ -213,6 +213,34 @@ namespace ArchiSteamFarm {
|
|||
return body.chat_group_summary.chat_group_id;
|
||||
}
|
||||
|
||||
internal async Task<uint?> GetLevel() {
|
||||
if (!Client.IsConnected) {
|
||||
return null;
|
||||
}
|
||||
|
||||
CPlayer_GetGameBadgeLevels_Request request = new CPlayer_GetGameBadgeLevels_Request { };
|
||||
SteamUnifiedMessages.ServiceMethodResponse response;
|
||||
|
||||
try {
|
||||
response = await UnifiedPlayerService.SendMessage(x => x.GetGameBadgeLevels(request));
|
||||
} catch (Exception e) {
|
||||
ArchiLogger.LogGenericWarningException(e);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (response == null) {
|
||||
ArchiLogger.LogNullError(nameof(response));
|
||||
return null;
|
||||
}
|
||||
|
||||
if (response.Result != EResult.OK) {
|
||||
return null;
|
||||
}
|
||||
|
||||
CPlayer_GetGameBadgeLevels_Response body = response.GetDeserializedResponse<CPlayer_GetGameBadgeLevels_Response>();
|
||||
return body.player_level;
|
||||
}
|
||||
|
||||
internal async Task<HashSet<ulong>> GetMyChatGroupIDs() {
|
||||
if (!Client.IsConnected) {
|
||||
return null;
|
||||
|
|
|
@ -85,6 +85,8 @@ namespace ArchiSteamFarm {
|
|||
return ResponseIdleBlacklist(steamID);
|
||||
case "IQ":
|
||||
return ResponseIdleQueue(steamID);
|
||||
case "LEVEL":
|
||||
return await ResponseLevel(steamID).ConfigureAwait(false);
|
||||
case "LOOT":
|
||||
return await ResponseLoot(steamID).ConfigureAwait(false);
|
||||
case "LOOT&":
|
||||
|
@ -188,6 +190,8 @@ namespace ArchiSteamFarm {
|
|||
}
|
||||
|
||||
return await ResponseIdleQueueRemove(steamID, args[1]).ConfigureAwait(false);
|
||||
case "LEVEL":
|
||||
return await ResponseLevel(steamID, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false);
|
||||
case "LOOT":
|
||||
return await ResponseLoot(steamID, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false);
|
||||
case "LOOT^":
|
||||
|
@ -1169,6 +1173,46 @@ namespace ArchiSteamFarm {
|
|||
return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null;
|
||||
}
|
||||
|
||||
private async Task<string> ResponseLevel(ulong steamID) {
|
||||
if (steamID == 0) {
|
||||
Bot.ArchiLogger.LogNullError(nameof(steamID));
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!Bot.IsConnectedAndLoggedOn) {
|
||||
return FormatBotResponse(Strings.BotNotConnected);
|
||||
}
|
||||
|
||||
if (!Bot.IsMaster(steamID)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
uint? level = await Bot.ArchiHandler.GetLevel().ConfigureAwait(false);
|
||||
|
||||
if (!level.HasValue) {
|
||||
return FormatBotResponse(Strings.WarningFailed);
|
||||
}
|
||||
|
||||
return FormatBotResponse(string.Format(Strings.BotLevel, level.Value));
|
||||
}
|
||||
|
||||
private static async Task<string> ResponseLevel(ulong steamID, string botNames) {
|
||||
if ((steamID == 0) || string.IsNullOrEmpty(botNames)) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botNames));
|
||||
return null;
|
||||
}
|
||||
|
||||
HashSet<Bot> bots = Bot.GetBots(botNames);
|
||||
if ((bots == null) || (bots.Count == 0)) {
|
||||
return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(Strings.BotNotFound, botNames)) : null;
|
||||
}
|
||||
|
||||
IList<string> results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseLevel(steamID))).ConfigureAwait(false);
|
||||
|
||||
List<string> responses = new List<string>(results.Where(result => !string.IsNullOrEmpty(result)));
|
||||
return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null;
|
||||
}
|
||||
|
||||
private async Task<string> ResponseLoot(ulong steamID) {
|
||||
if (steamID == 0) {
|
||||
Bot.ArchiLogger.LogNullError(nameof(steamID));
|
||||
|
|
349
ArchiSteamFarm/Localization/Strings.Designer.cs
generated
349
ArchiSteamFarm/Localization/Strings.Designer.cs
generated
File diff suppressed because it is too large
Load diff
|
@ -668,4 +668,8 @@ StackTrace:
|
|||
<data name="BotHasNoWallet" xml:space="preserve">
|
||||
<value>Bot has no wallet.</value>
|
||||
</data>
|
||||
</root>
|
||||
<data name="BotLevel" xml:space="preserve">
|
||||
<value>Bot has level {0}.</value>
|
||||
<comment>{0} will be replaced by bot's level</comment>
|
||||
</data>
|
||||
</root>
|
Loading…
Reference in a new issue