slack-smart-bot 1.7.0 → 1.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -12
- data/lib/slack-smart-bot.rb +53 -43
- data/lib/slack-smart-bot_general_rules.rb +7 -4
- data/lib/slack-smart-bot_rules.rb +8 -6
- data/lib/slack/smart-bot/comm.rb +6 -1
- data/lib/slack/smart-bot/comm/ask.rb +12 -5
- data/lib/slack/smart-bot/comm/dont_understand.rb +1 -1
- data/lib/slack/smart-bot/comm/event_hello.rb +30 -0
- data/lib/slack/smart-bot/comm/get_channel_members.rb +8 -0
- data/lib/slack/smart-bot/comm/get_channels.rb +20 -0
- data/lib/slack/smart-bot/comm/get_user_info.rb +16 -0
- data/lib/slack/smart-bot/comm/react.rb +21 -8
- data/lib/slack/smart-bot/comm/respond.rb +38 -12
- data/lib/slack/smart-bot/comm/send_file.rb +1 -1
- data/lib/slack/smart-bot/comm/send_msg_channel.rb +2 -2
- data/lib/slack/smart-bot/comm/send_msg_user.rb +4 -4
- data/lib/slack/smart-bot/comm/unreact.rb +29 -0
- data/lib/slack/smart-bot/commands.rb +3 -1
- data/lib/slack/smart-bot/commands/general/bot_help.rb +16 -3
- data/lib/slack/smart-bot/commands/general/bot_stats.rb +313 -0
- data/lib/slack/smart-bot/commands/general/bot_status.rb +1 -1
- data/lib/slack/smart-bot/commands/general/bye_bot.rb +1 -1
- data/lib/slack/smart-bot/commands/general/hi_bot.rb +1 -1
- data/lib/slack/smart-bot/commands/general/use_rules.rb +6 -9
- data/lib/slack/smart-bot/commands/general/whats_new.rb +19 -0
- data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +65 -33
- data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +42 -9
- data/lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb +3 -7
- data/lib/slack/smart-bot/commands/on_bot/admin/pause_bot.rb +1 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +9 -2
- data/lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb +1 -0
- data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +1 -1
- data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +52 -21
- data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +5 -5
- data/lib/slack/smart-bot/commands/on_bot/repl.rb +50 -18
- data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +34 -9
- data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +2 -3
- data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +1 -1
- data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +27 -9
- data/lib/slack/smart-bot/commands/on_extended/bot_rules.rb +14 -1
- data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +3 -3
- data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +1 -1
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb +41 -0
- data/lib/slack/smart-bot/commands/on_master/create_bot.rb +4 -8
- data/lib/slack/smart-bot/listen.rb +6 -5
- data/lib/slack/smart-bot/process.rb +230 -186
- data/lib/slack/smart-bot/process_first.rb +104 -87
- data/lib/slack/smart-bot/treat_message.rb +128 -52
- data/lib/slack/smart-bot/utils.rb +2 -0
- data/lib/slack/smart-bot/utils/answer.rb +18 -0
- data/lib/slack/smart-bot/utils/answer_delete.rb +15 -0
- data/lib/slack/smart-bot/utils/build_help.rb +57 -5
- data/lib/slack/smart-bot/utils/create_routine_thread.rb +48 -8
- data/lib/slack/smart-bot/utils/get_channels_name_and_id.rb +1 -7
- data/lib/slack/smart-bot/utils/get_help.rb +79 -17
- data/lib/slack/smart-bot/utils/save_stats.rb +21 -8
- data/lib/slack/smart-bot/utils/update_shortcuts_file.rb +6 -0
- data/whats_new.txt +24 -0
- metadata +23 -13
- data/lib/slack/smart-bot/commands/on_bot/admin_master/bot_stats.rb +0 -135
@@ -24,13 +24,9 @@ class SlackSmartBot
|
|
24
24
|
channel_id = @channels_id[channel]
|
25
25
|
end
|
26
26
|
#todo: add pagination for case more than 1000 channels on the workspace
|
27
|
-
channels =
|
28
|
-
types: "private_channel,public_channel",
|
29
|
-
limit: "1000",
|
30
|
-
exclude_archived: "true",
|
31
|
-
).channels
|
27
|
+
channels = get_channels()
|
32
28
|
channel_found = channels.detect { |c| c.name == channel }
|
33
|
-
members =
|
29
|
+
members = get_channel_members(@channels_id[channel]) unless channel_found.nil?
|
34
30
|
|
35
31
|
if channel_id.nil?
|
36
32
|
respond "There is no channel with that name: #{channel}, please be sure is written exactly the same", dest
|
@@ -39,7 +35,7 @@ class SlackSmartBot
|
|
39
35
|
elsif @bots_created.keys.include?(channel_id)
|
40
36
|
respond "There is already a bot in this channel: #{channel}, kill it before", dest
|
41
37
|
elsif config[:nick_id] != channel_found.creator and !members.include?(config[:nick_id])
|
42
|
-
respond "You need to add first to the channel the smart bot user:
|
38
|
+
respond "You need to add first to the channel the smart bot user: <@#{config[:nick_id]}>", dest
|
43
39
|
else
|
44
40
|
if channel_id != config[:channel]
|
45
41
|
begin
|
@@ -60,7 +56,7 @@ class SlackSmartBot
|
|
60
56
|
FileUtils.copy_file(default_rules, config.path + rules_file) unless File.exist?(config.path + rules_file)
|
61
57
|
FileUtils.copy_file(default_general_rules, config.path + general_rules_file) unless File.exist?(config.path + general_rules_file)
|
62
58
|
admin_users = Array.new()
|
63
|
-
creator_info =
|
59
|
+
creator_info = get_user_info(channel_found.creator)
|
64
60
|
admin_users = [from, creator_info.user.name] + config.masters
|
65
61
|
admin_users.uniq!
|
66
62
|
@logger.info "ruby #{config.file_path} \"#{channel}\" \"#{admin_users.join(",")}\" \"#{rules_file}\" on"
|
@@ -6,7 +6,7 @@ class SlackSmartBot
|
|
6
6
|
get_bots_created()
|
7
7
|
@buffer_complete = [] unless defined?(@buffer_complete)
|
8
8
|
b = File.read("#{config.path}/buffer_complete.log")
|
9
|
-
result = b.scan(/^\|(\w+)\|(\w+)\|([^~]+)~~~/m)
|
9
|
+
result = b.scan(/^\|(\w+)\|(\w+)\|(\w+)\|([^~]+)~~~/m)
|
10
10
|
result.delete(nil)
|
11
11
|
new_messages = result[@buffer_complete.size..-1]
|
12
12
|
unless new_messages.nil? or new_messages.empty?
|
@@ -14,7 +14,8 @@ class SlackSmartBot
|
|
14
14
|
new_messages.each do |message|
|
15
15
|
channel = message[0].strip
|
16
16
|
user = message[1].strip
|
17
|
-
|
17
|
+
user_name = message[2].strip
|
18
|
+
command = message[3].to_s.strip
|
18
19
|
# take in consideration that on simulation we are treating all messages even those that are not populated on real cases like when the message is not populated to the specific bot connection when message is sent with the bot
|
19
20
|
@logger.info "treat message: #{message}" if config.testing
|
20
21
|
|
@@ -23,18 +24,18 @@ class SlackSmartBot
|
|
23
24
|
command.scan(/`([^`]+)`/).flatten.each do |cmd|
|
24
25
|
if cmd.to_s!=''
|
25
26
|
cmd = "^#{cmd}"
|
26
|
-
treat_message({channel: channel, user: user, text: cmd}, false)
|
27
|
+
treat_message({channel: channel, user: user, text: cmd, user_name: user_name}, false)
|
27
28
|
end
|
28
29
|
end
|
29
30
|
elsif command.match?(/^\s*\-!/)
|
30
31
|
command.scan(/`([^`]+)`/).flatten.each do |cmd|
|
31
32
|
if cmd.to_s!=''
|
32
33
|
cmd = "!#{cmd}"
|
33
|
-
treat_message({channel: channel, user: user, text: cmd}, false)
|
34
|
+
treat_message({channel: channel, user: user, text: cmd, user_name: user_name}, false)
|
34
35
|
end
|
35
36
|
end
|
36
37
|
else
|
37
|
-
treat_message({channel: channel, user: user, text: command})
|
38
|
+
treat_message({channel: channel, user: user, text: command, user_name: user_name})
|
38
39
|
end
|
39
40
|
end
|
40
41
|
end
|
@@ -1,11 +1,15 @@
|
|
1
1
|
class SlackSmartBot
|
2
2
|
def process(user, command, dest, dchannel, rules_file, typem, files, ts)
|
3
3
|
from = user.name
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
if config.simulate
|
5
|
+
display_name = user.profile.display_name
|
6
|
+
else
|
7
|
+
if user.profile.display_name.to_s.match?(/\A\s*\z/)
|
8
|
+
user.profile.display_name = user.profile.real_name
|
9
|
+
end
|
10
|
+
display_name = user.profile.display_name
|
7
11
|
end
|
8
|
-
|
12
|
+
|
9
13
|
processed = true
|
10
14
|
|
11
15
|
on_demand = false
|
@@ -23,203 +27,243 @@ class SlackSmartBot
|
|
23
27
|
command = command2
|
24
28
|
on_demand = true
|
25
29
|
end
|
30
|
+
if (on_demand or typem == :on_dm or
|
31
|
+
(@listening.key?(from) and (@listening[from].key?(dest) or @listening[from].key?(Thread.current[:thread_ts])) )) and
|
32
|
+
config.on_maintenance and !command.match?(/\A(set|turn)\s+maintenance\s+off\s*\z/)
|
33
|
+
respond config.on_maintenance_message, dest
|
34
|
+
processed = true
|
35
|
+
end
|
26
36
|
|
27
|
-
|
28
|
-
|
29
|
-
|
37
|
+
if !config.on_maintenance or (config.on_maintenance and command.match?(/\A(set|turn)\s+maintenance\s+off\s*\z/))
|
38
|
+
#todo: check :on_pg in this case
|
39
|
+
if typem == :on_master or typem == :on_bot or typem == :on_pg or typem == :on_dm
|
40
|
+
|
41
|
+
case command
|
30
42
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
43
|
+
when /^\s*(Hello|Hallo|Hi|Hola|What's\sup|Hey|Hæ)\s+(#{@salutations.join("|")})\s*$/i
|
44
|
+
hi_bot(user, dest, dchannel, from, display_name)
|
45
|
+
when /^\s*what's\s+new\s*$/i
|
46
|
+
whats_new(user, dest, dchannel, from, display_name)
|
47
|
+
when /^\s*(Bye|Bæ|Good\s+Bye|Adiós|Ciao|Bless|Bless\sBless|Adeu)\s+(#{@salutations.join("|")})\s*$/i
|
48
|
+
bye_bot(dest, from, display_name)
|
49
|
+
when /^\s*bot\s+(rules|help)\s*(.+)?$/i, /^bot,? what can I do/i
|
50
|
+
$1.to_s.match?(/rules/i) ? specific = true : specific = false
|
51
|
+
help_command = $2
|
38
52
|
|
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
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
53
|
+
bot_help(user, from, dest, dchannel, specific, help_command, rules_file)
|
54
|
+
when /^\s*use\s+(rules\s+)?(from\s+)?<#C\w+\|(.+)>\s*$/i, /^use\s+(rules\s+)?(from\s+)?([^\s]+\s*$)/i
|
55
|
+
channel = $3
|
56
|
+
use_rules(dest, channel, user, dchannel)
|
57
|
+
when /^\s*stop\s+using\s+rules\s+(from\s+)<#\w+\|(.+)>/i, /^stop\s+using\s+rules\s+(from\s+)(.+)/i
|
58
|
+
channel = $2
|
59
|
+
stop_using_rules(dest, channel, user, dchannel)
|
60
|
+
when /^\s*extend\s+rules\s+(to\s+)<#C\w+\|(.+)>/i, /^extend\s+rules\s+(to\s+)(.+)/i,
|
61
|
+
/^\s*use\s+rules\s+(on\s+)<#C\w+\|(.+)>/i, /^use\s+rules\s+(on\s+)(.+)/i
|
62
|
+
channel = $2
|
63
|
+
extend_rules(dest, user, from, channel, typem)
|
64
|
+
when /^\s*stop\s+using\s+rules\s+(on\s+)<#\w+\|(.+)>/i, /^stop\s+using\s+rules\s+(on\s+)(.+)/i
|
65
|
+
channel = $2
|
66
|
+
stop_using_rules_on(dest, user, from, channel, typem)
|
67
|
+
when /^\s*exit\s+bot\s*$/i, /^quit\s+bot\s*$/i, /^close\s+bot\s*$/i
|
68
|
+
exit_bot(command, from, dest, display_name)
|
69
|
+
when /^\s*start\s+(this\s+)?bot$/i
|
70
|
+
start_bot(dest, from)
|
71
|
+
when /^\s*pause\s+(this\s+)?bot$/i
|
72
|
+
pause_bot(dest, from)
|
73
|
+
when /^\s*bot\s+status/i
|
74
|
+
bot_status(dest, user)
|
75
|
+
when /\Anotify\s+<#(C\w+)\|.+>\s+(.+)\s*\z/im, /\Anotify\s+(all)?\s*(.+)\s*\z/im
|
76
|
+
where = $1
|
77
|
+
message = $2
|
78
|
+
notify_message(dest, from, where, message)
|
79
|
+
when /^\s*create\s+(cloud\s+)?bot\s+on\s+<#C\w+\|(.+)>\s*/i, /^create\s+(cloud\s+)?bot\s+on\s+(.+)\s*/i
|
80
|
+
cloud = !$1.nil?
|
81
|
+
channel = $2
|
82
|
+
create_bot(dest, user, cloud, channel)
|
83
|
+
when /^\s*kill\s+bot\s+on\s+<#C\w+\|(.+)>\s*$/i, /^kill\s+bot\s+on\s+(.+)\s*$/i
|
84
|
+
channel = $1
|
85
|
+
kill_bot_on_channel(dest, from, channel)
|
86
|
+
when /^\s*(add|create)\s+(silent\s+)?routine\s+(\w+)\s+(every)\s+(\d+)\s*(days|hours|minutes|seconds|mins|min|secs|sec|d|h|m|s)\s*(\s#(\w+)\s*)(\s.+)?\s*$/i,
|
87
|
+
/^\s*(add|create)\s+(silent\s+)?routine\s+(\w+)\s+(every)\s+(\d+)\s*(days|hours|minutes|seconds|mins|min|secs|sec|d|h|m|s)\s*(\s<#(C\w+)\|.+>\s*)?(\s.+)?\s*$/i,
|
88
|
+
/^\s*(add|create)\s+(silent\s+)?routine\s+(\w+)\s+on\s+(monday|tuesday|wednesday|thursday|friday|saturday|sunday)s?\s+at\s+(\d+:\d+:?\d+?)\s*()(\s#(\w+)\s*)(\s.+)?\s*$/i,
|
89
|
+
/^\s*(add|create)\s+(silent\s+)?routine\s+(\w+)\s+on\s+(monday|tuesday|wednesday|thursday|friday|saturday|sunday)s?\s+at\s+(\d+:\d+:?\d+?)\s*()(\s<#(C\w+)\|.+>\s*)?(\s.+)?\s*$/i,
|
90
|
+
/^\s*(add|create)\s+(silent\s+)?routine\s+(\w+)\s+(at)\s+(\d+:\d+:?\d+?)\s*()(\s#(\w+)\s*)(\s.+)?\s*$/i,
|
91
|
+
/^\s*(add|create)\s+(silent\s+)?routine\s+(\w+)\s+(at)\s+(\d+:\d+:?\d+?)\s*()(\s<#(C\w+)\|.+>\s*)?(\s.+)?\s*$/i
|
92
|
+
silent = $2.to_s!=''
|
93
|
+
name = $3.downcase
|
94
|
+
type = $4
|
95
|
+
number_time = $5
|
96
|
+
period = $6
|
97
|
+
channel = $8
|
98
|
+
command_to_run = $9
|
99
|
+
add_routine(dest, from, user, name, type, number_time, period, command_to_run, files, silent, channel)
|
100
|
+
when /^\s*(kill|delete|remove)\s+routine\s+(\w+)\s*$/i
|
101
|
+
name = $2.downcase
|
102
|
+
remove_routine(dest, from, name)
|
103
|
+
when /^\s*(run|execute)\s+routine\s+(\w+)\s*$/i
|
104
|
+
name = $2.downcase
|
105
|
+
run_routine(dest, from, name)
|
106
|
+
when /^\s*pause\s+routine\s+(\w+)\s*$/i
|
107
|
+
name = $1.downcase
|
108
|
+
pause_routine(dest, from, name)
|
109
|
+
when /^\s*start\s+routine\s+(\w+)\s*$/i
|
110
|
+
name = $1.downcase
|
111
|
+
start_routine(dest, from, name)
|
112
|
+
when /^\s*see\s+(all\s+)?routines\s*$/i
|
113
|
+
all = $1.to_s != ""
|
114
|
+
see_routines(dest, from, user, all)
|
115
|
+
when /^\s*get\s+bot\s+logs?\s*$/i
|
116
|
+
get_bot_logs(dest, from, typem)
|
117
|
+
when /^\s*bot\s+stats\s*(.*)\s*$/i
|
118
|
+
opts = $1.to_s
|
119
|
+
all_opts = opts.downcase.split(' ')
|
120
|
+
all_data = all_opts.include?('alldata')
|
121
|
+
st_channel = opts.scan(/<#(\w+)\|.+>/).join
|
122
|
+
st_from = opts.scan(/from\s+(\d\d\d\d[\/\-\.]\d\d[\/\-\.]\d\d)/).join
|
123
|
+
st_from = st_from.gsub('.','-').gsub('/','-')
|
124
|
+
st_to = opts.scan(/to\s+(\d\d\d\d[\/\-\.]\d\d[\/\-\.]\d\d)/).join
|
125
|
+
st_to = st_to.gsub('.','-').gsub('/','-')
|
126
|
+
st_user = opts.scan(/<@([^>]+)>/).join
|
127
|
+
st_command = opts.scan(/\s+command\s+(\w+)/i).join.downcase
|
128
|
+
st_command = opts.scan(/^command\s+(\w+)/i).join.downcase if st_command == ''
|
129
|
+
exclude_masters = all_opts.include?('exclude') && all_opts.include?('masters')
|
130
|
+
exclude_routines = all_opts.include?('exclude') && all_opts.include?('routines')
|
131
|
+
if exclude_masters
|
132
|
+
opts.gsub!(/\s+masters$/,'')
|
133
|
+
opts.gsub!(/\s+masters\s+/,'')
|
134
|
+
end
|
135
|
+
if exclude_routines
|
136
|
+
opts.gsub!(/\s+routines$/,'')
|
137
|
+
opts.gsub!(/\s+routines\s+/,'')
|
138
|
+
end
|
139
|
+
monthly = false
|
140
|
+
if all_opts.include?('today')
|
141
|
+
st_from = st_to = "#{Time.now.strftime("%Y-%m-%d")}"
|
142
|
+
elsif all_opts.include?('monthly')
|
143
|
+
monthly = true
|
144
|
+
end
|
145
|
+
exclude_command = opts.scan(/exclude\s+([^\s]+)/i).join
|
146
|
+
unless @master_admin_users_id.include?(user.id)
|
147
|
+
st_user = user.id
|
148
|
+
end
|
149
|
+
if (typem == :on_master or typem == :on_bot) and dest[0]!='D' #routine bot stats to be published on DM
|
150
|
+
st_channel = dchannel
|
151
|
+
end
|
152
|
+
bot_stats(dest, user, typem, st_channel, st_from, st_to, st_user, st_command, exclude_masters, exclude_routines, exclude_command, monthly, all_data)
|
153
|
+
when /\A(set|turn)\s+maintenance\s+(on|off)\s*()\z/im, /\A(set|turn)\s+maintenance\s+(on)\s*(.+)\s*\z/im
|
154
|
+
status = $2.downcase
|
155
|
+
message = $3.to_s
|
156
|
+
set_maintenance(from, status, message)
|
157
|
+
else
|
158
|
+
processed = false
|
113
159
|
end
|
114
|
-
exclude_command = opts.scan(/exclude\s+([^\s]+)/i).join
|
115
|
-
exclude_command = '' if exclude_command == 'masters'
|
116
|
-
bot_stats(dest, from, typem, st_channel, st_from, st_to, st_user, exclude_masters, exclude_command, monthly)
|
117
160
|
else
|
118
161
|
processed = false
|
119
162
|
end
|
120
|
-
else
|
121
|
-
processed = false
|
122
|
-
end
|
123
163
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
164
|
+
# only when :on and (listening or on demand or direct message)
|
165
|
+
if @status == :on and
|
166
|
+
(!answer.empty? or
|
167
|
+
(@repl_sessions.key?(from) and dest==@repl_sessions[from][:dest] and
|
168
|
+
((@repl_sessions[from][:on_thread] and Thread.current[:thread_ts] == @repl_sessions[from][:thread_ts]) or
|
169
|
+
(!@repl_sessions[from][:on_thread] and !Thread.current[:on_thread]))) or
|
170
|
+
(@listening.key?(from) and typem != :on_extended and
|
171
|
+
((@listening[from].key?(dest) and !Thread.current[:on_thread]) or
|
172
|
+
(@listening[from].key?(Thread.current[:thread_ts]) and Thread.current[:on_thread] ) )) or
|
173
|
+
typem == :on_dm or typem == :on_pg or on_demand)
|
174
|
+
processed2 = true
|
175
|
+
|
176
|
+
case command
|
135
177
|
|
136
|
-
|
178
|
+
# bot rules for extended channels
|
179
|
+
when /^bot\s+rules\s*(.+)?$/i
|
180
|
+
help_command = $1
|
181
|
+
bot_rules(dest, help_command, typem, rules_file, user)
|
182
|
+
when /^\s*(add\s+)?(global\s+|generic\s+)?shortcut\s+(for\sall)?\s*([^:]+)\s*:\s*(.+)/i,
|
183
|
+
/^(add\s+)(global\s+|generic\s+)?sc\s+(for\sall)?\s*([^:]+)\s*:\s*(.+)/i
|
184
|
+
for_all = $3
|
185
|
+
shortcut_name = $4.to_s.downcase
|
186
|
+
command_to_run = $5
|
187
|
+
global = $2.to_s != ''
|
188
|
+
add_shortcut(dest, user, typem, for_all, shortcut_name, command, command_to_run, global)
|
189
|
+
when /^\s*(delete|remove)\s+(global\s+|generic\s+)?shortcut\s+(.+)/i,
|
190
|
+
/^(delete|remove)\s+(global\s+|generic\s+)?sc\s+(.+)/i
|
191
|
+
shortcut = $3.to_s.downcase
|
192
|
+
global = $2.to_s != ''
|
137
193
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
bot_rules(dest, help_command, typem, rules_file, user)
|
142
|
-
when /^\s*(add\s)?shortcut\s(for\sall)?\s*([^:]+)\s*:\s*(.+)/i, /^(add\s)sc\s(for\sall)?\s*([^:]+)\s*:\s*(.+)/i
|
143
|
-
for_all = $2
|
144
|
-
shortcut_name = $3.to_s.downcase
|
145
|
-
command_to_run = $4
|
146
|
-
add_shortcut(dest, user, typem, for_all, shortcut_name, command, command_to_run)
|
147
|
-
when /^\s*(delete|remove)\s+shortcut\s+(.+)/i, /^(delete|remove)\s+sc\s+(.+)/i
|
148
|
-
shortcut = $2.to_s.downcase
|
149
|
-
delete_shortcut(dest, user, shortcut, typem, command)
|
150
|
-
when /^\s*see\sshortcuts/i, /^see\ssc/i
|
151
|
-
see_shortcuts(dest, user, typem)
|
194
|
+
delete_shortcut(dest, user, shortcut, typem, command, global)
|
195
|
+
when /^\s*see\s+shortcuts/i, /^see\ssc/i
|
196
|
+
see_shortcuts(dest, user, typem)
|
152
197
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
198
|
+
#kept to be backwards compatible
|
199
|
+
when /^\s*id\schannel\s<#C\w+\|(.+)>\s*/i, /^id channel (.+)/
|
200
|
+
unless typem == :on_extended
|
201
|
+
channel_name = $1
|
202
|
+
get_channels_name_and_id()
|
203
|
+
if @channels_id.keys.include?(channel_name)
|
204
|
+
respond "the id of #{channel_name} is #{@channels_id[channel_name]}", dest
|
205
|
+
else
|
206
|
+
respond "channel: #{channel_name} not found", dest
|
207
|
+
end
|
162
208
|
end
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
type =
|
209
|
+
when /^\s*ruby\s(.+)/im, /^\s*code\s(.+)/im
|
210
|
+
code = $1
|
211
|
+
code.gsub!("\\n", "\n")
|
212
|
+
code.gsub!("\\r", "\r")
|
213
|
+
@logger.info code
|
214
|
+
ruby_code(dest, user, code, rules_file)
|
215
|
+
when /^\s*(private\s+|clean\s+|clean\s+private\s+|private\s+clean\s+)?(repl|irb|live)\s*()()()$/i,
|
216
|
+
/^\s*(private\s+|clean\s+|clean\s+private\s+|private\s+clean\s+)?(repl|irb|live)\s+([\w\-]+)()()\s*$/i,
|
217
|
+
/^\s*(private\s+|clean\s+|clean\s+private\s+|private\s+clean\s+)?(repl|irb|live)\s+([\w\-]+)\s*:\s+"([^"]+)"()\s*$/i,
|
218
|
+
/^\s*(private\s+|clean\s+|clean\s+private\s+|private\s+clean\s+)?(repl|irb|live)\s+([\w\-]+)\s*:\s+"([^"]+)"\s+(.+)\s*$/i,
|
219
|
+
/^\s*(private\s+|clean\s+|clean\s+private\s+|private\s+clean\s+)?(repl|irb|live)\s+([\w\-]+)()\s+(.+)\s*$/i,
|
220
|
+
/^\s*(private\s+|clean\s+|clean\s+private\s+|private\s+clean\s+)?(repl|irb|live)()\s+()(.+)\s*$/i
|
221
|
+
opts_type = $1.to_s.downcase.split(' ')
|
222
|
+
opts_type.include?('private') ? type = :private : type = :public
|
223
|
+
type = "#{type}_clean".to_sym if opts_type.include?('clean')
|
224
|
+
|
225
|
+
session_name = $3
|
226
|
+
description = $4
|
227
|
+
opts = " #{$5}"
|
228
|
+
env_vars = opts.scan(/\s+[\w\-]+="[^"]+"/i) + opts.scan(/\s+[\w\-]+='[^']+'/i)
|
229
|
+
opts.scan(/\s+[\w\-]+=[^'"\s]+/i).flatten.each do |ev|
|
230
|
+
env_vars << ev.gsub('=',"='") + "'"
|
231
|
+
end
|
232
|
+
env_vars.each_with_index do |ev, idx|
|
233
|
+
ev.gsub!("=","']=")
|
234
|
+
ev.lstrip!
|
235
|
+
env_vars[idx] = "ENV['#{ev}"
|
236
|
+
end
|
237
|
+
repl(dest, user, session_name, env_vars.flatten, rules_file, command, description, type)
|
238
|
+
when /^\s*get\s+(repl|irb|live)\s+([\w\-]+)\s*/i
|
239
|
+
session_name = $2
|
240
|
+
get_repl(dest, user, session_name)
|
241
|
+
when /^\s*run\s+(repl|irb|live)\s+([\w\-]+)()\s*$/i,
|
242
|
+
/^\s*run\s+(repl|irb|live)\s+([\w\-]+)\s+(.+)\s*$/i
|
243
|
+
session_name = $2
|
244
|
+
opts = " #{$3}"
|
245
|
+
env_vars = opts.scan(/\s+[\w\-]+="[^"]+"/i) + opts.scan(/\s+[\w\-]+='[^']+'/i)
|
246
|
+
opts.scan(/\s+[\w\-]+=[^'"\s]+/i).flatten.each do |ev|
|
247
|
+
env_vars << ev.gsub('=',"='") + "'"
|
248
|
+
end
|
249
|
+
env_vars.each_with_index do |ev, idx|
|
250
|
+
ev.gsub!("=","']=")
|
251
|
+
ev.lstrip!
|
252
|
+
env_vars[idx] = "ENV['#{ev}"
|
253
|
+
end
|
254
|
+
run_repl(dest, user, session_name, env_vars.flatten, rules_file)
|
255
|
+
when /^\s*(delete|remove)\s+(repl|irb|live)\s+([\w\-]+)\s*$/i
|
256
|
+
repl_name = $3
|
257
|
+
delete_repl(dest, user, repl_name)
|
258
|
+
when /^\s*see\s+(repls|repl|irb|irbs)\s*$/i
|
259
|
+
see_repls(dest, user, typem)
|
178
260
|
else
|
179
|
-
|
180
|
-
end
|
181
|
-
session_name = $3
|
182
|
-
description = $4
|
183
|
-
opts = " #{$5}"
|
184
|
-
env_vars = opts.scan(/\s+[\w\-]+="[^"]+"/i) + opts.scan(/\s+[\w\-]+='[^']+'/i)
|
185
|
-
opts.scan(/\s+[\w\-]+=[^'"\s]+/i).flatten.each do |ev|
|
186
|
-
env_vars << ev.gsub('=',"='") + "'"
|
187
|
-
end
|
188
|
-
env_vars.each_with_index do |ev, idx|
|
189
|
-
ev.gsub!("=","']=")
|
190
|
-
ev.lstrip!
|
191
|
-
env_vars[idx] = "ENV['#{ev}"
|
192
|
-
end
|
193
|
-
repl(dest, user, session_name, env_vars.flatten, rules_file, command, description, type)
|
194
|
-
when /^\s*get\s+(repl|irb|live)\s+([\w\-]+)\s*/i
|
195
|
-
session_name = $2
|
196
|
-
get_repl(dest, user, session_name)
|
197
|
-
when /^\s*run\s+(repl|irb|live)\s+([\w\-]+)()\s*$/i,
|
198
|
-
/^\s*run\s+(repl|irb|live)\s+([\w\-]+)\s+(.+)\s*$/i
|
199
|
-
session_name = $2
|
200
|
-
opts = " #{$3}"
|
201
|
-
env_vars = opts.scan(/\s+[\w\-]+="[^"]+"/i) + opts.scan(/\s+[\w\-]+='[^']+'/i)
|
202
|
-
opts.scan(/\s+[\w\-]+=[^'"\s]+/i).flatten.each do |ev|
|
203
|
-
env_vars << ev.gsub('=',"='") + "'"
|
204
|
-
end
|
205
|
-
env_vars.each_with_index do |ev, idx|
|
206
|
-
ev.gsub!("=","']=")
|
207
|
-
ev.lstrip!
|
208
|
-
env_vars[idx] = "ENV['#{ev}"
|
209
|
-
end
|
210
|
-
run_repl(dest, user, session_name, env_vars.flatten, rules_file)
|
211
|
-
when /^\s*(delete|remove)\s+(repl|irb|live)\s+([\w\-]+)\s*$/i
|
212
|
-
repl_name = $3
|
213
|
-
delete_repl(dest, user, repl_name)
|
214
|
-
when /^\s*see\s+(repls|repl|irb|irbs)\s*$/i
|
215
|
-
see_repls(dest, user, typem)
|
216
|
-
else
|
217
|
-
processed2 = false
|
218
|
-
end #of case
|
261
|
+
processed2 = false
|
262
|
+
end #of case
|
219
263
|
|
220
|
-
|
264
|
+
processed = true if processed or processed2
|
265
|
+
end
|
221
266
|
end
|
222
|
-
|
223
267
|
return processed
|
224
268
|
end
|
225
269
|
end
|