Sha256: b2be6972c2adf325d3679265bccb6395627ed9d1b226b5a42f8a34a9ee7a94b9
Contents?: true
Size: 1.34 KB
Versions: 1
Compression:
Stored size: 1.34 KB
Contents
require "time" require "slack" require "slackgetter/version" require "slackgetter/cli" module Slackgetter def self.configure_token(token) Slack.configure do |config| config.token = token end end def self.messages(channel_name, oldest, latest) channel_id = channel_id(channel_name) oldest = Time.parse(oldest) latest = Time.parse(latest) messages = Slack.channels_history(channel: channel_id, oldest: oldest.to_f, latest: latest.to_f) text = text(messages) puts text end def self.url_to_time(url) Time.at url.gsub(/.+\/p(.+)\z/){$1}.insert(10, ".").to_f end 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 def self.text(messages) if messages["ok"] == true text = messages["messages"].map{|message| message["text"]} convert(text) end end def self.convert(text) text.reverse.join("\n\n").gsub(/\</, '<').gsub(/\>/, '>') .gsub(/<(http[^>]*)>/){ $1 } .gsub(/\*([^*]*)\*/){ "*#{$&}*" } .gsub(/\~([^~]*)\~/){ "~#{$&}~" } # 離れている ~ 同士で ~~ になってしまう end def self.convert_link_of(text) # text.gsub(/<(http[^>]*)>/, '\1') text.gsub(/<(http[^>]*)>/){ $1 } end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
slackgetter-0.1.1 | lib/slackgetter.rb |