A Godot Engine app to help streamers organize Majority Judgment polls in their streams.
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.
 
 

57 lines
1.4 KiB

extends MajorityJudgmentAbstractJudgmentsProvider
class_name MajorityJudgmentChatCommandJudgmentsProvider
# Base class for chat command providers to extend.
# Is able to process_chat_command().
#
# Command Syntax
# --------------
#
# <candidate><grade>
#
# such as
#
# A2
#
# means give grade #2 (passable) to candidate A.
#
# Grades (when there are 6):
#
# 0. TO_REJECT .0
# 1. POOR .1
# 2. PASSABLE .2
# 3. GOOD .3
# 4. VERY_GOOD .4
# 5. EXCELLENT .5
#
#
# Command examples
# ----------------
#
# A0 B2 c0 D1
#
# We would like to get word grades, because numbers, although handy,
# create a bias. They don't mean the same thing to everyone.
# See https://git.mieuxvoter.fr/MieuxVoter/majority-judgment-for-streamers/issues/12
#
func process_chat_command(author_identifier:String, chat_command:String):
var regex = RegEx.new()
regex.compile("(?<candidate>[a-zA-Z]{2})[ ]*(?<grade>[0-9]{2})")
var results = regex.search_all(chat_command)
if results:
for result in results:
var candidate_string : String = result.get_string('candidate')
candidate_string = candidate_string.to_upper()
var candidate_index = ord(candidate_string) - ord("A")
var grade_string : String = result.get_string('grade')
var grade_index = str2var(grade_string) # FIXME: safer, please
emit_signal(
"judgment_emitted",
author_identifier,
candidate_index,
grade_index
)