slack-smart-bot 1.8.1 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +127 -21
- data/lib/slack/smart-bot/comm/ask.rb +55 -42
- data/lib/slack/smart-bot/comm/dont_understand.rb +2 -2
- data/lib/slack/smart-bot/comm/event_hello.rb +34 -0
- data/lib/slack/smart-bot/comm/get_channel_members.rb +13 -0
- data/lib/slack/smart-bot/comm/get_channels.rb +35 -0
- data/lib/slack/smart-bot/comm/get_user_info.rb +20 -0
- data/lib/slack/smart-bot/comm/get_users.rb +24 -0
- data/lib/slack/smart-bot/comm/react.rb +38 -8
- data/lib/slack/smart-bot/comm/respond.rb +219 -48
- data/lib/slack/smart-bot/comm/respond_direct.rb +2 -3
- data/lib/slack/smart-bot/comm/respond_thread.rb +5 -0
- data/lib/slack/smart-bot/comm/send_file.rb +38 -34
- data/lib/slack/smart-bot/comm/send_msg_channel.rb +27 -22
- data/lib/slack/smart-bot/comm/send_msg_user.rb +58 -33
- data/lib/slack/smart-bot/comm/unreact.rb +24 -7
- data/lib/slack/smart-bot/comm.rb +7 -1
- data/lib/slack/smart-bot/commands/general/add_announcement.rb +32 -0
- data/lib/slack/smart-bot/commands/general/bot_help.rb +68 -28
- data/lib/slack/smart-bot/commands/general/bot_stats.rb +314 -0
- data/lib/slack/smart-bot/commands/general/bot_status.rb +3 -5
- data/lib/slack/smart-bot/commands/general/bye_bot.rb +0 -7
- data/lib/slack/smart-bot/commands/general/delete_announcement.rb +34 -0
- data/lib/slack/smart-bot/commands/general/delete_share.rb +34 -0
- data/lib/slack/smart-bot/commands/general/hi_bot.rb +16 -11
- data/lib/slack/smart-bot/commands/general/leaderboard.rb +200 -0
- data/lib/slack/smart-bot/commands/general/see_announcements.rb +113 -0
- data/lib/slack/smart-bot/commands/general/see_favorite_commands.rb +54 -0
- data/lib/slack/smart-bot/commands/general/see_shares.rb +41 -0
- data/lib/slack/smart-bot/commands/general/see_statuses.rb +78 -0
- data/lib/slack/smart-bot/commands/general/share_messages.rb +58 -0
- data/lib/slack/smart-bot/commands/general/stop_using_rules.rb +11 -6
- data/lib/slack/smart-bot/commands/general/suggest_command.rb +30 -0
- data/lib/slack/smart-bot/commands/general/use_rules.rb +13 -16
- data/lib/slack/smart-bot/commands/general/whats_new.rb +19 -0
- data/lib/slack/smart-bot/commands/general_bot_commands.rb +243 -0
- data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +67 -38
- data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +49 -14
- data/lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb +5 -7
- data/lib/slack/smart-bot/commands/on_bot/admin/pause_bot.rb +4 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/pause_routine.rb +1 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/remove_routine.rb +2 -3
- data/lib/slack/smart-bot/commands/on_bot/admin/run_routine.rb +6 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/see_result_routine.rb +32 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +12 -4
- data/lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb +4 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/start_routine.rb +1 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/stop_using_rules_on.rb +2 -0
- data/lib/slack/smart-bot/commands/on_bot/admin_master/react_to.rb +32 -0
- data/lib/slack/smart-bot/commands/on_bot/admin_master/send_message.rb +24 -0
- data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +3 -5
- data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +54 -25
- data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +7 -9
- data/lib/slack/smart-bot/commands/on_bot/repl.rb +55 -25
- data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +36 -13
- data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +5 -7
- data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +4 -6
- data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +29 -13
- data/lib/slack/smart-bot/commands/on_extended/bot_rules.rb +55 -9
- data/lib/slack/smart-bot/commands/on_master/admin/kill_bot_on_channel.rb +4 -1
- data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +5 -3
- data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +2 -1
- data/lib/slack/smart-bot/commands/on_master/admin_master/publish_announcements.rb +32 -0
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_general_message.rb +38 -0
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb +49 -0
- data/lib/slack/smart-bot/commands/on_master/create_bot.rb +30 -21
- data/lib/slack/smart-bot/commands.rb +19 -1
- data/lib/slack/smart-bot/listen.rb +7 -8
- data/lib/slack/smart-bot/process.rb +373 -192
- data/lib/slack/smart-bot/process_first.rb +202 -104
- data/lib/slack/smart-bot/treat_message.rb +325 -186
- 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 +83 -30
- data/lib/slack/smart-bot/utils/get_bots_created.rb +4 -1
- data/lib/slack/smart-bot/utils/get_channels_name_and_id.rb +1 -7
- data/lib/slack/smart-bot/utils/get_help.rb +87 -35
- data/lib/slack/smart-bot/utils/get_shares.rb +12 -0
- data/lib/slack/smart-bot/utils/has_access.rb +12 -0
- data/lib/slack/smart-bot/utils/save_stats.rb +23 -8
- data/lib/slack/smart-bot/utils/save_status.rb +52 -0
- data/lib/slack/smart-bot/utils/update_shortcuts_file.rb +6 -0
- data/lib/slack/smart-bot/utils.rb +5 -0
- data/lib/slack-smart-bot.rb +88 -47
- data/lib/slack-smart-bot_general_commands.rb +46 -0
- data/lib/slack-smart-bot_general_rules.rb +5 -2
- data/lib/slack-smart-bot_rules.rb +49 -23
- data/whats_new.txt +36 -0
- metadata +44 -13
- data/lib/slack/smart-bot/commands/on_bot/admin_master/bot_stats.rb +0 -195
@@ -1,6 +1,8 @@
|
|
1
|
+
require_relative "commands/general/whats_new"
|
1
2
|
require_relative "commands/general/hi_bot"
|
2
3
|
require_relative "commands/general/bye_bot"
|
3
4
|
require_relative "commands/general/bot_help"
|
5
|
+
require_relative "commands/general/suggest_command"
|
4
6
|
require_relative "commands/on_bot/ruby_code"
|
5
7
|
require_relative "commands/on_bot/repl"
|
6
8
|
require_relative "commands/on_bot/get_repl"
|
@@ -17,6 +19,7 @@ require_relative "commands/on_bot/admin/add_routine"
|
|
17
19
|
require_relative "commands/on_bot/admin/start_bot"
|
18
20
|
require_relative "commands/on_bot/admin/pause_bot"
|
19
21
|
require_relative "commands/on_bot/admin/remove_routine"
|
22
|
+
require_relative "commands/on_bot/admin/see_result_routine"
|
20
23
|
require_relative "commands/on_bot/admin/run_routine"
|
21
24
|
require_relative "commands/on_bot/admin/pause_routine"
|
22
25
|
require_relative "commands/on_bot/admin/start_routine"
|
@@ -29,4 +32,19 @@ require_relative "commands/on_bot/delete_shortcut"
|
|
29
32
|
require_relative "commands/on_bot/see_shortcuts"
|
30
33
|
require_relative "commands/on_extended/bot_rules"
|
31
34
|
require_relative "commands/on_bot/admin_master/get_bot_logs"
|
32
|
-
require_relative "commands/on_bot/admin_master/
|
35
|
+
require_relative "commands/on_bot/admin_master/send_message"
|
36
|
+
require_relative "commands/on_bot/admin_master/react_to"
|
37
|
+
require_relative "commands/general/bot_stats"
|
38
|
+
require_relative "commands/general/leaderboard"
|
39
|
+
require_relative "commands/general/add_announcement"
|
40
|
+
require_relative "commands/general/delete_announcement"
|
41
|
+
require_relative "commands/general/see_announcements"
|
42
|
+
require_relative "commands/general/see_statuses"
|
43
|
+
require_relative "commands/general/see_favorite_commands"
|
44
|
+
require_relative "commands/on_master/admin_master/publish_announcements"
|
45
|
+
require_relative "commands/on_master/admin_master/set_maintenance"
|
46
|
+
require_relative "commands/on_master/admin_master/set_general_message"
|
47
|
+
require_relative "commands/general_bot_commands"
|
48
|
+
require_relative "commands/general/share_messages"
|
49
|
+
require_relative "commands/general/see_shares"
|
50
|
+
require_relative "commands/general/delete_share"
|
@@ -1,12 +1,12 @@
|
|
1
1
|
class SlackSmartBot
|
2
2
|
def listen_simulate
|
3
|
-
@salutations = [config[:nick], "<@#{config[:nick_id]}>", "bot", "smart"]
|
3
|
+
@salutations = [config[:nick], "<@#{config[:nick_id]}>", "bot", "smart", "smartbot", "smart-bot", "smart bot"]
|
4
4
|
@pings = []
|
5
5
|
@last_activity_check = Time.now
|
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,27 +14,26 @@ 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
|
-
|
22
21
|
if command.match?(/^\s*\-!!/) or command.match?(/^\s*\-\^/)
|
23
22
|
command.scan(/`([^`]+)`/).flatten.each do |cmd|
|
24
23
|
if cmd.to_s!=''
|
25
24
|
cmd = "^#{cmd}"
|
26
|
-
treat_message({channel: channel, user: user, text: cmd}, false)
|
25
|
+
treat_message({channel: channel, user: user, text: cmd, user_name: user_name}, false)
|
27
26
|
end
|
28
27
|
end
|
29
28
|
elsif command.match?(/^\s*\-!/)
|
30
29
|
command.scan(/`([^`]+)`/).flatten.each do |cmd|
|
31
30
|
if cmd.to_s!=''
|
32
31
|
cmd = "!#{cmd}"
|
33
|
-
treat_message({channel: channel, user: user, text: cmd}, false)
|
32
|
+
treat_message({channel: channel, user: user, text: cmd, user_name: user_name}, false)
|
34
33
|
end
|
35
34
|
end
|
36
35
|
else
|
37
|
-
treat_message({channel: channel, user: user, text: command})
|
36
|
+
treat_message({channel: channel, user: user, text: command, user_name: user_name})
|
38
37
|
end
|
39
38
|
end
|
40
39
|
end
|
@@ -1,19 +1,23 @@
|
|
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
|
12
|
-
if command.match(
|
13
|
-
command.match(
|
14
|
-
command.match(
|
15
|
-
command.match(
|
16
|
-
command.match(
|
16
|
+
if command.match(/\A@?(#{config[:nick]}):*\s+(.+)/im) or
|
17
|
+
command.match(/\A()!!(.+)/im) or
|
18
|
+
command.match(/\A()\^(.+)/im) or
|
19
|
+
command.match(/\A()!(.+)/im) or
|
20
|
+
command.match(/\A()<@#{config[:nick_id]}>\s+(.+)/im)
|
17
21
|
command2 = $2
|
18
22
|
Thread.current[:command] = command2
|
19
23
|
if command2.match?(/^()!!(.+)/im) or
|
@@ -23,204 +27,381 @@ 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
|
+
unless Thread.current.key?(:routine) and Thread.current[:routine]
|
34
|
+
respond eval("\"" + config.on_maintenance_message + "\"")
|
35
|
+
end
|
36
|
+
processed = true
|
37
|
+
end
|
38
|
+
if !config.on_maintenance or (config.on_maintenance and command.match?(/\A(set|turn)\s+maintenance\s+off\s*\z/))
|
39
|
+
#todo: check :on_pg in this case
|
40
|
+
if typem == :on_master or typem == :on_bot or typem == :on_pg or typem == :on_dm
|
41
|
+
|
42
|
+
case command
|
43
|
+
|
44
|
+
when /\A\s*what's\s+new\s*$/i
|
45
|
+
whats_new(user, dest, dchannel, from, display_name)
|
46
|
+
when /\A\s*(#{@salutations.join("|")})\s+(rules|help)\s*(.+)?$/i, /\A(#{@salutations.join("|")}),? what can I do/i
|
47
|
+
$2.to_s.match?(/rules/i) ? specific = true : specific = false
|
48
|
+
help_command = $3
|
49
|
+
bot_help(user, from, dest, dchannel, specific, help_command, rules_file)
|
50
|
+
when /\A\s*(suggest|random)\s+(command|rule)\s*\z/i, /\A\s*(command|rule)\s+suggestion\s*\z/i
|
51
|
+
$2.to_s.match?(/rule/i) || $1.to_s.match?(/rule/i) ? specific = true : specific = false
|
52
|
+
suggest_command(from, dest, dchannel, specific, rules_file)
|
53
|
+
when /\A\s*use\s+(rules\s+)?(from\s+)?<#C\w+\|(.+)>\s*$/i,
|
54
|
+
/\A\s*use\s+(rules\s+)?(from\s+)?<#(\w+)\|>\s*$/i,
|
55
|
+
/\Ause\s+(rules\s+)?(from\s+)?([^\s]+\s*$)/i
|
56
|
+
channel = $3
|
57
|
+
use_rules(dest, channel, user, dchannel)
|
58
|
+
when /\A\s*stop\s+using\s+rules\s+(on\s+)<#\w+\|(.+)>/i,
|
59
|
+
/\A\s*stop\s+using\s+rules\s+(on\s+)<#(\w+)\|>/i,
|
60
|
+
/\A\s*stop\s+using\s+rules\s+(on\s+)(.+)\s*$/i
|
61
|
+
channel = $2
|
62
|
+
stop_using_rules_on(dest, user, from, channel, typem)
|
63
|
+
when /\A\s*stop\s+using\s+(rules\s+from\s+)?<#\w+\|(.+)>/i,
|
64
|
+
/\A\s*stop\s+using\s+(rules\s+from\s+)?<#(\w+)\|>/i,
|
65
|
+
/\A\s*stop\s+using\s+(rules\s+from\s+)?(.+)\s*$/i
|
66
|
+
channel = $2
|
67
|
+
stop_using_rules(dest, channel, user, dchannel)
|
68
|
+
when /\A\s*extend\s+rules\s+(to\s+)<#C\w+\|(.+)>/i, /\A\s*extend\s+rules\s+(to\s+)<#(\w+)\|>/i,
|
69
|
+
/\A\s*extend\s+rules\s+(to\s+)(.+)/i,
|
70
|
+
/\A\s*use\s+rules\s+(on\s+)<#C\w+\|(.+)>/i, /\A\s*use\s+rules\s+(on\s+)<#(\w+)\|>/i,
|
71
|
+
/\A\s*use\s+rules\s+(on\s+)(.+)/i
|
72
|
+
channel = $2
|
73
|
+
extend_rules(dest, user, from, channel, typem)
|
74
|
+
when /\A\s*exit\s+bot\s*$/i, /\A\s*quit\s+bot\s*$/i, /\A\s*close\s+bot\s*$/i
|
75
|
+
exit_bot(command, from, dest, display_name)
|
76
|
+
when /\A\s*start\s+(this\s+)?bot$/i
|
77
|
+
start_bot(dest, from)
|
78
|
+
when /\A\s*pause\s+(this\s+)?bot$/i
|
79
|
+
pause_bot(dest, from)
|
80
|
+
when /\A\s*bot\s+status/i
|
81
|
+
bot_status(dest, user)
|
82
|
+
when /\Anotify\s+<#(C\w+)\|.+>\s+(.+)\s*\z/im,
|
83
|
+
/\Anotify\s+<#(\w+)\|>\s+(.+)\s*\z/im,
|
84
|
+
/\Anotify\s+(all)?\s*(.+)\s*\z/im
|
85
|
+
where = $1
|
86
|
+
message = $2
|
87
|
+
notify_message(dest, from, where, message)
|
88
|
+
when /\Apublish\s+announcements\s*\z/i
|
89
|
+
publish_announcements(user)
|
90
|
+
when /\A\s*create\s+(cloud\s+|silent\s+)?bot\s+on\s+<#C\w+\|(.+)>\s*/i,
|
91
|
+
/\A\s*create\s+(cloud\s+|silent\s+)?bot\s+on\s+<#(\w+)\|>\s*/i,
|
92
|
+
/\Acreate\s+(cloud\s+|silent\s+)?bot\s+on\s+#(.+)\s*/i,
|
93
|
+
/\Acreate\s+(cloud\s+|silent\s+)?bot\s+on\s+(.+)\s*/i
|
94
|
+
type = $1.to_s.downcase
|
95
|
+
channel = $2
|
96
|
+
create_bot(dest, user, type, channel)
|
97
|
+
when /\A\s*kill\s+bot\s+on\s+<#C\w+\|(.+)>\s*$/i,
|
98
|
+
/\A\s*kill\s+bot\s+on\s+<#(\w+)\|>\s*$/i,
|
99
|
+
/\Akill\s+bot\s+on\s+#(.+)\s*$/i, /\Akill\s+bot\s+on\s+(.+)\s*$/i
|
100
|
+
channel = $1
|
101
|
+
kill_bot_on_channel(dest, from, channel)
|
102
|
+
when /\A\s*(add|create)\s+(silent\s+)?(bgroutine|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*\z/im,
|
103
|
+
/\A\s*(add|create)\s+(silent\s+)?(bgroutine|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*\z/im,
|
104
|
+
/\A\s*(add|create)\s+(silent\s+)?(bgroutine|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*\z/im,
|
105
|
+
/\A\s*(add|create)\s+(silent\s+)?(bgroutine|routine)\s+([\w\.]+)\s+on\s+(monday|tuesday|wednesday|thursday|friday|saturday|sunday|weekend|weekday)s?\s+at\s+(\d+:\d+:?\d+?)\s*()(\s#(\w+)\s*)(\s.+)?\s*\z/im,
|
106
|
+
/\A\s*(add|create)\s+(silent\s+)?(bgroutine|routine)\s+([\w\.]+)\s+on\s+(monday|tuesday|wednesday|thursday|friday|saturday|sunday|weekend|weekday)s?\s+at\s+(\d+:\d+:?\d+?)\s*()(\s<#(C\w+)\|.+>\s*)?(\s.+)?\s*\z/im,
|
107
|
+
/\A\s*(add|create)\s+(silent\s+)?(bgroutine|routine)\s+([\w\.]+)\s+on\s+(monday|tuesday|wednesday|thursday|friday|saturday|sunday|weekend|weekday)s?\s+at\s+(\d+:\d+:?\d+?)\s*()(\s<#(\w+)\|>\s*)?(\s.+)?\s*\z/im,
|
108
|
+
/\A\s*(add|create)\s+(silent\s+)?(bgroutine|routine)\s+([\w\.]+)\s+(at)\s+(\d+:\d+:?\d+?)\s*()(\s#(\w+)\s*)(\s.+)?\s*\z/im,
|
109
|
+
/\A\s*(add|create)\s+(silent\s+)?(bgroutine|routine)\s+([\w\.]+)\s+(at)\s+(\d+:\d+:?\d+?)\s*()(\s<#(C\w+)\|.+>\s*)?(\s.+)?\s*\z/im,
|
110
|
+
/\A\s*(add|create)\s+(silent\s+)?(bgroutine|routine)\s+([\w\.]+)\s+(at)\s+(\d+:\d+:?\d+?)\s*()(\s<#(\w+)\|>\s*)?(\s.+)?\s*\z/im
|
111
|
+
silent = $2.to_s!=''
|
112
|
+
routine_type = $3.downcase
|
113
|
+
name = $4.downcase
|
114
|
+
type = $5.to_s.downcase
|
115
|
+
number_time = $6
|
116
|
+
period = $7
|
117
|
+
channel = $9
|
118
|
+
command_to_run = $10
|
119
|
+
content = command_to_run.to_s.scan(/\A\s*```(.+)```\s*\z/im).join
|
120
|
+
unless content == ''
|
121
|
+
files = [
|
122
|
+
{
|
123
|
+
name: name,
|
124
|
+
filetype: '',
|
125
|
+
content: content
|
126
|
+
}
|
127
|
+
]
|
128
|
+
command_to_run = ''
|
129
|
+
end
|
130
|
+
add_routine(dest, from, user, name, type, number_time, period, command_to_run, files, silent, channel, routine_type)
|
131
|
+
when /\A\s*(kill|delete|remove)\s+routine\s+([\w\.]+)\s*$/i
|
132
|
+
name = $2.downcase
|
133
|
+
remove_routine(dest, from, name)
|
134
|
+
when /\A\s*see\s+routines?\s+results?\s+([\w\.]+)\s*$/i,
|
135
|
+
/\A\s*see\s+results?\s+routines?\s+([\w\.]+)\s*$/i,
|
136
|
+
/\A\s*results?\s+routines?\s+([\w\.]+)\s*$/i
|
137
|
+
name = $1.downcase
|
138
|
+
see_result_routine(dest, from, name)
|
139
|
+
when /\A\s*(run|execute)\s+routine\s+([\w\.]+)\s*$/i
|
140
|
+
name = $2.downcase
|
141
|
+
run_routine(dest, from, name)
|
142
|
+
when /\A\s*pause\s+routine\s+([\w\.]+)\s*$/i
|
143
|
+
name = $1.downcase
|
144
|
+
pause_routine(dest, from, name)
|
145
|
+
when /\A\s*start\s+routine\s+([\w\.]+)\s*$/i
|
146
|
+
name = $1.downcase
|
147
|
+
start_routine(dest, from, name)
|
148
|
+
when /\A\s*see\s+(all\s+)?routines\s*$/i
|
149
|
+
all = $1.to_s != ""
|
150
|
+
see_routines(dest, from, user, all)
|
151
|
+
when /\A\s*get\s+bot\s+logs?\s*$/i
|
152
|
+
get_bot_logs(dest, from, typem)
|
153
|
+
when /\A\s*send\s+message\s+(on|to|in)\s*([^\s]+)\s+([^\s]+)\s*:\s*(.+)\s*$/i,
|
154
|
+
/\A\s*send\s+message\s+(on|to|in)\s*([^\s]+)\s*():\s*(.+)\s*$/i
|
155
|
+
to = $2
|
156
|
+
thread_ts = $3.to_s
|
157
|
+
message = $4
|
158
|
+
to_channel = to.scan(/<#([^>]+)\|.*>/).join
|
159
|
+
to_channel = to.scan(/#([^\s]+)/).join if to_channel == ''
|
160
|
+
if to_channel == ''
|
161
|
+
to_user = to.scan(/<@(\w+)>/).join
|
162
|
+
if to_user == ''
|
163
|
+
# message_id
|
164
|
+
else
|
165
|
+
to = to_user
|
166
|
+
end
|
167
|
+
else
|
168
|
+
to = to_channel
|
169
|
+
end
|
170
|
+
send_message(dest, from, typem, to, thread_ts, message)
|
171
|
+
when /\A\s*react\s+(on|to|in)\s*([^\s]+)\s+([^\s]+)\s+(.+)\s*$/i
|
172
|
+
to = $2
|
173
|
+
thread_ts = $3.to_s
|
174
|
+
emojis = $4
|
175
|
+
to_channel = to.scan(/<#([^>]+)\|.*>/).join
|
176
|
+
if to_channel == ''
|
177
|
+
to_channel = to.scan(/#([^\s]+)/).join
|
178
|
+
to_channel = @channels_id[to_channel].to_s
|
179
|
+
end
|
180
|
+
if to_channel == ''
|
181
|
+
respond "The channel specified doesn't exist or is in a incorrect format"
|
182
|
+
else
|
183
|
+
to = to_channel
|
184
|
+
react_to(dest, from, typem, to, thread_ts, emojis)
|
185
|
+
end
|
26
186
|
|
27
|
-
|
28
|
-
|
29
|
-
|
187
|
+
when /\A\s*(leader\s+board|leaderboard|ranking|podium)()()\s*$/i,
|
188
|
+
/\A\s*(leader\s+board|leaderboard|ranking|podium)\s+from\s+(\d\d\d\d[\/\-\.]\d\d[\/\-\.]\d\d)\s+to\s+(\d\d\d\d[\/\-\.]\d\d[\/\-\.]\d\d)\s*$/i,
|
189
|
+
/\A\s*(leader\s+board|leaderboard|ranking|podium)\s+from\s+(\d\d\d\d[\/\-\.]\d\d[\/\-\.]\d\d)()\s*$/i,
|
190
|
+
/\A\s*(leader\s+board|leaderboard|ranking|podium)\s+(today|yesterday|last\s+week|this\s+week|last\s+month|this\s+month|last\s+year|this year)()\s*$/i
|
191
|
+
require 'date'
|
192
|
+
opt1 = $2.to_s
|
193
|
+
to = $3.to_s
|
194
|
+
if opt1.match?(/\d/)
|
195
|
+
from = opt1
|
196
|
+
period = ''
|
197
|
+
from = from.gsub('.','-').gsub('/','-')
|
198
|
+
if to.empty?
|
199
|
+
to = Date.today.strftime("%Y-%m-%d")
|
200
|
+
else
|
201
|
+
to = to.gsub('.','-').gsub('/','-')
|
202
|
+
end
|
203
|
+
elsif opt1.to_s==''
|
204
|
+
period = 'last week'
|
205
|
+
date = Date.today
|
206
|
+
wday = date.wday
|
207
|
+
wday = 7 if wday==0
|
208
|
+
wday-=1
|
209
|
+
from = "#{(date-wday-7).strftime("%Y-%m-%d")}"
|
210
|
+
to = "#{(date-wday-1).strftime("%Y-%m-%d")}"
|
211
|
+
else
|
212
|
+
from = ''
|
213
|
+
period = opt1.downcase
|
214
|
+
case period
|
215
|
+
when 'today'
|
216
|
+
from = to = "#{Date.today.strftime("%Y-%m-%d")}"
|
217
|
+
when 'yesterday'
|
218
|
+
from = to ="#{(Date.today-1).strftime("%Y-%m-%d")}"
|
219
|
+
when /this\s+month/
|
220
|
+
from = "#{Date.today.strftime("%Y-%m-01")}"
|
221
|
+
to = "#{Date.today.strftime("%Y-%m-%d")}"
|
222
|
+
when /last\s+month/
|
223
|
+
date = Date.today<<1
|
224
|
+
from = "#{date.strftime("%Y-%m-01")}"
|
225
|
+
to = "#{(Date.new(date.year, date.month, -1)).strftime("%Y-%m-%d")}"
|
226
|
+
when /this\s+year/
|
227
|
+
from = "#{Date.today.strftime("%Y-01-01")}"
|
228
|
+
to = "#{Date.today.strftime("%Y-%m-%d")}"
|
229
|
+
when /last\s+year/
|
230
|
+
date = Date.today.prev_year
|
231
|
+
from = "#{date.strftime("%Y-01-01")}"
|
232
|
+
to = "#{(Date.new(date.year, 12, 31)).strftime("%Y-%m-%d")}"
|
233
|
+
when /this\s+week/
|
234
|
+
date = Date.today
|
235
|
+
wday = date.wday
|
236
|
+
wday = 7 if wday==0
|
237
|
+
wday-=1
|
238
|
+
from = "#{(date-wday).strftime("%Y-%m-%d")}"
|
239
|
+
to = "#{date.strftime("%Y-%m-%d")}"
|
240
|
+
when /last\s+week/
|
241
|
+
date = Date.today
|
242
|
+
wday = date.wday
|
243
|
+
wday = 7 if wday==0
|
244
|
+
wday-=1
|
245
|
+
from = "#{(date-wday-7).strftime("%Y-%m-%d")}"
|
246
|
+
to = "#{(date-wday-1).strftime("%Y-%m-%d")}"
|
247
|
+
end
|
248
|
+
end
|
30
249
|
|
31
|
-
|
32
|
-
hi_bot(user, dest, dchannel, from, display_name)
|
33
|
-
when /^\s*(Bye|Bæ|Good\sBye|Adiós|Ciao|Bless|Bless\sBless|Adeu)\s(#{@salutations.join("|")})\s*$/i
|
34
|
-
bye_bot(dest, from, display_name)
|
35
|
-
when /^\s*bot\s+(rules|help)\s*(.+)?$/i, /^bot,? what can I do/i
|
36
|
-
$1.to_s.match?(/rules/i) ? specific = true : specific = false
|
37
|
-
help_command = $2
|
250
|
+
leaderboard(from, to, period)
|
38
251
|
|
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
|
-
name = $2.downcase
|
87
|
-
run_routine(dest, from, name)
|
88
|
-
when /^\s*pause\s+routine\s+(\w+)\s*$/i
|
89
|
-
name = $1.downcase
|
90
|
-
pause_routine(dest, from, name)
|
91
|
-
when /^\s*start\s+routine\s+(\w+)\s*$/i
|
92
|
-
name = $1.downcase
|
93
|
-
start_routine(dest, from, name)
|
94
|
-
when /^\s*see\s+(all\s+)?routines\s*$/i
|
95
|
-
all = $1.to_s != ""
|
96
|
-
see_routines(dest, from, user, all)
|
97
|
-
when /^\s*get\s+bot\s+logs?\s*$/i
|
98
|
-
get_bot_logs(dest, from, typem)
|
99
|
-
when /^\s*bot\s+stats\s*(.*)\s*$/i
|
100
|
-
opts = $1.to_s
|
101
|
-
all_opts = opts.downcase.split(' ')
|
102
|
-
st_channel = opts.scan(/<#(\w+)\|.+>/).join
|
103
|
-
st_from = opts.scan(/from\s+(\d\d\d\d[\/\-\.]\d\d[\/\-\.]\d\d)/).join
|
104
|
-
st_from = st_from.gsub('.','-').gsub('/','-')
|
105
|
-
st_to = opts.scan(/to\s+(\d\d\d\d[\/\-\.]\d\d[\/\-\.]\d\d)/).join
|
106
|
-
st_to = st_to.gsub('.','-').gsub('/','-')
|
107
|
-
st_user = opts.scan(/<@([^>]+)>/).join
|
108
|
-
exclude_masters = opts.match?(/exclude\s+masters?/i)
|
109
|
-
monthly = false
|
110
|
-
if all_opts.include?('today')
|
111
|
-
st_from = st_to = "#{Time.now.strftime("%Y-%m-%d")}"
|
112
|
-
elsif all_opts.include?('monthly')
|
113
|
-
monthly = true
|
252
|
+
when /\A\s*bot\s+stats\s*(.*)\s*$/i
|
253
|
+
opts = $1.to_s
|
254
|
+
all_opts = opts.downcase.split(' ')
|
255
|
+
all_data = all_opts.include?('alldata')
|
256
|
+
st_channel = opts.scan(/<#(\w+)\|.*>/).join
|
257
|
+
st_from = opts.scan(/from\s+(\d\d\d\d[\/\-\.]\d\d[\/\-\.]\d\d)/).join
|
258
|
+
st_from = st_from.gsub('.','-').gsub('/','-')
|
259
|
+
st_to = opts.scan(/to\s+(\d\d\d\d[\/\-\.]\d\d[\/\-\.]\d\d)/).join
|
260
|
+
st_to = st_to.gsub('.','-').gsub('/','-')
|
261
|
+
st_user = opts.scan(/<@([^>]+)>/).join
|
262
|
+
st_command = opts.scan(/\s+command\s+(\w+)/i).join.downcase
|
263
|
+
st_command = opts.scan(/^command\s+(\w+)/i).join.downcase if st_command == ''
|
264
|
+
exclude_masters = all_opts.include?('exclude') && all_opts.include?('masters')
|
265
|
+
exclude_routines = all_opts.include?('exclude') && all_opts.include?('routines')
|
266
|
+
if exclude_masters
|
267
|
+
opts.gsub!(/\s+masters$/,'')
|
268
|
+
opts.gsub!(/\s+masters\s+/,'')
|
269
|
+
end
|
270
|
+
if exclude_routines
|
271
|
+
opts.gsub!(/\s+routines$/,'')
|
272
|
+
opts.gsub!(/\s+routines\s+/,'')
|
273
|
+
end
|
274
|
+
monthly = false
|
275
|
+
if all_opts.include?('today')
|
276
|
+
st_from = st_to = "#{Time.now.strftime("%Y-%m-%d")}"
|
277
|
+
elsif all_opts.include?('monthly')
|
278
|
+
monthly = true
|
279
|
+
end
|
280
|
+
exclude_command = opts.scan(/exclude\s+([^\s]+)/i).join
|
281
|
+
unless @master_admin_users_id.include?(user.id)
|
282
|
+
st_user = user.id
|
283
|
+
end
|
284
|
+
if (typem == :on_master or typem == :on_bot) and dest[0]!='D' #routine bot stats to be published on DM
|
285
|
+
st_channel = dchannel
|
286
|
+
end
|
287
|
+
bot_stats(dest, user, typem, st_channel, st_from, st_to, st_user, st_command, exclude_masters, exclude_routines, exclude_command, monthly, all_data)
|
288
|
+
when /\A(set|turn)\s+maintenance\s+(on|off)\s*()\z/im, /\A(set|turn)\s+maintenance\s+(on)\s*(.+)\s*\z/im
|
289
|
+
status = $2.downcase
|
290
|
+
message = $3.to_s
|
291
|
+
set_maintenance(from, status, message)
|
292
|
+
when /\A(set|turn)\s+(general|generic)\s+message\s+(off)\s*()\z/im, /\A(set|turn)\s+(general|generic)\s+message\s+(on\s+)?\s*(.+)\s*\z/im
|
293
|
+
status = $3.to_s.downcase
|
294
|
+
status = 'on' if status == ''
|
295
|
+
message = $4.to_s
|
296
|
+
set_general_message(from, status, message)
|
297
|
+
else
|
298
|
+
processed = false
|
114
299
|
end
|
115
|
-
exclude_command = opts.scan(/exclude\s+([^\s]+)/i).join
|
116
|
-
exclude_command = '' if exclude_command == 'masters'
|
117
|
-
bot_stats(dest, from, typem, st_channel, st_from, st_to, st_user, exclude_masters, exclude_command, monthly)
|
118
300
|
else
|
119
301
|
processed = false
|
120
302
|
end
|
121
|
-
else
|
122
|
-
processed = false
|
123
|
-
end
|
124
303
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
304
|
+
# only when :on and (listening or on demand or direct message)
|
305
|
+
if @status == :on and
|
306
|
+
(!answer.empty? or
|
307
|
+
(@repl_sessions.key?(from) and dest==@repl_sessions[from][:dest] and
|
308
|
+
((@repl_sessions[from][:on_thread] and Thread.current[:thread_ts] == @repl_sessions[from][:thread_ts]) or
|
309
|
+
(!@repl_sessions[from][:on_thread] and !Thread.current[:on_thread]))) or
|
310
|
+
(@listening.key?(from) and typem != :on_extended and
|
311
|
+
((@listening[from].key?(dest) and !Thread.current[:on_thread]) or
|
312
|
+
(@listening[from].key?(Thread.current[:thread_ts]) and Thread.current[:on_thread] ) )) or
|
313
|
+
typem == :on_dm or typem == :on_pg or on_demand)
|
314
|
+
processed2 = true
|
315
|
+
|
316
|
+
case command
|
136
317
|
|
137
|
-
|
318
|
+
when /\A\s*(add\s+)?(global\s+|generic\s+)?shortcut\s+(for\sall)?\s*([^:]+)\s*:\s*(.+)/i,
|
319
|
+
/\A(add\s+)(global\s+|generic\s+)?sc\s+(for\sall)?\s*([^:]+)\s*:\s*(.+)/i
|
320
|
+
for_all = $3
|
321
|
+
shortcut_name = $4.to_s.downcase
|
322
|
+
command_to_run = $5
|
323
|
+
global = $2.to_s != ''
|
324
|
+
add_shortcut(dest, user, typem, for_all, shortcut_name, command, command_to_run, global)
|
325
|
+
when /\A\s*(delete|remove)\s+(global\s+|generic\s+)?shortcut\s+(.+)/i,
|
326
|
+
/\A(delete|remove)\s+(global\s+|generic\s+)?sc\s+(.+)/i
|
327
|
+
shortcut = $3.to_s.downcase
|
328
|
+
global = $2.to_s != ''
|
138
329
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
bot_rules(dest, help_command, typem, rules_file, user)
|
143
|
-
when /^\s*(add\s)?shortcut\s(for\sall)?\s*([^:]+)\s*:\s*(.+)/i, /^(add\s)sc\s(for\sall)?\s*([^:]+)\s*:\s*(.+)/i
|
144
|
-
for_all = $2
|
145
|
-
shortcut_name = $3.to_s.downcase
|
146
|
-
command_to_run = $4
|
147
|
-
add_shortcut(dest, user, typem, for_all, shortcut_name, command, command_to_run)
|
148
|
-
when /^\s*(delete|remove)\s+shortcut\s+(.+)/i, /^(delete|remove)\s+sc\s+(.+)/i
|
149
|
-
shortcut = $2.to_s.downcase
|
150
|
-
delete_shortcut(dest, user, shortcut, typem, command)
|
151
|
-
when /^\s*see\sshortcuts/i, /^see\ssc/i
|
152
|
-
see_shortcuts(dest, user, typem)
|
330
|
+
delete_shortcut(dest, user, shortcut, typem, command, global)
|
331
|
+
when /\A\s*see\s+shortcuts/i, /^see\s+sc/i
|
332
|
+
see_shortcuts(dest, user, typem)
|
153
333
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
334
|
+
#kept to be backwards compatible
|
335
|
+
when /\A\s*id\schannel\s<#C\w+\|(.+)>\s*/i, /^id channel (.+)/
|
336
|
+
unless typem == :on_extended
|
337
|
+
channel_name = $1
|
338
|
+
get_channels_name_and_id()
|
339
|
+
if @channels_id.keys.include?(channel_name)
|
340
|
+
respond "the id of #{channel_name} is #{@channels_id[channel_name]}", dest
|
341
|
+
else
|
342
|
+
respond "channel: #{channel_name} not found", dest
|
343
|
+
end
|
163
344
|
end
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
345
|
+
when /\A\s*ruby\s+(.+)/im, /\A\s*code\s+(.+)/im
|
346
|
+
code = $1
|
347
|
+
code.gsub!("\\n", "\n")
|
348
|
+
code.gsub!("\\r", "\r")
|
349
|
+
code.gsub!(/^\s*```/,'')
|
350
|
+
code.gsub!(/```\s*$/,'')
|
351
|
+
@logger.info code
|
352
|
+
ruby_code(dest, user, code, rules_file)
|
353
|
+
when /\A\s*(private\s+|clean\s+|clean\s+private\s+|private\s+clean\s+)?(repl|irb|live)\s*()()()\z/i,
|
354
|
+
/\A\s*(private\s+|clean\s+|clean\s+private\s+|private\s+clean\s+)?(repl|irb|live)\s+([\w\-]+)()()\s*\z/i,
|
355
|
+
/\A\s*(private\s+|clean\s+|clean\s+private\s+|private\s+clean\s+)?(repl|irb|live)\s+([\w\-]+)\s*:\s+"([^"]+)"()\s*\z/i,
|
356
|
+
/\A\s*(private\s+|clean\s+|clean\s+private\s+|private\s+clean\s+)?(repl|irb|live)\s+([\w\-]+)\s*:\s+"([^"]+)"\s+(.+)\s*\z/i,
|
357
|
+
/\A\s*(private\s+|clean\s+|clean\s+private\s+|private\s+clean\s+)?(repl|irb|live)\s+([\w\-]+)()\s+(.+)\s*\z/i,
|
358
|
+
/\A\s*(private\s+|clean\s+|clean\s+private\s+|private\s+clean\s+)?(repl|irb|live)()\s+()(.+)\s*\z/i
|
359
|
+
opts_type = $1.to_s.downcase.split(' ')
|
360
|
+
opts_type.include?('private') ? type = :private : type = :public
|
361
|
+
type = "#{type}_clean".to_sym if opts_type.include?('clean')
|
362
|
+
|
363
|
+
session_name = $3
|
364
|
+
description = $4
|
365
|
+
opts = " #{$5}"
|
366
|
+
env_vars = opts.scan(/\s+[\w\-]+="[^"]+"/i) + opts.scan(/\s+[\w\-]+='[^']+'/i)
|
367
|
+
opts.scan(/\s+[\w\-]+=[^'"\s]+/i).flatten.each do |ev|
|
368
|
+
env_vars << ev.gsub('=',"='") + "'"
|
369
|
+
end
|
370
|
+
env_vars.each_with_index do |ev, idx|
|
371
|
+
ev.gsub!("=","']=")
|
372
|
+
ev.lstrip!
|
373
|
+
env_vars[idx] = "ENV['#{ev}"
|
374
|
+
end
|
375
|
+
repl(dest, user, session_name, env_vars.flatten, rules_file, command, description, type)
|
376
|
+
when /\A\s*get\s+(repl|irb|live)\s+([\w\-]+)\s*/i
|
377
|
+
session_name = $2
|
378
|
+
get_repl(dest, user, session_name)
|
379
|
+
when /\A\s*run\s+(repl|irb|live)\s+([\w\-]+)()\s*$/i,
|
380
|
+
/^\s*run\s+(repl|irb|live)\s+([\w\-]+)\s+(.+)\s*$/i
|
381
|
+
session_name = $2
|
382
|
+
opts = " #{$3}"
|
383
|
+
env_vars = opts.scan(/\s+[\w\-]+="[^"]+"/i) + opts.scan(/\s+[\w\-]+='[^']+'/i)
|
384
|
+
opts.scan(/\s+[\w\-]+=[^'"\s]+/i).flatten.each do |ev|
|
385
|
+
env_vars << ev.gsub('=',"='") + "'"
|
386
|
+
end
|
387
|
+
env_vars.each_with_index do |ev, idx|
|
388
|
+
ev.gsub!("=","']=")
|
389
|
+
ev.lstrip!
|
390
|
+
env_vars[idx] = "ENV['#{ev}"
|
391
|
+
end
|
392
|
+
run_repl(dest, user, session_name, env_vars.flatten, rules_file)
|
393
|
+
when /\A\s*(delete|remove)\s+(repl|irb|live)\s+([\w\-]+)\s*$/i
|
394
|
+
repl_name = $3
|
395
|
+
delete_repl(dest, user, repl_name)
|
396
|
+
when /\A\s*see\s+(repls|repl|irb|irbs)\s*$/i
|
397
|
+
see_repls(dest, user, typem)
|
179
398
|
else
|
180
|
-
|
181
|
-
end
|
182
|
-
session_name = $3
|
183
|
-
description = $4
|
184
|
-
opts = " #{$5}"
|
185
|
-
env_vars = opts.scan(/\s+[\w\-]+="[^"]+"/i) + opts.scan(/\s+[\w\-]+='[^']+'/i)
|
186
|
-
opts.scan(/\s+[\w\-]+=[^'"\s]+/i).flatten.each do |ev|
|
187
|
-
env_vars << ev.gsub('=',"='") + "'"
|
188
|
-
end
|
189
|
-
env_vars.each_with_index do |ev, idx|
|
190
|
-
ev.gsub!("=","']=")
|
191
|
-
ev.lstrip!
|
192
|
-
env_vars[idx] = "ENV['#{ev}"
|
193
|
-
end
|
194
|
-
repl(dest, user, session_name, env_vars.flatten, rules_file, command, description, type)
|
195
|
-
when /^\s*get\s+(repl|irb|live)\s+([\w\-]+)\s*/i
|
196
|
-
session_name = $2
|
197
|
-
get_repl(dest, user, session_name)
|
198
|
-
when /^\s*run\s+(repl|irb|live)\s+([\w\-]+)()\s*$/i,
|
199
|
-
/^\s*run\s+(repl|irb|live)\s+([\w\-]+)\s+(.+)\s*$/i
|
200
|
-
session_name = $2
|
201
|
-
opts = " #{$3}"
|
202
|
-
env_vars = opts.scan(/\s+[\w\-]+="[^"]+"/i) + opts.scan(/\s+[\w\-]+='[^']+'/i)
|
203
|
-
opts.scan(/\s+[\w\-]+=[^'"\s]+/i).flatten.each do |ev|
|
204
|
-
env_vars << ev.gsub('=',"='") + "'"
|
205
|
-
end
|
206
|
-
env_vars.each_with_index do |ev, idx|
|
207
|
-
ev.gsub!("=","']=")
|
208
|
-
ev.lstrip!
|
209
|
-
env_vars[idx] = "ENV['#{ev}"
|
210
|
-
end
|
211
|
-
run_repl(dest, user, session_name, env_vars.flatten, rules_file)
|
212
|
-
when /^\s*(delete|remove)\s+(repl|irb|live)\s+([\w\-]+)\s*$/i
|
213
|
-
repl_name = $3
|
214
|
-
delete_repl(dest, user, repl_name)
|
215
|
-
when /^\s*see\s+(repls|repl|irb|irbs)\s*$/i
|
216
|
-
see_repls(dest, user, typem)
|
217
|
-
else
|
218
|
-
processed2 = false
|
219
|
-
end #of case
|
399
|
+
processed2 = false
|
400
|
+
end #of case
|
220
401
|
|
221
|
-
|
402
|
+
processed = true if processed or processed2
|
403
|
+
end
|
222
404
|
end
|
223
|
-
|
224
405
|
return processed
|
225
406
|
end
|
226
407
|
end
|