diff --git a/ArchiSteamFarm.CustomPlugins.ExamplePlugin/ExamplePlugin.cs b/ArchiSteamFarm.CustomPlugins.ExamplePlugin/ExamplePlugin.cs index 84175718a..8110e6ce3 100644 --- a/ArchiSteamFarm.CustomPlugins.ExamplePlugin/ExamplePlugin.cs +++ b/ArchiSteamFarm.CustomPlugins.ExamplePlugin/ExamplePlugin.cs @@ -28,7 +28,6 @@ using ArchiSteamFarm.Core; using ArchiSteamFarm.Plugins.Interfaces; using ArchiSteamFarm.Steam; using ArchiSteamFarm.Steam.Data; -using ArchiSteamFarm.Steam.Storage; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using SteamKit2; @@ -41,7 +40,7 @@ namespace ArchiSteamFarm.CustomPlugins.ExamplePlugin; // Your plugin class should inherit the plugin interfaces it wants to handle // If you do not want to handle a particular action (e.g. OnBotMessage that is offered in IBotMessage), it's the best idea to not inherit it at all // This will keep your code compact, efficient and less dependent. You can always add additional interfaces when you'll need them, this example project will inherit quite a bit of them to show you potential usage -internal sealed class ExamplePlugin : IASF, IBot, IBotCommand, IBotConnection, IBotFriendRequest, IBotMessage, IBotModules, IBotTradeOffer { +internal sealed class ExamplePlugin : IASF, IBot, IBotCommand2, IBotConnection, IBotFriendRequest, IBotMessage, IBotModules, IBotTradeOffer { // This is used for identification purposes, typically you want to use a friendly name of your plugin here, such as the name of your main class // Please note that this property can have direct dependencies only on structures that were initialized by the constructor, as it's possible to be called before OnLoaded() takes place public string Name => nameof(ExamplePlugin); @@ -86,11 +85,11 @@ internal sealed class ExamplePlugin : IASF, IBot, IBotCommand, IBotConnection, I // Since ASF already had to do initial parsing in order to determine that the command is unknown, args[] are splitted using standard ASF delimiters // If by any chance you want to handle message in its raw format, you also have it available, although for usual ASF pattern you can most likely stick with args[] exclusively. The message has CommandPrefix already stripped for your convenience // If you do not recognize the command, just return null/empty and allow ASF to gracefully return "unknown command" to user on usual basis - public async Task OnBotCommand(Bot bot, ulong steamID, string message, string[] args) { + public async Task OnBotCommand(Bot bot, EAccess access, string message, string[] args, ulong steamID = 0) { // In comparison with OnBotMessage(), we're using asynchronous CatAPI call here, so we declare our method as async and return the message as usual // Notice how we handle access here as well, it'll work only for FamilySharing+ switch (args[0].ToUpperInvariant()) { - case "CAT" when bot.HasAccess(steamID, BotConfig.EAccess.FamilySharing): + case "CAT" when access >= EAccess.FamilySharing: // Notice how we can decide whether to use bot's AWH WebBrowser or ASF's one. For Steam-related requests, AWH's one should always be used, for third-party requests like those it doesn't really matter // Still, it makes sense to pass AWH's one, so in case you get some errors or alike, you know from which bot instance they come from. It's similar to using Bot's ArchiLogger compared to ASF's one string? randomCatURL = await CatAPI.GetRandomCatURL(bot.ArchiWebHandler.WebBrowser).ConfigureAwait(false); diff --git a/ArchiSteamFarm/IPC/Controllers/Api/CommandController.cs b/ArchiSteamFarm/IPC/Controllers/Api/CommandController.cs index fcd424598..8c5f97a57 100644 --- a/ArchiSteamFarm/IPC/Controllers/Api/CommandController.cs +++ b/ArchiSteamFarm/IPC/Controllers/Api/CommandController.cs @@ -54,12 +54,6 @@ public sealed class CommandController : ArchiController { return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(request.Command)))); } - ulong steamOwnerID = ASF.GlobalConfig?.SteamOwnerID ?? GlobalConfig.DefaultSteamOwnerID; - - if (steamOwnerID == 0) { - return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, nameof(ASF.GlobalConfig.SteamOwnerID)))); - } - Bot? targetBot = Bot.Bots?.OrderBy(static bot => bot.Key, Bot.BotsComparer).Select(static bot => bot.Value).FirstOrDefault(); if (targetBot == null) { @@ -80,7 +74,7 @@ public sealed class CommandController : ArchiController { command = command[commandPrefix.Length..]; } - string? response = await targetBot.Commands.Response(steamOwnerID, command).ConfigureAwait(false); + string? response = await targetBot.Commands.Response(EAccess.Owner, command).ConfigureAwait(false); return Ok(new GenericResponse(response)); } diff --git a/ArchiSteamFarm/Localization/Strings.Designer.cs b/ArchiSteamFarm/Localization/Strings.Designer.cs index c6c279f84..ba5b5fde6 100644 --- a/ArchiSteamFarm/Localization/Strings.Designer.cs +++ b/ArchiSteamFarm/Localization/Strings.Designer.cs @@ -1029,12 +1029,6 @@ namespace ArchiSteamFarm.Localization { } } - public static string InteractiveConsoleNotAvailable { - get { - return ResourceManager.GetString("InteractiveConsoleNotAvailable", resourceCulture); - } - } - public static string BotGamesToRedeemInBackgroundCount { get { return ResourceManager.GetString("BotGamesToRedeemInBackgroundCount", resourceCulture); diff --git a/ArchiSteamFarm/Localization/Strings.bg-BG.resx b/ArchiSteamFarm/Localization/Strings.bg-BG.resx index 62df3b9ca..6f56def38 100644 --- a/ArchiSteamFarm/Localization/Strings.bg-BG.resx +++ b/ArchiSteamFarm/Localization/Strings.bg-BG.resx @@ -551,10 +551,6 @@ Интерактивната конзола е вече активна, натиснете 'c' за да влезето в команден режим. - - Интерактивната конзола не е налична, защото липсва {0} конфигурирана стойност. - {0} will be replaced by the name of the missing config property (string) - Ботът има {0} игри оставащи в опашката на заден фон. {0} will be replaced by remaining number of games in BGR's queue diff --git a/ArchiSteamFarm/Localization/Strings.cs-CZ.resx b/ArchiSteamFarm/Localization/Strings.cs-CZ.resx index 2fc3b45b5..6bf484f63 100644 --- a/ArchiSteamFarm/Localization/Strings.cs-CZ.resx +++ b/ArchiSteamFarm/Localization/Strings.cs-CZ.resx @@ -637,10 +637,6 @@ StackTrace: Interaktivní konzole je nyní aktivní, napište "c" pro vstup do příkazového režimu. - - Interaktivní konzole není dostupná z důvodu chybějící {0} konfigurace. - {0} will be replaced by the name of the missing config property (string) - Bot má {0} zbývajících her ve frontě. {0} will be replaced by remaining number of games in BGR's queue diff --git a/ArchiSteamFarm/Localization/Strings.da-DK.resx b/ArchiSteamFarm/Localization/Strings.da-DK.resx index 4f42ce011..9aeaae0a5 100644 --- a/ArchiSteamFarm/Localization/Strings.da-DK.resx +++ b/ArchiSteamFarm/Localization/Strings.da-DK.resx @@ -556,10 +556,6 @@ Processens oppetid: {1} Den interaktive konsol er nu aktiv, tast "c" for at skifte til kommando-mode. - - Den interaktive konsol den ikke tilgængelig på grund af at {0} mangler en eller flere konfigurationsindstillinger. - {0} will be replaced by the name of the missing config property (string) - Bot har {0} spil tilbage i sin baggrundskø. {0} will be replaced by remaining number of games in BGR's queue diff --git a/ArchiSteamFarm/Localization/Strings.de-DE.resx b/ArchiSteamFarm/Localization/Strings.de-DE.resx index 456fbb8a8..ced13deec 100644 --- a/ArchiSteamFarm/Localization/Strings.de-DE.resx +++ b/ArchiSteamFarm/Localization/Strings.de-DE.resx @@ -637,10 +637,6 @@ Prozesslaufzeit: {1} Interaktive Konsole ist jetzt aktiv, geben Sie 'c' ein, um den Befehlsmodus zu wechseln. - - Die interaktive Konsole ist aufgrund der fehlenden Konfigurationseigenschaften {0} nicht verfügbar. - {0} will be replaced by the name of the missing config property (string) - Bot hat {0} Spiele, die in seiner Hintergrundwarteschlange verbleiben. {0} will be replaced by remaining number of games in BGR's queue diff --git a/ArchiSteamFarm/Localization/Strings.el-GR.resx b/ArchiSteamFarm/Localization/Strings.el-GR.resx index 828d16f39..376d9af15 100644 --- a/ArchiSteamFarm/Localization/Strings.el-GR.resx +++ b/ArchiSteamFarm/Localization/Strings.el-GR.resx @@ -634,10 +634,6 @@ StackTrace: Η διαδραστική κονσόλα είναι ενεργή, πατήστε 'c' για να εισάγετε εντολή. - - Η διαδραστική κονσόλα δεν είναι διαθέσιμη διότι λείπει η ιδιότητα {0} από το αρχείο διαμόρφωσης. - {0} will be replaced by the name of the missing config property (string) - Το bot έχει {0} παιχνίδια που απομένουν στην ουρά. {0} will be replaced by remaining number of games in BGR's queue diff --git a/ArchiSteamFarm/Localization/Strings.es-ES.resx b/ArchiSteamFarm/Localization/Strings.es-ES.resx index 232f24ae8..edc55b899 100644 --- a/ArchiSteamFarm/Localization/Strings.es-ES.resx +++ b/ArchiSteamFarm/Localization/Strings.es-ES.resx @@ -636,10 +636,6 @@ Tiempo de actividad del proceso: {1} La consola interactiva está activa, presiona 'c' para entrar al modo de comandos. - - La consola interactiva no está disponible debido a que falta la propiedad de configuración {0}. - {0} will be replaced by the name of the missing config property (string) - El bot tiene {0} juegos restantes en la cola en segundo plano. {0} will be replaced by remaining number of games in BGR's queue diff --git a/ArchiSteamFarm/Localization/Strings.fi-FI.resx b/ArchiSteamFarm/Localization/Strings.fi-FI.resx index 3aa240596..946598879 100644 --- a/ArchiSteamFarm/Localization/Strings.fi-FI.resx +++ b/ArchiSteamFarm/Localization/Strings.fi-FI.resx @@ -543,10 +543,6 @@ StackTrace: Vuorovaikutteinen konsoli on nyt aktiivinen. Paina 'c' siirtyäksesi komento-tilaan. - - Vuorovaikutteinen konsoli ei ole käytettävissä, koska {0} asetus puuttuu. - {0} will be replaced by the name of the missing config property (string) - Botilla on {0} peliä jäljellä taustajonossa. {0} will be replaced by remaining number of games in BGR's queue diff --git a/ArchiSteamFarm/Localization/Strings.fr-FR.resx b/ArchiSteamFarm/Localization/Strings.fr-FR.resx index 7fab98804..917ff81d5 100644 --- a/ArchiSteamFarm/Localization/Strings.fr-FR.resx +++ b/ArchiSteamFarm/Localization/Strings.fr-FR.resx @@ -634,10 +634,6 @@ Durée de fonctionnement : {1} La console interactive est maintenant active, tapez 'c' pour entrer en mode commande. - - La console interactive n'est pas disponible en raison de la propriété de configuration {0} manquante. - {0} will be replaced by the name of the missing config property (string) - Le bot a {0} jeux restants dans sa file d'attente. {0} will be replaced by remaining number of games in BGR's queue diff --git a/ArchiSteamFarm/Localization/Strings.hu-HU.resx b/ArchiSteamFarm/Localization/Strings.hu-HU.resx index 8b4267d71..e57b401b1 100644 --- a/ArchiSteamFarm/Localization/Strings.hu-HU.resx +++ b/ArchiSteamFarm/Localization/Strings.hu-HU.resx @@ -562,10 +562,6 @@ Ennyi ideje fut: {1} Az interaktív konzol aktív, nyomd meg a 'c' billentyűt, hogy a parancs módba lépj. - - Az interaktív konzol nem elérhető mivel a(z) {0} tulajdonság hiányzik a konfigurációból. - {0} will be replaced by the name of the missing config property (string) - A botnak {0} játéka maradt a várólistán. {0} will be replaced by remaining number of games in BGR's queue diff --git a/ArchiSteamFarm/Localization/Strings.it-IT.resx b/ArchiSteamFarm/Localization/Strings.it-IT.resx index d1c6443df..fd5876ffe 100644 --- a/ArchiSteamFarm/Localization/Strings.it-IT.resx +++ b/ArchiSteamFarm/Localization/Strings.it-IT.resx @@ -635,10 +635,6 @@ Tempo di attività: {1} La console interattiva è stata attivata, digita 'c' per entrare nella modalità comando. - - La console interattiva non è disponibile a causa della proprietà di configurazione {0} mancante. - {0} will be replaced by the name of the missing config property (string) - Il bot ha {0} giochi rimanenti nella coda di background. {0} will be replaced by remaining number of games in BGR's queue diff --git a/ArchiSteamFarm/Localization/Strings.ja-JP.resx b/ArchiSteamFarm/Localization/Strings.ja-JP.resx index 8debc7b66..084e1783b 100644 --- a/ArchiSteamFarm/Localization/Strings.ja-JP.resx +++ b/ArchiSteamFarm/Localization/Strings.ja-JP.resx @@ -597,10 +597,6 @@ Process uptime: {1} 対話型コンソールがアクティブになりました。コマンドモードに入るには「c」と入力します。 - - {0} の設定が見つからないため、対話型コンソールが無効にしました。 - {0} will be replaced by the name of the missing config property (string) - bot のバックグラウンドキューに {0} つのゲームが残っています。 {0} will be replaced by remaining number of games in BGR's queue diff --git a/ArchiSteamFarm/Localization/Strings.ko-KR.resx b/ArchiSteamFarm/Localization/Strings.ko-KR.resx index e8f52fcca..7d6c0152e 100644 --- a/ArchiSteamFarm/Localization/Strings.ko-KR.resx +++ b/ArchiSteamFarm/Localization/Strings.ko-KR.resx @@ -632,10 +632,6 @@ StackTrace: 대화형 콘솔이 활성화되었습니다. 명령어 모드로 들어가려면 ' c '를 입력하십시오. - - 환경설정 속성값 {0} 이 누락되어 대화형 콘솔을 사용할 수 없습니다. - {0} will be replaced by the name of the missing config property (string) - {0} 개의 게임이 이 봇의 배경 큐에 남아있습니다. {0} will be replaced by remaining number of games in BGR's queue diff --git a/ArchiSteamFarm/Localization/Strings.lt-LT.resx b/ArchiSteamFarm/Localization/Strings.lt-LT.resx index 693162dbd..42d14f29c 100644 --- a/ArchiSteamFarm/Localization/Strings.lt-LT.resx +++ b/ArchiSteamFarm/Localization/Strings.lt-LT.resx @@ -552,10 +552,6 @@ Proceso veikimo laikas: {1} Interaktyvi konsolė aktyvuota, norėdami pateikti į komandų rėžimą paspauskite „c“. - - Interaktyvi konsolė yra negalima dėl trūkstamų konfigūracinių parametrų: {0} - {0} will be replaced by the name of the missing config property (string) - Boto foninėje eilėje yra likę {0} žaidimai. {0} will be replaced by remaining number of games in BGR's queue diff --git a/ArchiSteamFarm/Localization/Strings.lv-LV.resx b/ArchiSteamFarm/Localization/Strings.lv-LV.resx index 097d2770d..834472e0a 100644 --- a/ArchiSteamFarm/Localization/Strings.lv-LV.resx +++ b/ArchiSteamFarm/Localization/Strings.lv-LV.resx @@ -560,10 +560,6 @@ Darbspējas laiks: {1} Interaktīvā konsole ir pieejama, raksti 'c', lai piekļūtu komandu rindai. - - Interaktīvā konsole nav pieejama, jo konfigurācijā trūkst {0} vērtība. - {0} will be replaced by the name of the missing config property (string) - Botam palikušas {0} rindā stāvošas spēles. {0} will be replaced by remaining number of games in BGR's queue diff --git a/ArchiSteamFarm/Localization/Strings.nl-NL.resx b/ArchiSteamFarm/Localization/Strings.nl-NL.resx index f73057c17..0d88f0902 100644 --- a/ArchiSteamFarm/Localization/Strings.nl-NL.resx +++ b/ArchiSteamFarm/Localization/Strings.nl-NL.resx @@ -571,10 +571,6 @@ Proces uptime: {1} De interactieve console is nu actief, typ 'c' om naar de opdrachtprompt te gaan. - - De interactieve console is niet beschikbaar vanwege de ontbrekende configuratie-eigenschap {0}. - {0} will be replaced by the name of the missing config property (string) - Bot heeft {0} spellen resterend in de achtergrondwachtrij. {0} will be replaced by remaining number of games in BGR's queue diff --git a/ArchiSteamFarm/Localization/Strings.pl-PL.resx b/ArchiSteamFarm/Localization/Strings.pl-PL.resx index 309c17924..586078d49 100644 --- a/ArchiSteamFarm/Localization/Strings.pl-PL.resx +++ b/ArchiSteamFarm/Localization/Strings.pl-PL.resx @@ -637,10 +637,6 @@ Czas procesu: {1} Interaktywna konsola jest teraz aktywna, wciśnij 'c', aby przejść do trybu poleceń. - - Interaktywna konsola nie jest dostępna ze względu na brakującą konfigurację {0}. - {0} will be replaced by the name of the missing config property (string) - Bot ma {0} gier oczekujących w tle. {0} will be replaced by remaining number of games in BGR's queue diff --git a/ArchiSteamFarm/Localization/Strings.pt-BR.resx b/ArchiSteamFarm/Localization/Strings.pt-BR.resx index 0700befb7..acd565817 100644 --- a/ArchiSteamFarm/Localization/Strings.pt-BR.resx +++ b/ArchiSteamFarm/Localization/Strings.pt-BR.resx @@ -634,10 +634,6 @@ Tempo de execução: {1} O console interativo está ativo, digite 'c' para enviar comandos. - - O console interativo não está disponível devido à falta da propriedade de configuração {0}. - {0} will be replaced by the name of the missing config property (string) - Há {0} jogos restantes na lista de ativação em segundo plano desse bot. {0} will be replaced by remaining number of games in BGR's queue diff --git a/ArchiSteamFarm/Localization/Strings.resx b/ArchiSteamFarm/Localization/Strings.resx index 92a536911..fd14e710f 100644 --- a/ArchiSteamFarm/Localization/Strings.resx +++ b/ArchiSteamFarm/Localization/Strings.resx @@ -637,10 +637,6 @@ Process uptime: {1} Interactive console is now active, type 'c' in order to enter command mode. - - Interactive console is not available due to missing {0} config property. - {0} will be replaced by the name of the missing config property (string) - Bot has {0} games remaining in its background queue. {0} will be replaced by remaining number of games in BGR's queue diff --git a/ArchiSteamFarm/Localization/Strings.ro-RO.resx b/ArchiSteamFarm/Localization/Strings.ro-RO.resx index 04380589e..6c8f7a935 100644 --- a/ArchiSteamFarm/Localization/Strings.ro-RO.resx +++ b/ArchiSteamFarm/Localization/Strings.ro-RO.resx @@ -634,10 +634,6 @@ Proces: {1} Consola interactivă este acum activă, tastați 'c' pentru a introduce modul de comandă. - - Consola interactivă nu este disponibilă deoarece lipsesc {0} din configurare. - {0} will be replaced by the name of the missing config property (string) - Botul are {0} jocuri rămase la rând în fundal. {0} will be replaced by remaining number of games in BGR's queue diff --git a/ArchiSteamFarm/Localization/Strings.ru-RU.resx b/ArchiSteamFarm/Localization/Strings.ru-RU.resx index 6cbb2c7a2..5e65a8c27 100644 --- a/ArchiSteamFarm/Localization/Strings.ru-RU.resx +++ b/ArchiSteamFarm/Localization/Strings.ru-RU.resx @@ -637,10 +637,6 @@ Включена интерактивная консоль, нажмите 'c' чтобы перейти в режим команд. - - Интерактивная консоль недоступна из-за отсутствия параметра конфигурации {0}. - {0} will be replaced by the name of the missing config property (string) - У бота в фоновой очереди осталось {0} игр. {0} will be replaced by remaining number of games in BGR's queue diff --git a/ArchiSteamFarm/Localization/Strings.sk-SK.resx b/ArchiSteamFarm/Localization/Strings.sk-SK.resx index a003581ab..5eb3d5c07 100644 --- a/ArchiSteamFarm/Localization/Strings.sk-SK.resx +++ b/ArchiSteamFarm/Localization/Strings.sk-SK.resx @@ -635,10 +635,6 @@ Doba prevádzky procesu: {1} Interaktivní konzole je nyní aktivní, napište "c" pro vstup do příkazového režimu. Interaktívna konzola je teraz aktívna, napíšte "c" pre vstup do príkazového režimu. - - Interaktívna konzola nie je dostupná z dôvodu chýbajúcej {0} konfigurácie. - {0} will be replaced by the name of the missing config property (string) - Bot má {0} zostávajúcich hier vo fronte. {0} will be replaced by remaining number of games in BGR's queue diff --git a/ArchiSteamFarm/Localization/Strings.sr-Latn.resx b/ArchiSteamFarm/Localization/Strings.sr-Latn.resx index dfd8d2a63..21e76786c 100644 --- a/ArchiSteamFarm/Localization/Strings.sr-Latn.resx +++ b/ArchiSteamFarm/Localization/Strings.sr-Latn.resx @@ -610,10 +610,6 @@ Vrijeme rada procesa: {1} Interaktivna konsola je dostupna, pritisnice "c" da bi ste je koristili. - - Interaktivna konsola nije dostupna zbog nedostatka {0} u konfiguraciji. - {0} will be replaced by the name of the missing config property (string) - Bot ima {0} igricu/e preostale u pozadinskom redu. {0} will be replaced by remaining number of games in BGR's queue diff --git a/ArchiSteamFarm/Localization/Strings.tr-TR.resx b/ArchiSteamFarm/Localization/Strings.tr-TR.resx index 9324d4de2..88c211834 100644 --- a/ArchiSteamFarm/Localization/Strings.tr-TR.resx +++ b/ArchiSteamFarm/Localization/Strings.tr-TR.resx @@ -637,10 +637,6 @@ Süreç çalışma zamanı: {1} Etkileşimli konsol şimdi etkin, komut girme moduna girmek için 'c' tuşuna basın. - - Etkileşimli konsol eksik {0} yapılandırma özelliği nedeniyle kullanılamıyor. - {0} will be replaced by the name of the missing config property (string) - Bot kuyruğunda {0} oyun kaldı. {0} will be replaced by remaining number of games in BGR's queue diff --git a/ArchiSteamFarm/Localization/Strings.uk-UA.resx b/ArchiSteamFarm/Localization/Strings.uk-UA.resx index 5f215247d..14d09d911 100644 --- a/ArchiSteamFarm/Localization/Strings.uk-UA.resx +++ b/ArchiSteamFarm/Localization/Strings.uk-UA.resx @@ -556,10 +556,6 @@ Інтерактивну консоль активовано, натисніть 'c' щоб перейти до режиму команд. - - Інтерактивну консоль не активовано через відсутність параметру конфігурації {0}. - {0} will be replaced by the name of the missing config property (string) - Бот має {0} ігор у фоновій черзі. {0} will be replaced by remaining number of games in BGR's queue diff --git a/ArchiSteamFarm/Localization/Strings.vi-VN.resx b/ArchiSteamFarm/Localization/Strings.vi-VN.resx index 5f7a5f88f..a31595e20 100644 --- a/ArchiSteamFarm/Localization/Strings.vi-VN.resx +++ b/ArchiSteamFarm/Localization/Strings.vi-VN.resx @@ -634,10 +634,6 @@ Thời gian hoạt động: {1} Bảng điều khiển tương tác hiện đang hoạt động, ấn 'c' để vào chế độ lệnh. - - Bảng điều khiển tương tác không khả dụng do thiếu thuộc tính cấu hình {0}. - {0} will be replaced by the name of the missing config property (string) - Bot có {0} trò chơi còn lại trong hàng chờ. {0} will be replaced by remaining number of games in BGR's queue diff --git a/ArchiSteamFarm/NLog/ArchiLogger.cs b/ArchiSteamFarm/NLog/ArchiLogger.cs index d32d4c64b..369898f61 100644 --- a/ArchiSteamFarm/NLog/ArchiLogger.cs +++ b/ArchiSteamFarm/NLog/ArchiLogger.cs @@ -209,7 +209,7 @@ public sealed class ArchiLogger { internal void LogInvite(SteamID steamID, bool? handled = null, [CallerMemberName] string? previousMethodName = null) { if ((steamID == null) || (steamID.AccountType == EAccountType.Invalid)) { - throw new ArgumentNullException(nameof(steamID)); + throw new ArgumentOutOfRangeException(nameof(steamID)); } ulong steamID64 = steamID; diff --git a/ArchiSteamFarm/NLog/Logging.cs b/ArchiSteamFarm/NLog/Logging.cs index 996d799e6..6a08ca334 100644 --- a/ArchiSteamFarm/NLog/Logging.cs +++ b/ArchiSteamFarm/NLog/Logging.cs @@ -240,12 +240,6 @@ internal static class Logging { } internal static void StartInteractiveConsole() { - if ((ASF.GlobalConfig == null) || (ASF.GlobalConfig.SteamOwnerID == 0)) { - ASF.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.InteractiveConsoleNotAvailable, nameof(ASF.GlobalConfig.SteamOwnerID))); - - return; - } - Utilities.InBackground(HandleConsoleInteractively, true); ASF.ArchiLogger.LogGenericInfo(Strings.InteractiveConsoleEnabled); } @@ -368,10 +362,8 @@ internal static class Logging { Console.WriteLine($@"<> {Strings.Executing}"); - ulong steamOwnerID = ASF.GlobalConfig?.SteamOwnerID ?? GlobalConfig.DefaultSteamOwnerID; - // ReSharper disable once RedundantSuppressNullableWarningExpression - required for .NET Framework - string? response = await targetBot.Commands.Response(steamOwnerID, command!).ConfigureAwait(false); + string? response = await targetBot.Commands.Response(EAccess.Owner, command!).ConfigureAwait(false); if (string.IsNullOrEmpty(response)) { ASF.ArchiLogger.LogNullError(nameof(response)); diff --git a/ArchiSteamFarm/Plugins/Interfaces/IBotCommand.cs b/ArchiSteamFarm/Plugins/Interfaces/IBotCommand.cs index 0114913c1..77357d3da 100644 --- a/ArchiSteamFarm/Plugins/Interfaces/IBotCommand.cs +++ b/ArchiSteamFarm/Plugins/Interfaces/IBotCommand.cs @@ -19,6 +19,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using System.Threading.Tasks; using ArchiSteamFarm.Steam; using ArchiSteamFarm.Storage; @@ -27,6 +28,7 @@ using JetBrains.Annotations; namespace ArchiSteamFarm.Plugins.Interfaces; [PublicAPI] +[Obsolete($"Use {nameof(IBotCommand2)} instead, this one will be removed soon.", true)] public interface IBotCommand : IPlugin { /// /// ASF will call this method for unrecognized commands. diff --git a/ArchiSteamFarm/Plugins/Interfaces/IBotCommand2.cs b/ArchiSteamFarm/Plugins/Interfaces/IBotCommand2.cs new file mode 100644 index 000000000..d53b488ad --- /dev/null +++ b/ArchiSteamFarm/Plugins/Interfaces/IBotCommand2.cs @@ -0,0 +1,41 @@ +// _ _ _ ____ _ _____ +// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ +// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ +// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | +// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| +// | +// Copyright 2015-2022 Łukasz "JustArchi" Domeradzki +// Contact: JustArchi@JustArchi.net +// | +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// | +// http://www.apache.org/licenses/LICENSE-2.0 +// | +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System.Threading.Tasks; +using ArchiSteamFarm.Steam; +using ArchiSteamFarm.Storage; +using JetBrains.Annotations; + +namespace ArchiSteamFarm.Plugins.Interfaces; + +[PublicAPI] +public interface IBotCommand2 : IPlugin { + /// + /// ASF will call this method for unrecognized commands. + /// + /// Bot object related to this callback. + /// Access of user executing the command. + /// Command message in its raw format, stripped of . + /// Pre-parsed message using standard ASF delimiters. + /// Optionally, steamID of the user who executed the command - may not be available with value of 0 (e.g. ASF API). + /// Response to the command, or null/empty (as the task value) if the command isn't handled by this plugin. + Task OnBotCommand(Bot bot, EAccess access, string message, string[] args, ulong steamID = 0); +} diff --git a/ArchiSteamFarm/Plugins/PluginsCore.cs b/ArchiSteamFarm/Plugins/PluginsCore.cs index 8b1f3d57b..f00234083 100644 --- a/ArchiSteamFarm/Plugins/PluginsCore.cs +++ b/ArchiSteamFarm/Plugins/PluginsCore.cs @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; +using System.ComponentModel; using System.Composition; using System.Composition.Convention; using System.Composition.Hosting; @@ -39,6 +40,7 @@ using ArchiSteamFarm.Steam; using ArchiSteamFarm.Steam.Data; using ArchiSteamFarm.Steam.Exchange; using ArchiSteamFarm.Steam.Integration.Callbacks; +using ArchiSteamFarm.Storage; using Newtonsoft.Json.Linq; using SteamKit2; @@ -266,11 +268,11 @@ internal static class PluginsCore { } } - internal static async Task OnBotCommand(Bot bot, ulong steamID, string message, string[] args) { + internal static async Task OnBotCommand(Bot bot, EAccess access, string message, string[] args, ulong steamID = 0) { ArgumentNullException.ThrowIfNull(bot); - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(message)) { @@ -288,13 +290,37 @@ internal static class PluginsCore { IList responses; try { - responses = await Utilities.InParallel(ActivePlugins.OfType().Select(plugin => plugin.OnBotCommand(bot, steamID, message, args))).ConfigureAwait(false); + responses = await Utilities.InParallel(ActivePlugins.OfType().Select(plugin => plugin.OnBotCommand(bot, access, message, args, steamID))).ConfigureAwait(false); } catch (Exception e) { ASF.ArchiLogger.LogGenericException(e); return null; } + ulong oldSteamID = steamID; + + if (oldSteamID == 0) { + oldSteamID = ASF.GlobalConfig?.SteamOwnerID ?? GlobalConfig.DefaultSteamOwnerID; + } + + if ((oldSteamID != 0) && new SteamID(oldSteamID).IsIndividualAccount) { + IList oldResponses; + + try { +#pragma warning disable CS0618 // We intentionally support deprecated interface for a while longer + oldResponses = await Utilities.InParallel(ActivePlugins.OfType().Select(plugin => plugin.OnBotCommand(bot, oldSteamID, message, args))).ConfigureAwait(false); +#pragma warning restore CS0618 // We intentionally support deprecated interface for a while longer + } catch (Exception e) { + ASF.ArchiLogger.LogGenericException(e); + + return null; + } + + foreach (string? oldResponse in oldResponses) { + responses.Add(oldResponse); + } + } + return string.Join(Environment.NewLine, responses.Where(static response => !string.IsNullOrEmpty(response))); } diff --git a/ArchiSteamFarm/Steam/Bot.cs b/ArchiSteamFarm/Steam/Bot.cs index 18080ce9f..45edd685f 100644 --- a/ArchiSteamFarm/Steam/Bot.cs +++ b/ArchiSteamFarm/Steam/Bot.cs @@ -409,6 +409,38 @@ public sealed class Bot : IAsyncDisposable { return true; } + [PublicAPI] + public EAccess GetAccess(ulong steamID) { + if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { + throw new ArgumentOutOfRangeException(nameof(steamID)); + } + + if (ASF.IsOwner(steamID)) { + return EAccess.Owner; + } + + EAccess familySharingAccess = SteamFamilySharingIDs.Contains(steamID) ? EAccess.FamilySharing : EAccess.None; + + if (!BotConfig.SteamUserPermissions.TryGetValue(steamID, out BotConfig.EAccess permission)) { + return familySharingAccess; + } + + switch (permission) { + case BotConfig.EAccess.None: + return EAccess.None; + case BotConfig.EAccess.FamilySharing: + return EAccess.FamilySharing; + case BotConfig.EAccess.Operator: + return EAccess.Operator; + case BotConfig.EAccess.Master: + return EAccess.Master; + default: + ASF.ArchiLogger.LogGenericError(string.Format(CultureInfo.CurrentCulture, Strings.WarningUnknownValuePleaseReport, nameof(permission), permission)); + + return familySharingAccess; + } + } + [PublicAPI] public static Bot? GetBot(string botName) { if (string.IsNullOrEmpty(botName)) { @@ -726,9 +758,10 @@ public sealed class Bot : IAsyncDisposable { } [PublicAPI] + [Obsolete($"Use {nameof(GetAccess)} instead (if you still need it), this one will be removed soon.", true)] public bool HasAccess(ulong steamID, BotConfig.EAccess access) { if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentNullException(nameof(steamID)); + throw new ArgumentOutOfRangeException(nameof(steamID)); } if ((access == BotConfig.EAccess.None) || !Enum.IsDefined(typeof(BotConfig.EAccess), access)) { @@ -2120,7 +2153,7 @@ public sealed class Bot : IAsyncDisposable { private bool IsMasterClanID(ulong steamID) { if ((steamID == 0) || !new SteamID(steamID).IsClanAccount) { - throw new ArgumentNullException(nameof(steamID)); + throw new ArgumentOutOfRangeException(nameof(steamID)); } return steamID == BotConfig.SteamMasterClanID; @@ -2435,7 +2468,7 @@ public sealed class Bot : IAsyncDisposable { break; default: - if (HasAccess(friend.SteamID, BotConfig.EAccess.FamilySharing)) { + if (GetAccess(friend.SteamID) >= EAccess.FamilySharing) { ArchiLogger.LogInvite(friend.SteamID, true); if (!await ArchiHandler.AddFriend(friend.SteamID).ConfigureAwait(false)) { diff --git a/ArchiSteamFarm/Steam/EAccess.cs b/ArchiSteamFarm/Steam/EAccess.cs new file mode 100644 index 000000000..a282a51a8 --- /dev/null +++ b/ArchiSteamFarm/Steam/EAccess.cs @@ -0,0 +1,33 @@ +// _ _ _ ____ _ _____ +// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ +// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ +// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | +// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| +// | +// Copyright 2015-2022 Łukasz "JustArchi" Domeradzki +// Contact: JustArchi@JustArchi.net +// | +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// | +// http://www.apache.org/licenses/LICENSE-2.0 +// | +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using JetBrains.Annotations; + +namespace ArchiSteamFarm.Steam; + +[PublicAPI] +public enum EAccess : byte { + None, + FamilySharing = 10, + Operator = 50, + Master = 100, + Owner = 255 +} diff --git a/ArchiSteamFarm/Steam/Exchange/Trading.cs b/ArchiSteamFarm/Steam/Exchange/Trading.cs index 81538bce3..6b9a6bf51 100644 --- a/ArchiSteamFarm/Steam/Exchange/Trading.cs +++ b/ArchiSteamFarm/Steam/Exchange/Trading.cs @@ -524,7 +524,7 @@ public sealed class Trading : IDisposable { if (tradeOffer.OtherSteamID64 != 0) { // Always accept trades from SteamMasterID - if (Bot.HasAccess(tradeOffer.OtherSteamID64, BotConfig.EAccess.Master)) { + if (Bot.GetAccess(tradeOffer.OtherSteamID64) >= EAccess.Master) { Bot.ArchiLogger.LogGenericDebug(string.Format(CultureInfo.CurrentCulture, Strings.BotTradeOfferResult, tradeOffer.TradeOfferID, ParseTradeResult.EResult.Accepted, $"{nameof(tradeOffer.OtherSteamID64)} {tradeOffer.OtherSteamID64}: {BotConfig.EAccess.Master}")); return ParseTradeResult.EResult.Accepted; diff --git a/ArchiSteamFarm/Steam/Interaction/Commands.cs b/ArchiSteamFarm/Steam/Interaction/Commands.cs index ec320f9ea..f11da1a1c 100644 --- a/ArchiSteamFarm/Steam/Interaction/Commands.cs +++ b/ArchiSteamFarm/Steam/Interaction/Commands.cs @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Globalization; using System.Linq; using System.Net.Http; @@ -81,11 +82,23 @@ public sealed class Commands { } [PublicAPI] + [Obsolete($"Use overload which accepts {nameof(EAccess)} instead, this one will be removed soon.", true)] public async Task Response(ulong steamID, string message) { if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { throw new ArgumentOutOfRangeException(nameof(steamID)); } + EAccess access = Bot.GetAccess(steamID); + + return await Response(access, message).ConfigureAwait(false); + } + + [PublicAPI] + public async Task Response(EAccess access, string message, ulong steamID = 0) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); + } + if (string.IsNullOrEmpty(message)) { throw new ArgumentNullException(nameof(message)); } @@ -98,220 +111,220 @@ public sealed class Commands { case 1: switch (args[0].ToUpperInvariant()) { case "2FA": - return await Response2FA(steamID).ConfigureAwait(false); + return await Response2FA(access).ConfigureAwait(false); case "2FANO": - return await Response2FAConfirm(steamID, false).ConfigureAwait(false); + return await Response2FAConfirm(access, false).ConfigureAwait(false); case "2FAOK": - return await Response2FAConfirm(steamID, true).ConfigureAwait(false); + return await Response2FAConfirm(access, true).ConfigureAwait(false); case "BALANCE": - return ResponseWalletBalance(steamID); + return ResponseWalletBalance(access); case "BGR": - return ResponseBackgroundGamesRedeemer(steamID); + return ResponseBackgroundGamesRedeemer(access); case "EXIT": - return ResponseExit(steamID); + return ResponseExit(access); case "FARM": - return await ResponseFarm(steamID).ConfigureAwait(false); + return await ResponseFarm(access).ConfigureAwait(false); case "FB": - return ResponseFarmingBlacklist(steamID); + return ResponseFarmingBlacklist(access); case "FQ": - return ResponseFarmingQueue(steamID); + return ResponseFarmingQueue(access); case "HELP": - return ResponseHelp(steamID); + return ResponseHelp(access); case "MAB": - return ResponseMatchActivelyBlacklist(steamID); + return ResponseMatchActivelyBlacklist(access); case "LEVEL": - return await ResponseLevel(steamID).ConfigureAwait(false); + return await ResponseLevel(access).ConfigureAwait(false); case "LOOT": - return await ResponseLoot(steamID).ConfigureAwait(false); + return await ResponseLoot(access).ConfigureAwait(false); case "PAUSE": - return await ResponsePause(steamID, true).ConfigureAwait(false); + return await ResponsePause(access, true).ConfigureAwait(false); case "PAUSE~": - return await ResponsePause(steamID, false).ConfigureAwait(false); + return await ResponsePause(access, false).ConfigureAwait(false); case "POINTS": - return await ResponsePointsBalance(steamID).ConfigureAwait(false); + return await ResponsePointsBalance(access).ConfigureAwait(false); case "RESET": - return await ResponseReset(steamID).ConfigureAwait(false); + return await ResponseReset(access).ConfigureAwait(false); case "RESUME": - return ResponseResume(steamID); + return ResponseResume(access); case "RESTART": - return ResponseRestart(steamID); + return ResponseRestart(access); case "SA": - return await ResponseStatus(steamID, SharedInfo.ASF).ConfigureAwait(false); + return await ResponseStatus(access, SharedInfo.ASF).ConfigureAwait(false); case "START": - return ResponseStart(steamID); + return ResponseStart(access); case "STATS": - return ResponseStats(steamID); + return ResponseStats(access); case "STATUS": - return ResponseStatus(steamID).Response; + return ResponseStatus(access).Response; case "STOP": - return ResponseStop(steamID); + return ResponseStop(access); case "TB": - return ResponseTradingBlacklist(steamID); + return ResponseTradingBlacklist(access); case "UNPACK": - return await ResponseUnpackBoosters(steamID).ConfigureAwait(false); + return await ResponseUnpackBoosters(access).ConfigureAwait(false); case "UPDATE": - return await ResponseUpdate(steamID).ConfigureAwait(false); + return await ResponseUpdate(access).ConfigureAwait(false); case "VERSION": - return ResponseVersion(steamID); + return ResponseVersion(access); default: - string? pluginsResponse = await PluginsCore.OnBotCommand(Bot, steamID, message, args).ConfigureAwait(false); + string? pluginsResponse = await PluginsCore.OnBotCommand(Bot, access, message, args, steamID).ConfigureAwait(false); - return !string.IsNullOrEmpty(pluginsResponse) ? pluginsResponse : ResponseUnknown(steamID); + return !string.IsNullOrEmpty(pluginsResponse) ? pluginsResponse : ResponseUnknown(access); } default: switch (args[0].ToUpperInvariant()) { case "2FA": - return await Response2FA(steamID, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); + return await Response2FA(access, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); case "2FANO": - return await Response2FAConfirm(steamID, Utilities.GetArgsAsText(args, 1, ","), false).ConfigureAwait(false); + return await Response2FAConfirm(access, Utilities.GetArgsAsText(args, 1, ","), false).ConfigureAwait(false); case "2FAOK": - return await Response2FAConfirm(steamID, Utilities.GetArgsAsText(args, 1, ","), true).ConfigureAwait(false); + return await Response2FAConfirm(access, Utilities.GetArgsAsText(args, 1, ","), true).ConfigureAwait(false); case "ADDLICENSE" when args.Length > 2: - return await ResponseAddLicense(steamID, args[1], Utilities.GetArgsAsText(args, 2, ",")).ConfigureAwait(false); + return await ResponseAddLicense(access, args[1], Utilities.GetArgsAsText(args, 2, ",")).ConfigureAwait(false); case "ADDLICENSE": - return await ResponseAddLicense(steamID, args[1]).ConfigureAwait(false); + return await ResponseAddLicense(access, args[1]).ConfigureAwait(false); case "BALANCE": - return await ResponseWalletBalance(steamID, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); + return await ResponseWalletBalance(access, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); case "BGR": - return await ResponseBackgroundGamesRedeemer(steamID, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); + return await ResponseBackgroundGamesRedeemer(access, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); case "ENCRYPT" when args.Length > 2: - return ResponseEncrypt(steamID, args[1], Utilities.GetArgsAsText(message, 2)); + return ResponseEncrypt(access, args[1], Utilities.GetArgsAsText(message, 2)); case "FARM": - return await ResponseFarm(steamID, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); + return await ResponseFarm(access, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); case "FB": - return await ResponseFarmingBlacklist(steamID, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); + return await ResponseFarmingBlacklist(access, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); case "FBADD" when args.Length > 2: - return await ResponseFarmingBlacklistAdd(steamID, args[1], Utilities.GetArgsAsText(args, 2, ",")).ConfigureAwait(false); + return await ResponseFarmingBlacklistAdd(access, args[1], Utilities.GetArgsAsText(args, 2, ",")).ConfigureAwait(false); case "FBADD": - return ResponseFarmingBlacklistAdd(steamID, args[1]); + return ResponseFarmingBlacklistAdd(access, args[1]); case "FBRM" when args.Length > 2: - return await ResponseFarmingBlacklistRemove(steamID, args[1], Utilities.GetArgsAsText(args, 2, ",")).ConfigureAwait(false); + return await ResponseFarmingBlacklistRemove(access, args[1], Utilities.GetArgsAsText(args, 2, ",")).ConfigureAwait(false); case "FBRM": - return ResponseFarmingBlacklistRemove(steamID, args[1]); + return ResponseFarmingBlacklistRemove(access, args[1]); case "FQ": - return await ResponseFarmingQueue(steamID, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); + return await ResponseFarmingQueue(access, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); case "FQADD" when args.Length > 2: - return await ResponseFarmingQueueAdd(steamID, args[1], Utilities.GetArgsAsText(args, 2, ",")).ConfigureAwait(false); + return await ResponseFarmingQueueAdd(access, args[1], Utilities.GetArgsAsText(args, 2, ",")).ConfigureAwait(false); case "FQADD": - return ResponseFarmingQueueAdd(steamID, args[1]); + return ResponseFarmingQueueAdd(access, args[1]); case "FQRM" when args.Length > 2: - return await ResponseFarmingQueueRemove(steamID, args[1], Utilities.GetArgsAsText(args, 2, ",")).ConfigureAwait(false); + return await ResponseFarmingQueueRemove(access, args[1], Utilities.GetArgsAsText(args, 2, ",")).ConfigureAwait(false); case "FQRM": - return ResponseFarmingQueueRemove(steamID, args[1]); + return ResponseFarmingQueueRemove(access, args[1]); case "HASH" when args.Length > 2: - return ResponseHash(steamID, args[1], Utilities.GetArgsAsText(message, 2)); + return ResponseHash(access, args[1], Utilities.GetArgsAsText(message, 2)); case "INPUT" when args.Length > 3: - return await ResponseInput(steamID, args[1], args[2], Utilities.GetArgsAsText(message, 3)).ConfigureAwait(false); + return await ResponseInput(access, args[1], args[2], Utilities.GetArgsAsText(message, 3)).ConfigureAwait(false); case "INPUT" when args.Length > 2: - return ResponseInput(steamID, args[1], args[2]); + return ResponseInput(access, args[1], args[2]); case "LEVEL": - return await ResponseLevel(steamID, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); + return await ResponseLevel(access, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); case "LOOT": - return await ResponseLoot(steamID, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); + return await ResponseLoot(access, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); case "LOOT^" when args.Length > 3: - return await ResponseAdvancedLoot(steamID, args[1], args[2], Utilities.GetArgsAsText(message, 3)).ConfigureAwait(false); + return await ResponseAdvancedLoot(access, args[1], args[2], Utilities.GetArgsAsText(message, 3)).ConfigureAwait(false); case "LOOT^" when args.Length > 2: - return await ResponseAdvancedLoot(steamID, args[1], args[2]).ConfigureAwait(false); + return await ResponseAdvancedLoot(access, args[1], args[2]).ConfigureAwait(false); case "LOOT@" when args.Length > 2: - return await ResponseLootByRealAppIDs(steamID, args[1], Utilities.GetArgsAsText(args, 2, ",")).ConfigureAwait(false); + return await ResponseLootByRealAppIDs(access, args[1], Utilities.GetArgsAsText(args, 2, ",")).ConfigureAwait(false); case "LOOT@": - return await ResponseLootByRealAppIDs(steamID, args[1]).ConfigureAwait(false); + return await ResponseLootByRealAppIDs(access, args[1]).ConfigureAwait(false); case "LOOT%" when args.Length > 2: - return await ResponseLootByRealAppIDs(steamID, args[1], Utilities.GetArgsAsText(args, 2, ","), true).ConfigureAwait(false); + return await ResponseLootByRealAppIDs(access, args[1], Utilities.GetArgsAsText(args, 2, ","), true).ConfigureAwait(false); case "LOOT%": - return await ResponseLootByRealAppIDs(steamID, args[1], true).ConfigureAwait(false); + return await ResponseLootByRealAppIDs(access, args[1], true).ConfigureAwait(false); case "MAB": - return await ResponseMatchActivelyBlacklist(steamID, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); + return await ResponseMatchActivelyBlacklist(access, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); case "MABADD" when args.Length > 2: - return await ResponseMatchActivelyBlacklistAdd(steamID, args[1], Utilities.GetArgsAsText(args, 2, ",")).ConfigureAwait(false); + return await ResponseMatchActivelyBlacklistAdd(access, args[1], Utilities.GetArgsAsText(args, 2, ",")).ConfigureAwait(false); case "MABADD": - return ResponseMatchActivelyBlacklistAdd(steamID, args[1]); + return ResponseMatchActivelyBlacklistAdd(access, args[1]); case "MABRM" when args.Length > 2: - return await ResponseMatchActivelyBlacklistRemove(steamID, args[1], Utilities.GetArgsAsText(args, 2, ",")).ConfigureAwait(false); + return await ResponseMatchActivelyBlacklistRemove(access, args[1], Utilities.GetArgsAsText(args, 2, ",")).ConfigureAwait(false); case "MABRM": - return ResponseMatchActivelyBlacklistRemove(steamID, args[1]); + return ResponseMatchActivelyBlacklistRemove(access, args[1]); case "NICKNAME" when args.Length > 2: - return await ResponseNickname(steamID, args[1], Utilities.GetArgsAsText(message, 2)).ConfigureAwait(false); + return await ResponseNickname(access, args[1], Utilities.GetArgsAsText(message, 2)).ConfigureAwait(false); case "NICKNAME": - return ResponseNickname(steamID, args[1]); + return ResponseNickname(access, args[1]); case "OA": - return await ResponseOwns(steamID, SharedInfo.ASF, Utilities.GetArgsAsText(message, 1)).ConfigureAwait(false); + return await ResponseOwns(access, SharedInfo.ASF, Utilities.GetArgsAsText(message, 1)).ConfigureAwait(false); case "OWNS" when args.Length > 2: - return await ResponseOwns(steamID, args[1], Utilities.GetArgsAsText(message, 2)).ConfigureAwait(false); + return await ResponseOwns(access, args[1], Utilities.GetArgsAsText(message, 2)).ConfigureAwait(false); case "OWNS": - return (await ResponseOwns(steamID, args[1]).ConfigureAwait(false)).Response; + return (await ResponseOwns(access, args[1]).ConfigureAwait(false)).Response; case "PAUSE": - return await ResponsePause(steamID, Utilities.GetArgsAsText(args, 1, ","), true).ConfigureAwait(false); + return await ResponsePause(access, Utilities.GetArgsAsText(args, 1, ","), true).ConfigureAwait(false); case "PAUSE~": - return await ResponsePause(steamID, Utilities.GetArgsAsText(args, 1, ","), false).ConfigureAwait(false); + return await ResponsePause(access, Utilities.GetArgsAsText(args, 1, ","), false).ConfigureAwait(false); case "PAUSE&" when args.Length > 2: - return await ResponsePause(steamID, args[1], true, Utilities.GetArgsAsText(message, 2)).ConfigureAwait(false); + return await ResponsePause(access, args[1], true, Utilities.GetArgsAsText(message, 2)).ConfigureAwait(false); case "PAUSE&": - return await ResponsePause(steamID, true, args[1]).ConfigureAwait(false); + return await ResponsePause(access, true, args[1]).ConfigureAwait(false); case "PLAY" when args.Length > 2: - return await ResponsePlay(steamID, args[1], Utilities.GetArgsAsText(message, 2)).ConfigureAwait(false); + return await ResponsePlay(access, args[1], Utilities.GetArgsAsText(message, 2)).ConfigureAwait(false); case "PLAY": - return await ResponsePlay(steamID, args[1]).ConfigureAwait(false); + return await ResponsePlay(access, args[1]).ConfigureAwait(false); case "POINTS": - return await ResponsePointsBalance(steamID, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); + return await ResponsePointsBalance(access, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); case "PRIVACY" when args.Length > 2: - return await ResponsePrivacy(steamID, args[1], Utilities.GetArgsAsText(args, 2, ",")).ConfigureAwait(false); + return await ResponsePrivacy(access, args[1], Utilities.GetArgsAsText(args, 2, ",")).ConfigureAwait(false); case "PRIVACY": - return await ResponsePrivacy(steamID, args[1]).ConfigureAwait(false); + return await ResponsePrivacy(access, args[1]).ConfigureAwait(false); case "R" when args.Length > 2: case "REDEEM" when args.Length > 2: - return await ResponseRedeem(steamID, args[1], Utilities.GetArgsAsText(args, 2, ",")).ConfigureAwait(false); + return await ResponseRedeem(access, args[1], Utilities.GetArgsAsText(args, 2, ","), steamID).ConfigureAwait(false); case "R": case "REDEEM": - return await ResponseRedeem(steamID, args[1]).ConfigureAwait(false); + return await ResponseRedeem(access, args[1], steamID).ConfigureAwait(false); case "R^" when args.Length > 3: case "REDEEM^" when args.Length > 3: - return await ResponseAdvancedRedeem(steamID, args[1], args[2], Utilities.GetArgsAsText(args, 3, ",")).ConfigureAwait(false); + return await ResponseAdvancedRedeem(access, args[1], args[2], Utilities.GetArgsAsText(args, 3, ","), steamID).ConfigureAwait(false); case "R^" when args.Length > 2: case "REDEEM^" when args.Length > 2: - return await ResponseAdvancedRedeem(steamID, args[1], args[2]).ConfigureAwait(false); + return await ResponseAdvancedRedeem(access, args[1], args[2], steamID).ConfigureAwait(false); case "RESET": - return await ResponseReset(steamID, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); + return await ResponseReset(access, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); case "RESUME": - return await ResponseResume(steamID, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); + return await ResponseResume(access, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); case "START": - return await ResponseStart(steamID, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); + return await ResponseStart(access, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); case "STATUS": - return await ResponseStatus(steamID, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); + return await ResponseStatus(access, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); case "STOP": - return await ResponseStop(steamID, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); + return await ResponseStop(access, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); case "TB": - return await ResponseTradingBlacklist(steamID, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); + return await ResponseTradingBlacklist(access, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); case "TBADD" when args.Length > 2: - return await ResponseTradingBlacklistAdd(steamID, args[1], Utilities.GetArgsAsText(args, 2, ",")).ConfigureAwait(false); + return await ResponseTradingBlacklistAdd(access, args[1], Utilities.GetArgsAsText(args, 2, ",")).ConfigureAwait(false); case "TBADD": - return ResponseTradingBlacklistAdd(steamID, args[1]); + return ResponseTradingBlacklistAdd(access, args[1]); case "TBRM" when args.Length > 2: - return await ResponseTradingBlacklistRemove(steamID, args[1], Utilities.GetArgsAsText(args, 2, ",")).ConfigureAwait(false); + return await ResponseTradingBlacklistRemove(access, args[1], Utilities.GetArgsAsText(args, 2, ",")).ConfigureAwait(false); case "TBRM": - return ResponseTradingBlacklistRemove(steamID, args[1]); + return ResponseTradingBlacklistRemove(access, args[1]); case "TRANSFER" when args.Length > 2: - return await ResponseTransfer(steamID, args[1], Utilities.GetArgsAsText(message, 2)).ConfigureAwait(false); + return await ResponseTransfer(access, args[1], Utilities.GetArgsAsText(message, 2)).ConfigureAwait(false); case "TRANSFER": - return await ResponseTransfer(steamID, args[1]).ConfigureAwait(false); + return await ResponseTransfer(access, args[1]).ConfigureAwait(false); case "TRANSFER^" when args.Length > 4: - return await ResponseAdvancedTransfer(steamID, args[1], args[2], args[3], Utilities.GetArgsAsText(message, 4)).ConfigureAwait(false); + return await ResponseAdvancedTransfer(access, args[1], args[2], args[3], Utilities.GetArgsAsText(message, 4)).ConfigureAwait(false); case "TRANSFER^" when args.Length > 3: - return await ResponseAdvancedTransfer(steamID, args[1], args[2], args[3]).ConfigureAwait(false); + return await ResponseAdvancedTransfer(access, args[1], args[2], args[3]).ConfigureAwait(false); case "TRANSFER@" when args.Length > 3: - return await ResponseTransferByRealAppIDs(steamID, args[1], args[2], Utilities.GetArgsAsText(message, 3)).ConfigureAwait(false); + return await ResponseTransferByRealAppIDs(access, args[1], args[2], Utilities.GetArgsAsText(message, 3)).ConfigureAwait(false); case "TRANSFER@" when args.Length > 2: - return await ResponseTransferByRealAppIDs(steamID, args[1], args[2]).ConfigureAwait(false); + return await ResponseTransferByRealAppIDs(access, args[1], args[2]).ConfigureAwait(false); case "TRANSFER%" when args.Length > 3: - return await ResponseTransferByRealAppIDs(steamID, args[1], args[2], Utilities.GetArgsAsText(message, 3), true).ConfigureAwait(false); + return await ResponseTransferByRealAppIDs(access, args[1], args[2], Utilities.GetArgsAsText(message, 3), true).ConfigureAwait(false); case "TRANSFER%" when args.Length > 2: - return await ResponseTransferByRealAppIDs(steamID, args[1], args[2], true).ConfigureAwait(false); + return await ResponseTransferByRealAppIDs(access, args[1], args[2], true).ConfigureAwait(false); case "UNPACK": - return await ResponseUnpackBoosters(steamID, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); + return await ResponseUnpackBoosters(access, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); default: - string? pluginsResponse = await PluginsCore.OnBotCommand(Bot, steamID, message, args).ConfigureAwait(false); + string? pluginsResponse = await PluginsCore.OnBotCommand(Bot, access, message, args, steamID).ConfigureAwait(false); - return !string.IsNullOrEmpty(pluginsResponse) ? pluginsResponse : ResponseUnknown(steamID); + return !string.IsNullOrEmpty(pluginsResponse) ? pluginsResponse : ResponseUnknown(access); } } } @@ -352,9 +365,11 @@ public sealed class Commands { message = message[commandPrefix.Length..]; } - Task responseTask = Response(steamID, message); + EAccess access = Bot.GetAccess(steamID); - bool feedback = Bot.HasAccess(steamID, BotConfig.EAccess.FamilySharing); + Task responseTask = Response(access, message); + + bool feedback = access >= EAccess.FamilySharing; if (feedback && !responseTask.IsCompleted) { if (!await Bot.SendTypingMessage(steamID).ConfigureAwait(false)) { @@ -429,9 +444,11 @@ public sealed class Commands { message = message[commandPrefix.Length..]; } - Task responseTask = Response(steamID, message); + EAccess access = Bot.GetAccess(steamID); - bool feedback = Bot.HasAccess(steamID, BotConfig.EAccess.FamilySharing); + Task responseTask = Response(access, message); + + bool feedback = access >= EAccess.FamilySharing; if (feedback && !responseTask.IsCompleted) { string pleaseWaitMessage = FormatBotResponse(Strings.PleaseWait); @@ -499,12 +516,12 @@ public sealed class Commands { return gamesOwned; } - private async Task Response2FA(ulong steamID) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private async Task Response2FA(EAccess access) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } @@ -513,9 +530,9 @@ public sealed class Commands { return FormatBotResponse(success && !string.IsNullOrEmpty(token) ? string.Format(CultureInfo.CurrentCulture, Strings.BotAuthenticatorToken, token) : string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, message)); } - private static async Task Response2FA(ulong steamID, string botNames) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task Response2FA(EAccess access, string botNames) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -525,22 +542,22 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.Response2FA(steamID))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.Response2FA(access))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private async Task Response2FAConfirm(ulong steamID, bool confirm) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private async Task Response2FAConfirm(EAccess access, bool confirm) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } @@ -557,9 +574,9 @@ public sealed class Commands { return FormatBotResponse(success ? message : string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, message)); } - private static async Task Response2FAConfirm(ulong steamID, string botNames, bool confirm) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task Response2FAConfirm(EAccess access, string botNames, bool confirm) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -569,26 +586,26 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.Response2FAConfirm(steamID, confirm))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.Response2FAConfirm(access, confirm))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private async Task ResponseAddLicense(ulong steamID, string query) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private async Task ResponseAddLicense(EAccess access, string query) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(query)) { throw new ArgumentNullException(nameof(query)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Operator)) { + if (access < EAccess.Operator) { return null; } @@ -651,9 +668,9 @@ public sealed class Commands { return response.Length > 0 ? response.ToString() : null; } - private static async Task ResponseAddLicense(ulong steamID, string botNames, string query) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseAddLicense(EAccess access, string botNames, string query) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -667,19 +684,19 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseAddLicense(steamID, query))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseAddLicense(access, query))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private async Task ResponseAdvancedLoot(ulong steamID, string targetAppID, string targetContextID) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private async Task ResponseAdvancedLoot(EAccess access, string targetAppID, string targetContextID) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(targetAppID)) { @@ -690,7 +707,7 @@ public sealed class Commands { throw new ArgumentNullException(nameof(targetContextID)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } @@ -711,9 +728,9 @@ public sealed class Commands { return FormatBotResponse(success ? message : string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, message)); } - private static async Task ResponseAdvancedLoot(ulong steamID, string botNames, string appID, string contextID) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseAdvancedLoot(EAccess access, string botNames, string appID, string contextID) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -731,19 +748,19 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseAdvancedLoot(steamID, appID, contextID))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseAdvancedLoot(access, appID, contextID))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private async Task ResponseAdvancedRedeem(ulong steamID, string options, string keys) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private async Task ResponseAdvancedRedeem(EAccess access, string options, string keys, ulong steamID = 0) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(options)) { @@ -754,7 +771,7 @@ public sealed class Commands { throw new ArgumentNullException(nameof(keys)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Operator)) { + if (access < EAccess.Operator) { return null; } @@ -823,12 +840,12 @@ public sealed class Commands { } } - return await ResponseRedeem(steamID, keys, redeemFlags).ConfigureAwait(false); + return await ResponseRedeem(access, keys, steamID, redeemFlags).ConfigureAwait(false); } - private static async Task ResponseAdvancedRedeem(ulong steamID, string botNames, string options, string keys) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseAdvancedRedeem(EAccess access, string botNames, string options, string keys, ulong steamID = 0) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -846,19 +863,19 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseAdvancedRedeem(steamID, options, keys))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseAdvancedRedeem(access, options, keys, steamID))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private async Task ResponseAdvancedTransfer(ulong steamID, uint appID, ulong contextID, Bot targetBot) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private async Task ResponseAdvancedTransfer(EAccess access, uint appID, ulong contextID, Bot targetBot) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (appID == 0) { @@ -871,7 +888,7 @@ public sealed class Commands { ArgumentNullException.ThrowIfNull(targetBot); - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } @@ -888,9 +905,9 @@ public sealed class Commands { return FormatBotResponse(success ? message : string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, message)); } - private async Task ResponseAdvancedTransfer(ulong steamID, string targetAppID, string targetContextID, string botNameTo) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private async Task ResponseAdvancedTransfer(EAccess access, string targetAppID, string targetContextID, string botNameTo) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(targetAppID)) { @@ -908,7 +925,7 @@ public sealed class Commands { Bot? targetBot = Bot.GetBot(botNameTo); if (targetBot == null) { - return ASF.IsOwner(steamID) ? FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNameTo)) : null; + return access >= EAccess.Owner ? FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNameTo)) : null; } if (!uint.TryParse(targetAppID, out uint appID) || (appID == 0)) { @@ -919,12 +936,12 @@ public sealed class Commands { return FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, nameof(contextID))); } - return await ResponseAdvancedTransfer(steamID, appID, contextID, targetBot).ConfigureAwait(false); + return await ResponseAdvancedTransfer(access, appID, contextID, targetBot).ConfigureAwait(false); } - private static async Task ResponseAdvancedTransfer(ulong steamID, string botNames, string targetAppID, string targetContextID, string botNameTo) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseAdvancedTransfer(EAccess access, string botNames, string targetAppID, string targetContextID, string botNameTo) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -946,7 +963,7 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } if (!uint.TryParse(targetAppID, out uint appID) || (appID == 0)) { @@ -960,22 +977,22 @@ public sealed class Commands { Bot? targetBot = Bot.GetBot(botNameTo); if (targetBot == null) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNameTo)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNameTo)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseAdvancedTransfer(steamID, appID, contextID, targetBot))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseAdvancedTransfer(access, appID, contextID, targetBot))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private string? ResponseBackgroundGamesRedeemer(ulong steamID) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private string? ResponseBackgroundGamesRedeemer(EAccess access) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } @@ -984,9 +1001,9 @@ public sealed class Commands { return FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotGamesToRedeemInBackgroundCount, count)); } - private static async Task ResponseBackgroundGamesRedeemer(ulong steamID, string botNames) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseBackgroundGamesRedeemer(EAccess access, string botNames) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -996,19 +1013,19 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseBackgroundGamesRedeemer(steamID)))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseBackgroundGamesRedeemer(access)))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private static string? ResponseEncrypt(ulong steamID, string cryptoMethodText, string stringToEncrypt) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static string? ResponseEncrypt(EAccess access, string cryptoMethodText, string stringToEncrypt) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(cryptoMethodText)) { @@ -1019,7 +1036,7 @@ public sealed class Commands { throw new ArgumentNullException(nameof(stringToEncrypt)); } - if (!ASF.IsOwner(steamID)) { + if (access < EAccess.Owner) { return null; } @@ -1032,12 +1049,12 @@ public sealed class Commands { return FormatStaticResponse(!string.IsNullOrEmpty(encryptedString) ? string.Format(CultureInfo.CurrentCulture, Strings.Result, encryptedString) : Strings.WarningFailed); } - private static string? ResponseExit(ulong steamID) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static string? ResponseExit(EAccess access) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } - if (!ASF.IsOwner(steamID)) { + if (access < EAccess.Owner) { return null; } @@ -1046,12 +1063,12 @@ public sealed class Commands { return FormatStaticResponse(success ? message : string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, message)); } - private async Task ResponseFarm(ulong steamID) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private async Task ResponseFarm(EAccess access) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } @@ -1068,9 +1085,9 @@ public sealed class Commands { return FormatBotResponse(Strings.Done); } - private static async Task ResponseFarm(ulong steamID, string botNames) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseFarm(EAccess access, string botNames) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -1080,27 +1097,27 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseFarm(steamID))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseFarm(access))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private string? ResponseFarmingBlacklist(ulong steamID) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private string? ResponseFarmingBlacklist(EAccess access) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } - return !Bot.HasAccess(steamID, BotConfig.EAccess.Master) ? null : FormatBotResponse(Bot.BotDatabase.FarmingBlacklistAppIDs.Count == 0 ? string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(Bot.BotDatabase.FarmingBlacklistAppIDs)) : string.Join(", ", Bot.BotDatabase.FarmingBlacklistAppIDs)); + return access < EAccess.Master ? null : FormatBotResponse(Bot.BotDatabase.FarmingBlacklistAppIDs.Count == 0 ? string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(Bot.BotDatabase.FarmingBlacklistAppIDs)) : string.Join(", ", Bot.BotDatabase.FarmingBlacklistAppIDs)); } - private static async Task ResponseFarmingBlacklist(ulong steamID, string botNames) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseFarmingBlacklist(EAccess access, string botNames) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -1110,26 +1127,26 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseFarmingBlacklist(steamID)))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseFarmingBlacklist(access)))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private string? ResponseFarmingBlacklistAdd(ulong steamID, string targetAppIDs) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private string? ResponseFarmingBlacklistAdd(EAccess access, string targetAppIDs) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(targetAppIDs)) { throw new ArgumentNullException(nameof(targetAppIDs)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } @@ -1165,9 +1182,9 @@ public sealed class Commands { return FormatBotResponse(Strings.Done); } - private static async Task ResponseFarmingBlacklistAdd(ulong steamID, string botNames, string targetAppIDs) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseFarmingBlacklistAdd(EAccess access, string botNames, string targetAppIDs) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -1181,26 +1198,26 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseFarmingBlacklistAdd(steamID, targetAppIDs)))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseFarmingBlacklistAdd(access, targetAppIDs)))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private string? ResponseFarmingBlacklistRemove(ulong steamID, string targetAppIDs) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private string? ResponseFarmingBlacklistRemove(EAccess access, string targetAppIDs) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(targetAppIDs)) { throw new ArgumentNullException(nameof(targetAppIDs)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } @@ -1231,9 +1248,9 @@ public sealed class Commands { return FormatBotResponse(Strings.Done); } - private static async Task ResponseFarmingBlacklistRemove(ulong steamID, string botNames, string targetAppIDs) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseFarmingBlacklistRemove(EAccess access, string botNames, string targetAppIDs) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -1247,27 +1264,27 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseFarmingBlacklistRemove(steamID, targetAppIDs)))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseFarmingBlacklistRemove(access, targetAppIDs)))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private string? ResponseFarmingQueue(ulong steamID) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private string? ResponseFarmingQueue(EAccess access) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } - return !Bot.HasAccess(steamID, BotConfig.EAccess.Master) ? null : FormatBotResponse(Bot.BotDatabase.FarmingPriorityQueueAppIDs.Count == 0 ? string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(Bot.BotDatabase.FarmingPriorityQueueAppIDs)) : string.Join(", ", Bot.BotDatabase.FarmingPriorityQueueAppIDs)); + return access < EAccess.Master ? null : FormatBotResponse(Bot.BotDatabase.FarmingPriorityQueueAppIDs.Count == 0 ? string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(Bot.BotDatabase.FarmingPriorityQueueAppIDs)) : string.Join(", ", Bot.BotDatabase.FarmingPriorityQueueAppIDs)); } - private static async Task ResponseFarmingQueue(ulong steamID, string botNames) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseFarmingQueue(EAccess access, string botNames) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -1277,26 +1294,26 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseFarmingQueue(steamID)))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseFarmingQueue(access)))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private string? ResponseFarmingQueueAdd(ulong steamID, string targetAppIDs) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private string? ResponseFarmingQueueAdd(EAccess access, string targetAppIDs) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(targetAppIDs)) { throw new ArgumentNullException(nameof(targetAppIDs)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } @@ -1339,9 +1356,9 @@ public sealed class Commands { return FormatBotResponse(Strings.Done); } - private static async Task ResponseFarmingQueueAdd(ulong steamID, string botNames, string targetAppIDs) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseFarmingQueueAdd(EAccess access, string botNames, string targetAppIDs) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -1355,26 +1372,26 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseFarmingQueueAdd(steamID, targetAppIDs)))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseFarmingQueueAdd(access, targetAppIDs)))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private string? ResponseFarmingQueueRemove(ulong steamID, string targetAppIDs) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private string? ResponseFarmingQueueRemove(EAccess access, string targetAppIDs) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(targetAppIDs)) { throw new ArgumentNullException(nameof(targetAppIDs)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } @@ -1410,9 +1427,9 @@ public sealed class Commands { return FormatBotResponse(Strings.Done); } - private static async Task ResponseFarmingQueueRemove(ulong steamID, string botNames, string targetAppIDs) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseFarmingQueueRemove(EAccess access, string botNames, string targetAppIDs) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -1426,19 +1443,19 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseFarmingQueueRemove(steamID, targetAppIDs)))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseFarmingQueueRemove(access, targetAppIDs)))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private static string? ResponseHash(ulong steamID, string hashingMethodText, string stringToHash) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static string? ResponseHash(EAccess access, string hashingMethodText, string stringToHash) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(hashingMethodText)) { @@ -1449,7 +1466,7 @@ public sealed class Commands { throw new ArgumentNullException(nameof(stringToHash)); } - if (!ASF.IsOwner(steamID)) { + if (access < EAccess.Owner) { return null; } @@ -1462,17 +1479,17 @@ public sealed class Commands { return FormatStaticResponse(!string.IsNullOrEmpty(hash) ? string.Format(CultureInfo.CurrentCulture, Strings.Result, hash) : Strings.WarningFailed); } - private string? ResponseHelp(ulong steamID) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private string? ResponseHelp(EAccess access) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } - return Bot.HasAccess(steamID, BotConfig.EAccess.FamilySharing) ? FormatBotResponse($"{SharedInfo.ProjectURL}/wiki/Commands") : null; + return access >= EAccess.FamilySharing ? FormatBotResponse($"{SharedInfo.ProjectURL}/wiki/Commands") : null; } - private string? ResponseInput(ulong steamID, string propertyName, string inputValue) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private string? ResponseInput(EAccess access, string propertyName, string inputValue) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(propertyName)) { @@ -1483,7 +1500,7 @@ public sealed class Commands { throw new ArgumentNullException(nameof(inputValue)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } @@ -1502,9 +1519,9 @@ public sealed class Commands { return FormatBotResponse(result ? Strings.Done : Strings.WarningFailed); } - private static async Task ResponseInput(ulong steamID, string botNames, string propertyName, string inputValue) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseInput(EAccess access, string botNames, string propertyName, string inputValue) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -1522,22 +1539,22 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseInput(steamID, propertyName, inputValue)))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseInput(access, propertyName, inputValue)))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private async Task ResponseLevel(ulong steamID) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private async Task ResponseLevel(EAccess access) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } @@ -1550,9 +1567,9 @@ public sealed class Commands { return FormatBotResponse(level.HasValue ? string.Format(CultureInfo.CurrentCulture, Strings.BotLevel, level.Value) : Strings.WarningFailed); } - private static async Task ResponseLevel(ulong steamID, string botNames) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseLevel(EAccess access, string botNames) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -1562,22 +1579,22 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseLevel(steamID))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseLevel(access))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private async Task ResponseLoot(ulong steamID) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private async Task ResponseLoot(EAccess access) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } @@ -1594,9 +1611,9 @@ public sealed class Commands { return FormatBotResponse(success ? message : string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, message)); } - private static async Task ResponseLoot(ulong steamID, string botNames) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseLoot(EAccess access, string botNames) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -1606,26 +1623,26 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseLoot(steamID))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseLoot(access))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private async Task ResponseLootByRealAppIDs(ulong steamID, string realAppIDsText, bool exclude = false) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private async Task ResponseLootByRealAppIDs(EAccess access, string realAppIDsText, bool exclude = false) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(realAppIDsText)) { throw new ArgumentNullException(nameof(realAppIDsText)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } @@ -1658,9 +1675,9 @@ public sealed class Commands { return FormatBotResponse(success ? message : string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, message)); } - private static async Task ResponseLootByRealAppIDs(ulong steamID, string botNames, string realAppIDsText, bool exclude = false) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseLootByRealAppIDs(EAccess access, string botNames, string realAppIDsText, bool exclude = false) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -1674,27 +1691,27 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseLootByRealAppIDs(steamID, realAppIDsText, exclude))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseLootByRealAppIDs(access, realAppIDsText, exclude))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private string? ResponseMatchActivelyBlacklist(ulong steamID) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private string? ResponseMatchActivelyBlacklist(EAccess access) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } - return !Bot.HasAccess(steamID, BotConfig.EAccess.Master) ? null : FormatBotResponse(Bot.BotDatabase.MatchActivelyBlacklistAppIDs.Count == 0 ? string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(Bot.BotDatabase.MatchActivelyBlacklistAppIDs)) : string.Join(", ", Bot.BotDatabase.MatchActivelyBlacklistAppIDs)); + return access < EAccess.Master ? null : FormatBotResponse(Bot.BotDatabase.MatchActivelyBlacklistAppIDs.Count == 0 ? string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(Bot.BotDatabase.MatchActivelyBlacklistAppIDs)) : string.Join(", ", Bot.BotDatabase.MatchActivelyBlacklistAppIDs)); } - private static async Task ResponseMatchActivelyBlacklist(ulong steamID, string botNames) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseMatchActivelyBlacklist(EAccess access, string botNames) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -1704,26 +1721,26 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseMatchActivelyBlacklist(steamID)))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseMatchActivelyBlacklist(access)))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private string? ResponseMatchActivelyBlacklistAdd(ulong steamID, string targetAppIDs) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private string? ResponseMatchActivelyBlacklistAdd(EAccess access, string targetAppIDs) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(targetAppIDs)) { throw new ArgumentNullException(nameof(targetAppIDs)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } @@ -1746,9 +1763,9 @@ public sealed class Commands { return FormatBotResponse(Bot.BotDatabase.MatchActivelyBlacklistAppIDs.AddRange(appIDs) ? Strings.Done : Strings.NothingFound); } - private static async Task ResponseMatchActivelyBlacklistAdd(ulong steamID, string botNames, string targetAppIDs) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseMatchActivelyBlacklistAdd(EAccess access, string botNames, string targetAppIDs) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -1762,26 +1779,26 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseMatchActivelyBlacklistAdd(steamID, targetAppIDs)))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseMatchActivelyBlacklistAdd(access, targetAppIDs)))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private string? ResponseMatchActivelyBlacklistRemove(ulong steamID, string targetAppIDs) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private string? ResponseMatchActivelyBlacklistRemove(EAccess access, string targetAppIDs) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(targetAppIDs)) { throw new ArgumentNullException(nameof(targetAppIDs)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } @@ -1804,9 +1821,9 @@ public sealed class Commands { return FormatBotResponse(Bot.BotDatabase.MatchActivelyBlacklistAppIDs.RemoveRange(appIDs) ? Strings.Done : Strings.NothingFound); } - private static async Task ResponseMatchActivelyBlacklistRemove(ulong steamID, string botNames, string targetAppIDs) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseMatchActivelyBlacklistRemove(EAccess access, string botNames, string targetAppIDs) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -1820,26 +1837,26 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseMatchActivelyBlacklistRemove(steamID, targetAppIDs)))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseMatchActivelyBlacklistRemove(access, targetAppIDs)))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private string? ResponseNickname(ulong steamID, string nickname) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private string? ResponseNickname(EAccess access, string nickname) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(nickname)) { throw new ArgumentNullException(nameof(nickname)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } @@ -1852,9 +1869,9 @@ public sealed class Commands { return FormatBotResponse(Strings.Done); } - private static async Task ResponseNickname(ulong steamID, string botNames, string nickname) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseNickname(EAccess access, string botNames, string nickname) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -1868,26 +1885,26 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseNickname(steamID, nickname)))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseNickname(access, nickname)))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private async Task<(string? Response, Dictionary? OwnedGames)> ResponseOwns(ulong steamID, string query) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private async Task<(string? Response, Dictionary? OwnedGames)> ResponseOwns(EAccess access, string query) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(query)) { throw new ArgumentNullException(nameof(query)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Operator)) { + if (access < EAccess.Operator) { return (null, null); } @@ -2030,9 +2047,9 @@ public sealed class Commands { return (response.Length > 0 ? response.ToString() : FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotOwnedYet, query)), result); } - private static async Task ResponseOwns(ulong steamID, string botNames, string query) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseOwns(EAccess access, string botNames, string query) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -2046,10 +2063,10 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList<(string? Response, Dictionary? OwnedGames)> results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseOwns(steamID, query))).ConfigureAwait(false); + IList<(string? Response, Dictionary? OwnedGames)> results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseOwns(access, query))).ConfigureAwait(false); List<(string Response, Dictionary OwnedGames)> validResults = new(results.Where(static result => !string.IsNullOrEmpty(result.Response) && (result.OwnedGames != null))!); @@ -2078,16 +2095,16 @@ public sealed class Commands { return string.Join(Environment.NewLine, validResults.Select(static result => result.Response).Concat(extraResponses)); } - private async Task ResponsePause(ulong steamID, bool permanent, string? resumeInSecondsText = null) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private async Task ResponsePause(EAccess access, bool permanent, string? resumeInSecondsText = null) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.FamilySharing)) { + if (access < EAccess.FamilySharing) { return null; } - if (permanent && !Bot.HasAccess(steamID, BotConfig.EAccess.Operator)) { + if (permanent && (access < EAccess.Operator)) { return FormatBotResponse(Strings.ErrorAccessDenied); } @@ -2102,9 +2119,9 @@ public sealed class Commands { return FormatBotResponse(success ? message : string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, message)); } - private static async Task ResponsePause(ulong steamID, string botNames, bool permanent, string? resumeInSecondsText = null) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponsePause(EAccess access, string botNames, bool permanent, string? resumeInSecondsText = null) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -2114,19 +2131,19 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponsePause(steamID, permanent, resumeInSecondsText))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponsePause(access, permanent, resumeInSecondsText))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private async Task ResponsePlay(ulong steamID, IReadOnlyCollection gameIDs, string? gameName = null) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private async Task ResponsePlay(EAccess access, IReadOnlyCollection gameIDs, string? gameName = null) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } ArgumentNullException.ThrowIfNull(gameIDs); @@ -2135,7 +2152,7 @@ public sealed class Commands { throw new ArgumentOutOfRangeException(nameof(gameIDs)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } @@ -2148,16 +2165,16 @@ public sealed class Commands { return FormatBotResponse(success ? message : string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, message)); } - private async Task ResponsePlay(ulong steamID, string targetGameIDs) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private async Task ResponsePlay(EAccess access, string targetGameIDs) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(targetGameIDs)) { throw new ArgumentNullException(nameof(targetGameIDs)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } @@ -2192,12 +2209,12 @@ public sealed class Commands { gamesToPlay.Add(gameID); } - return await ResponsePlay(steamID, gamesToPlay, gameName.Length > 0 ? gameName.ToString() : null).ConfigureAwait(false); + return await ResponsePlay(access, gamesToPlay, gameName.Length > 0 ? gameName.ToString() : null).ConfigureAwait(false); } - private static async Task ResponsePlay(ulong steamID, string botNames, string targetGameIDs) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponsePlay(EAccess access, string botNames, string targetGameIDs) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -2211,22 +2228,22 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponsePlay(steamID, targetGameIDs))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponsePlay(access, targetGameIDs))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private async Task ResponsePointsBalance(ulong steamID) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private async Task ResponsePointsBalance(EAccess access) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } @@ -2239,9 +2256,9 @@ public sealed class Commands { return FormatBotResponse(points.HasValue ? string.Format(CultureInfo.CurrentCulture, Strings.BotPointsBalance, points) : Strings.WarningFailed); } - private static async Task ResponsePointsBalance(ulong steamID, string botNames) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponsePointsBalance(EAccess access, string botNames) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -2251,26 +2268,26 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponsePointsBalance(steamID))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponsePointsBalance(access))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private async Task ResponsePrivacy(ulong steamID, string privacySettingsText) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private async Task ResponsePrivacy(EAccess access, string privacySettingsText) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(privacySettingsText)) { throw new ArgumentNullException(nameof(privacySettingsText)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } @@ -2395,9 +2412,9 @@ public sealed class Commands { return FormatBotResponse(await Bot.ArchiWebHandler.ChangePrivacySettings(userPrivacy).ConfigureAwait(false) ? Strings.Success : Strings.WarningFailed); } - private static async Task ResponsePrivacy(ulong steamID, string botNames, string privacySettingsText) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponsePrivacy(EAccess access, string botNames, string privacySettingsText) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -2411,30 +2428,34 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponsePrivacy(steamID, privacySettingsText))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponsePrivacy(access, privacySettingsText))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private async Task ResponseRedeem(ulong steamID, string keysText, ERedeemFlags redeemFlags = ERedeemFlags.None) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private async Task ResponseRedeem(EAccess access, string keysText, ulong steamID = 0, ERedeemFlags redeemFlags = ERedeemFlags.None) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(keysText)) { throw new ArgumentNullException(nameof(keysText)); } + if ((steamID != 0) && !new SteamID(steamID).IsIndividualAccount) { + throw new ArgumentOutOfRangeException(nameof(steamID)); + } + if (Bot.Bots == null) { throw new InvalidOperationException(nameof(Bot.Bots)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Operator)) { + if (access < EAccess.Operator) { return null; } @@ -2470,7 +2491,7 @@ public sealed class Commands { // ReSharper disable once RedundantSuppressNullableWarningExpression - required for .NET Framework string startingKey = key!; - using (IEnumerator botsEnumerator = Bot.Bots.Where(bot => (bot.Value != Bot) && bot.Value.IsConnectedAndLoggedOn && bot.Value.Commands.Bot.HasAccess(steamID, BotConfig.EAccess.Operator)).OrderByDescending(bot => Bot.BotsComparer?.Compare(bot.Key, Bot.BotName) > 0).ThenBy(static bot => bot.Key, Bot.BotsComparer).Select(static bot => bot.Value).GetEnumerator()) { + using (IEnumerator botsEnumerator = Bot.Bots.Where(bot => (bot.Value != Bot) && bot.Value.IsConnectedAndLoggedOn && ((access >= EAccess.Owner) || ((steamID != 0) && (bot.Value.GetAccess(steamID) >= EAccess.Operator)))).OrderByDescending(bot => Bot.BotsComparer?.Compare(bot.Key, Bot.BotName) > 0).ThenBy(static bot => bot.Key, Bot.BotsComparer).Select(static bot => bot.Value).GetEnumerator()) { Bot? currentBot = Bot; while (!string.IsNullOrEmpty(key) && (currentBot != null)) { @@ -2583,7 +2604,7 @@ public sealed class Commands { bool alreadyHandled = false; - foreach (Bot innerBot in Bot.Bots.Where(bot => (bot.Value != currentBot) && (!redeemFlags.HasFlag(ERedeemFlags.SkipInitial) || (bot.Value != Bot)) && !triedBots.Contains(bot.Value) && !rateLimitedBots.Contains(bot.Value) && bot.Value.IsConnectedAndLoggedOn && bot.Value.Commands.Bot.HasAccess(steamID, BotConfig.EAccess.Operator) && ((items.Count == 0) || items.Keys.Any(packageID => !bot.Value.OwnedPackageIDs.ContainsKey(packageID)))).OrderBy(static bot => bot.Key, Bot.BotsComparer).Select(static bot => bot.Value)) { + foreach (Bot innerBot in Bot.Bots.Where(bot => (bot.Value != currentBot) && (!redeemFlags.HasFlag(ERedeemFlags.SkipInitial) || (bot.Value != Bot)) && !triedBots.Contains(bot.Value) && !rateLimitedBots.Contains(bot.Value) && bot.Value.IsConnectedAndLoggedOn && ((access >= EAccess.Owner) || ((steamID != 0) && (bot.Value.GetAccess(steamID) >= EAccess.Operator))) && ((items.Count == 0) || items.Keys.Any(packageID => !bot.Value.OwnedPackageIDs.ContainsKey(packageID)))).OrderBy(static bot => bot.Key, Bot.BotsComparer).Select(static bot => bot.Value)) { // ReSharper disable once RedundantSuppressNullableWarningExpression - required for .NET Framework SteamApps.PurchaseResponseCallback? redeemResult = await innerBot.Actions.RedeemKey(key!).ConfigureAwait(false); @@ -2676,9 +2697,9 @@ public sealed class Commands { return response.Length > 0 ? response.ToString() : null; } - private static async Task ResponseRedeem(ulong steamID, string botNames, string keysText, ERedeemFlags redeemFlags = ERedeemFlags.None) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseRedeem(EAccess access, string botNames, string keysText, ulong steamID = 0, ERedeemFlags redeemFlags = ERedeemFlags.None) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -2692,22 +2713,22 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseRedeem(steamID, keysText, redeemFlags))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseRedeem(access, keysText, steamID, redeemFlags))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private async Task ResponseReset(ulong steamID) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private async Task ResponseReset(EAccess access) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } @@ -2720,9 +2741,9 @@ public sealed class Commands { return FormatBotResponse(Strings.Done); } - private static async Task ResponseReset(ulong steamID, string botNames) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseReset(EAccess access, string botNames) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -2732,22 +2753,22 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseReset(steamID))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseReset(access))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private static string? ResponseRestart(ulong steamID) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static string? ResponseRestart(EAccess access) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } - if (!ASF.IsOwner(steamID)) { + if (access < EAccess.Owner) { return null; } @@ -2756,12 +2777,12 @@ public sealed class Commands { return FormatStaticResponse(success ? message : string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, message)); } - private string? ResponseResume(ulong steamID) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private string? ResponseResume(EAccess access) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.FamilySharing)) { + if (access < EAccess.FamilySharing) { return null; } @@ -2770,9 +2791,9 @@ public sealed class Commands { return FormatBotResponse(success ? message : string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, message)); } - private static async Task ResponseResume(ulong steamID, string botNames) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseResume(EAccess access, string botNames) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -2782,22 +2803,22 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseResume(steamID)))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseResume(access)))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private string? ResponseStart(ulong steamID) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private string? ResponseStart(EAccess access) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } @@ -2806,9 +2827,9 @@ public sealed class Commands { return FormatBotResponse(success ? message : string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, message)); } - private static async Task ResponseStart(ulong steamID, string botNames) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseStart(EAccess access, string botNames) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -2818,22 +2839,22 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseStart(steamID)))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseStart(access)))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private string? ResponseStats(ulong steamID) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private string? ResponseStats(EAccess access) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } - if (!ASF.IsOwner(steamID)) { + if (access < EAccess.Owner) { return null; } @@ -2843,12 +2864,12 @@ public sealed class Commands { return FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotStats, memoryInMegabytes, uptime.ToHumanReadable())); } - private (string? Response, Bot Bot) ResponseStatus(ulong steamID) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private (string? Response, Bot Bot) ResponseStatus(EAccess access) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.FamilySharing)) { + if (access < EAccess.FamilySharing) { return (null, Bot); } @@ -2885,9 +2906,9 @@ public sealed class Commands { return (FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotStatusIdling, soloGame.AppID, soloGame.GameName, soloGame.CardsRemaining, Bot.CardsFarmer.GamesToFarmReadOnly.Count, Bot.CardsFarmer.GamesToFarmReadOnly.Sum(static game => game.CardsRemaining), Bot.CardsFarmer.TimeRemaining.ToHumanReadable())), Bot); } - private static async Task ResponseStatus(ulong steamID, string botNames) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseStatus(EAccess access, string botNames) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -2897,10 +2918,10 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList<(string? Response, Bot Bot)> results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseStatus(steamID)))).ConfigureAwait(false); + IList<(string? Response, Bot Bot)> results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseStatus(access)))).ConfigureAwait(false); List<(string Response, Bot Bot)> validResults = new(results.Where(static result => !string.IsNullOrEmpty(result.Response))!); @@ -2915,12 +2936,12 @@ public sealed class Commands { return string.Join(Environment.NewLine, validResults.Select(static result => result.Response).Union(extraResponse.ToEnumerable())); } - private string? ResponseStop(ulong steamID) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private string? ResponseStop(EAccess access) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } @@ -2929,9 +2950,9 @@ public sealed class Commands { return FormatBotResponse(success ? message : string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, message)); } - private static async Task ResponseStop(ulong steamID, string botNames) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseStop(EAccess access, string botNames) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -2941,27 +2962,27 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseStop(steamID)))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseStop(access)))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private string? ResponseTradingBlacklist(ulong steamID) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private string? ResponseTradingBlacklist(EAccess access) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } - return !Bot.HasAccess(steamID, BotConfig.EAccess.Master) ? null : FormatBotResponse(Bot.BotDatabase.TradingBlacklistSteamIDs.Count == 0 ? string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(Bot.BotDatabase.TradingBlacklistSteamIDs)) : string.Join(", ", Bot.BotDatabase.TradingBlacklistSteamIDs)); + return access < EAccess.Master ? null : FormatBotResponse(Bot.BotDatabase.TradingBlacklistSteamIDs.Count == 0 ? string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(Bot.BotDatabase.TradingBlacklistSteamIDs)) : string.Join(", ", Bot.BotDatabase.TradingBlacklistSteamIDs)); } - private static async Task ResponseTradingBlacklist(ulong steamID, string botNames) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseTradingBlacklist(EAccess access, string botNames) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -2971,26 +2992,26 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseTradingBlacklist(steamID)))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseTradingBlacklist(access)))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private string? ResponseTradingBlacklistAdd(ulong steamID, string targetSteamIDs) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private string? ResponseTradingBlacklistAdd(EAccess access, string targetSteamIDs) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(targetSteamIDs)) { throw new ArgumentNullException(nameof(targetSteamIDs)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } @@ -3013,9 +3034,9 @@ public sealed class Commands { return FormatBotResponse(Bot.BotDatabase.TradingBlacklistSteamIDs.AddRange(targetIDs) ? Strings.Done : Strings.NothingFound); } - private static async Task ResponseTradingBlacklistAdd(ulong steamID, string botNames, string targetSteamIDs) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseTradingBlacklistAdd(EAccess access, string botNames, string targetSteamIDs) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -3029,26 +3050,26 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseTradingBlacklistAdd(steamID, targetSteamIDs)))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseTradingBlacklistAdd(access, targetSteamIDs)))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private string? ResponseTradingBlacklistRemove(ulong steamID, string targetSteamIDs) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private string? ResponseTradingBlacklistRemove(EAccess access, string targetSteamIDs) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(targetSteamIDs)) { throw new ArgumentNullException(nameof(targetSteamIDs)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } @@ -3071,9 +3092,9 @@ public sealed class Commands { return FormatBotResponse(Bot.BotDatabase.TradingBlacklistSteamIDs.RemoveRange(targetIDs) ? Strings.Done : Strings.NothingFound); } - private static async Task ResponseTradingBlacklistRemove(ulong steamID, string botNames, string targetSteamIDs) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseTradingBlacklistRemove(EAccess access, string botNames, string targetSteamIDs) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -3087,26 +3108,26 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseTradingBlacklistRemove(steamID, targetSteamIDs)))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseTradingBlacklistRemove(access, targetSteamIDs)))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private async Task ResponseTransfer(ulong steamID, string botNameTo) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private async Task ResponseTransfer(EAccess access, string botNameTo) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNameTo)) { throw new ArgumentNullException(nameof(botNameTo)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } @@ -3121,7 +3142,7 @@ public sealed class Commands { Bot? targetBot = Bot.GetBot(botNameTo); if (targetBot == null) { - return ASF.IsOwner(steamID) ? FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNameTo)) : null; + return access >= EAccess.Owner ? FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNameTo)) : null; } if (!targetBot.IsConnectedAndLoggedOn) { @@ -3137,9 +3158,9 @@ public sealed class Commands { return FormatBotResponse(success ? message : string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, message)); } - private static async Task ResponseTransfer(ulong steamID, string botNames, string botNameTo) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseTransfer(EAccess access, string botNames, string botNameTo) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -3153,19 +3174,19 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseTransfer(steamID, botNameTo))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseTransfer(access, botNameTo))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private async Task ResponseTransferByRealAppIDs(ulong steamID, IReadOnlyCollection realAppIDs, Bot targetBot, bool exclude = false) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private async Task ResponseTransferByRealAppIDs(EAccess access, IReadOnlyCollection realAppIDs, Bot targetBot, bool exclude = false) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if ((realAppIDs == null) || (realAppIDs.Count == 0)) { @@ -3174,7 +3195,7 @@ public sealed class Commands { ArgumentNullException.ThrowIfNull(targetBot); - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } @@ -3199,9 +3220,9 @@ public sealed class Commands { return FormatBotResponse(success ? message : string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, message)); } - private async Task ResponseTransferByRealAppIDs(ulong steamID, string realAppIDsText, string botNameTo, bool exclude = false) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private async Task ResponseTransferByRealAppIDs(EAccess access, string realAppIDsText, string botNameTo, bool exclude = false) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(realAppIDsText)) { @@ -3212,14 +3233,14 @@ public sealed class Commands { throw new ArgumentNullException(nameof(botNameTo)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } Bot? targetBot = Bot.GetBot(botNameTo); if (targetBot == null) { - return ASF.IsOwner(steamID) ? FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNameTo)) : null; + return access >= EAccess.Owner ? FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNameTo)) : null; } string[] appIDTexts = realAppIDsText.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); @@ -3238,12 +3259,12 @@ public sealed class Commands { realAppIDs.Add(appID); } - return await ResponseTransferByRealAppIDs(steamID, realAppIDs, targetBot, exclude).ConfigureAwait(false); + return await ResponseTransferByRealAppIDs(access, realAppIDs, targetBot, exclude).ConfigureAwait(false); } - private static async Task ResponseTransferByRealAppIDs(ulong steamID, string botNames, string realAppIDsText, string botNameTo, bool exclude = false) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseTransferByRealAppIDs(EAccess access, string botNames, string realAppIDsText, string botNameTo, bool exclude = false) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -3261,7 +3282,7 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } string[] appIDTexts = realAppIDsText.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); @@ -3283,30 +3304,30 @@ public sealed class Commands { Bot? targetBot = Bot.GetBot(botNameTo); if (targetBot == null) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNameTo)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNameTo)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseTransferByRealAppIDs(steamID, realAppIDs, targetBot, exclude))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseTransferByRealAppIDs(access, realAppIDs, targetBot, exclude))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private string? ResponseUnknown(ulong steamID) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private string? ResponseUnknown(EAccess access) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } - return Bot.HasAccess(steamID, BotConfig.EAccess.Operator) ? FormatBotResponse(Strings.UnknownCommand) : null; + return access >= EAccess.Operator ? FormatBotResponse(Strings.UnknownCommand) : null; } - private async Task ResponseUnpackBoosters(ulong steamID) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private async Task ResponseUnpackBoosters(EAccess access) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } @@ -3337,9 +3358,9 @@ public sealed class Commands { return FormatBotResponse(completeSuccess ? Strings.Success : Strings.Done); } - private static async Task ResponseUnpackBoosters(ulong steamID, string botNames) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseUnpackBoosters(EAccess access, string botNames) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -3349,22 +3370,22 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseUnpackBoosters(steamID))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseUnpackBoosters(access))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } - private static async Task ResponseUpdate(ulong steamID) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseUpdate(EAccess access) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } - if (!ASF.IsOwner(steamID)) { + if (access < EAccess.Owner) { return null; } @@ -3373,29 +3394,29 @@ public sealed class Commands { return FormatStaticResponse($"{(success ? Strings.Success : Strings.WarningFailed)}{(!string.IsNullOrEmpty(message) ? $" {message}" : version != null ? $" {version}" : "")}"); } - private string? ResponseVersion(ulong steamID) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private string? ResponseVersion(EAccess access) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } - return Bot.HasAccess(steamID, BotConfig.EAccess.Operator) ? FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotVersion, SharedInfo.ASF, SharedInfo.Version)) : null; + return access >= EAccess.Operator ? FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotVersion, SharedInfo.ASF, SharedInfo.Version)) : null; } - private string? ResponseWalletBalance(ulong steamID) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private string? ResponseWalletBalance(EAccess access) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } - if (!Bot.HasAccess(steamID, BotConfig.EAccess.Master)) { + if (access < EAccess.Master) { return null; } return !Bot.IsConnectedAndLoggedOn ? FormatBotResponse(Strings.BotNotConnected) : FormatBotResponse(Bot.WalletCurrency != ECurrencyCode.Invalid ? string.Format(CultureInfo.CurrentCulture, Strings.BotWalletBalance, Bot.WalletBalance / 100.0, Bot.WalletCurrency.ToString()) : Strings.BotHasNoWallet); } - private static async Task ResponseWalletBalance(ulong steamID, string botNames) { - if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { - throw new ArgumentOutOfRangeException(nameof(steamID)); + private static async Task ResponseWalletBalance(EAccess access, string botNames) { + if (!Enum.IsDefined(typeof(EAccess), access)) { + throw new InvalidEnumArgumentException(nameof(access), (int) access, typeof(EAccess)); } if (string.IsNullOrEmpty(botNames)) { @@ -3405,10 +3426,10 @@ public sealed class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null; } - IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseWalletBalance(steamID)))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseWalletBalance(access)))).ConfigureAwait(false); List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!);