Module: Slackgetter
- Defined in:
- lib/slackgetter.rb,
lib/slackgetter/cli.rb,
lib/slackgetter/version.rb
Defined Under Namespace
Classes: CLI
Constant Summary collapse
- VERSION =
"0.1.1"
Class Method Summary collapse
- .channel_id(channel_name) ⇒ Object
- .configure_token(token) ⇒ Object
- .convert(text) ⇒ Object
- .convert_link_of(text) ⇒ Object
- .messages(channel_name, oldest, latest) ⇒ Object
- .text(messages) ⇒ Object
- .url_to_time(url) ⇒ Object
Class Method Details
.channel_id(channel_name) ⇒ Object
28 29 30 31 32 |
# File 'lib/slackgetter.rb', line 28 def self.channel_id(channel_name) channels = Slack.channels_list["channels"] channel = channels.select{|channel| channel["name"] == channel_name} channel_id = channel.first["id"] end |
.configure_token(token) ⇒ Object
8 9 10 11 12 |
# File 'lib/slackgetter.rb', line 8 def self.configure_token(token) Slack.configure do |config| config.token = token end end |
.convert(text) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/slackgetter.rb', line 41 def self.convert(text) text.reverse.join("\n\n").gsub(/\</, '<').gsub(/\>/, '>') .gsub(/<(http[^>]*)>/){ $1 } .gsub(/\*([^*]*)\*/){ "*#{$&}*" } .gsub(/\~([^~]*)\~/){ "~#{$&}~" } # 離れている ~ 同士で ~~ になってしまう end |
.convert_link_of(text) ⇒ Object
49 50 51 52 |
# File 'lib/slackgetter.rb', line 49 def self.convert_link_of(text) # text.gsub(/<(http[^>]*)>/, '\1') text.gsub(/<(http[^>]*)>/){ $1 } end |
.messages(channel_name, oldest, latest) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/slackgetter.rb', line 14 def self.(channel_name, oldest, latest) channel_id = channel_id(channel_name) oldest = Time.parse(oldest) latest = Time.parse(latest) = Slack.channels_history(channel: channel_id, oldest: oldest.to_f, latest: latest.to_f) text = text() puts text end |
.text(messages) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/slackgetter.rb', line 34 def self.text() if ["ok"] == true text = ["messages"].map{|| ["text"]} convert(text) end end |
.url_to_time(url) ⇒ Object
24 25 26 |
# File 'lib/slackgetter.rb', line 24 def self.url_to_time(url) Time.at url.gsub(/.+\/p(.+)\z/){$1}.insert(10, ".").to_f end |