You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
1.8 KiB
78 lines
1.8 KiB
extends MajorityJudgmentChatCommandJudgmentsProvider
|
|
class_name MajorityJudgmentTwitchChatProvider
|
|
|
|
|
|
var enable_logging := false # toggle for dev
|
|
|
|
|
|
var twitch:TwiCIL
|
|
var unique_session_identifier:String
|
|
|
|
|
|
const Tac = preload("res://gui/forms/twitch_config/TwitchAuthConfig.gd")
|
|
func get_oauth_config():
|
|
var tac = Tac.new()
|
|
return tac.read_from_file()
|
|
|
|
|
|
func start_providing():
|
|
assert(null == self.twitch) # wip
|
|
|
|
var oauth_config = get_oauth_config()
|
|
if not oauth_config:
|
|
printerr(
|
|
"Twitch OAuth config was not set."+
|
|
"You need to set it in the settings."
|
|
)
|
|
return
|
|
|
|
var dt = OS.get_datetime(true)
|
|
self.unique_session_identifier = "%s-%s-%s_%s:%s:%s" % [
|
|
dt['year'],
|
|
dt['month'],
|
|
dt['day'],
|
|
dt['hour'],
|
|
dt['minute'],
|
|
dt['second'],
|
|
]
|
|
|
|
self.twitch = TwiCIL.new()
|
|
self.twitch.name = "TwiCIL"
|
|
self.twitch.set_logging(self.enable_logging)
|
|
App.add_child(self.twitch)
|
|
|
|
var nick = oauth_config['nick']
|
|
var channel = oauth_config['channel']
|
|
var client_id = oauth_config['client']
|
|
var oauth = oauth_config['oauth']
|
|
if not oauth.begins_with('oauth:'):
|
|
oauth = "oauth:%s" % [oauth]
|
|
|
|
self.twitch.connect_to_twitch_chat()
|
|
self.twitch.connect_to_channel(channel, client_id, oauth, nick)
|
|
|
|
var _c = self.twitch.connect("message_received", self, "_on_message_received")
|
|
|
|
|
|
func stop_providing():
|
|
pass
|
|
|
|
|
|
func _on_message_received(user_name:String, text:String, emotes:Array):
|
|
# I. Log it to file
|
|
var log_filepath = "user://twitch_chat_%s.log" % [
|
|
self.unique_session_identifier,
|
|
]
|
|
var log_file = File.new()
|
|
if log_file.file_exists(log_filepath):
|
|
log_file.open(log_filepath, File.READ_WRITE)
|
|
log_file.seek_end()
|
|
OS.get_executable_path()
|
|
else:
|
|
log_file.open(log_filepath, File.WRITE_READ)
|
|
log_file.store_csv_line([user_name, text], ":")
|
|
log_file.close()
|
|
# II. Process it
|
|
process_chat_command(user_name, text)
|
|
# III. Isaac?
|