slack-smart-bot 1.8.1 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -0,0 +1,58 @@
|
|
1
|
+
class SlackSmartBot
|
2
|
+
#todo: reaction type not added yet since RTM doesn't support it. See if we can add it as an event
|
3
|
+
def share_messages(user, from_channel, to_channel, condition)
|
4
|
+
save_stats(__method__)
|
5
|
+
if has_access?(__method__, user)
|
6
|
+
#todo: add a @shared variable to control not to be shared more than once when using reactions
|
7
|
+
#todo: it is only possible to share if smartbot is a member in both channels and the person adding the share command also
|
8
|
+
if Thread.current[:typem] == :on_call or Thread.current[:typem] == :on_dm
|
9
|
+
respond "You can use this command only from the source channel."
|
10
|
+
elsif from_channel == to_channel
|
11
|
+
respond "You cannot share messages on the same channel than source channel."
|
12
|
+
else
|
13
|
+
channels = get_channels(types: 'public_channel')
|
14
|
+
channel_found = channels.detect { |c| c.name == from_channel }
|
15
|
+
get_channels_name_and_id() unless @channels_id.key?(to_channel)
|
16
|
+
channel_found = false if !@channels_id.key?(to_channel)
|
17
|
+
if channel_found
|
18
|
+
members = get_channel_members(@channels_id[to_channel])
|
19
|
+
if members.include?(config.nick_id) and members.include?(user.id)
|
20
|
+
if condition.match?(/^\/.+\/$/)
|
21
|
+
type = :regexp
|
22
|
+
elsif condition.match?(/^".+"$/) or condition.match?(/^'.+'$/)
|
23
|
+
type = :text
|
24
|
+
else
|
25
|
+
type = :reaction
|
26
|
+
end
|
27
|
+
if File.exists?("#{config.path}/shares/#{from_channel}.csv")
|
28
|
+
t = CSV.table("#{config.path}/shares/#{from_channel}.csv", headers: ['share_id', 'user_deleted', 'user_created', 'date', 'time', 'type', 'to_channel', 'condition'])
|
29
|
+
@shares[from_channel] = t
|
30
|
+
if t.size>0
|
31
|
+
num = t[:share_id].max + 1
|
32
|
+
else
|
33
|
+
num = 1
|
34
|
+
end
|
35
|
+
elsif !@shares.key?(from_channel)
|
36
|
+
File.open("#{config.path}/shares/#{from_channel}.csv","w")
|
37
|
+
t = CSV.table("#{config.path}/shares/#{from_channel}.csv", headers: ['share_id', 'user_deleted', 'user_created', 'date', 'time', 'type', 'to_channel', 'condition'])
|
38
|
+
num = 1
|
39
|
+
@shares[from_channel] = t
|
40
|
+
else
|
41
|
+
num = @shares[from_channel][:share_id].max + 1
|
42
|
+
end
|
43
|
+
values = [num, '', user.name, Time.now.strftime("%Y/%m/%d"), Time.now.strftime("%H:%M"), type.to_s, to_channel, condition]
|
44
|
+
@shares[from_channel] << values
|
45
|
+
CSV.open("#{config.path}/shares/#{from_channel}.csv", "a+") do |csv|
|
46
|
+
csv << values
|
47
|
+
end
|
48
|
+
respond "*Share command*: id:#{num} Messages #{condition} will be shared from now on. Related commands `see shares`, `delete share ID`"
|
49
|
+
else
|
50
|
+
respond "*Share command*: The channel ##{to_channel} need to exist and the SmartBot and you have to be members."
|
51
|
+
end
|
52
|
+
else
|
53
|
+
respond "*Share command*: The channel <##{@channels_id[from_channel]}|#{from_channel}> has to be a public channel and the destination channel has to be a valid channel."
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -1,10 +1,13 @@
|
|
1
1
|
class SlackSmartBot
|
2
2
|
# help: ----------------------------------------------
|
3
3
|
# help: `stop using rules from CHANNEL`
|
4
|
+
# help: `stop using CHANNEL`
|
4
5
|
# help: it will stop using the rules from the specified channel.
|
6
|
+
# help: <https://github.com/MarioRuiz/slack-smart-bot#using-rules-from-other-channels|more info>
|
5
7
|
# help:
|
6
8
|
def stop_using_rules(dest, channel, user, dchannel)
|
7
9
|
save_stats(__method__)
|
10
|
+
channel.gsub!('#','') # for the case the channel name is in plain text including #
|
8
11
|
if @channels_id.key?(channel)
|
9
12
|
channel_id = @channels_id[channel]
|
10
13
|
else
|
@@ -12,11 +15,12 @@ class SlackSmartBot
|
|
12
15
|
end
|
13
16
|
|
14
17
|
if dest[0] == "C" or dest[0] == "G" #channel
|
15
|
-
if @rules_imported.key?(user.
|
16
|
-
if @rules_imported[user.
|
18
|
+
if @rules_imported.key?(user.name) and @rules_imported[user.name].key?(dchannel)
|
19
|
+
if @rules_imported[user.name][dchannel] != channel_id
|
17
20
|
respond "You are not using those rules.", dest
|
18
21
|
else
|
19
|
-
@rules_imported[user.
|
22
|
+
@rules_imported[user.name].delete(dchannel)
|
23
|
+
sleep 0.5
|
20
24
|
update_rules_imported()
|
21
25
|
respond "You won't be using those rules from now on.", dest
|
22
26
|
|
@@ -27,11 +31,12 @@ class SlackSmartBot
|
|
27
31
|
respond "You were not using those rules.", dest
|
28
32
|
end
|
29
33
|
else #direct message
|
30
|
-
if @rules_imported.key?(user.
|
31
|
-
if @rules_imported[user.
|
34
|
+
if @rules_imported.key?(user.name) and @rules_imported[user.name].key?(user.name)
|
35
|
+
if @rules_imported[user.name][user.name] != channel_id
|
32
36
|
respond "You are not using those rules.", dest
|
33
37
|
else
|
34
|
-
@rules_imported[user.
|
38
|
+
@rules_imported[user.name].delete(user.name)
|
39
|
+
sleep 0.5
|
35
40
|
update_rules_imported()
|
36
41
|
respond "You won't be using those rules from now on.", dest
|
37
42
|
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class SlackSmartBot
|
2
|
+
|
3
|
+
# help: ----------------------------------------------
|
4
|
+
# help: `suggest command`
|
5
|
+
# help: `random command`
|
6
|
+
# help: `command suggestion`
|
7
|
+
# help: `suggest rule`
|
8
|
+
# help: `random rule`
|
9
|
+
# help: `rule suggestion`
|
10
|
+
# help: it will display the help content for a random command.
|
11
|
+
# help: if used 'rule' then it will display a random rule.
|
12
|
+
# help: if used 'command' it will show any kind of command or rule.
|
13
|
+
# help:
|
14
|
+
def suggest_command(from, dest, dchannel, specific, rules_file)
|
15
|
+
save_stats(__method__)
|
16
|
+
help_message = get_help(rules_file, dest, from, specific, true, descriptions: false, only_normal_user: true)
|
17
|
+
commands = help_message.gsub(/====+/,'-'*30).split(/^\s*-------*$/).flatten
|
18
|
+
commands.reject!{|c| c.match?(/These are specific commands for this bot on this/i) || c.match?(/\A\s*\z/)}
|
19
|
+
@last_suggested_commands ||= []
|
20
|
+
@last_suggested_commands.shift if @last_suggested_commands.size >=5
|
21
|
+
command = ''
|
22
|
+
begin
|
23
|
+
command = commands.sample
|
24
|
+
end until !@last_suggested_commands.include?(command) or commands.size <= 5
|
25
|
+
@last_suggested_commands << command
|
26
|
+
message = "*Command suggestion*:\n#{command}"
|
27
|
+
respond message, dest, unfurl_links: false, unfurl_media: false
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -6,26 +6,22 @@ class SlackSmartBot
|
|
6
6
|
# help: `use CHANNEL`
|
7
7
|
# help: it will use the rules from the specified channel.
|
8
8
|
# help: you need to be part of that channel to be able to use the rules.
|
9
|
+
# help: <https://github.com/MarioRuiz/slack-smart-bot#using-rules-from-other-channels|more info>
|
9
10
|
# help:
|
10
11
|
def use_rules(dest, channel, user, dchannel)
|
11
12
|
save_stats(__method__)
|
12
13
|
get_bots_created()
|
13
|
-
if
|
14
|
-
(!user.key?(:enterprise_user) or ( user.key?(:enterprise_user) and !config[:allow_access][__method__].include?(user[:enterprise_user].id)))
|
15
|
-
respond "You don't have access to use this command, please contact an Admin to be able to use it: <@#{config.admins.join(">, <@")}>"
|
16
|
-
else
|
14
|
+
if has_access?(__method__, user)
|
17
15
|
#todo: add pagination for case more than 1000 channels on the workspace
|
18
|
-
channels =
|
19
|
-
|
20
|
-
|
21
|
-
exclude_archived: "true",
|
22
|
-
).channels
|
23
|
-
|
16
|
+
channels = get_channels()
|
17
|
+
channel.gsub!('#','') # for the case the channel name is in plain text including #
|
18
|
+
channel = @channels_name[channel] if @channels_name.key?(channel)
|
24
19
|
channel_found = channels.detect { |c| c.name == channel }
|
25
|
-
|
20
|
+
get_channels_name_and_id() unless @channels_id.key?(channel)
|
21
|
+
members = get_channel_members(@channels_id[channel]) unless channel_found.nil? or !@channels_id.key?(channel)
|
26
22
|
|
27
|
-
if channel_found.nil?
|
28
|
-
respond "The channel you are trying to use doesn't exist", dest
|
23
|
+
if channel_found.nil? or !@channels_id.key?(channel)
|
24
|
+
respond "The channel you are trying to use doesn't exist or cannot be found.", dest
|
29
25
|
elsif channel_found.name == config.master_channel
|
30
26
|
respond "You cannot use the rules from Master Channel on any other channel.", dest
|
31
27
|
elsif !@bots_created.key?(@channels_id[channel])
|
@@ -34,12 +30,13 @@ class SlackSmartBot
|
|
34
30
|
respond "The bot in that channel is not :on", dest
|
35
31
|
else
|
36
32
|
if user.id == channel_found.creator or members.include?(user.id)
|
37
|
-
@rules_imported[user.
|
33
|
+
@rules_imported[user.name] = {} unless @rules_imported.key?(user.name)
|
38
34
|
if dest[0] == "C" or dest[0] == "G" #todo: take in consideration bots that are not master
|
39
|
-
@rules_imported[user.
|
35
|
+
@rules_imported[user.name][dchannel] = channel_found.id
|
40
36
|
else
|
41
|
-
@rules_imported[user.
|
37
|
+
@rules_imported[user.name][user.name] = channel_found.id
|
42
38
|
end
|
39
|
+
sleep 0.5
|
43
40
|
update_rules_imported()
|
44
41
|
respond "I'm using now the rules from <##{channel_found.id}>", dest
|
45
42
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class SlackSmartBot
|
2
|
+
|
3
|
+
# help: ----------------------------------------------
|
4
|
+
# help: `What's new`
|
5
|
+
# help: It will display the last user changes on Slack Smart Bot
|
6
|
+
# help:
|
7
|
+
def whats_new(user, dest, dchannel, from, display_name)
|
8
|
+
if @status == :on
|
9
|
+
save_stats(__method__)
|
10
|
+
whats_new_file = (__FILE__).gsub(/lib\/slack\/smart-bot\/commands\/general\/whats_new\.rb$/, "whats_new.txt")
|
11
|
+
whats_new = File.read(whats_new_file)
|
12
|
+
whats_new.split(/^\-\-\-\-\-\-+$/).each do |msg|
|
13
|
+
respond msg
|
14
|
+
sleep 0.3
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,243 @@
|
|
1
|
+
# add here the general commands you will be using in any channel where The SmartBot is part of. Not necessary to use ! or ^, it will answer directly.
|
2
|
+
def general_bot_commands(user, command, dest, files = [])
|
3
|
+
|
4
|
+
begin
|
5
|
+
if config.simulate
|
6
|
+
display_name = user.profile.display_name
|
7
|
+
else
|
8
|
+
if user.profile.display_name.to_s.match?(/\A\s*\z/)
|
9
|
+
user.profile.display_name = user.profile.real_name
|
10
|
+
end
|
11
|
+
display_name = user.profile.display_name
|
12
|
+
end
|
13
|
+
|
14
|
+
case command
|
15
|
+
|
16
|
+
|
17
|
+
# help: ----------------------------------------------
|
18
|
+
# help: `bot help`
|
19
|
+
# help: `bot help COMMAND`
|
20
|
+
# help: `bot rules`
|
21
|
+
# help: `bot rules COMMAND`
|
22
|
+
# help: `bot help expanded`
|
23
|
+
# help: `bot rules expanded`
|
24
|
+
# help: `bot what can I do?`
|
25
|
+
# help: it will display this help. For a more detailed help call `bot help expanded` or `bot rules expanded`.
|
26
|
+
# help: if COMMAND supplied just help for that command
|
27
|
+
# help: you can use the option 'expanded' or the alias 'extended'
|
28
|
+
# help: `bot rules` will show only the specific rules for this channel.
|
29
|
+
# help: <https://github.com/MarioRuiz/slack-smart-bot#bot-help|more info>
|
30
|
+
# help:
|
31
|
+
|
32
|
+
|
33
|
+
# help: ----------------------------------------------
|
34
|
+
# help: `Hi Bot`
|
35
|
+
# help: `Hi Smart`
|
36
|
+
# help: `Hello Bot` `Hola Bot` `Hallo Bot` `What's up Bot` `Hey Bot` `Hæ Bot`
|
37
|
+
# help: `Hello THE_NAME_OF_THE_BOT`
|
38
|
+
# help: Bot starts listening to you if you are on a Bot channel
|
39
|
+
# help: After that if you want to avoid a single message to be treated by the smart bot, start the message by -
|
40
|
+
# help: Also apart of Hello you can use _Hallo, Hi, Hola, What's up, Hey, Hæ_
|
41
|
+
# help: <https://github.com/MarioRuiz/slack-smart-bot#how-to-access-the-smart-bot|more info>
|
42
|
+
# help:
|
43
|
+
when /\A\s*(Hello|Hallo|Hi|Hola|What's\sup|Hey|Hæ)\s+(#{@salutations.join("|")})\s*$/i
|
44
|
+
hi_bot(user, dest, user.name, display_name)
|
45
|
+
|
46
|
+
# help: ----------------------------------------------
|
47
|
+
# help: `Bye Bot`
|
48
|
+
# help: `Bye Smart`
|
49
|
+
# help: `Bye NAME_OF_THE_BOT`
|
50
|
+
# help: Bot stops listening to you if you are on a Bot channel
|
51
|
+
# help: Also apart of Bye you can use _Bæ, Good Bye, Adiós, Ciao, Bless, Bless Bless, Adeu_
|
52
|
+
# help: <https://github.com/MarioRuiz/slack-smart-bot#how-to-access-the-smart-bot|more info>
|
53
|
+
# help:
|
54
|
+
when /\A\s*(Bye|Bæ|Good\s+Bye|Adiós|Ciao|Bless|Bless\sBless|Adeu)\s+(#{@salutations.join("|")})\s*$/i
|
55
|
+
bye_bot(dest, user.name, display_name)
|
56
|
+
|
57
|
+
# help: ----------------------------------------------
|
58
|
+
# help: `add announcement MESSAGE`
|
59
|
+
# help: `add red announcement MESSAGE`
|
60
|
+
# help: `add green announcement MESSAGE`
|
61
|
+
# help: `add yellow announcement MESSAGE`
|
62
|
+
# help: `add white announcement MESSAGE`
|
63
|
+
# help: `add EMOJI announcement MESSAGE`
|
64
|
+
# help: It will store the message on the announcement list labeled with the color or emoji specified, white by default.
|
65
|
+
# help: aliases for announcement: statement, declaration, message
|
66
|
+
# help: Examples:
|
67
|
+
# help: _add green announcement :heavy_check_mark: All customer services are up and running_
|
68
|
+
# help: _add red declaration Customers db is down :x:_
|
69
|
+
# help: _add yellow statement Don't access the linux server without VPN_
|
70
|
+
# help: _add message `*Party* will start at *20:00* :tada:`_
|
71
|
+
# help: _add :heavy_exclamation_mark: message Pay attention all DB are on maintenance until 20:00 GMT_
|
72
|
+
# help: <https://github.com/MarioRuiz/slack-smart-bot#announcements|more info>
|
73
|
+
# help:
|
74
|
+
when /\A\s*(add|create)\s+(red\s+|green\s+|white\s+|yellow\s+)?(announcement|statement|declaration|message)\s+(.+)\s*\z/i,
|
75
|
+
/\A\s*(add|create)\s+(:\w+:)\s+(announcement|statement|declaration|message)\s+(.+)\s*\z/i
|
76
|
+
type = $2.to_s.downcase.strip
|
77
|
+
type = 'white' if type == ''
|
78
|
+
message = $4
|
79
|
+
add_announcement(user, type, message)
|
80
|
+
|
81
|
+
|
82
|
+
# help: ----------------------------------------------
|
83
|
+
# help: `delete announcement ID`
|
84
|
+
# help: It will delete the message on the announcement list.
|
85
|
+
# help: aliases for announcement: statement, declaration, message
|
86
|
+
# help: Examples:
|
87
|
+
# help: _delete announcement 24_
|
88
|
+
# help: _delete message 645_
|
89
|
+
# help: _delete statement 77_
|
90
|
+
# help: _delete declaration 334_
|
91
|
+
# help: <https://github.com/MarioRuiz/slack-smart-bot#announcements|more info>
|
92
|
+
# help:
|
93
|
+
when /\A\s*(delete|remove)\s+(announcement|statement|declaration|message)\s+(\d+)\s*\z/i
|
94
|
+
message_id = $3
|
95
|
+
delete_announcement(user, message_id)
|
96
|
+
|
97
|
+
# help: ----------------------------------------------
|
98
|
+
# help: `see announcements`
|
99
|
+
# help: `see red announcements`
|
100
|
+
# help: `see green announcements`
|
101
|
+
# help: `see yellow announcements`
|
102
|
+
# help: `see white announcements`
|
103
|
+
# help: `see EMOJI announcements`
|
104
|
+
# helpmaster: `see announcements #CHANNEL`
|
105
|
+
# helpmaster: `see all announcements`
|
106
|
+
# help: It will display the announcements for the channel.
|
107
|
+
# help: aliases for announcements: statements, declarations, messages
|
108
|
+
# helpmaster: In case #CHANNEL it will display the announcements for that channel. Only master admins can use it from a DM with the Smartbot.
|
109
|
+
# helpmaster: In case 'all' it will display all the announcements for all channels. Only master admins can use it from a DM with the Smartbot.
|
110
|
+
# help: Examples:
|
111
|
+
# help: _see announcements_
|
112
|
+
# help: _see white messages_
|
113
|
+
# help: _see red statements_
|
114
|
+
# help: _see yellow declarations_
|
115
|
+
# help: _see messages_
|
116
|
+
# help: _see :heavy_exclamation_mark: messages_
|
117
|
+
# help: <https://github.com/MarioRuiz/slack-smart-bot#announcements|more info>
|
118
|
+
# help:
|
119
|
+
when /\A\s*see\s+(red\s+|green\s+|white\s+|yellow\s+|:\w+:\s+)?(announcements|statements|declarations|messages)()\s*\z/i,
|
120
|
+
/\A\s*see\s+(all\s+)?(announcements|statements|declarations|messages)()\s*\z/i,
|
121
|
+
/\A\s*see\s+(red\s+|green\s+|white\s+|yellow\s+|:\w+:\s+)?(announcements|statements|declarations|messages)\s+#([\w\-]+)\s*\z/i,
|
122
|
+
/\A\s*see\s+(red\s+|green\s+|white\s+|yellow\s+|:\w+:\s+)?(announcements|statements|declarations|messages)\s+<#(C\w+)\|.*>\s*\z/i
|
123
|
+
|
124
|
+
type = $1.to_s.downcase.strip
|
125
|
+
channel = $3.to_s
|
126
|
+
|
127
|
+
see_announcements(user, type, channel)
|
128
|
+
|
129
|
+
|
130
|
+
# help: ----------------------------------------------
|
131
|
+
# help: `share messages /REGEXP/ on #CHANNEL`
|
132
|
+
# help: `share messages "TEXT" on #CHANNEL`
|
133
|
+
# xhelp: `share messages :EMOJI: on #CHANNEL`
|
134
|
+
# help: It will automatically share new messages published that meet the specified criteria.
|
135
|
+
# xhelp: In case :EMOJI: it will share the messages with the indicated reaction.
|
136
|
+
# help: SmartBot user and user adding the share need to be members on both channels.
|
137
|
+
# help: The Regexp will automatically add the parameters /im
|
138
|
+
# help: Only available on public channels.
|
139
|
+
# help: Examples:
|
140
|
+
# help: _share messages /(last\s+|previous\s+)?sales\s+results\s+/ on #sales_
|
141
|
+
# help: _share messages "share post" on #announcements_
|
142
|
+
# xhelp: _share messages :tada: on #announcements_
|
143
|
+
# xhelp: _share messages :moneybag: from #sales_
|
144
|
+
# help: <https://github.com/MarioRuiz/slack-smart-bot#share-messages|more info>
|
145
|
+
# help:
|
146
|
+
when /\A\s*share\s+messages\s+(\/.+\/|".+"|'.+')\s+on\s+<#\w+\|(.+)>\s*\z/i,
|
147
|
+
/\A\s*share\s+messages\s+(\/.+\/|".+"|'.+')\s+on\s+<#(\w+)\|>\s*\z/,
|
148
|
+
/\A\s*share\s+messages\s+(\/.+\/|".+"|'.+')\s+on\s+(.+)\s*\z/i
|
149
|
+
condition = $1
|
150
|
+
channel = $2
|
151
|
+
channel.gsub!('#','') # for the case the channel name is in plain text including #
|
152
|
+
channel = @channels_name[channel] if @channels_name.key?(channel)
|
153
|
+
channel_from = @channels_name[dest]
|
154
|
+
channel_to = channel
|
155
|
+
share_messages(user, channel_from, channel_to, condition)
|
156
|
+
|
157
|
+
# help: ----------------------------------------------
|
158
|
+
# help: `see shares`
|
159
|
+
# help: It will display the active shares from this channel.
|
160
|
+
# help: <https://github.com/MarioRuiz/slack-smart-bot#share-messages|more info>
|
161
|
+
# help:
|
162
|
+
when /\A\s*see\s+shares\s*\z/i
|
163
|
+
see_shares()
|
164
|
+
|
165
|
+
# help: ----------------------------------------------
|
166
|
+
# help: `delete share ID`
|
167
|
+
# help: It will delete the share id specified.
|
168
|
+
# help: Examples:
|
169
|
+
# help: _delete share 24_
|
170
|
+
# help: <https://github.com/MarioRuiz/slack-smart-bot#share-messages|more info>
|
171
|
+
# help:
|
172
|
+
when /\A\s*(delete|remove)\s+share\s+(\d+)\s*\z/i
|
173
|
+
share_id = $2
|
174
|
+
delete_share(user, share_id)
|
175
|
+
|
176
|
+
# help: ----------------------------------------------
|
177
|
+
# help: `see statuses`
|
178
|
+
# help: `see statuses #CHANNEL`
|
179
|
+
# help: `see status EMOJI`
|
180
|
+
# help: `see status EMOJI #CHANNEL`
|
181
|
+
# help: `see status EMOJI1 EMOJI99`
|
182
|
+
# help: `who is on vacation?`
|
183
|
+
# help: `who is on EMOJI`
|
184
|
+
# help: `who is on EMOJI #CHANNEL`
|
185
|
+
# help: `who is on EMOJI1 EMOJI99`
|
186
|
+
# help: `who is not on vacation?`
|
187
|
+
# help: `who is not on EMOJI`
|
188
|
+
# help: It will display the current statuses of the members of the channel where you are calling the command or on the channel you supply.
|
189
|
+
# help: <https://github.com/MarioRuiz/slack-smart-bot#see-statuses|more info>
|
190
|
+
# help:
|
191
|
+
when /\A\s*(see|get)\s+(statuses)()\s*\z/i,
|
192
|
+
/\A\s*(see\s+status|get\s+status|who\s+is\s+on|who\s+is\s+not\s+on)\s+(:[\w\-\:\s]+:)\s*\??()\s*\z/i,
|
193
|
+
/\A\s*(who\s+is\s+on|who\s+is\s+not\s+on)\s+(vacation|holiday)\s*\??()\s*\z/i,
|
194
|
+
/\A\s*(see|get)\s+(statuses)\s+#([\w\-]+)\s*\z/i,
|
195
|
+
/\A\s*(see\s+status|get\s+status|who\s+is\s+on|who\s+is\s+not\s+on)\s+(:[\w\-\:\s]+:)\s*\??\s+#([\w\-]+)\s*\z/i,
|
196
|
+
/\A\s*(who\s+is\s+on|who\s+is\s+not\s+on)\s+(vacation|holiday)\s*\??\s+#([\w\-]+)\s*\z/i,
|
197
|
+
/\A\s*(see|get)\s+(statuses)\s+<#(C\w+)\|.+>\s*\z/i,
|
198
|
+
/\A\s*(see\s+status|get\s+status|who\s+is\s+on|who\s+is\s+not\s+on)\s+(:[\w\-\:\s]+:)\s*\??\s+<#(C\w+)\|.+>\s*\z/i,
|
199
|
+
/\A\s*(who\s+is\s+on|who\s+is\s+not\s+on)\s+(vacation|holiday)\s*\??\s+<#(C\w+)\|.+>\s*\z/i
|
200
|
+
|
201
|
+
not_on = $1.match?(/who\s+is\s+not\s+on/i)
|
202
|
+
type = $2.downcase
|
203
|
+
channel = $3.to_s
|
204
|
+
if type == 'statuses'
|
205
|
+
types = []
|
206
|
+
elsif type =='vacation' or type == 'holiday'
|
207
|
+
types = [':palm_tree:']
|
208
|
+
else
|
209
|
+
type.gsub!(' ', '')
|
210
|
+
type.gsub!('::',': :')
|
211
|
+
types = type.split(' ')
|
212
|
+
end
|
213
|
+
see_statuses(user, channel, types, dest, not_on)
|
214
|
+
|
215
|
+
|
216
|
+
# help: ----------------------------------------------
|
217
|
+
# help: `see favorite commands`
|
218
|
+
# help: `see my favorite commands`
|
219
|
+
# help: `favorite commands`
|
220
|
+
# help: `my favorite commands`
|
221
|
+
# help: It will display the favorite commands.
|
222
|
+
# help: aliases for favorite: favourite, most used, fav
|
223
|
+
# helpmaster: You need to set stats to true to generate the stats when running the bot instance and get this info.
|
224
|
+
# help: <https://github.com/MarioRuiz/slack-smart-bot#see-favorite-commands|more info>
|
225
|
+
# help:
|
226
|
+
when /\A\s*(see\s+)?(my\s+)?(fav|favorite|favourite|most\s+used)\s+commands\s*\z/i
|
227
|
+
only_mine = $2.to_s!=''
|
228
|
+
see_favorite_commands(user, only_mine)
|
229
|
+
|
230
|
+
else
|
231
|
+
return false
|
232
|
+
end
|
233
|
+
return true
|
234
|
+
rescue => exception
|
235
|
+
if defined?(@logger)
|
236
|
+
@logger.fatal exception
|
237
|
+
respond "Unexpected error!! Please contact an admin to solve it: <@#{config.admins.join(">, <@")}>"
|
238
|
+
else
|
239
|
+
puts exception
|
240
|
+
end
|
241
|
+
return false
|
242
|
+
end
|
243
|
+
end
|