Skip to content

Commit 844ca7d

Browse files
committed
Enhance !owns command
Now doesn't only support multiple games for querying, but also a mixed combination of appIDs and strings
1 parent b14b9f8 commit 844ca7d

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

ArchiSteamFarm/Bot.cs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -946,8 +946,8 @@ private static async Task<string> ResponseAddLicense(ulong steamID, string botNa
946946
return await bot.ResponseAddLicense(steamID, gamesToRedeem).ConfigureAwait(false);
947947
}
948948

949-
private async Task<string> ResponseOwns(ulong steamID, string games) {
950-
if (steamID == 0 || string.IsNullOrEmpty(games) || !IsMaster(steamID)) {
949+
private async Task<string> ResponseOwns(ulong steamID, string query) {
950+
if (steamID == 0 || string.IsNullOrEmpty(query) || !IsMaster(steamID)) {
951951
return null;
952952
}
953953

@@ -956,32 +956,37 @@ private async Task<string> ResponseOwns(ulong steamID, string games) {
956956
return "List of owned games is empty!";
957957
}
958958

959-
// Check if this is uint
960-
uint appID;
961-
if (uint.TryParse(games, out appID)) {
962-
string ownedName;
963-
if (ownedGames.TryGetValue(appID, out ownedName)) {
964-
return "Owned already: " + appID + " | " + ownedName;
965-
} else {
966-
return "Not owned yet: " + appID;
967-
}
968-
}
969-
970959
StringBuilder response = new StringBuilder();
971960

972-
// This is a string
973-
foreach (KeyValuePair<uint, string> game in ownedGames) {
974-
if (game.Value.IndexOf(games, StringComparison.OrdinalIgnoreCase) < 0) {
961+
string[] games = query.Split(',');
962+
foreach (string game in games) {
963+
// Check if this is appID
964+
uint appID;
965+
if (uint.TryParse(game, out appID)) {
966+
string ownedName;
967+
if (ownedGames.TryGetValue(appID, out ownedName)) {
968+
response.Append(Environment.NewLine + "Owned already: " + appID + " | " + ownedName);
969+
} else {
970+
response.Append(Environment.NewLine + "Not owned yet: " + appID);
971+
}
972+
975973
continue;
976974
}
977975

978-
response.AppendLine(Environment.NewLine + "Owned already: " + game.Key + " | " + game.Value);
976+
// This is a string, so check our entire library
977+
foreach (KeyValuePair<uint, string> ownedGame in ownedGames) {
978+
if (ownedGame.Value.IndexOf(game, StringComparison.OrdinalIgnoreCase) < 0) {
979+
continue;
980+
}
981+
982+
response.Append(Environment.NewLine + "Owned already: " + ownedGame.Key + " | " + ownedGame.Value);
983+
}
979984
}
980985

981986
if (response.Length > 0) {
982987
return response.ToString();
983988
} else {
984-
return "Not owned yet: " + games;
989+
return "Not owned yet: " + query;
985990
}
986991
}
987992

0 commit comments

Comments
 (0)