Class: TermtterIrcGateway

Inherits:
Net::IRC::Server::Session
  • Object
show all
Defined in:
lib/plugins/irc_gw.rb

Constant Summary collapse

@@listners =
[]
@@last_statuses =
[]

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ TermtterIrcGateway

Returns a new instance of TermtterIrcGateway.



33
34
35
36
# File 'lib/plugins/irc_gw.rb', line 33

def initialize(*args)
  super
  @@listners << self
end

Instance Method Details

#call(statuses, event) ⇒ Object



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

def call(statuses, event)
  msg_type =
    case event
    when :update_friends_timeline
      PRIVMSG
    else
      NOTICE
    end

  statuses.each do |s|
    post s.user.screen_name, msg_type, main_channel, [s.text, s.id].join(' ')
  end
end

#main_channelObject



31
# File 'lib/plugins/irc_gw.rb', line 31

def main_channel; '#termtter' end

#on_message(m) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/plugins/irc_gw.rb', line 52

def on_message(m)
  termtter_command = m.command.downcase + ' ' + m.params.join(' ')
  unless Termtter::Client.find_commands(termtter_command).empty?
    post '#termtter', NOTICE, main_channel, '> ' + termtter_command
    Termtter::Client.call_commands(termtter_command)
  end
end

#on_privmsg(m) ⇒ Object



67
68
69
70
# File 'lib/plugins/irc_gw.rb', line 67

def on_privmsg(m)
  target, message = *m.params
  Termtter::Client.call_commands('update ' + message)
end

#on_user(m) ⇒ Object



60
61
62
63
64
65
# File 'lib/plugins/irc_gw.rb', line 60

def on_user(m)
  super
  post @prefix, JOIN, main_channel
  post server_name, MODE, main_channel, "+o", @prefix.nick
  self.call(@@last_statuses || [], :update_friends_timeline)
end

#server_nameObject



29
# File 'lib/plugins/irc_gw.rb', line 29

def server_name; 'termtter' end

#server_versionObject



30
# File 'lib/plugins/irc_gw.rb', line 30

def server_version; '0.0.0' end