feat: Add opened_at and closed_at properties to Polls

Those are timestamps, ie. seconds since UNIX EPOCH
UNIX EPOCH is 01-01-1970
The information era has entered its jubilee! \o/
master
Dominique Merle 4 years ago
parent d18b4c6202
commit ee1d95699f

@ -7,9 +7,14 @@ gives a single grade to each of the candidates.
The candidates are then sorted by their median grade. The candidates are then sorted by their median grade.
https://en.wikipedia.org/wiki/Majority_Judgment https://en.wikipedia.org/wiki/Majority_Judgment
The constitutive details of the poll are up to you. The constitutive details of the poll are up to you, of course,
the poll can be imperative or informative.
""" """
const NOT_OPENED := -1
const NOT_CLOSED := -1
# Minimum length: 4 unicode characters (? TBD) # Minimum length: 4 unicode characters (? TBD)
# Maximum length: 256 unicode characters (? TBD) # Maximum length: 256 unicode characters (? TBD)
export(String) var title:String setget set_title, get_title export(String) var title:String setget set_title, get_title
@ -36,6 +41,10 @@ export(Array, Resource) var candidates:Array setget set_candidates, get_candidat
export(Array, Resource) var judgments:Array setget set_judgments, get_judgments export(Array, Resource) var judgments:Array setget set_judgments, get_judgments
# Seconds since UNIX EPOCH (01-01-1970)
export var opened_at:int = NOT_OPENED
export var closed_at:int = NOT_CLOSED
# Don't pass parameters in _init(). # Don't pass parameters in _init().
# ResourceLoader.load() won't like it. # ResourceLoader.load() won't like it.
@ -43,7 +52,7 @@ func _init():
pass pass
# Instead, use a factory approach # Instead, use a factory approach.
static func make(__title, __grading, __candidates): static func make(__title, __grading, __candidates):
var poll = load("res://addons/majority_judgment/MajorityJudgmentPoll.gd").new() var poll = load("res://addons/majority_judgment/MajorityJudgmentPoll.gd").new()
poll.set_title(__title) poll.set_title(__title)
@ -52,7 +61,6 @@ static func make(__title, __grading, __candidates):
return poll return poll
func set_title(__title:String) -> void: func set_title(__title:String) -> void:
title = __title title = __title
@ -116,6 +124,24 @@ func get_judgments() -> Array:
return judgments return judgments
func is_open() -> bool:
var now = App.get_now()
return (
(NOT_OPENED != opened_at and opened_at <= now)
and
(NOT_CLOSED == closed_at or closed_at >= now)
)
func is_closed() -> bool:
return not is_open()
func open() -> void:
assert(NOT_OPENED == opened_at, "Cannot open() an already opened poll.")
opened_at = App.get_now()
func tally() -> MajorityJudgmentPollTally: func tally() -> MajorityJudgmentPollTally:
if not has_judgments(): if not has_judgments():
return null return null

@ -13,6 +13,7 @@ class_name MajorityJudgmentAbstractJudgmentsProvider
# - IRC chat commands (low, as a bot would be better) # - IRC chat commands (low, as a bot would be better)
# - Discord, somehow # - Discord, somehow
# - Riot, Jami, etc. # - Riot, Jami, etc.
# - SMS
# - Heck, any videoconferencing software with a workable API # - Heck, any videoconferencing software with a workable API
# #
# So far, providers don't care about whether the candidate or grade indices # So far, providers don't care about whether the candidate or grade indices

@ -35,7 +35,7 @@ class_name MajorityJudgmentChatCommandJudgmentsProvider
func process_chat_command(author_identifier:String, chat_command:String): func process_chat_command(author_identifier:String, chat_command:String):
var regex = RegEx.new() var regex = RegEx.new()
regex.compile("(?<candidate>[a-zA-Z]{1})(?<grade>[0-9]{1})") regex.compile("(?<candidate>[a-zA-Z]{1,2})(?<grade>[0-9]{1,2})")
var results = regex.search_all(chat_command) var results = regex.search_all(chat_command)
if results: if results:

@ -54,6 +54,10 @@ func start_providing():
var _c = self.twitch.connect("message_received", self, "_on_message_received") var _c = self.twitch.connect("message_received", self, "_on_message_received")
func stop_providing():
pass
func _on_message_received(user_name:String, text:String, emotes:Array): func _on_message_received(user_name:String, text:String, emotes:Array):
# I. Log it to file # I. Log it to file
var log_filepath = "user://twitch_chat_%s.log" % [ var log_filepath = "user://twitch_chat_%s.log" % [

Loading…
Cancel
Save