Skip to content

Commit

Permalink
Merge pull request #46 from MarioRuiz/revert-45-v1.11.0
Browse files Browse the repository at this point in the history
Revert "V1.11.0"
  • Loading branch information
MarioRuiz committed Oct 6, 2021
2 parents 43426ba + cf6e448 commit f60fc8e
Show file tree
Hide file tree
Showing 78 changed files with 124 additions and 945 deletions.
12 changes: 2 additions & 10 deletions README.md
Expand Up @@ -31,7 +31,7 @@ slack-smart-bot can create bots on demand, create shortcuts, run ruby code... ju
* [Share Messages](#share-messages)
* [See Statuses](#see-statuses)
* [Routines](#routines)
* [Control who has access to a command](#control-who-has-access-to-a-command)
* [Limit who has access to a command](#limit-who-has-access-to-a-command)
* [See favorite commands](#see-favorite-commands)
* [Tips](#tips)
+ [Send a file](#send-a-file)
Expand Down Expand Up @@ -309,10 +309,6 @@ If you are a Master Admin on a Direct Message with the Smart Bot you can call th

You can also get the bot logs of the bot channel you are using by calling `get bot logs`. You need to be a Master Admin user on a DM with the Smart Bot.

You can add, remove and list admins of any channel by using: `add admin @user`, `remove admin @user` and `see admins`. You need to be the creator of the channel, a Master admin or an admin.

To see the full list of available command ids on any channel call: `see command ids`

#### Cloud Bots
If you want to create a bot that will be running on a different machine: **_`create cloud bot on CHANNEL`_**. Even though the cloud bots are running on different machines, the management can be done through the MASTER CHANNEL. The new cloud bot will be managed by your Master Bot like the others, closing, pausing...

Expand Down Expand Up @@ -499,11 +495,7 @@ Other routine commands:
* **_`see routines`_**
* **_`see result routine NAME`_**

### Control who has access to a command

You can add, remove and list admins of any channel by using: `add admin @user`, `remove admin @user` and `see admins`. You need to be the creator of the channel, a Master admin or an admin.

To see the full list of available command ids on any channel call: `see command ids`
### Limit who has access to a command

If you want to define who has access to certain commands you can specify it on the settings when starting the Smart Bot:

Expand Down
7 changes: 2 additions & 5 deletions lib/slack-smart-bot.rb
Expand Up @@ -77,7 +77,7 @@ def initialize(config)
default_rules = (__FILE__).gsub(/\.rb$/, "_rules.rb")
FileUtils.copy_file(default_rules, config.path + '/' + config.rules_file)
end
config.admins = config.masters.dup unless config.admins.to_s!=''
config.admins = config.masters unless config.admins.to_s!=''
config.channel = config.master_channel unless config.channel.to_s!=''
config.status_init = :on unless config.status_init.to_s!=''
else
Expand Down Expand Up @@ -179,6 +179,7 @@ def initialize(config)
@shares = Hash.new()
@last_status_change = Time.now


if File.exist?("#{config.path}/shortcuts/#{config.shortcuts_file}")
file_sc = IO.readlines("#{config.path}/shortcuts/#{config.shortcuts_file}").join
unless file_sc.to_s() == ""
Expand Down Expand Up @@ -269,17 +270,13 @@ def initialize(config)
@datetime_general_commands = 0
@channels_id = Hash.new()
@channels_name = Hash.new()
@channels_creator = Hash.new()
get_channels_name_and_id()
@channel_id = @channels_id[config.channel].dup
@master_bot_id = @channels_id[config.master_channel].dup

Dir.mkdir("#{config.path}/rules/#{@channel_id}") unless Dir.exist?("#{config.path}/rules/#{@channel_id}/")

get_routines()
get_repls()
get_shares()
get_admins_channels()

if @routines.key?(@channel_id)
@routines[@channel_id].each do |k, v|
Expand Down
2 changes: 1 addition & 1 deletion lib/slack-smart-bot_general_commands.rb
Expand Up @@ -21,7 +21,7 @@ def general_commands(user, command, dest, files = [])


# this is a hidden command that it is not listed when calling bot help
when /\s*(that's\s+)?(thanks|thank\s+you|I\s+love\s+you|nice|cool)\s+(#{@salutations.join("|")})\s*!*\s*$/i
when /\A\s*(that's\s+)?(thanks|thank\s+you|I\s+love\s+you|nice|cool)\s+(#{@salutations.join("|")})\s*!*\s*$/i
save_stats :thanks
reactions = [:heart, :heart_eyes, :blush, :relaxed, :simple_smile, :smiley, :two_hearts, :heartbeat, :green_heart ]
reactions.sample(rand(3)+1).each {|rt| react rt }
Expand Down
1 change: 0 additions & 1 deletion lib/slack/smart-bot/comm.rb
Expand Up @@ -13,4 +13,3 @@
require_relative 'comm/event_hello'
require_relative 'comm/get_channel_members'
require_relative 'comm/get_channels'
require_relative 'comm/delete'
13 changes: 0 additions & 13 deletions lib/slack/smart-bot/comm/delete.rb

This file was deleted.

12 changes: 5 additions & 7 deletions lib/slack/smart-bot/comm/respond.rb
@@ -1,7 +1,6 @@
class SlackSmartBot
def respond(msg = "", dest = nil, unfurl_links: true, unfurl_media: true, thread_ts: "", web_client: true, blocks: [], dont_share: false, return_message: false)
def respond(msg = "", dest = nil, unfurl_links: true, unfurl_media: true, thread_ts: "", web_client: true, blocks: [], dont_share: false)
result = true
resp = nil
if (msg.to_s != "" or !msg.to_s.match?(/^A\s*\z/) or !blocks.empty?) and Thread.current[:routine_type].to_s != "bgroutine"
if !web_client.is_a?(TrueClass) and !web_client.is_a?(FalseClass)
(!unfurl_links or !unfurl_media) ? web_client = true : web_client = false
Expand Down Expand Up @@ -120,14 +119,14 @@ def respond(msg = "", dest = nil, unfurl_links: true, unfurl_media: true, thread
end
elsif dest[0] == "D" or dest[0] == "U" or dest[0] == "W" # Direct message
msgs.each do |msg|
resp = send_msg_user(dest, msg, on_thread, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
send_msg_user(dest, msg, on_thread, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
sleep wait
end
elsif dest[0] == "@"
begin
user_info = @users.select { |u| u.id == dest[1..-1] or u.name == dest[1..-1] or (u.key?(:enterprise_user) and u.enterprise_user.id == dest[1..-1]) }[-1]
msgs.each do |msg|
resp = send_msg_user(user_info.id, msg, on_thread, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
send_msg_user(user_info.id, msg, on_thread, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
sleep wait
end
rescue Exception => stack
Expand Down Expand Up @@ -194,14 +193,14 @@ def respond(msg = "", dest = nil, unfurl_links: true, unfurl_media: true, thread
end
elsif dest[0] == "D" or dest[0] == "U" or dest[0] == "W" # Direct message
blocks.each_slice(40).to_a.each do |blockstmp|
resp = send_msg_user(dest, msg, on_thread, unfurl_links: unfurl_links, unfurl_media: unfurl_media, blocks: blockstmp)
send_msg_user(dest, msg, on_thread, unfurl_links: unfurl_links, unfurl_media: unfurl_media, blocks: blockstmp)
sleep wait
end
elsif dest[0] == "@"
begin
user_info = @users.select { |u| u.id == dest[1..-1] or (u.key?(:enterprise_user) and u.enterprise_user.id == dest[1..-1]) }[-1]
blocks.each_slice(40).to_a.each do |blockstmp|
resp = send_msg_user(user_info.id, msg, on_thread, unfurl_links: unfurl_links, unfurl_media: unfurl_media, blocks: blockstmp)
send_msg_user(user_info.id, msg, on_thread, unfurl_links: unfurl_links, unfurl_media: unfurl_media, blocks: blockstmp)
sleep wait
end
rescue Exception => stack
Expand All @@ -226,7 +225,6 @@ def respond(msg = "", dest = nil, unfurl_links: true, unfurl_media: true, thread
if Thread.current.key?(:routine) and Thread.current[:routine]
File.write("#{config.path}/routines/#{@channel_id}/#{Thread.current[:routine_name]}_output.txt", msg, mode: "a+")
end
result = resp if return_message
return result
end
end
23 changes: 11 additions & 12 deletions lib/slack/smart-bot/comm/send_msg_user.rb
@@ -1,12 +1,12 @@
class SlackSmartBot

#to send messages without listening for a response to users
def send_msg_user(id_user, msg='', on_thread=nil, unfurl_links: true, unfurl_media: true, blocks: [], web_client: true)
resp = nil
def send_msg_user(id_user, msg='', on_thread=nil, unfurl_links: true, unfurl_media: true, blocks: [])
unless msg == "" and blocks.empty?
begin
on_thread = Thread.current[:on_thread] if on_thread.nil?
web_client = true if !blocks.empty? or !unfurl_links or !unfurl_media
(!unfurl_links or !unfurl_media) ? web_client = true : web_client = false
web_client = true if !blocks.empty?
if id_user[0] == "D"
if config[:simulate]
open("#{config.path}/buffer_complete.log", "a") { |f|
Expand All @@ -15,15 +15,15 @@ def send_msg_user(id_user, msg='', on_thread=nil, unfurl_links: true, unfurl_med
else
if web_client
if on_thread
resp = client.web_client.chat_postMessage(channel: id_user, text: msg, blocks: blocks, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media, thread_ts: Thread.current[:thread_ts])
client.web_client.chat_postMessage(channel: id_user, text: msg, blocks: blocks, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media, thread_ts: Thread.current[:thread_ts])
else
resp = client.web_client.chat_postMessage(channel: id_user, text: msg, blocks: blocks, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
client.web_client.chat_postMessage(channel: id_user, text: msg, blocks: blocks, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
end
else
if on_thread
resp = client.message(channel: id_user, as_user: true, text: msg, thread_ts: Thread.current[:thread_ts], unfurl_links: unfurl_links, unfurl_media: unfurl_media)
client.message(channel: id_user, as_user: true, text: msg, thread_ts: Thread.current[:thread_ts], unfurl_links: unfurl_links, unfurl_media: unfurl_media)
else
resp = client.message(channel: id_user, as_user: true, text: msg, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
client.message(channel: id_user, as_user: true, text: msg, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
end
end
end
Expand All @@ -42,15 +42,15 @@ def send_msg_user(id_user, msg='', on_thread=nil, unfurl_links: true, unfurl_med
im = client.web_client.conversations_open(users: id_user)
if web_client
if on_thread
resp = client.web_client.chat_postMessage(channel: im["channel"]["id"], text: msg, blocks: blocks, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media, thread_ts: Thread.current[:thread_ts])
client.web_client.chat_postMessage(channel: im["channel"]["id"], text: msg, blocks: blocks, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media, thread_ts: Thread.current[:thread_ts])
else
resp = client.web_client.chat_postMessage(channel: im["channel"]["id"], text: msg, blocks: blocks, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
client.web_client.chat_postMessage(channel: im["channel"]["id"], text: msg, blocks: blocks, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
end
else
if on_thread
resp = client.message(channel: im["channel"]["id"], as_user: true, text: msg, thread_ts: Thread.current[:thread_ts], unfurl_links: unfurl_links, unfurl_media: unfurl_media)
client.message(channel: im["channel"]["id"], as_user: true, text: msg, thread_ts: Thread.current[:thread_ts], unfurl_links: unfurl_links, unfurl_media: unfurl_media)
else
resp = client.message(channel: im["channel"]["id"], as_user: true, text: msg, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
client.message(channel: im["channel"]["id"], as_user: true, text: msg, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
end
end
end
Expand All @@ -65,7 +65,6 @@ def send_msg_user(id_user, msg='', on_thread=nil, unfurl_links: true, unfurl_med
@logger.warn stack
end
end
return resp
end

end
19 changes: 7 additions & 12 deletions lib/slack/smart-bot/commands.rb
@@ -1,16 +1,16 @@
require_relative "commands/general/whats_new"
require_relative "commands/general/hi_bot"
require_relative "commands/general/bye_bot"
require_relative "commands/general/bot_help"
require_relative "commands/on_bot/general/suggest_command"
require_relative "commands/general/suggest_command"
require_relative "commands/on_bot/ruby_code"
require_relative "commands/on_bot/repl"
require_relative "commands/on_bot/get_repl"
require_relative "commands/on_bot/run_repl"
require_relative "commands/on_bot/delete_repl"
require_relative "commands/on_bot/see_repls"
require_relative "commands/on_bot/general/whats_new"
require_relative "commands/on_bot/general/use_rules"
require_relative "commands/on_bot/general/stop_using_rules"
require_relative "commands/general/use_rules"
require_relative "commands/general/stop_using_rules"
require_relative "commands/on_master/admin_master/exit_bot"
require_relative "commands/on_master/admin_master/notify_message"
require_relative "commands/on_master/admin/kill_bot_on_channel"
Expand All @@ -26,17 +26,16 @@
require_relative "commands/on_bot/admin/see_routines"
require_relative "commands/on_bot/admin/extend_rules"
require_relative "commands/on_bot/admin/stop_using_rules_on"
require_relative "commands/on_bot/general/bot_status"
require_relative "commands/general/bot_status"
require_relative "commands/on_bot/add_shortcut"
require_relative "commands/on_bot/delete_shortcut"
require_relative "commands/on_bot/see_shortcuts"
require_relative "commands/on_extended/bot_rules"
require_relative "commands/on_bot/admin_master/get_bot_logs"
require_relative "commands/on_bot/admin_master/send_message"
require_relative "commands/on_bot/admin_master/delete_message"
require_relative "commands/on_bot/admin_master/react_to"
require_relative "commands/on_bot/general/bot_stats"
require_relative "commands/on_bot/general/leaderboard"
require_relative "commands/general/bot_stats"
require_relative "commands/general/leaderboard"
require_relative "commands/general/add_announcement"
require_relative "commands/general/delete_announcement"
require_relative "commands/general/see_announcements"
Expand All @@ -49,7 +48,3 @@
require_relative "commands/general/share_messages"
require_relative "commands/general/see_shares"
require_relative "commands/general/delete_share"
require_relative "commands/general/see_admins"
require_relative "commands/general/add_admin"
require_relative "commands/general/remove_admin"
require_relative "commands/general/see_command_ids"
51 changes: 0 additions & 51 deletions lib/slack/smart-bot/commands/general/add_admin.rb

This file was deleted.

58 changes: 0 additions & 58 deletions lib/slack/smart-bot/commands/general/remove_admin.rb

This file was deleted.

0 comments on commit f60fc8e

Please sign in to comment.