mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 14:10:53 +00:00
!input command
This commit is contained in:
@@ -663,6 +663,14 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
return await ResponseRedeem(steamID, args[1], ERedeemFlags.ForceForwarding | ERedeemFlags.SkipInitial).ConfigureAwait(false);
|
||||
case "!INPUT":
|
||||
if(args.Length > 3) {
|
||||
return ResponseInput(steamID, args[1], args[2], args[3]);
|
||||
} else if(args.Length == 3) {
|
||||
return ResponseInput(steamID, BotName, args[1], args[2]);
|
||||
}
|
||||
|
||||
return ResponseUnknown(steamID);
|
||||
case "!RESUME":
|
||||
return await ResponseResume(steamID, args[1]).ConfigureAwait(false);
|
||||
case "!START":
|
||||
@@ -2638,6 +2646,35 @@ namespace ArchiSteamFarm {
|
||||
|
||||
return FormatStaticResponse(Strings.Done);
|
||||
}
|
||||
private string ResponseInput(ulong steamID, string botName, string propertyName, string inputValue) {
|
||||
if(steamID == 0) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(steamID));
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!IsOwner(steamID)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!Program.GlobalConfig.Headless) {
|
||||
//TODO: l10n
|
||||
return "Avaliable only in headless mode!";
|
||||
}
|
||||
|
||||
ASF.EUserInputType inputType = ASF.EUserInputType.Unknown;
|
||||
|
||||
if (!Enum.TryParse<ASF.EUserInputType>(propertyName, out inputType) || inputType == ASF.EUserInputType.Unknown ) {
|
||||
return ResponseUnknown(steamID);
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(inputValue)) {
|
||||
return ResponseUnknown(steamID);
|
||||
}
|
||||
|
||||
Program.SetUserInput(inputType, botName, inputValue);
|
||||
|
||||
return FormatStaticResponse(Strings.Done);
|
||||
}
|
||||
|
||||
private static string ResponseRestart(ulong steamID) {
|
||||
if (steamID == 0) {
|
||||
|
||||
@@ -52,6 +52,8 @@ namespace ArchiSteamFarm {
|
||||
|
||||
private static bool ShutdownSequenceInitialized;
|
||||
|
||||
private static Dictionary<KeyValuePair<string, ASF.EUserInputType>, string> UserInputs = new Dictionary<KeyValuePair<string, ASF.EUserInputType>, string>();
|
||||
|
||||
internal static async Task Exit(byte exitCode = 0) {
|
||||
if (exitCode != 0) {
|
||||
ASF.ArchiLogger.LogGenericError(Strings.ErrorExitingWithNonZeroErrorCode);
|
||||
@@ -66,12 +68,20 @@ namespace ArchiSteamFarm {
|
||||
return null;
|
||||
}
|
||||
|
||||
string result;
|
||||
|
||||
if (GlobalConfig.Headless || !Runtime.IsUserInteractive) {
|
||||
var userInputKey = new KeyValuePair<string, ASF.EUserInputType>(botName, userInputType);
|
||||
if (UserInputs.ContainsKey(userInputKey)) {
|
||||
result = UserInputs[userInputKey];
|
||||
UserInputs.Remove(userInputKey);
|
||||
return result;
|
||||
}
|
||||
|
||||
ASF.ArchiLogger.LogGenericWarning(Strings.ErrorUserInputRunningInHeadlessMode);
|
||||
return null;
|
||||
}
|
||||
|
||||
string result;
|
||||
lock (ConsoleLock) {
|
||||
Logging.OnUserInputStart();
|
||||
switch (userInputType) {
|
||||
@@ -114,6 +124,19 @@ namespace ArchiSteamFarm {
|
||||
return !string.IsNullOrEmpty(result) ? result.Trim() : null;
|
||||
}
|
||||
|
||||
internal static void SetUserInput(ASF.EUserInputType userInputType, string botName, string userInputValue) {
|
||||
if (String.IsNullOrEmpty(botName) || String.IsNullOrEmpty(userInputValue) || userInputType == ASF.EUserInputType.Unknown) {
|
||||
ASF.ArchiLogger.LogGenericWarning(Strings.ErrorObjectIsNull);
|
||||
return;
|
||||
}
|
||||
var userInputKey = new KeyValuePair<string, ASF.EUserInputType>(botName, userInputType);
|
||||
if (UserInputs.ContainsKey(userInputKey)) {
|
||||
UserInputs[userInputKey] = userInputValue;
|
||||
} else {
|
||||
UserInputs.Add(userInputKey, userInputValue);
|
||||
}
|
||||
}
|
||||
|
||||
internal static async Task Restart() {
|
||||
if (!await InitShutdownSequence().ConfigureAwait(false)) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user