slack-smart-bot 1.13.2 → 1.14.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 +100 -4
- data/lib/slack/smart-bot/ai/open_ai/connect.rb +61 -0
- data/lib/slack/smart-bot/ai/open_ai/models.rb +21 -0
- data/lib/slack/smart-bot/ai/open_ai/send_gpt_chat.rb +24 -0
- data/lib/slack/smart-bot/ai/open_ai/send_image_edit.rb +23 -0
- data/lib/slack/smart-bot/ai/open_ai/send_image_generation.rb +18 -0
- data/lib/slack/smart-bot/ai/open_ai/send_image_variation.rb +22 -0
- data/lib/slack/smart-bot/ai/open_ai/whisper_transcribe.rb +21 -0
- data/lib/slack/smart-bot/ai.rb +8 -0
- data/lib/slack/smart-bot/comm/get_channel_members.rb +15 -13
- data/lib/slack/smart-bot/comm/get_channels.rb +31 -29
- data/lib/slack/smart-bot/comm/respond_thread.rb +2 -2
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat.rb +40 -0
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_edit_image.rb +66 -0
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_generate_image.rb +65 -0
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_models.rb +37 -0
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_variations_image.rb +84 -0
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_whisper.rb +51 -0
- data/lib/slack/smart-bot/commands/general/bot_help.rb +1 -0
- data/lib/slack/smart-bot/commands/general/personal_settings.rb +38 -0
- data/lib/slack/smart-bot/commands/general/poster.rb +107 -104
- data/lib/slack/smart-bot/commands/general/public_holidays.rb +116 -114
- data/lib/slack/smart-bot/commands/general/set_public_holidays.rb +6 -2
- data/lib/slack/smart-bot/commands/general/teams/add_team.rb +87 -0
- data/lib/slack/smart-bot/commands/general/teams/delete_team.rb +69 -0
- data/lib/slack/smart-bot/commands/general/teams/memos/add_memo_team.rb +136 -0
- data/lib/slack/smart-bot/commands/general/teams/memos/add_memo_team_comment.rb +37 -0
- data/lib/slack/smart-bot/commands/general/teams/memos/delete_memo_team.rb +83 -0
- data/lib/slack/smart-bot/commands/general/teams/memos/see_memo_team.rb +97 -0
- data/lib/slack/smart-bot/commands/general/teams/memos/see_memos_team.rb +304 -0
- data/lib/slack/smart-bot/commands/general/teams/memos/set_memo_status.rb +66 -0
- data/lib/slack/smart-bot/commands/general/teams/ping_team.rb +104 -0
- data/lib/slack/smart-bot/commands/general/teams/see_teams.rb +236 -0
- data/lib/slack/smart-bot/commands/general/teams/see_vacations_team.rb +183 -0
- data/lib/slack/smart-bot/commands/general/teams/update_team.rb +137 -0
- data/lib/slack/smart-bot/commands/general_bot_commands.rb +905 -741
- data/lib/slack/smart-bot/commands/on_bot/general/bot_stats.rb +379 -353
- data/lib/slack/smart-bot/commands/on_bot/repl.rb +6 -107
- data/lib/slack/smart-bot/commands/on_bot/repl_client.rb +233 -0
- data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +17 -4
- data/lib/slack/smart-bot/commands.rb +26 -10
- data/lib/slack/smart-bot/process.rb +14 -3
- data/lib/slack/smart-bot/process_first.rb +36 -2
- data/lib/slack/smart-bot/treat_message.rb +28 -0
- data/lib/slack/smart-bot/utils/check_vacations.rb +1 -0
- data/lib/slack/smart-bot/utils/create_routine_thread.rb +1 -1
- data/lib/slack/smart-bot/utils/display_calendar.rb +17 -10
- data/lib/slack/smart-bot/utils/encryption/decrypt.rb +23 -0
- data/lib/slack/smart-bot/utils/encryption/encrypt.rb +27 -0
- data/lib/slack/smart-bot/utils/{encryption_get_key_iv.rb → encryption/encryption_get_key_iv.rb} +12 -8
- data/lib/slack/smart-bot/utils/get_help.rb +3 -1
- data/lib/slack/smart-bot/utils/get_personal_settings.rb +14 -0
- data/lib/slack/smart-bot/utils/get_teams.rb +2 -2
- data/lib/slack/smart-bot/utils/get_vacations.rb +2 -2
- data/lib/slack/smart-bot/utils/save_stats.rb +3 -1
- data/lib/slack/smart-bot/utils/update_personal_settings.rb +18 -0
- data/lib/slack/smart-bot/utils/update_teams.rb +1 -1
- data/lib/slack/smart-bot/utils/update_vacations.rb +1 -1
- data/lib/slack/smart-bot/utils.rb +5 -3
- data/lib/slack-smart-bot.rb +12 -0
- data/whats_new.txt +13 -14
- metadata +63 -15
- data/lib/slack/smart-bot/commands/general/add_memo_team.rb +0 -117
- data/lib/slack/smart-bot/commands/general/add_team.rb +0 -81
- data/lib/slack/smart-bot/commands/general/delete_memo_team.rb +0 -69
- data/lib/slack/smart-bot/commands/general/delete_team.rb +0 -55
- data/lib/slack/smart-bot/commands/general/ping_team.rb +0 -100
- data/lib/slack/smart-bot/commands/general/see_memos_team.rb +0 -202
- data/lib/slack/smart-bot/commands/general/see_teams.rb +0 -230
- data/lib/slack/smart-bot/commands/general/see_vacations_team.rb +0 -136
- data/lib/slack/smart-bot/commands/general/set_memo_status.rb +0 -58
- data/lib/slack/smart-bot/commands/general/update_team.rb +0 -131
- data/lib/slack/smart-bot/utils/decrypt.rb +0 -15
- data/lib/slack/smart-bot/utils/encrypt.rb +0 -15
@@ -0,0 +1,65 @@
|
|
1
|
+
class SlackSmartBot
|
2
|
+
module Commands
|
3
|
+
module General
|
4
|
+
module AI
|
5
|
+
module OpenAI
|
6
|
+
def open_ai_generate_image(message, delete_history = false, repeat: false)
|
7
|
+
save_stats(__method__)
|
8
|
+
get_personal_settings()
|
9
|
+
@ai_open_ai, message_connect = SlackSmartBot::AI::OpenAI.connect(@ai_open_ai, config, @personal_settings, reconnect: delete_history)
|
10
|
+
respond message_connect if message_connect
|
11
|
+
user = Thread.current[:user]
|
12
|
+
if !@ai_open_ai[user.name].nil? and !@ai_open_ai[user.name][:client].nil?
|
13
|
+
@ai_open_ai_image ||= {}
|
14
|
+
@ai_open_ai_image[user.name] ||= []
|
15
|
+
react :art
|
16
|
+
begin
|
17
|
+
@ai_open_ai_image[user.name] = [] if delete_history
|
18
|
+
if delete_history and message == ""
|
19
|
+
respond "*OpenAI*: Let's start a new image generation. Use `?i PROMPT` to generate an image."
|
20
|
+
elsif repeat and @ai_open_ai_image[user.name].empty? and message == ""
|
21
|
+
respond "*OpenAI*: Sorry, I need to generate an image first. Use `?i PROMPT` to generate an image."
|
22
|
+
else
|
23
|
+
@ai_open_ai_image[user.name] << message unless repeat
|
24
|
+
success, res = SlackSmartBot::AI::OpenAI.send_image_generation(@ai_open_ai[user.name][:client], @ai_open_ai_image[user.name].join("\n"), @ai_open_ai[user.name][:image_size])
|
25
|
+
if success
|
26
|
+
urls = res
|
27
|
+
urls = [urls] if urls.is_a?(String)
|
28
|
+
if urls.nil? or urls.empty?
|
29
|
+
respond "*OpenAI*: Sorry, I'm having some problems. OpenAI was not able to generate an image."
|
30
|
+
else
|
31
|
+
session_name = @ai_open_ai_image[user.name].first[0..29]
|
32
|
+
messagersp = "OpenAI Session: _<#{session_name}...>_ (id:#{@ai_open_ai_image[user.name].object_id})"
|
33
|
+
message = "Repeat" if repeat
|
34
|
+
require "uri"
|
35
|
+
urls.each do |url|
|
36
|
+
uri = URI.parse(url)
|
37
|
+
require "nice_http"
|
38
|
+
http = NiceHttp.new(host: "https://#{uri.host}")
|
39
|
+
Dir.mkdir("#{config.path}/tmp") unless Dir.exist?("#{config.path}/tmp")
|
40
|
+
file_path_name = "#{config.path}/tmp/#{user.name}_#{@ai_open_ai_image[user.name].object_id}.png"
|
41
|
+
res = http.get(uri.path + "?#{uri.query}", save_data: file_path_name)
|
42
|
+
if config.simulate
|
43
|
+
respond "file: #{file_path_name}, #{messagersp}, #{message}, image/png, png"
|
44
|
+
else
|
45
|
+
send_file(Thread.current[:dest], messagersp, file_path_name, message, "image/png", "png")
|
46
|
+
end
|
47
|
+
http.close unless http.nil?
|
48
|
+
end
|
49
|
+
end
|
50
|
+
else
|
51
|
+
respond res
|
52
|
+
end
|
53
|
+
end
|
54
|
+
rescue => exception
|
55
|
+
respond "*OpenAI*: Sorry, I'm having some problems. OpenAI probably is not available. Please try again later."
|
56
|
+
@logger.warn exception
|
57
|
+
end
|
58
|
+
unreact :art
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class SlackSmartBot
|
2
|
+
module Commands
|
3
|
+
module General
|
4
|
+
module AI
|
5
|
+
module OpenAI
|
6
|
+
def open_ai_models(model='')
|
7
|
+
save_stats(__method__)
|
8
|
+
get_personal_settings()
|
9
|
+
@ai_open_ai, message_connect = SlackSmartBot::AI::OpenAI.connect(@ai_open_ai, config, @personal_settings)
|
10
|
+
respond message_connect if message_connect
|
11
|
+
user = Thread.current[:user]
|
12
|
+
if !@ai_open_ai[user.name].nil? and !@ai_open_ai[user.name][:client].nil?
|
13
|
+
react :running
|
14
|
+
begin
|
15
|
+
res = SlackSmartBot::AI::OpenAI.models(@ai_open_ai[user.name][:client], model)
|
16
|
+
if model == ''
|
17
|
+
message = ["*OpenAI*"]
|
18
|
+
message << "If you want to use a model, you can use on a DM with the SmartBot the command"
|
19
|
+
message << "`set personal settings ai.open_ai.gpt_model MODEL_NAME`"
|
20
|
+
message << "`set personal settings ai.open_ai.whisper_model MODEL_NAME`"
|
21
|
+
message << "Here are the models available for use:"
|
22
|
+
message << "```#{res.strip}```"
|
23
|
+
respond message.join("\n")
|
24
|
+
else
|
25
|
+
respond "*OpenAI* Info about #{model} model:\n```#{res.strip}```"
|
26
|
+
end
|
27
|
+
rescue => exception
|
28
|
+
respond "*OpenAI*: Sorry, I'm having some problems. OpenAI probably is not available. Please try again later."
|
29
|
+
end
|
30
|
+
unreact :running
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
class SlackSmartBot
|
2
|
+
module Commands
|
3
|
+
module General
|
4
|
+
module AI
|
5
|
+
module OpenAI
|
6
|
+
def open_ai_variations_image(message, variations, files)
|
7
|
+
save_stats(__method__)
|
8
|
+
get_personal_settings()
|
9
|
+
@ai_open_ai, message_connect = SlackSmartBot::AI::OpenAI.connect(@ai_open_ai, config, @personal_settings)
|
10
|
+
respond message_connect if message_connect
|
11
|
+
user = Thread.current[:user]
|
12
|
+
if !@ai_open_ai[user.name].nil? and !@ai_open_ai[user.name][:client].nil?
|
13
|
+
if variations > 9
|
14
|
+
respond "*OpenAI*: I'm sorry, I can only generate up to 9 variations at a time. Please try again."
|
15
|
+
else
|
16
|
+
variations = 1 if variations == 0
|
17
|
+
@ai_open_ai_image ||= {}
|
18
|
+
@ai_open_ai_image[user.name] ||= []
|
19
|
+
react :art
|
20
|
+
begin
|
21
|
+
@ai_open_ai_image[user.name] = [] if !files.nil? and files.size == 1
|
22
|
+
|
23
|
+
if (!File.exist?("#{config.path}/tmp/#{user.name}_#{@ai_open_ai_image[user.name].object_id}.png") and (files.nil? or files.size != 1))
|
24
|
+
respond "*OpenAI*: Sorry, I need to generate an image first. Use `?i PROMPT` to generate an image or upload an image to generate variations."
|
25
|
+
else
|
26
|
+
image = "#{config.path}/tmp/#{user.name}_#{@ai_open_ai_image[user.name].object_id}.png"
|
27
|
+
if !files.nil? and files.size == 1
|
28
|
+
require "nice_http"
|
29
|
+
http = NiceHttp.new(host: "https://files.slack.com", headers: { "Authorization" => "Bearer #{config.token}" })
|
30
|
+
res = http.get(files[0].url_private_download, save_data: image)
|
31
|
+
success, res = SlackSmartBot::AI::OpenAI.send_image_variation(@ai_open_ai[user.name].client, image, variations, size: @ai_open_ai[user.name][:image_size])
|
32
|
+
else
|
33
|
+
success, res = SlackSmartBot::AI::OpenAI.send_image_variation(@ai_open_ai[user.name].client, image, variations, size: @ai_open_ai[user.name][:image_size])
|
34
|
+
end
|
35
|
+
if success
|
36
|
+
urls = res
|
37
|
+
urls = [urls] if urls.is_a?(String)
|
38
|
+
if urls.nil? or urls.empty?
|
39
|
+
respond "*OpenAI*: Sorry, I'm having some problems. OpenAI was not able to generate an image."
|
40
|
+
else
|
41
|
+
if @ai_open_ai_image[user.name].empty?
|
42
|
+
session_name = "Temporary Variation"
|
43
|
+
else
|
44
|
+
session_name = @ai_open_ai_image[user.name].first[0..29]
|
45
|
+
end
|
46
|
+
messagersp = "OpenAI Session: _<#{session_name}...>_ (id:#{@ai_open_ai_image[user.name].object_id})"
|
47
|
+
require "uri"
|
48
|
+
urls.each do |url|
|
49
|
+
uri = URI.parse(url)
|
50
|
+
require "nice_http"
|
51
|
+
http = NiceHttp.new(host: "https://#{uri.host}")
|
52
|
+
file_path_name = "#{config.path}/tmp/#{user.name}_#{@ai_open_ai_image[user.name].object_id}.png"
|
53
|
+
res = http.get(uri.path + "?#{uri.query}", save_data: file_path_name)
|
54
|
+
message = "Variation #{urls.index(url)+1} of #{urls.size}"
|
55
|
+
if config.simulate
|
56
|
+
respond "file: #{file_path_name}, #{messagersp}, #{message}, image/png, png"
|
57
|
+
else
|
58
|
+
send_file(Thread.current[:dest], messagersp, file_path_name, message, "image/png", "png")
|
59
|
+
end
|
60
|
+
http.close unless http.nil?
|
61
|
+
end
|
62
|
+
end
|
63
|
+
else
|
64
|
+
respond res
|
65
|
+
end
|
66
|
+
end
|
67
|
+
rescue => exception
|
68
|
+
respond "*OpenAI*: Sorry, I'm having some problems. OpenAI probably is not available. Please try again later."
|
69
|
+
@logger.warn exception
|
70
|
+
end
|
71
|
+
unreact :art
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
if variations > 9
|
76
|
+
respond "*OpenAI*: I'm sorry, I can only generate up to 9 variations at a time. Please try again."
|
77
|
+
else
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class SlackSmartBot
|
2
|
+
module Commands
|
3
|
+
module General
|
4
|
+
module AI
|
5
|
+
module OpenAI
|
6
|
+
def open_ai_whisper(message, files)
|
7
|
+
save_stats(__method__)
|
8
|
+
get_personal_settings()
|
9
|
+
@ai_open_ai, message_connect = SlackSmartBot::AI::OpenAI.connect(@ai_open_ai, config, @personal_settings)
|
10
|
+
respond message_connect if message_connect
|
11
|
+
user = Thread.current[:user]
|
12
|
+
if !@ai_open_ai[user.name].nil? and !@ai_open_ai[user.name][:client].nil?
|
13
|
+
react :speech_balloon
|
14
|
+
begin
|
15
|
+
if files.nil? or files.size != 1
|
16
|
+
respond "*OpenAI Whisper*: Sorry, I need an audio file to transcribe. Please upload an audio file and try again."
|
17
|
+
else
|
18
|
+
require "nice_http"
|
19
|
+
audio = "#{config.path}/tmp/#{user.name}_audio.wav"
|
20
|
+
http = NiceHttp.new(host: "https://files.slack.com", headers: { "Authorization" => "Bearer #{config.token}" })
|
21
|
+
res = http.get(files[0].url_private_download, save_data: audio)
|
22
|
+
success, res = SlackSmartBot::AI::OpenAI.whisper_transcribe(@ai_open_ai[user.name][:client], @ai_open_ai[user.name].whisper_model, audio)
|
23
|
+
if success
|
24
|
+
if message.to_s != ''
|
25
|
+
success, res = SlackSmartBot::AI::OpenAI.send_gpt_chat(@ai_open_ai[user.name][:client], @ai_open_ai[user.name].gpt_model, "#{message}:\n#{res}")
|
26
|
+
type_whisper = message
|
27
|
+
else
|
28
|
+
type_whisper = "Transcribe"
|
29
|
+
end
|
30
|
+
if res.size > 3000
|
31
|
+
send_file(Thread.current[:dest], "*OpenAI Whisper*", '', type_whisper, "text/plain", "text", content: res)
|
32
|
+
else
|
33
|
+
respond "*OpenAI Whisper* \n#{res.strip}"
|
34
|
+
end
|
35
|
+
else
|
36
|
+
respond "*OpenAI Whisper* \n#{res.strip}"
|
37
|
+
end
|
38
|
+
File.delete(audio) if File.exist?(audio)
|
39
|
+
end
|
40
|
+
rescue => exception
|
41
|
+
respond "*OpenAI Whisper*: Sorry, I'm having some problems. OpenAI probably is not available. Please try again later."
|
42
|
+
@logger.warn exception
|
43
|
+
end
|
44
|
+
unreact :speech_balloon
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -20,6 +20,7 @@ class SlackSmartBot
|
|
20
20
|
commands = []
|
21
21
|
commands_search = []
|
22
22
|
if help_command.to_s != ""
|
23
|
+
help_command.gsub!("?", "\\?") # for open ai commands
|
23
24
|
help_message.gsub(/====+/,'-'*30).split(/^\s*-------*$/).each do |h|
|
24
25
|
if strict
|
25
26
|
if h.match?(/`#{help_command}`/i) or h.match?(/^\s*command_id:\s+:#{help_command.gsub(' ', '_')}\s*$/)
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class SlackSmartBot
|
2
|
+
def personal_settings(user, type, settings_id, settings_value)
|
3
|
+
save_stats "#{type}_personal_settings"
|
4
|
+
if Thread.current[:typem] == :on_dm
|
5
|
+
get_personal_settings()
|
6
|
+
@personal_settings[user.name] ||= {}
|
7
|
+
if type == :get
|
8
|
+
if settings_id.to_s == ''
|
9
|
+
personal_settings_txt = ""
|
10
|
+
@personal_settings[user.name].each do |key, value|
|
11
|
+
personal_settings_txt << "`#{key}`: #{value}\n"
|
12
|
+
end
|
13
|
+
respond "Personal settings for *#{user.name}* are:\n#{personal_settings_txt}"
|
14
|
+
else
|
15
|
+
if @personal_settings[user.name].key?(settings_id)
|
16
|
+
respond "Personal settings for *#{settings_id}* is: *#{@personal_settings[user.name][settings_id]}*."
|
17
|
+
else
|
18
|
+
respond "Personal settings for *#{settings_id}* not found."
|
19
|
+
end
|
20
|
+
end
|
21
|
+
elsif type == :delete
|
22
|
+
if @personal_settings[user.name].key?(settings_id)
|
23
|
+
@personal_settings[user.name].delete(settings_id)
|
24
|
+
update_personal_settings()
|
25
|
+
respond "Personal settings deleted for *#{settings_id}*."
|
26
|
+
else
|
27
|
+
respond "Personal settings for *#{settings_id}* not found."
|
28
|
+
end
|
29
|
+
else #set
|
30
|
+
@personal_settings[user.name][settings_id] = settings_value
|
31
|
+
update_personal_settings()
|
32
|
+
respond "Personal settings set for *#{settings_id}*."
|
33
|
+
end
|
34
|
+
else
|
35
|
+
respond "This command can only be called on a DM with the SmartBot."
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -1,116 +1,119 @@
|
|
1
|
-
|
2
|
-
chars = { a: ["0000", "1111", "1001", "1111", "1001", "1001", "0000"],
|
3
|
-
b: ["0000", "1111", "1001", "1110", "1001", "1111", "0000"],
|
4
|
-
c: ["0000", "0111", "1000", "1000", "1000", "0111", "0000"],
|
5
|
-
d: ["0000", "1110", "1001", "1001", "1001", "1110", "0000"],
|
6
|
-
e: ["0000", "1111", "1000", "1110", "1000", "1111", "0000"],
|
7
|
-
f: ["0000", "1111", "1000", "1110", "1000", "1000", "0000"],
|
8
|
-
g: ["0000", "1111", "1000", "1011", "1001", "1111", "0000"],
|
9
|
-
h: ["0000", "1001", "1001", "1111", "1001", "1001", "0000"],
|
10
|
-
i: ["000", "111", "010", "010", "010", "111", "000"],
|
11
|
-
j: ["0000", "0111", "0010", "0010", "1010", "0110", "0000"],
|
12
|
-
k: ["0000", "1001", "1010", "1100", "1010", "1001", "0000"],
|
13
|
-
l: ["000", "100", "100", "100", "100", "111", "000"],
|
14
|
-
m: ["00000", "10001", "11011", "10101", "10001", "10001", "00000"],
|
15
|
-
n: ["00000", "10001", "11001", "10101", "10011", "10001", "00000"],
|
16
|
-
o: ["0000", "0110", "1001", "1001", "1001", "0110", "0000"],
|
17
|
-
p: ["0000", "1110", "1001", "1110", "1000", "1000", "0000"],
|
18
|
-
q: ["00000", "01100", "10010", "10010", "10010", "01111", "00000"],
|
19
|
-
r: ["0000", "1110", "1001", "1110", "1010", "1001", "0000"],
|
20
|
-
s: ["0000", "0111", "1000", "0110", "0001", "1110", "0000"],
|
21
|
-
t: ["00000", "11111", "00100", "00100", "00100", "00100", "00000"],
|
22
|
-
u: ["00000", "10001", "10001", "10001", "10001", "01110", "00000"],
|
23
|
-
v: ["00000", "10001", "10001", "10001", "01010", "00100", "00000"],
|
24
|
-
w: ["0000000", "1000001", "1000001", "1001001", "1010101", "0100010", "0000000"],
|
25
|
-
x: ["00000", "10001", "01010", "00100", "01010", "10001", "00000"],
|
26
|
-
y: ["00000", "10001", "01010", "00100", "00100", "00100", "00000"],
|
27
|
-
z: ["00000", "11111", "00010", "00100", "01000", "11111", "00000"],
|
28
|
-
'!': ["0", "1", "1", "1", "0", "1", "0"],
|
29
|
-
'+': ["000", "000", "010", "111", "010", "000", "000"],
|
30
|
-
'-': ["000", "000", "000", "111", "000", "000", "000"],
|
31
|
-
'=': ["000", "000", "111", "000", "111", "000", "000"],
|
32
|
-
'?': ["000", "111", "001", "010", "000", "010", "000"],
|
33
|
-
'0': ["000", "111", "101", "101", "101", "111", "000"],
|
34
|
-
'1': ["00", "01", "11", "01", "01", "01", "00"],
|
35
|
-
'2': ["000", "111", "001", "010", "100", "111", "000"],
|
36
|
-
'3': ["000", "111", "001", "111", "001", "111", "000"],
|
37
|
-
'4': ["000", "101", "101", "111", "001", "001", "000"],
|
38
|
-
'5': ["000", "111", "100", "111", "001", "111", "000"],
|
39
|
-
'6': ["000", "111", "100", "111", "101", "111", "000"],
|
40
|
-
'7': ["000", "111", "001", "010", "100", "100", "000"],
|
41
|
-
'8': ["000", "111", "101", "111", "101", "111", "000"],
|
42
|
-
'9': ["000", "111", "101", "111", "001", "111", "000"],
|
43
|
-
' ': ["0", "0", "0", "0", "0", "0", "0"] }
|
1
|
+
class SlackSmartBot
|
44
2
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
3
|
+
def poster(permanent, emoticon_text, emoticon_bg, string, minutes)
|
4
|
+
chars = { a: ["0000", "1111", "1001", "1111", "1001", "1001", "0000"],
|
5
|
+
b: ["0000", "1111", "1001", "1110", "1001", "1111", "0000"],
|
6
|
+
c: ["0000", "0111", "1000", "1000", "1000", "0111", "0000"],
|
7
|
+
d: ["0000", "1110", "1001", "1001", "1001", "1110", "0000"],
|
8
|
+
e: ["0000", "1111", "1000", "1110", "1000", "1111", "0000"],
|
9
|
+
f: ["0000", "1111", "1000", "1110", "1000", "1000", "0000"],
|
10
|
+
g: ["0000", "1111", "1000", "1011", "1001", "1111", "0000"],
|
11
|
+
h: ["0000", "1001", "1001", "1111", "1001", "1001", "0000"],
|
12
|
+
i: ["000", "111", "010", "010", "010", "111", "000"],
|
13
|
+
j: ["0000", "0111", "0010", "0010", "1010", "0110", "0000"],
|
14
|
+
k: ["0000", "1001", "1010", "1100", "1010", "1001", "0000"],
|
15
|
+
l: ["000", "100", "100", "100", "100", "111", "000"],
|
16
|
+
m: ["00000", "10001", "11011", "10101", "10001", "10001", "00000"],
|
17
|
+
n: ["00000", "10001", "11001", "10101", "10011", "10001", "00000"],
|
18
|
+
o: ["0000", "0110", "1001", "1001", "1001", "0110", "0000"],
|
19
|
+
p: ["0000", "1110", "1001", "1110", "1000", "1000", "0000"],
|
20
|
+
q: ["00000", "01100", "10010", "10010", "10010", "01111", "00000"],
|
21
|
+
r: ["0000", "1110", "1001", "1110", "1010", "1001", "0000"],
|
22
|
+
s: ["0000", "0111", "1000", "0110", "0001", "1110", "0000"],
|
23
|
+
t: ["00000", "11111", "00100", "00100", "00100", "00100", "00000"],
|
24
|
+
u: ["00000", "10001", "10001", "10001", "10001", "01110", "00000"],
|
25
|
+
v: ["00000", "10001", "10001", "10001", "01010", "00100", "00000"],
|
26
|
+
w: ["0000000", "1000001", "1000001", "1001001", "1010101", "0100010", "0000000"],
|
27
|
+
x: ["00000", "10001", "01010", "00100", "01010", "10001", "00000"],
|
28
|
+
y: ["00000", "10001", "01010", "00100", "00100", "00100", "00000"],
|
29
|
+
z: ["00000", "11111", "00010", "00100", "01000", "11111", "00000"],
|
30
|
+
'!': ["0", "1", "1", "1", "0", "1", "0"],
|
31
|
+
'+': ["000", "000", "010", "111", "010", "000", "000"],
|
32
|
+
'-': ["000", "000", "000", "111", "000", "000", "000"],
|
33
|
+
'=': ["000", "000", "111", "000", "111", "000", "000"],
|
34
|
+
'?': ["000", "111", "001", "010", "000", "010", "000"],
|
35
|
+
'0': ["000", "111", "101", "101", "101", "111", "000"],
|
36
|
+
'1': ["00", "01", "11", "01", "01", "01", "00"],
|
37
|
+
'2': ["000", "111", "001", "010", "100", "111", "000"],
|
38
|
+
'3': ["000", "111", "001", "111", "001", "111", "000"],
|
39
|
+
'4': ["000", "101", "101", "111", "001", "001", "000"],
|
40
|
+
'5': ["000", "111", "100", "111", "001", "111", "000"],
|
41
|
+
'6': ["000", "111", "100", "111", "101", "111", "000"],
|
42
|
+
'7': ["000", "111", "001", "010", "100", "100", "000"],
|
43
|
+
'8': ["000", "111", "101", "111", "101", "111", "000"],
|
44
|
+
'9': ["000", "111", "101", "111", "001", "111", "000"],
|
45
|
+
' ': ["0", "0", "0", "0", "0", "0", "0"] }
|
49
46
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
if t.size
|
59
|
-
t
|
60
|
-
lines << tt.strip
|
61
|
-
end
|
62
|
-
lines[-1] += " " if lines[-1].size < 6
|
63
|
-
else
|
64
|
-
lines << t.strip + " "
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
lines[-1].strip!
|
69
|
-
messages = []
|
70
|
-
lines.each do |line|
|
71
|
-
results = []
|
72
|
-
all_spaces = true
|
73
|
-
line.each_char do |char|
|
74
|
-
if chars.key?(char.to_sym)
|
75
|
-
results << chars[char.to_sym]
|
76
|
-
all_spaces = false
|
47
|
+
emoticon_bg = ":white_square:" if emoticon_bg.to_s == ""
|
48
|
+
emoticon_text = ":black_square:" if emoticon_text.to_s == ""
|
49
|
+
string.downcase!
|
50
|
+
messages = []
|
51
|
+
|
52
|
+
string = string.strip.split(" ").join(" ")
|
53
|
+
lines = [""]
|
54
|
+
string.split(" ").each do |t|
|
55
|
+
if ("#{lines[-1]}#{t}").size <= 6
|
56
|
+
lines[-1] = "#{lines[-1]}#{t} "
|
77
57
|
else
|
78
|
-
|
58
|
+
lines[-1].strip!
|
59
|
+
lines.pop if lines[-1] == ""
|
60
|
+
if t.size > 6
|
61
|
+
t.chars.each_slice(6).map(&:join).each do |tt|
|
62
|
+
lines << tt.strip
|
63
|
+
end
|
64
|
+
lines[-1] += " " if lines[-1].size < 6
|
65
|
+
else
|
66
|
+
lines << t.strip + " "
|
67
|
+
end
|
79
68
|
end
|
80
69
|
end
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
70
|
+
lines[-1].strip!
|
71
|
+
messages = []
|
72
|
+
lines.each do |line|
|
73
|
+
results = []
|
74
|
+
all_spaces = true
|
75
|
+
line.each_char do |char|
|
76
|
+
if chars.key?(char.to_sym)
|
77
|
+
results << chars[char.to_sym]
|
78
|
+
all_spaces = false
|
79
|
+
else
|
80
|
+
results << chars[:' ']
|
86
81
|
end
|
87
|
-
rtxt += "\n"
|
88
82
|
end
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
83
|
+
unless all_spaces
|
84
|
+
rtxt = ""
|
85
|
+
7.times do |n|
|
86
|
+
results.size.times do |i|
|
87
|
+
rtxt += "0#{results[i][n]}0"
|
88
|
+
end
|
89
|
+
rtxt += "\n"
|
90
|
+
end
|
91
|
+
rtxt.gsub!("1", emoticon_text)
|
92
|
+
rtxt.gsub!("0", emoticon_bg)
|
93
|
+
txt = ""
|
94
|
+
msgs = []
|
95
|
+
rtxt.split("\n").each do |m|
|
96
|
+
if (m + txt).size > 4000
|
97
|
+
msgs << txt unless txt == ""
|
98
|
+
txt = ""
|
99
|
+
end
|
100
|
+
txt += (m + "\n")
|
101
|
+
end
|
102
|
+
msgs << txt
|
103
|
+
msgs.flatten!
|
104
|
+
msgs.each do |msg|
|
105
|
+
messages << respond(msg, return_message: true)
|
97
106
|
end
|
98
|
-
txt += (m + "\n")
|
99
|
-
end
|
100
|
-
msgs << txt
|
101
|
-
msgs.flatten!
|
102
|
-
msgs.each do |msg|
|
103
|
-
messages << respond(msg, return_message: true)
|
104
107
|
end
|
105
108
|
end
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
109
|
+
unless permanent
|
110
|
+
react :heavy_check_mark
|
111
|
+
sleep (minutes.to_i * 60)
|
112
|
+
messages.delete(nil)
|
113
|
+
messages.each do |message|
|
114
|
+
delete(message.channel, message.ts)
|
115
|
+
end
|
116
|
+
react :heavy_minus_sign
|
113
117
|
end
|
114
|
-
react :heavy_minus_sign
|
115
118
|
end
|
116
|
-
end
|
119
|
+
end
|