Browse Source

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 2 years ago
parent
commit
ee1d95699f
  1. 32
      addons/majority_judgment/MajorityJudgmentPoll.gd
  2. 1
      addons/majority_judgment/providers/MajorityJudgmentAbstractJudgmentsProvider.gd
  3. 2
      addons/majority_judgment/providers/MajorityJudgmentChatCommandJudgmentsProvider.gd
  4. 4
      addons/majority_judgment/providers/MajorityJudgmentTwitchChatProvider.gd

32
addons/majority_judgment/MajorityJudgmentPoll.gd

@ -7,9 +7,14 @@ gives a single grade to each of the candidates.
The candidates are then sorted by their median grade.
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)
# Maximum length: 256 unicode characters (? TBD)
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
# 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().
# ResourceLoader.load() won't like it.
@ -43,7 +52,7 @@ func _init():
pass
# Instead, use a factory approach
# Instead, use a factory approach.
static func make(__title, __grading, __candidates):
var poll = load("res://addons/majority_judgment/MajorityJudgmentPoll.gd").new()
poll.set_title(__title)
@ -52,7 +61,6 @@ static func make(__title, __grading, __candidates):
return poll
func set_title(__title:String) -> void:
title = __title
@ -116,6 +124,24 @@ func get_judgments() -> Array:
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:
if not has_judgments():
return null

1
addons/majority_judgment/providers/MajorityJudgmentAbstractJudgmentsProvider.gd

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

2
addons/majority_judgment/providers/MajorityJudgmentChatCommandJudgmentsProvider.gd

@ -35,7 +35,7 @@ class_name MajorityJudgmentChatCommandJudgmentsProvider
func process_chat_command(author_identifier:String, chat_command:String):
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)
if results:

4
addons/majority_judgment/providers/MajorityJudgmentTwitchChatProvider.gd

@ -54,6 +54,10 @@ func start_providing():
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):
# I. Log it to file
var log_filepath = "user://twitch_chat_%s.log" % [

Loading…
Cancel
Save