slack-smart-bot 1.9.1 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +184 -16
  3. data/lib/slack/smart-bot/comm/ask.rb +55 -49
  4. data/lib/slack/smart-bot/comm/delete.rb +13 -0
  5. data/lib/slack/smart-bot/comm/dont_understand.rb +3 -3
  6. data/lib/slack/smart-bot/comm/event_hello.rb +8 -4
  7. data/lib/slack/smart-bot/comm/get_channel_members.rb +13 -4
  8. data/lib/slack/smart-bot/comm/get_channels.rb +31 -16
  9. data/lib/slack/smart-bot/comm/get_presence.rb +20 -0
  10. data/lib/slack/smart-bot/comm/get_user_info.rb +12 -8
  11. data/lib/slack/smart-bot/comm/get_users.rb +24 -0
  12. data/lib/slack/smart-bot/comm/react.rb +19 -2
  13. data/lib/slack/smart-bot/comm/respond.rb +224 -53
  14. data/lib/slack/smart-bot/comm/respond_direct.rb +2 -3
  15. data/lib/slack/smart-bot/comm/respond_thread.rb +5 -0
  16. data/lib/slack/smart-bot/comm/send_file.rb +38 -34
  17. data/lib/slack/smart-bot/comm/send_msg_channel.rb +27 -22
  18. data/lib/slack/smart-bot/comm/send_msg_user.rb +59 -33
  19. data/lib/slack/smart-bot/comm/unreact.rb +22 -18
  20. data/lib/slack/smart-bot/comm.rb +4 -0
  21. data/lib/slack/smart-bot/commands/general/add_admin.rb +51 -0
  22. data/lib/slack/smart-bot/commands/general/add_announcement.rb +32 -0
  23. data/lib/slack/smart-bot/commands/general/add_team.rb +80 -0
  24. data/lib/slack/smart-bot/commands/general/allow_access.rb +67 -0
  25. data/lib/slack/smart-bot/commands/general/bot_help.rb +69 -33
  26. data/lib/slack/smart-bot/commands/general/bye_bot.rb +0 -7
  27. data/lib/slack/smart-bot/commands/general/delete_announcement.rb +34 -0
  28. data/lib/slack/smart-bot/commands/general/delete_share.rb +34 -0
  29. data/lib/slack/smart-bot/commands/general/delete_team.rb +34 -0
  30. data/lib/slack/smart-bot/commands/general/deny_access.rb +36 -0
  31. data/lib/slack/smart-bot/commands/general/hi_bot.rb +16 -11
  32. data/lib/slack/smart-bot/commands/general/ping_team.rb +100 -0
  33. data/lib/slack/smart-bot/commands/general/poster.rb +116 -0
  34. data/lib/slack/smart-bot/commands/general/remove_admin.rb +58 -0
  35. data/lib/slack/smart-bot/commands/general/see_access.rb +24 -0
  36. data/lib/slack/smart-bot/commands/general/see_admins.rb +33 -0
  37. data/lib/slack/smart-bot/commands/general/see_announcements.rb +115 -0
  38. data/lib/slack/smart-bot/commands/general/see_command_ids.rb +29 -0
  39. data/lib/slack/smart-bot/commands/general/see_favorite_commands.rb +53 -0
  40. data/lib/slack/smart-bot/commands/general/see_shares.rb +41 -0
  41. data/lib/slack/smart-bot/commands/general/see_statuses.rb +91 -0
  42. data/lib/slack/smart-bot/commands/general/see_teams.rb +252 -0
  43. data/lib/slack/smart-bot/commands/general/share_messages.rb +58 -0
  44. data/lib/slack/smart-bot/commands/general/update_team.rb +109 -0
  45. data/lib/slack/smart-bot/commands/general_bot_commands.rb +504 -0
  46. data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +4 -6
  47. data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +45 -14
  48. data/lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb +4 -1
  49. data/lib/slack/smart-bot/commands/on_bot/admin/pause_bot.rb +6 -3
  50. data/lib/slack/smart-bot/commands/on_bot/admin/pause_routine.rb +3 -1
  51. data/lib/slack/smart-bot/commands/on_bot/admin/remove_routine.rb +4 -4
  52. data/lib/slack/smart-bot/commands/on_bot/admin/run_routine.rb +8 -2
  53. data/lib/slack/smart-bot/commands/on_bot/admin/see_result_routine.rb +33 -0
  54. data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +13 -10
  55. data/lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb +6 -3
  56. data/lib/slack/smart-bot/commands/on_bot/admin/start_routine.rb +3 -1
  57. data/lib/slack/smart-bot/commands/on_bot/admin/stop_using_rules_on.rb +4 -1
  58. data/lib/slack/smart-bot/commands/on_bot/admin_master/delete_message.rb +25 -0
  59. data/lib/slack/smart-bot/commands/on_bot/admin_master/get_bot_logs.rb +1 -0
  60. data/lib/slack/smart-bot/commands/on_bot/admin_master/react_to.rb +34 -0
  61. data/lib/slack/smart-bot/commands/on_bot/admin_master/send_message.rb +37 -0
  62. data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +4 -5
  63. data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +7 -8
  64. data/lib/slack/smart-bot/commands/on_bot/general/bot_stats.rb +400 -0
  65. data/lib/slack/smart-bot/commands/{general → on_bot/general}/bot_status.rb +3 -4
  66. data/lib/slack/smart-bot/commands/on_bot/general/leaderboard.rb +201 -0
  67. data/lib/slack/smart-bot/commands/{general → on_bot/general}/stop_using_rules.rb +12 -6
  68. data/lib/slack/smart-bot/commands/on_bot/general/suggest_command.rb +36 -0
  69. data/lib/slack/smart-bot/commands/{general → on_bot/general}/use_rules.rb +13 -11
  70. data/lib/slack/smart-bot/commands/{general → on_bot/general}/whats_new.rb +2 -1
  71. data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +4 -5
  72. data/lib/slack/smart-bot/commands/on_bot/repl.rb +76 -21
  73. data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +3 -4
  74. data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +15 -7
  75. data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +5 -6
  76. data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +5 -6
  77. data/lib/slack/smart-bot/commands/on_extended/bot_rules.rb +45 -12
  78. data/lib/slack/smart-bot/commands/on_master/admin/kill_bot_on_channel.rb +7 -3
  79. data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +4 -1
  80. data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +3 -1
  81. data/lib/slack/smart-bot/commands/on_master/admin_master/publish_announcements.rb +33 -0
  82. data/lib/slack/smart-bot/commands/on_master/admin_master/set_general_message.rb +39 -0
  83. data/lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb +10 -1
  84. data/lib/slack/smart-bot/commands/on_master/create_bot.rb +28 -14
  85. data/lib/slack/smart-bot/commands/on_master/where_smartbot.rb +41 -0
  86. data/lib/slack/smart-bot/commands.rb +36 -5
  87. data/lib/slack/smart-bot/listen.rb +31 -33
  88. data/lib/slack/smart-bot/process.rb +234 -73
  89. data/lib/slack/smart-bot/process_first.rb +119 -38
  90. data/lib/slack/smart-bot/treat_message.rb +310 -237
  91. data/lib/slack/smart-bot/utils/build_help.rb +2 -2
  92. data/lib/slack/smart-bot/utils/create_routine_thread.rb +81 -46
  93. data/lib/slack/smart-bot/utils/get_access_channels.rb +13 -0
  94. data/lib/slack/smart-bot/utils/get_admins_channels.rb +13 -0
  95. data/lib/slack/smart-bot/utils/get_bots_created.rb +28 -8
  96. data/lib/slack/smart-bot/utils/get_channels_name_and_id.rb +7 -2
  97. data/lib/slack/smart-bot/utils/get_command_ids.rb +84 -0
  98. data/lib/slack/smart-bot/utils/get_help.rb +79 -73
  99. data/lib/slack/smart-bot/utils/get_repls.rb +22 -2
  100. data/lib/slack/smart-bot/utils/get_routines.rb +22 -2
  101. data/lib/slack/smart-bot/utils/get_shares.rb +12 -0
  102. data/lib/slack/smart-bot/utils/get_teams.rb +22 -0
  103. data/lib/slack/smart-bot/utils/has_access.rb +28 -0
  104. data/lib/slack/smart-bot/utils/is_admin.rb +27 -0
  105. data/lib/slack/smart-bot/utils/save_stats.rb +46 -41
  106. data/lib/slack/smart-bot/utils/save_status.rb +67 -0
  107. data/lib/slack/smart-bot/utils/update_access_channels.rb +8 -0
  108. data/lib/slack/smart-bot/utils/update_admins_channels.rb +8 -0
  109. data/lib/slack/smart-bot/utils/update_bots_file.rb +28 -7
  110. data/lib/slack/smart-bot/utils/update_repls.rb +7 -4
  111. data/lib/slack/smart-bot/utils/update_routines.rb +9 -3
  112. data/lib/slack/smart-bot/utils/update_shortcuts_file.rb +13 -6
  113. data/lib/slack/smart-bot/utils/update_teams.rb +16 -0
  114. data/lib/slack/smart-bot/utils.rb +11 -0
  115. data/lib/slack-smart-bot.rb +72 -12
  116. data/lib/slack-smart-bot_general_commands.rb +61 -0
  117. data/lib/slack-smart-bot_general_rules.rb +5 -2
  118. data/lib/slack-smart-bot_rules.rb +43 -17
  119. data/whats_new.txt +20 -15
  120. metadata +76 -9
  121. data/lib/slack/smart-bot/commands/general/bot_stats.rb +0 -313
@@ -13,11 +13,11 @@ class SlackSmartBot
13
13
  processed = true
14
14
 
15
15
  on_demand = false
16
- if command.match(/^@?(#{config[:nick]}):*\s+(.+)/im) or
17
- command.match(/^()!!(.+)/im) or
18
- command.match(/^()\^(.+)/im) or
19
- command.match(/^()!(.+)/im) or
20
- command.match(/^()<@#{config[:nick_id]}>\s+(.+)/im)
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)
21
21
  command2 = $2
22
22
  Thread.current[:command] = command2
23
23
  if command2.match?(/^()!!(.+)/im) or
@@ -27,100 +27,258 @@ class SlackSmartBot
27
27
  command = command2
28
28
  on_demand = true
29
29
  end
30
- if (on_demand or
30
+ if (on_demand or typem == :on_dm or
31
31
  (@listening.key?(from) and (@listening[from].key?(dest) or @listening[from].key?(Thread.current[:thread_ts])) )) and
32
32
  config.on_maintenance and !command.match?(/\A(set|turn)\s+maintenance\s+off\s*\z/)
33
- respond config.on_maintenance_message, dest
33
+ unless Thread.current.key?(:routine) and Thread.current[:routine]
34
+ respond eval("\"" + config.on_maintenance_message + "\"")
35
+ end
34
36
  processed = true
35
37
  end
36
-
37
38
  if !config.on_maintenance or (config.on_maintenance and command.match?(/\A(set|turn)\s+maintenance\s+off\s*\z/))
38
39
  #todo: check :on_pg in this case
39
40
  if typem == :on_master or typem == :on_bot or typem == :on_pg or typem == :on_dm
40
41
 
41
42
  case command
42
43
 
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
44
+ when /\A\s*what's\s+new\s*$/i
46
45
  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
52
-
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
53
49
  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
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
55
56
  channel = $3
56
57
  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
+ 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
58
66
  channel = $2
59
67
  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
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
62
72
  channel = $2
63
73
  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
74
+ when /\A\s*exit\s+bot\s*$/i, /\A\s*quit\s+bot\s*$/i, /\A\s*close\s+bot\s*$/i
68
75
  exit_bot(command, from, dest, display_name)
69
- when /^\s*start\s+(this\s+)?bot$/i
76
+ when /\A\s*start\s+(this\s+)?bot$/i
70
77
  start_bot(dest, from)
71
- when /^\s*pause\s+(this\s+)?bot$/i
78
+ when /\A\s*pause\s+(this\s+)?bot$/i
72
79
  pause_bot(dest, from)
73
- when /^\s*bot\s+status/i
80
+ when /\A\s*bot\s+status/i
74
81
  bot_status(dest, user)
75
- when /\Anotify\s+<#(C\w+)\|.+>\s+(.+)\s*\z/im, /\Anotify\s+(all)?\s*(.+)\s*\z/im
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
76
85
  where = $1
77
86
  message = $2
78
87
  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?
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
81
95
  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
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
84
100
  channel = $1
85
101
  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<#(C\w+)\|.+>\s*)?(\s.+)?\s*$/i,
87
- /^\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,
88
- /^\s*(add|create)\s+(silent\s+)?routine\s+(\w+)\s+(at)\s+(\d+:\d+:?\d+?)\s*()(\s<#(C\w+)\|.+>\s*)?(\s.+)?\s*$/i
102
+ when /\A\s*(where\s+is|which\s+channels|where\s+is\s+a\s+member)\s+(#{@salutations.join("|")})\??\s*$/i
103
+ where_smartbot(user)
104
+ 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,
105
+ /\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,
106
+ /\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,
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+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,
109
+ /\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,
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
+ /\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,
112
+ /\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
89
113
  silent = $2.to_s!=''
90
- name = $3.downcase
91
- type = $4
92
- number_time = $5
93
- period = $6
94
- channel = $8
95
- command_to_run = $9
96
- add_routine(dest, from, user, name, type, number_time, period, command_to_run, files, silent, channel)
97
- when /^\s*(kill|delete|remove)\s+routine\s+(\w+)\s*$/i
114
+ routine_type = $3.downcase
115
+ name = $4.downcase
116
+ type = $5.to_s.downcase
117
+ number_time = $6
118
+ period = $7
119
+ channel = $9
120
+ command_to_run = $10
121
+ content = command_to_run.to_s.scan(/\A\s*```(.+)```\s*\z/im).join
122
+ unless content == ''
123
+ files = [
124
+ {
125
+ name: name,
126
+ filetype: '',
127
+ content: content
128
+ }
129
+ ]
130
+ command_to_run = ''
131
+ end
132
+ add_routine(dest, from, user, name, type, number_time, period, command_to_run, files, silent, channel, routine_type)
133
+ when /\A\s*(kill|delete|remove)\s+routine\s+([\w\.]+)\s*$/i
98
134
  name = $2.downcase
99
135
  remove_routine(dest, from, name)
100
- when /^\s*(run|execute)\s+routine\s+(\w+)\s*$/i
136
+ when /\A\s*see\s+routines?\s+results?\s+([\w\.]+)\s*$/i,
137
+ /\A\s*see\s+results?\s+routines?\s+([\w\.]+)\s*$/i,
138
+ /\A\s*results?\s+routines?\s+([\w\.]+)\s*$/i
139
+ name = $1.downcase
140
+ see_result_routine(dest, from, name)
141
+ when /\A\s*(run|execute)\s+routine\s+([\w\.]+)\s*$/i
101
142
  name = $2.downcase
102
143
  run_routine(dest, from, name)
103
- when /^\s*pause\s+routine\s+(\w+)\s*$/i
144
+ when /\A\s*pause\s+routine\s+([\w\.]+)\s*$/i
104
145
  name = $1.downcase
105
146
  pause_routine(dest, from, name)
106
- when /^\s*start\s+routine\s+(\w+)\s*$/i
147
+ when /\A\s*start\s+routine\s+([\w\.]+)\s*$/i
107
148
  name = $1.downcase
108
149
  start_routine(dest, from, name)
109
- when /^\s*see\s+(all\s+)?routines\s*$/i
150
+ when /\A\s*see\s+(all\s+)?routines\s*$/i
110
151
  all = $1.to_s != ""
111
152
  see_routines(dest, from, user, all)
112
- when /^\s*get\s+bot\s+logs?\s*$/i
153
+ when /\A\s*get\s+bot\s+logs?\s*$/i
113
154
  get_bot_logs(dest, from, typem)
114
- when /^\s*bot\s+stats\s*(.*)\s*$/i
155
+ when /\A\s*send\s+message\s+(on|to|in)\s*(.+)\s*:\s*(.+)\s*$/im
156
+ opts = $2
157
+ message = $3
158
+ thread_ts = ''
159
+ to_channel = ''
160
+ to = []
161
+
162
+ opts.split(' ').each do |opt|
163
+ if opt.match?(/\Ahttps:/i)
164
+ to_channel, thread_ts = opt.scan(/\/archives\/(\w+)\/(\w\d+)/)[0]
165
+ to << to_channel
166
+ elsif opt.match(/<#([^>]+)\|.*>/) #channel
167
+ to << $1
168
+ elsif opt.match(/#([^\s]+)/) #channel
169
+ to << $1
170
+ elsif opt.match(/<@(\w+)>/)
171
+ to << $1
172
+ end
173
+ end
174
+
175
+ thread_ts.gsub!('.','')
176
+ send_message(dest, from, typem, to, thread_ts, message)
177
+ when /\A\s*delete\s+message\s+(.+)\s*$/i
178
+ url = $1
179
+ delete_message(from, typem, url)
180
+ when /\A\s*react\s+(on|to|in)\s*([^\s]+)\s+([p\d\.]+)\s+(.+)\s*$/i,
181
+ /\A\s*react\s+(on|to|in)\s*([^\s]+)\s+()(.+)\s*$/i
182
+ to = $2
183
+ thread_ts = $3.to_s
184
+ emojis = $4
185
+
186
+ if to.match?(/\A<?https:/i)
187
+ to_channel, thread_ts = to.scan(/\/archives\/(\w+)\/(\w\d+)/)[0]
188
+ else
189
+ to_channel = to.scan(/<#([^>]+)\|.*>/).join
190
+ end
191
+ if to_channel == ''
192
+ to_channel = to.scan(/#([^\s]+)/).join
193
+ to_channel = @channels_id[to_channel].to_s
194
+ end
195
+ if to_channel == ''
196
+ respond "The channel specified doesn't exist or is in a incorrect format"
197
+ else
198
+ to = to_channel
199
+ react_to(dest, from, typem, to, thread_ts, emojis)
200
+ end
201
+
202
+ when /\A\s*(leader\s+board|leaderboard|ranking|podium)()()\s*$/i,
203
+ /\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,
204
+ /\A\s*(leader\s+board|leaderboard|ranking|podium)\s+from\s+(\d\d\d\d[\/\-\.]\d\d[\/\-\.]\d\d)()\s*$/i,
205
+ /\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
206
+ require 'date'
207
+ opt1 = $2.to_s
208
+ to = $3.to_s
209
+ if opt1.match?(/\d/)
210
+ from = opt1
211
+ period = ''
212
+ from = from.gsub('.','-').gsub('/','-')
213
+ if to.empty?
214
+ to = Date.today.strftime("%Y-%m-%d")
215
+ else
216
+ to = to.gsub('.','-').gsub('/','-')
217
+ end
218
+ elsif opt1.to_s==''
219
+ period = 'last week'
220
+ date = Date.today
221
+ wday = date.wday
222
+ wday = 7 if wday==0
223
+ wday-=1
224
+ from = "#{(date-wday-7).strftime("%Y-%m-%d")}"
225
+ to = "#{(date-wday-1).strftime("%Y-%m-%d")}"
226
+ else
227
+ from = ''
228
+ period = opt1.downcase
229
+ case period
230
+ when 'today'
231
+ from = to = "#{Date.today.strftime("%Y-%m-%d")}"
232
+ when 'yesterday'
233
+ from = to ="#{(Date.today-1).strftime("%Y-%m-%d")}"
234
+ when /this\s+month/
235
+ from = "#{Date.today.strftime("%Y-%m-01")}"
236
+ to = "#{Date.today.strftime("%Y-%m-%d")}"
237
+ when /last\s+month/
238
+ date = Date.today<<1
239
+ from = "#{date.strftime("%Y-%m-01")}"
240
+ to = "#{(Date.new(date.year, date.month, -1)).strftime("%Y-%m-%d")}"
241
+ when /this\s+year/
242
+ from = "#{Date.today.strftime("%Y-01-01")}"
243
+ to = "#{Date.today.strftime("%Y-%m-%d")}"
244
+ when /last\s+year/
245
+ date = Date.today.prev_year
246
+ from = "#{date.strftime("%Y-01-01")}"
247
+ to = "#{(Date.new(date.year, 12, 31)).strftime("%Y-%m-%d")}"
248
+ when /this\s+week/
249
+ date = Date.today
250
+ wday = date.wday
251
+ wday = 7 if wday==0
252
+ wday-=1
253
+ from = "#{(date-wday).strftime("%Y-%m-%d")}"
254
+ to = "#{date.strftime("%Y-%m-%d")}"
255
+ when /last\s+week/
256
+ date = Date.today
257
+ wday = date.wday
258
+ wday = 7 if wday==0
259
+ wday-=1
260
+ from = "#{(date-wday-7).strftime("%Y-%m-%d")}"
261
+ to = "#{(date-wday-1).strftime("%Y-%m-%d")}"
262
+ end
263
+ end
264
+
265
+ leaderboard(from, to, period)
266
+
267
+ when /\A\s*bot\s+stats\s*(.*)\s*$/i
115
268
  opts = $1.to_s
269
+ exclude_members_channel = opts.scan(/exclude\s+members\s+<#(\w+)\|.*>/i).join #todo: add test
270
+ opts.gsub!(/exclude\s+members\s+<#\w+\|.*>/,'')
271
+ members_channel = opts.scan(/members\s+<#(\w+)\|.*>/i).join #todo: add test
272
+ opts.gsub!(/members\s+<#\w+\|.*>/,'')
116
273
  all_opts = opts.downcase.split(' ')
117
274
  all_data = all_opts.include?('alldata')
118
- st_channel = opts.scan(/<#(\w+)\|.+>/).join
275
+ st_channel = opts.scan(/<#(\w+)\|.*>/).join
119
276
  st_from = opts.scan(/from\s+(\d\d\d\d[\/\-\.]\d\d[\/\-\.]\d\d)/).join
120
277
  st_from = st_from.gsub('.','-').gsub('/','-')
121
278
  st_to = opts.scan(/to\s+(\d\d\d\d[\/\-\.]\d\d[\/\-\.]\d\d)/).join
122
279
  st_to = st_to.gsub('.','-').gsub('/','-')
123
280
  st_user = opts.scan(/<@([^>]+)>/).join
281
+ st_user = opts.scan(/@([^\s]+)/).join if st_user == ''
124
282
  st_command = opts.scan(/\s+command\s+(\w+)/i).join.downcase
125
283
  st_command = opts.scan(/^command\s+(\w+)/i).join.downcase if st_command == ''
126
284
  exclude_masters = all_opts.include?('exclude') && all_opts.include?('masters')
@@ -146,11 +304,16 @@ class SlackSmartBot
146
304
  if (typem == :on_master or typem == :on_bot) and dest[0]!='D' #routine bot stats to be published on DM
147
305
  st_channel = dchannel
148
306
  end
149
- bot_stats(dest, user, typem, st_channel, st_from, st_to, st_user, st_command, exclude_masters, exclude_routines, exclude_command, monthly, all_data)
307
+ bot_stats(dest, user, typem, st_channel, st_from, st_to, st_user, st_command, exclude_masters, exclude_routines, exclude_command, monthly, all_data, members_channel, exclude_members_channel)
150
308
  when /\A(set|turn)\s+maintenance\s+(on|off)\s*()\z/im, /\A(set|turn)\s+maintenance\s+(on)\s*(.+)\s*\z/im
151
309
  status = $2.downcase
152
310
  message = $3.to_s
153
311
  set_maintenance(from, status, message)
312
+ 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
313
+ status = $3.to_s.downcase
314
+ status = 'on' if status == ''
315
+ message = $4.to_s
316
+ set_general_message(from, status, message)
154
317
  else
155
318
  processed = false
156
319
  end
@@ -172,28 +335,24 @@ class SlackSmartBot
172
335
 
173
336
  case command
174
337
 
175
- # bot rules for extended channels
176
- when /^bot\s+rules\s*(.+)?$/i
177
- help_command = $1
178
- bot_rules(dest, help_command, typem, rules_file, user)
179
- when /^\s*(add\s+)?(global\s+|generic\s+)?shortcut\s+(for\sall)?\s*([^:]+)\s*:\s*(.+)/i,
180
- /^(add\s+)(global\s+|generic\s+)?sc\s+(for\sall)?\s*([^:]+)\s*:\s*(.+)/i
338
+ when /\A\s*(add\s+)?(global\s+|generic\s+)?shortcut\s+(for\sall)?\s*([^:]+)\s*:\s*(.+)/i,
339
+ /\A(add\s+)(global\s+|generic\s+)?sc\s+(for\sall)?\s*([^:]+)\s*:\s*(.+)/i
181
340
  for_all = $3
182
341
  shortcut_name = $4.to_s.downcase
183
342
  command_to_run = $5
184
343
  global = $2.to_s != ''
185
344
  add_shortcut(dest, user, typem, for_all, shortcut_name, command, command_to_run, global)
186
- when /^\s*(delete|remove)\s+(global\s+|generic\s+)?shortcut\s+(.+)/i,
187
- /^(delete|remove)\s+(global\s+|generic\s+)?sc\s+(.+)/i
345
+ when /\A\s*(delete|remove)\s+(global\s+|generic\s+)?shortcut\s+(.+)/i,
346
+ /\A(delete|remove)\s+(global\s+|generic\s+)?sc\s+(.+)/i
188
347
  shortcut = $3.to_s.downcase
189
348
  global = $2.to_s != ''
190
349
 
191
350
  delete_shortcut(dest, user, shortcut, typem, command, global)
192
- when /^\s*see\s+shortcuts/i, /^see\ssc/i
351
+ when /\A\s*see\s+shortcuts/i, /^see\s+sc/i
193
352
  see_shortcuts(dest, user, typem)
194
353
 
195
354
  #kept to be backwards compatible
196
- when /^\s*id\schannel\s<#C\w+\|(.+)>\s*/i, /^id channel (.+)/
355
+ when /\A\s*id\schannel\s<#C\w+\|(.+)>\s*/i, /^id channel (.+)/
197
356
  unless typem == :on_extended
198
357
  channel_name = $1
199
358
  get_channels_name_and_id()
@@ -203,18 +362,20 @@ class SlackSmartBot
203
362
  respond "channel: #{channel_name} not found", dest
204
363
  end
205
364
  end
206
- when /^\s*ruby\s(.+)/im, /^\s*code\s(.+)/im
365
+ when /\A\s*ruby\s+(.+)/im, /\A\s*code\s+(.+)/im
207
366
  code = $1
208
367
  code.gsub!("\\n", "\n")
209
368
  code.gsub!("\\r", "\r")
369
+ code.gsub!(/^\s*```/,'')
370
+ code.gsub!(/```\s*$/,'')
210
371
  @logger.info code
211
372
  ruby_code(dest, user, code, rules_file)
212
- when /^\s*(private\s+|clean\s+|clean\s+private\s+|private\s+clean\s+)?(repl|irb|live)\s*()()()$/i,
213
- /^\s*(private\s+|clean\s+|clean\s+private\s+|private\s+clean\s+)?(repl|irb|live)\s+([\w\-]+)()()\s*$/i,
214
- /^\s*(private\s+|clean\s+|clean\s+private\s+|private\s+clean\s+)?(repl|irb|live)\s+([\w\-]+)\s*:\s+"([^"]+)"()\s*$/i,
215
- /^\s*(private\s+|clean\s+|clean\s+private\s+|private\s+clean\s+)?(repl|irb|live)\s+([\w\-]+)\s*:\s+"([^"]+)"\s+(.+)\s*$/i,
216
- /^\s*(private\s+|clean\s+|clean\s+private\s+|private\s+clean\s+)?(repl|irb|live)\s+([\w\-]+)()\s+(.+)\s*$/i,
217
- /^\s*(private\s+|clean\s+|clean\s+private\s+|private\s+clean\s+)?(repl|irb|live)()\s+()(.+)\s*$/i
373
+ when /\A\s*(private\s+|clean\s+|clean\s+private\s+|private\s+clean\s+)?(repl|irb|live)\s*()()()\z/i,
374
+ /\A\s*(private\s+|clean\s+|clean\s+private\s+|private\s+clean\s+)?(repl|irb|live)\s+([\w\-]+)()()\s*\z/i,
375
+ /\A\s*(private\s+|clean\s+|clean\s+private\s+|private\s+clean\s+)?(repl|irb|live)\s+([\w\-]+)\s*:\s+"([^"]+)"()\s*\z/i,
376
+ /\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,
377
+ /\A\s*(private\s+|clean\s+|clean\s+private\s+|private\s+clean\s+)?(repl|irb|live)\s+([\w\-]+)()\s+(.+)\s*\z/i,
378
+ /\A\s*(private\s+|clean\s+|clean\s+private\s+|private\s+clean\s+)?(repl|irb|live)()\s+()(.+)\s*\z/i
218
379
  opts_type = $1.to_s.downcase.split(' ')
219
380
  opts_type.include?('private') ? type = :private : type = :public
220
381
  type = "#{type}_clean".to_sym if opts_type.include?('clean')
@@ -232,10 +393,10 @@ class SlackSmartBot
232
393
  env_vars[idx] = "ENV['#{ev}"
233
394
  end
234
395
  repl(dest, user, session_name, env_vars.flatten, rules_file, command, description, type)
235
- when /^\s*get\s+(repl|irb|live)\s+([\w\-]+)\s*/i
396
+ when /\A\s*get\s+(repl|irb|live)\s+([\w\-]+)\s*/i
236
397
  session_name = $2
237
398
  get_repl(dest, user, session_name)
238
- when /^\s*run\s+(repl|irb|live)\s+([\w\-]+)()\s*$/i,
399
+ when /\A\s*run\s+(repl|irb|live)\s+([\w\-]+)()\s*$/i,
239
400
  /^\s*run\s+(repl|irb|live)\s+([\w\-]+)\s+(.+)\s*$/i
240
401
  session_name = $2
241
402
  opts = " #{$3}"
@@ -249,10 +410,10 @@ class SlackSmartBot
249
410
  env_vars[idx] = "ENV['#{ev}"
250
411
  end
251
412
  run_repl(dest, user, session_name, env_vars.flatten, rules_file)
252
- when /^\s*(delete|remove)\s+(repl|irb|live)\s+([\w\-]+)\s*$/i
413
+ when /\A\s*(delete|remove)\s+(repl|irb|live)\s+([\w\-]+)\s*$/i
253
414
  repl_name = $3
254
415
  delete_repl(dest, user, repl_name)
255
- when /^\s*see\s+(repls|repl|irb|irbs)\s*$/i
416
+ when /\A\s*see\s+(repls|repl|irb|irbs)\s*$/i
256
417
  see_repls(dest, user, typem)
257
418
  else
258
419
  processed2 = false