Class: Atig::Command::Version
Instance Attribute Summary
Attributes inherited from Command
#api, #db, #gateway, #opts
Instance Method Summary
collapse
Methods inherited from Command
#find_by_tid, #initialize
Instance Method Details
#action(target, mesg, command, args) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/atig/command/version.rb', line 11
def action(target, mesg, command,args)
if args.empty?
yield "/me #{command} <ID>"
return
end
nick,*_ = args
entries = db.statuses.find_by_screen_name(nick, :limit => 1)
if entries && !entries.empty? then
entry = TwitterStruct.make('user' => entries.first.user,
'status' => { 'text' =>
format(entries.first.status.source) })
gateway[target].message entry, Net::IRC::Constants::NOTICE
else
api.delay(0) do|t|
begin
user = t.get("users/show", { :screen_name => nick})
db.statuses.transaction do|d|
d.add :user => user, :status => user.status, :source => :version
entry = TwitterStruct.make('user' => user,
'status' => { 'text' =>
format(user.status.source) })
gateway[target].message entry, Net::IRC::Constants::NOTICE
end
rescue Twitter::APIFailed => e
yield e.to_s
end
end
end
end
|
#command_name ⇒ Object
9
|
# File 'lib/atig/command/version.rb', line 9
def command_name; %w(version) end
|
42
43
44
45
46
|
# File 'lib/atig/command/version.rb', line 42
def format(source)
version = source.gsub(/<[^>]*>/, "").strip
version << " <#{$1}>" if source =~ / href="([^"]+)/
Net::IRC.ctcp_encode version
end
|