Token and controller commands work
This commit is contained in:
parent
ec1c5958ce
commit
1a2df3e539
8 changed files with 1137 additions and 376 deletions
47
main.py
47
main.py
|
|
@ -114,6 +114,7 @@ def main() -> None:
|
|||
parser.add_argument('--admin-users', type=str, help='Comma-separated list of additional admin users who have the same permissions as the channel owner')
|
||||
parser.add_argument('--config', type=str, default=DEFAULT_CONFIG_PATH,
|
||||
help=f'Path to configuration file (default: {DEFAULT_CONFIG_PATH})')
|
||||
parser.add_argument('--force-new-token', action='store_true', help='Force generation of a new token even if a cached one exists')
|
||||
args: argparse.Namespace = parser.parse_args()
|
||||
|
||||
# Load configuration from file if it exists
|
||||
|
|
@ -180,7 +181,24 @@ def main() -> None:
|
|||
admin_users = config["admin_users"]
|
||||
print(f"Additional admin users from config file: {', '.join(admin_users)}")
|
||||
|
||||
# Create bot instance
|
||||
# Make sure the cache directory exists
|
||||
cache_dir = os.path.dirname(args.token_cache)
|
||||
os.makedirs(cache_dir, exist_ok=True)
|
||||
|
||||
print(f"Using token cache file: {args.token_cache}")
|
||||
if args.force_new_token:
|
||||
print("Forcing new token generation (any cached token will be ignored)")
|
||||
# Remove cached token if forcing new one
|
||||
if os.path.exists(args.token_cache):
|
||||
try:
|
||||
os.remove(args.token_cache)
|
||||
print("Removed existing token cache file")
|
||||
except Exception as e:
|
||||
print(f"Warning: Could not remove existing token cache: {e}")
|
||||
else:
|
||||
print("Using cached token if available")
|
||||
|
||||
# Create bot instance - explicitly pass None for access_token to avoid using env vars
|
||||
bot: TwitchBot = TwitchBot(
|
||||
username=username,
|
||||
client_id=client_id,
|
||||
|
|
@ -188,7 +206,10 @@ def main() -> None:
|
|||
channel=channel,
|
||||
use_queue=args.use_queue,
|
||||
token_cache_file=args.token_cache,
|
||||
admin_users=admin_users
|
||||
admin_users=admin_users,
|
||||
force_new_token=args.force_new_token,
|
||||
access_token=None, # Explicitly set to None to avoid using env vars
|
||||
refresh_token=None # Explicitly set to None to avoid using env vars
|
||||
)
|
||||
|
||||
# Register basic commands
|
||||
|
|
@ -206,9 +227,13 @@ def main() -> None:
|
|||
# Start the Huey consumer if requested
|
||||
if args.start_consumer:
|
||||
try:
|
||||
from src.queue.server import start_consumer
|
||||
from src.queue.server import start_consumer, set_input_mode, get_input_mode
|
||||
import threading
|
||||
|
||||
# Make sure input mode is set before starting consumer
|
||||
if args.game_control and args.input_type:
|
||||
print(f"Consumer will use input mode: {get_input_mode()}")
|
||||
|
||||
consumer_thread = threading.Thread(target=start_consumer)
|
||||
consumer_thread.daemon = True
|
||||
consumer_thread.start()
|
||||
|
|
@ -251,6 +276,18 @@ def main() -> None:
|
|||
print("Falling back to keyboard/mouse input.")
|
||||
args.input_type = 'keyboard'
|
||||
|
||||
# Persist the input type to make it available to the queue consumer process
|
||||
try:
|
||||
from src.queue.server import set_input_mode, INPUT_MODE_KEYBOARD, INPUT_MODE_CONTROLLER
|
||||
if args.input_type == 'keyboard':
|
||||
set_input_mode(INPUT_MODE_KEYBOARD)
|
||||
print(f"Set persistent input mode to keyboard (this will be used by queue consumer)")
|
||||
else:
|
||||
set_input_mode(INPUT_MODE_CONTROLLER)
|
||||
print(f"Set persistent input mode to controller (this will be used by queue consumer)")
|
||||
except ImportError as e:
|
||||
print(f"Warning: Could not set persistent input mode: {e}")
|
||||
|
||||
print(f"Enabling game control in {args.game_mode} mode with {args.input_type} input...")
|
||||
|
||||
if args.input_type == 'keyboard' and not PYNPUT_AVAILABLE:
|
||||
|
|
@ -282,6 +319,7 @@ def main() -> None:
|
|||
if args.input_type == 'controller':
|
||||
print(" pip install vgamepad # For controller support")
|
||||
|
||||
print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxinput type: ", args.input_type)
|
||||
# Start the bot
|
||||
print(f"Starting bot for channel #{channel}")
|
||||
print("Basic commands: !hello, !dice [sides], !echo [message], !8ball")
|
||||
|
|
@ -290,6 +328,9 @@ def main() -> None:
|
|||
if args.use_queue:
|
||||
print("Queue mode enabled, commands will be processed by the queue system")
|
||||
print("Use !qstats to see queue statistics")
|
||||
|
||||
if args.force_new_token:
|
||||
print("Note: Forcing generation of a new authentication token")
|
||||
|
||||
try:
|
||||
# Make sure requests library is installed
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue