Module: Mchat::Command::Channel::InstanceMethods

Defined in:
lib/mchat/commands/channel.rb

Instance Method Summary collapse

Instance Method Details

#channel_command_run(channel_name = nil) ⇒ Object



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
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/mchat/commands/channel.rb', line 25

def channel_command_run(channel_name = nil)
  if !channel_name
    # 返回全部节点
    resp = _api.get_channels
    all_channels = resp.fetch("data")

    # cli
    content = "Mchat Channels:\n".style.primary
    if all_channels.length > 0
      all_channels.each do |c|
        content << "* #{c}\n"
      end
    else
      # TODO create channel
      content << "Opps."
    end

    content << ""
    content << "type `/join <channel_name>` to join the channel.\n"
    _puts content

    # printer
    _mchat_action("fetch all channels")
    # _puts2 content
  else
    # 指定节点
    resp = _api.get_channel(channel_name)
    code = resp.fetch("code")

    if code == StatusCode::RecordNotExist
      content = "#{"Mchat Channel:".style.primary} #{channel_name}\n"
      content << "channel not exist. use follow create new channel.\n"
      content << ">> /channel_new <channel name>"
      _puts content
      return
    else
      # 存在这个channel
      data = resp.fetch("data")

      online_users = data["online_users"]

      # cli
      content = "#{"Mchat Channel:".style.primary} #{channel_name}\n"
      content << "#{"online users:".style.jade}\n"
      online_users.each do |c|
        c = c.split(":").last # name
        content << "* #{c.style.jade}\n"
      end
      content << ""
      content << "total: #{online_users.length}.\n"
      _puts content

      # printer
      _mchat_action("channel #{channel_name} info:")
      # _puts2 content
    end
  end
end

#channel_help_docObject



15
16
17
18
19
20
21
22
23
# File 'lib/mchat/commands/channel.rb', line 15

def channel_help_doc
  _puts %Q(
#{"Help: Channel".style.bold}

command: /channel <channel_name>
explain: login the channel

)
end