feat: implement initial chat command processing to add judgments

As detailed in previous commit with the unit-test (which now pass),
the regex is as follows :

    (?<candidate>[a-zA-Z]{1})(?<grade>[0-9]{1})

We have room to support more than 25 candidates or 10 grades in the future.
Right now, this is enough, let's move on !
master
Dominique Merle 4 years ago
parent 019dd09158
commit 205608d75f

@ -0,0 +1,13 @@
extends Reference
class_name MajorityJudgmentAbstractJudgmentsProvider
# Abstract class for Judgment Providers
# The job of the children is to emit the judgment_emitted signal.
signal judgment_emitted(
author_identifier, # String, unique per author (aka participant)
candidate_index, # int
grade_index # int (0 == REJECT, up to the grading size minus one)
)

@ -0,0 +1,34 @@
extends MajorityJudgmentAbstractJudgmentsProvider
class_name MajorityJudgmentChatCommandJudgmentsProvider
# Command examples
# ----------------
#
# A0 B2 c0 D1
#
func process_chat_command(author_identifier:String, chat_command:String):
var candidate_index := 0
var grade_index := 0
var regex = RegEx.new()
regex.compile("(?<candidate>[a-zA-Z]{1})(?<grade>[0-9]{1})")
var results = regex.search_all(chat_command)
if results:
for result in results:
var candidate_string : String = result.get_string('candidate')
var grade_string : String = result.get_string('grade')
grade_index = str2var(grade_string)
candidate_string = candidate_string.to_upper()
candidate_index = ord(candidate_string) - ord("A")
emit_signal(
"judgment_emitted",
author_identifier,
candidate_index,
grade_index
)

@ -22,6 +22,7 @@ func test_single_command():
do_test_single_command("A0", [0, 0])
do_test_single_command("B2", [1, 2])
do_test_single_command("e4", [4, 4])
do_test_single_command("E4", [4, 4])
func do_test_single_command(command:String, expected:Array):

Loading…
Cancel
Save