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")
content = "Mchat Channels:\n".style.primary
if all_channels.length > 0
all_channels.each do |c|
content << "* #{c}\n"
end
else
content << "Opps."
end
content << ""
content << "type `/join <channel_name>` to join the channel.\n"
_puts content
_mchat_action("fetch all channels")
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
data = resp.fetch("data")
online_users = data["online_users"]
content = "#{"Mchat Channel:".style.primary} #{channel_name}\n"
content << "#{"online users:".style.jade}\n"
online_users.each do |c|
c = c.split(":").last content << "* #{c.style.jade}\n"
end
content << ""
content << "total: #{online_users.length}.\n"
_puts content
_mchat_action("channel #{channel_name} info:")
end
end
end
|