From 11b8b62fd544479c07f34c57aedd807de53308c4 Mon Sep 17 00:00:00 2001 From: Joe Rayhawk Date: Wed, 27 Dec 2023 12:21:38 -0800 Subject: crystal bungmobott: add YAML::Serializable configuration management system as module --- crystal/lib/bungmobott/src/bungmobott.cr | 71 ++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 crystal/lib/bungmobott/src/bungmobott.cr (limited to 'crystal/lib/bungmobott') diff --git a/crystal/lib/bungmobott/src/bungmobott.cr b/crystal/lib/bungmobott/src/bungmobott.cr new file mode 100644 index 0000000..d54eaad --- /dev/null +++ b/crystal/lib/bungmobott/src/bungmobott.cr @@ -0,0 +1,71 @@ +#--- +#statedir: /home/jrayhawk/.local/state/bungmobott/ +#tempdir: /tmp/bungmobott/ +#listen: 0.0.0.0:5555 +#join_channels: +# twitch: +# - bungmonkey +# - dopefish +# # - yackamov +# gamesurge: +# - bungmonkey +#twitch_user_id: 59895482 # saves a lookup +#chat_user: +# twitch: bungmonkey +# gamesurge: bungmoBott + +module BungmoBott + + EXE = "bungmobott" + + class ChatUser + include YAML::Serializable + include YAML::Serializable::Unmapped + property twitch : String? + property gamesurge : String? + end + + class JoinChannels + include YAML::Serializable + include YAML::Serializable::Unmapped + property twitch : Array(String)? + property gamesurge : Array(String)? + end + + class Config + include YAML::Serializable + include YAML::Serializable::Unmapped + property statedir : String = ( + ENV["LOCALAPPDATA"]? && Path.windows( ENV["LOCALAPPDATA"] + "\\#{EXE}\\state\\" ).to_s || + ENV["XDG_STATE_HOME"]? && ENV["XDG_STATE_HOME"] + "/#{EXE}/" || + Path.home./(".local/state/#{EXE}").to_s + ) + property tempdir : String = ( + ENV["TEMP"]? && ENV["TEMP"] + "\\#{EXE}\\" || + "/tmp/#{EXE}/" + ) + property rundir : String = ( + ENV["XDG_RUNTIME_DIR"]? && ENV["XDG_RUNTIME_DIR"] + "/#{EXE}/" || + "/tmp/#{EXE}/" + ) # FIXME: do sockets and such even work on Windows? + # Should probably warn about that somewhere around here. + #@[YAML::Field(emit_null: true)] + property listen : String? = nil + property chat_user : ChatUser? = ChatUser.from_yaml("---") + property join_channels : JoinChannels? = JoinChannels.from_yaml("---") + property twitch_user_id : UInt32? = nil + end + class Secrets + include YAML::Serializable + include YAML::Serializable::Unmapped + @[YAML::Field(emit_null: true)] + property twitch_access_token : String? + @[YAML::Field(emit_null: true)] + property twitch_client_id : String? + @[YAML::Field(emit_null: true)] + property gcloud_token : String? + @[YAML::Field(emit_null: true)] + property gamesurge_password : String? + end +end + -- cgit v1.2.3