I believe this commit closes the core feature loop. Now, it's all about QoL improvements, bugfixes and the dragon for which this project is meant to be a PoC: DELEGATIONmaster
parent
6efeb1b3ec
commit
0712e25b10
@ -0,0 +1,72 @@
|
||||
extends MajorityJudgmentChatCommandJudgmentsProvider
|
||||
class_name MajorityJudgmentTwitchChatProvider
|
||||
|
||||
|
||||
var twitch:TwiCIL
|
||||
var unique_session_identifier:String
|
||||
|
||||
var enable_logging := false # toggle for dev
|
||||
|
||||
|
||||
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 _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?
|
Loading…
Reference in new issue