Class: S3PO::Generator
- Inherits:
-
Object
- Object
- S3PO::Generator
- Defined in:
- lib/s-3po/generator.rb
Class Method Summary collapse
Class Method Details
.generate_message(message, id = nil) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/s-3po/generator.rb', line 8 def self.(, id = nil) @id ||= 0 obj = .object msg = {type: 'message', channel: obj[:channel], text: obj[:text]} msg[:id] = id ? id : @id @id += 1 unless id return JSON.fast_generate(msg) end |
.text_from_plain(plain) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/s-3po/generator.rb', line 17 def self.text_from_plain(plain) text = String.new(plain) # escape text.gsub!('&', '&') text.gsub!('<', '<') text.gsub!('>', '>') # add brackets to mentions text.gsub!(/(@[a-z0-9][a-z0-9.\-_]*)/, '<\1>') text.gsub!(/(@U[A-Z0-9]+)/, '<\1>') # add brackets to channels text.gsub!(/(#[a-z0-9\-_]+)/, '<\1>') text.gsub!(/(#C[A-Z0-9]+)/, '<\1>') # convert commands text.gsub!(/<@(everyone|channel|group)>/, '<!\1>') return text end |