extends Control # Allow streamers to define their twitch credentials. # Since this config is sensitive, should it be encrypted? # # Generate application # https://dev.twitch.tv/console/apps/create # # Get OAuth Token # https://twitchapps.com/tmi/ var config := { 'nick': '', # whatever you want 'channel': '', # twitch identifier, usually lowercase 'client': '', # Identifies the application registered on twitch 'oauth': '', # https://twitchapps.com/tmi/ } const TWITCH_OAUTH_FILE_PATH = "user://twitch_chat_auth_config.json" onready var OAuthEdit = find_node("OAuthLineEdit") onready var NickEdit = find_node("NickLineEdit") onready var ClientIdEdit = find_node("ClientIdLineEdit") onready var ChannelEdit = find_node("ChannelLineEdit") func _ready(): read_from_file() write_to_ui() # _____ _ _ # | ___(_) | ___ # | |_ | | |/ _ \ # | _| | | | __/ # |_| |_|_|\___| # func read_from_file(): var file = File.new() if not file.file_exists(TWITCH_OAUTH_FILE_PATH): return Dictionary() file.open(TWITCH_OAUTH_FILE_PATH, File.READ) var json = file.get_as_text() var dson = JSON.parse(json) if dson.error: printerr("Auth config file exists but is confusing me.") return null self.config = dson.result file.close() return self.config func write_to_file(): var file = File.new() file.open(TWITCH_OAUTH_FILE_PATH, File.WRITE) file.store_string(JSON.print(self.config, ' ')) file.close() # _ _ ___ # | | | |_ _| # | | | || | # | |_| || | # \___/|___| # func read_from_ui(): self.config['oauth'] = OAuthEdit.text self.config['nick'] = NickEdit.text self.config['channel'] = ChannelEdit.text self.config['client'] = ClientIdEdit.text func write_to_ui(): OAuthEdit.text = self.config['oauth'] NickEdit.text = self.config['nick'] ChannelEdit.text = self.config['channel'] ClientIdEdit.text = self.config['client'] # _____ _ # | ____|_ _____ _ __ | |_ ___ # | _| \ \ / / _ \ '_ \| __/ __| # | |___ \ V / __/ | | | |_\__ \ # |_____| \_/ \___|_| |_|\__|___/ # func _on_SaveButton_pressed(): read_from_ui() write_to_file() App.go_to_main_menu() func _on_CancelButton_pressed(): App.go_to_main_menu() func _on_ClientIdHelpButton_pressed(): var _done = OS.shell_open("https://dev.twitch.tv/dashboard/apps/create") func _on_OAuthHelpButton_pressed(): var _done = OS.shell_open("https://twitchapps.com/tmi/")