summaryrefslogtreecommitdiff
path: root/crystal/lib/bungmobott/src/bungmobott.cr
blob: d54eaadaff8483b56237e6a7db126e295420abe3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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