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
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
|
||||
)
|
Loading…
Reference in new issue