Module: SearchOnSlack

Included in:
BaezSlack, ConsoleSlack, MessageSlack
Defined in:
lib/modules/search_slack.rb

Overview

Module for searching content on Slack

Instance Method Summary collapse

Instance Method Details

#conversation_info(channel = @channel_id) ⇒ Object

[View source]

53
54
55
56
57
58
59
# File 'lib/modules/search_slack.rb', line 53

def conversation_info(channel = @channel_id)
  info = @web_client.conversations_info channel: channel
  @properties = info.channel
rescue Slack::Web::Api::Errors::SlackError => e
  print e.message
  false
end

#conversation_listObject

[View source]

61
62
63
64
65
66
# File 'lib/modules/search_slack.rb', line 61

def conversation_list
  @web_client.conversations_list.channels
rescue Slack::Web::Api::Errors::SlackError => e
  print e.message
  false
end

#conversation_type(channel = @channel_id) ⇒ Object

[View source]

38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/modules/search_slack.rb', line 38

def conversation_type(channel = @channel_id)
  @channel_id = channel if @channel_id.nil?
  result = conversation_info
  if result == false
    print 'Check if IM'
    @channel_id = get_user_id
    conversation_info == false ? false : verify_type
  else
    verify_type
  end
rescue Slack::Web::Api::Errors::SlackError => e
  print e.message
  false
end

#get_user_id(channel = @channel_id) ⇒ Object

[View source]

4
5
6
7
8
9
10
# File 'lib/modules/search_slack.rb', line 4

def get_user_id(channel = @channel_id)
  dm = @web_client.conversations_open users: channel
  dm.channel.id
rescue Slack::Web::Api::Errors::SlackError => e
  print e.message
  false
end

#get_user_info(user) ⇒ Object

[View source]

12
13
14
15
16
17
18
# File 'lib/modules/search_slack.rb', line 12

def (user)
  c = @web_client.users_info user: user
  c.user
rescue Slack::Web::Api::Errors::SlackError => e
  print e.message
  false
end

#get_user_listObject

[View source]

20
21
22
23
24
25
# File 'lib/modules/search_slack.rb', line 20

def get_user_list
  @web_client.users_list
rescue Slack::Web::Api::Errors::SlackError => e
  print e.message
  false
end

#search_messages_on(channel, quantity = 5) ⇒ Object

[View source]

69
70
71
72
73
74
75
# File 'lib/modules/search_slack.rb', line 69

def search_messages_on(channel, quantity = 5)
# type = conversation_type(channel)
@web_client.conversations_history channel: channel, count: quantity
  rescue Slack::Web::Api::Errors::SlackError => e
print e.message
"Channel not found #{channel}"
end

#verify_typeObject

[View source]

27
28
29
30
31
32
33
34
35
36
# File 'lib/modules/search_slack.rb', line 27

def verify_type
  properties = {
    'channel' => @properties.is_channel,
    'group' => @properties.is_group,
    'im' => @properties.is_im
  }
  check = ''
  properties.each { |k, v| check = k if v == true }
  check
end