diff --git a/addons/majority_judgment/nodes/MajorityJudgmentLinearResultsControl.gd b/addons/majority_judgment/nodes/MajorityJudgmentLinearResultsControl.gd index a2744da..3e220dc 100644 --- a/addons/majority_judgment/nodes/MajorityJudgmentLinearResultsControl.gd +++ b/addons/majority_judgment/nodes/MajorityJudgmentLinearResultsControl.gd @@ -20,60 +20,10 @@ func set_poll(__poll:MajorityJudgmentPoll): craft_nodes() update_nodes() - var provider = MajorityJudgmentDemoProvider.new() +# var provider = MajorityJudgmentDemoProvider.new() + var provider = MajorityJudgmentTwitchChatProvider.new() start_provider(provider) - -# yield(get_tree().create_timer(3), "timeout") -# -# var j = MajorityJudgmentJudgment.new() -# j.set_participant(MajorityJudgmentParticipant.make("Plume")) -# j.set_grade(poll.grading.grades[2]) -# j.set_candidate(poll.candidates[0]) -# poll.add_judgment(j) -# -# var sylvain = MajorityJudgmentParticipant.make("Sylvain") -# j = MajorityJudgmentJudgment.new() -# j.set_participant(sylvain) -# j.set_grade(poll.grading.grades[3]) -# j.set_candidate(poll.candidates[0]) -# poll.add_judgment(j) -# j = MajorityJudgmentJudgment.new() -# j.set_participant(sylvain) -# j.set_grade(poll.grading.grades[3]) -# j.set_candidate(poll.candidates[1]) -# poll.add_judgment(j) -# j = MajorityJudgmentJudgment.new() -# j.set_participant(sylvain) -# j.set_grade(poll.grading.grades[4]) -# j.set_candidate(poll.candidates[2]) -# poll.add_judgment(j) -# -# j = MajorityJudgmentJudgment.new() -# j.set_participant(MajorityJudgmentParticipant.make("Sabre")) -# j.set_grade(poll.grading.grades[5]) -# j.set_candidate(poll.candidates[0]) -# poll.add_judgment(j) -# -# update_nodes() -# -# yield(get_tree().create_timer(2), "timeout") -# -# var tiger = MajorityJudgmentParticipant.make("Tiger") -# j = MajorityJudgmentJudgment.new() -# j.set_participant(tiger) -# j.set_grade(poll.grading.grades[4]) -# j.set_candidate(poll.candidates[0]) -# poll.add_judgment(j) -# update_nodes() -# -# yield(get_tree().create_timer(2), "timeout") -# -# j = MajorityJudgmentJudgment.new() -# j.set_participant(tiger) -# j.set_grade(poll.grading.grades[1]) -# j.set_candidate(poll.candidates[2]) -# poll.add_judgment(j) -# update_nodes() + var profiles_nodes := Array() func craft_nodes(): @@ -129,51 +79,6 @@ func update_nodes(): candidate_index += 1 -#func test(): -# var poll : MajorityJudgmentPoll = MajorityJudgmentPoll.make( -# "Test", -# MajorityJudgmentGrading.make_quality_6(), -# [ -# MajorityJudgmentCandidate.make("Candidate A"), -# MajorityJudgmentCandidate.make("Candidate B"), -# MajorityJudgmentCandidate.make("Candidate C"), -# ] -# ) -# -# var poll_tally = MajorityJudgmentPollTally.new() -# poll_tally.poll = poll -# var candidate_tallies = Array() -# var candidate_tally := MajorityJudgmentCandidateTally.new() -# candidate_tally.poll = poll -# candidate_tally.merit_profile = MajorityJudgmentCandidateMeritProfile.new() -# candidate_tally.merit_profile.grades = [ -# 10, -# 2, -# 5, -# 7, -# 1, -# 11, -# ] -# candidate_tally.merit_profile.candidate_tally = candidate_tally -# candidate_tallies.append(candidate_tally) -# create_merit_profile_scene(candidate_tally.merit_profile) -# -## candidate_tally = MajorityJudgmentCandidateTally.new() -## candidate_tally.merit_profile = MajorityJudgmentCandidateMeritProfile.new() -## candidate_tally.merit_profile.grades = [ -## 2, -## 7, -## 10, -## 11, -## 1, -## 5, -## ] -## candidate_tallies.append(candidate_tally) -## create_merit_profile_scene(candidate_tally.merit_profile) -# -# poll_tally.candidates_tallies = candidate_tallies - - func create_merit_profile_scene(gradation_size:int): var mps = MeritProfileScene.instance() mps.set_poll(get_poll()) @@ -202,7 +107,20 @@ func get_or_create_participant(identifier:String) -> MajorityJudgmentParticipant func __on_judgment_emitted(author_identifier, grade_index, candidate_index): # Data comes from userland, best be careful here - + if ( + grade_index < 0 + or + grade_index >= poll.grading.grades.size() + ): +# printerr("Ignoring grade #%d since it's out of range.") + return + if ( + candidate_index < 0 + or + candidate_index >= poll.candidates.size() + ): +# printerr("Ignoring candidate %s since it's out of range." % [char(candidate_index)]) + return var j = MajorityJudgmentJudgment.new() j.set_participant(get_or_create_participant(author_identifier)) @@ -212,6 +130,3 @@ func __on_judgment_emitted(author_identifier, grade_index, candidate_index): update_nodes() - - - diff --git a/addons/majority_judgment/providers/MajorityJudgmentTwitchChatProvider.gd b/addons/majority_judgment/providers/MajorityJudgmentTwitchChatProvider.gd new file mode 100644 index 0000000..f0fc428 --- /dev/null +++ b/addons/majority_judgment/providers/MajorityJudgmentTwitchChatProvider.gd @@ -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? diff --git a/project.godot b/project.godot index 9058d8d..c0f4bb1 100644 --- a/project.godot +++ b/project.godot @@ -144,6 +144,11 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://addons/majority_judgment/MajorityJudgmentPollTally.gd" }, { +"base": "MajorityJudgmentChatCommandJudgmentsProvider", +"class": "MajorityJudgmentTwitchChatProvider", +"language": "GDScript", +"path": "res://addons/majority_judgment/providers/MajorityJudgmentTwitchChatProvider.gd" +}, { "base": "Reference", "class": "MessageWrapper", "language": "GDScript", @@ -217,6 +222,7 @@ _global_script_class_icons={ "MajorityJudgmentParticipant": "", "MajorityJudgmentPoll": "", "MajorityJudgmentPollTally": "", +"MajorityJudgmentTwitchChatProvider": "", "MessageWrapper": "", "Queue": "", "TwiCIL": "",