net-yail 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/IRCBot.rb +132 -0
- data/README +66 -0
- data/lib/net/yail.rb +525 -0
- data/lib/net/yail/default_events.rb +192 -0
- data/lib/net/yail/eventmap.yml +248 -0
- data/lib/net/yail/magic_events.rb +55 -0
- data/lib/net/yail/output_api.rb +134 -0
- metadata +54 -0
@@ -0,0 +1,134 @@
|
|
1
|
+
module Net
|
2
|
+
|
3
|
+
# All output APIs live here. In most cases, an outgoing handler will get a
|
4
|
+
# call, but will not be able to stop the socket output since that's sorta
|
5
|
+
# an essential part of this whole library.
|
6
|
+
module IRCOutputAPI
|
7
|
+
# Spits a raw string out to the server - in case a subclass wants to do
|
8
|
+
# something special on *all* output, please make all output go through this
|
9
|
+
# method. Don't use puts manually. I will kill violaters. Legally
|
10
|
+
# speaking, that is.
|
11
|
+
def raw(line, report = true)
|
12
|
+
@socket.puts line
|
13
|
+
report "bot: '#{line}'" if report
|
14
|
+
end
|
15
|
+
|
16
|
+
# Calls :outgoing_privmsg handler, then sends a message (text) out to the
|
17
|
+
# given channel/user (target), and reports itself with the given string.
|
18
|
+
# This method shouldn't be called directly most of the time - just use msg,
|
19
|
+
# act, or ctcp.
|
20
|
+
#
|
21
|
+
# This is sort of the central message output - everything that's based on
|
22
|
+
# PRIVMSG (messages, actions, other ctcp) uses this. Because these messages
|
23
|
+
# aren't insanely important, we actually buffer them instead of sending
|
24
|
+
# straight out to the channel. The output thread has to deal with
|
25
|
+
# sending these out.
|
26
|
+
def privmsg(target, text, report_string)
|
27
|
+
handle(:outgoing_privmsg, target, text)
|
28
|
+
|
29
|
+
@privmsg_buffer_mutex.synchronize do
|
30
|
+
@privmsg_buffer[target] ||= Array.new
|
31
|
+
@privmsg_buffer[target].push([text, report_string])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Calls :outgoing_msg handler, then privmsg to send the message out. Could
|
36
|
+
# be used to send any privmsg, but you're betting off using act and ctcp
|
37
|
+
# shortcut methods for those types. Target is a channel or username, text
|
38
|
+
# is the message.
|
39
|
+
def msg(target, text)
|
40
|
+
handle(:outgoing_msg, target, text)
|
41
|
+
|
42
|
+
report_string = @silent ? '' : "{#{target}} <#{@me}> #{text}"
|
43
|
+
privmsg(target, text, report_string)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Calls :outgoing_ctcp handler, then sends CTCP to target channel or user
|
47
|
+
def ctcp(target, text)
|
48
|
+
handle(:outgoing_ctcp, target, text)
|
49
|
+
|
50
|
+
report_string = @silent ? '' : "{#{target}} [#{@me} #{text}]"
|
51
|
+
privmsg(target, "\001#{text}\001", report_string)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Calls :outgoing_act handler, then ctcp to send a CTCP ACTION (text) to
|
55
|
+
# a given user or channel (target)
|
56
|
+
def act(target, text)
|
57
|
+
handle(:outgoing_act, target, text)
|
58
|
+
|
59
|
+
ctcp(target, "ACTION #{text}")
|
60
|
+
end
|
61
|
+
|
62
|
+
# Calls :outgoing_notice handler, then outputs raw NOTICE message
|
63
|
+
def notice(target, text)
|
64
|
+
handle(:outgoing_notice, target, text)
|
65
|
+
|
66
|
+
report "{#{target}} -#{@me}- #{text}" unless @silent
|
67
|
+
raw("NOTICE #{target} :#{text}", false)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Calls :outgoing_ctcpreply handler, then uses notice method to send the
|
71
|
+
# CTCP text
|
72
|
+
def ctcpreply(target, text)
|
73
|
+
handle(:outgoing_ctcpreply, target, text)
|
74
|
+
|
75
|
+
report "{#{target}} [Reply: #{@me} #{text}]" unless @silent
|
76
|
+
notice(target, "\001#{text}\001")
|
77
|
+
end
|
78
|
+
|
79
|
+
# Calls :outgoing_mode handler, then mode to set mode(s) on a channel
|
80
|
+
# and possibly specific users (objects). If modes and objects are blank,
|
81
|
+
# just sends a raw MODE query.
|
82
|
+
def mode(target, modes = '', objects = '')
|
83
|
+
handle(:outgoing_mode, target, modes, objects)
|
84
|
+
|
85
|
+
message = "MODE #{target}"
|
86
|
+
message += " #{modes}" unless modes.to_s.empty?
|
87
|
+
message += " #{objects}" unless objects.to_s.empty?
|
88
|
+
raw message
|
89
|
+
end
|
90
|
+
|
91
|
+
# Calls :outgoing_join handler and then raw JOIN message for a given channel
|
92
|
+
def join(target)
|
93
|
+
handle(:outgoing_join, target)
|
94
|
+
|
95
|
+
raw "JOIN #{target}"
|
96
|
+
end
|
97
|
+
|
98
|
+
# Calls :outgoing_part handler and then raw PART for leaving a given channel
|
99
|
+
# (with an optional message)
|
100
|
+
def part(target, text = '')
|
101
|
+
handle(:outgoing_part, target, text)
|
102
|
+
|
103
|
+
request = "PART #{target}";
|
104
|
+
request += " :#{text}" unless text.to_s.empty?
|
105
|
+
raw request
|
106
|
+
end
|
107
|
+
|
108
|
+
# Calls :outgoing_quit handler and then raw QUIT message with an optional
|
109
|
+
# reason
|
110
|
+
def quit(text = '')
|
111
|
+
handle(:outgoing_quit, text)
|
112
|
+
|
113
|
+
request = "QUIT";
|
114
|
+
request += " :#{text}" unless text.to_s.empty?
|
115
|
+
raw request
|
116
|
+
end
|
117
|
+
|
118
|
+
# Calls :outgoing_nick handler and then sends raw NICK message to change
|
119
|
+
# nickname.
|
120
|
+
def nick(new_nick)
|
121
|
+
handle(:outgoing_nick, new_nick)
|
122
|
+
|
123
|
+
raw "NICK :#{new_nick}"
|
124
|
+
end
|
125
|
+
|
126
|
+
def user(username, myaddress, address, realname)
|
127
|
+
handle(:outgoing_user, username, myaddress, address, realname)
|
128
|
+
|
129
|
+
raw "USER #{username} #{myaddress} #{address} :#{realname}"
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.4
|
3
|
+
specification_version: 1
|
4
|
+
name: net-yail
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 1.0.0
|
7
|
+
date: 2008-06-28 00:00:00 -04:00
|
8
|
+
summary: "Yet Another IRC Library: wrapper for IRC communications in Ruby."
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: yail<at>nerdbucket dot com
|
12
|
+
homepage:
|
13
|
+
rubyforge_project:
|
14
|
+
description:
|
15
|
+
autorequire: net/yail
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Jeremy Echols
|
31
|
+
files:
|
32
|
+
- IRCBot.rb
|
33
|
+
- lib/net/yail.rb
|
34
|
+
- lib/net/yail/magic_events.rb
|
35
|
+
- lib/net/yail/default_events.rb
|
36
|
+
- lib/net/yail/output_api.rb
|
37
|
+
- lib/net/yail/eventmap.yml
|
38
|
+
- README
|
39
|
+
test_files: []
|
40
|
+
|
41
|
+
rdoc_options:
|
42
|
+
- --main
|
43
|
+
- README
|
44
|
+
extra_rdoc_files:
|
45
|
+
- README
|
46
|
+
- IRCBot.rb
|
47
|
+
executables: []
|
48
|
+
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
requirements: []
|
52
|
+
|
53
|
+
dependencies: []
|
54
|
+
|