Module: Mchat::Command::ChannelNew::InstanceMethods

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

Instance Method Summary collapse

Instance Method Details

#channel_new_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
# File 'lib/mchat/commands/channel_new.rb', line 25

def channel_new_command_run(channel_name = nil)
  if !channel_name
    content << "/channel_new <new_channel_name>\n".style.warn
    content << "new_channel_name should not be nil\n".style.warn
    _puts content
  else
    # 指定节点
    resp = _api.create_channel(channel_name)
    code = resp.fetch("code")

    if code == StatusCode::RecordHaveExist
      content = "#{"Mchat Channel:".style.primary} #{channel_name}\n"
      content << "channel <#{channel_name}> have exist. use follow create new channel.\n"
      content << "type `/channel_new <new_channel_name>`"
      content << "you can also find all channels:"
      content << "type `/channel`"
      _puts content
      return
    elsif code == StatusCode::Success
      # 存在这个channel
      data = resp.fetch("data")

      online_users = data["online_users"]

      # cli
      _mchat_action("you create channel: #{channel_name}")
      _puts "create channel: #{channel_name} success. try auto join."

      _dispatch(:join_command_run, channel_name)
    end
  end
end

#channel_new_help_docObject



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

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

command: /channel_new <new_channel_name>
explain: create a new channel

)
end