summaryrefslogtreecommitdiff
path: root/rbot/ircsocket.rb
diff options
context:
space:
mode:
authorTom Gilbert <tom@linuxbrit.co.uk>2005-07-26 21:50:00 +0000
committerTom Gilbert <tom@linuxbrit.co.uk>2005-07-26 21:50:00 +0000
commit5d5d9df1a4825fad5ef045cfc0b21b16e5e2bcc7 (patch)
treef3814abafc8f1d6c589a29f4ddc89f55e510d493 /rbot/ircsocket.rb
parent3ba6917c904f5e664ae78b146f4e394ad805eb96 (diff)
* Prevent multiple plugin registrations of the same name
* reworking the config system to use yaml for persistence * reworking the config system key names * on first startup, the bot will prompt for the essential startup config * new config module for configuring the bot at runtime * new config module includes new configurables, for example changing the bot's language at runtime. * various other fixes * New way of mapping plugins to strings, using maps. These may be familiar to rails users. This is to reduce the amount of regexps plugins currently need to do to parse arguments. The old method (privmsg) is still supported, of course. Example plugin now: def MyPlugin < Plugin def foo(m, params) m.reply "bar" end def complexfoo(m, params) m.reply "qux! (#{params[:bar]} #{params[:baz]})" end end plugin = MyPlugin.new # simple map plugin.map 'foo' # this will match "rbot: foo somestring otherstring" and pass the # parameters as a hash using the names in the map. plugin.map 'foo :bar :baz', :action => 'complexfoo' # this means :foo is an optional parameter plugin.map 'foo :foo', :defaults => {:foo => 'bar'} # you can also gobble up into an array plugin.map 'foo *bar' # params[:bar] will be an array of string elements # and you can validate, here the first param must be a number plugin.map 'foo :bar', :requirements => {:foo => /^\d+$/}
Diffstat (limited to 'rbot/ircsocket.rb')
-rw-r--r--rbot/ircsocket.rb56
1 files changed, 28 insertions, 28 deletions
diff --git a/rbot/ircsocket.rb b/rbot/ircsocket.rb
index 25895644..35857736 100644
--- a/rbot/ircsocket.rb
+++ b/rbot/ircsocket.rb
@@ -8,29 +8,37 @@ module Irc
class IrcSocket
# total number of lines sent to the irc server
attr_reader :lines_sent
+
# total number of lines received from the irc server
attr_reader :lines_received
+
+ # delay between lines sent
+ attr_reader :sendq_delay
+
+ # max lines to burst
+ attr_reader :sendq_burst
+
# server:: server to connect to
# port:: IRCd port
# host:: optional local host to bind to (ruby 1.7+ required)
# create a new IrcSocket
- def initialize(server, port, host, sendfreq=2, maxburst=4)
+ def initialize(server, port, host, sendq_delay=2, sendq_burst=4)
@server = server.dup
@port = port.to_i
@host = host
@lines_sent = 0
@lines_received = 0
- if sendfreq
- @sendfreq = sendfreq.to_f
+ if sendq_delay
+ @sendq_delay = sendq_delay.to_f
else
- @sendfreq = 2
+ @sendq_delay = 2
end
- @last_send = Time.new - @sendfreq
+ @last_send = Time.new - @sendq_delay
@burst = 0
- if maxburst
- @maxburst = maxburst.to_i
+ if sendq_burst
+ @sendq_burst = sendq_burst.to_i
else
- @maxburst = 4
+ @sendq_burst = 4
end
end
@@ -52,15 +60,15 @@ module Irc
@qthread = false
@qmutex = Mutex.new
@sendq = Array.new
- if (@sendfreq > 0)
+ if (@sendq_delay > 0)
@qthread = Thread.new { spooler }
end
end
- def set_sendq(newfreq)
+ def sendq_delay=(newfreq)
debug "changing sendq frequency to #{newfreq}"
@qmutex.synchronize do
- @sendfreq = newfreq
+ @sendq_delay = newfreq
if newfreq == 0 && @qthread
clearq
Thread.kill(@qthread)
@@ -71,20 +79,12 @@ module Irc
end
end
- def set_maxburst(newburst)
+ def sendq_burst=(newburst)
@qmutex.synchronize do
- @maxburst = newburst
+ @sendq_burst = newburst
end
end
- def get_maxburst
- return @maxburst
- end
-
- def get_sendq
- return @sendfreq
- end
-
# used to send lines to the remote IRCd
# message: IRC message to send
def puts(message)
@@ -106,7 +106,7 @@ module Irc
end
def queue(msg)
- if @sendfreq > 0
+ if @sendq_delay > 0
@qmutex.synchronize do
# debug "QUEUEING: #{msg}"
@sendq.push msg
@@ -120,7 +120,7 @@ module Irc
def spooler
while true
spool
- sleep 0.1
+ sleep 0.2
end
end
@@ -128,17 +128,17 @@ module Irc
def spool
unless @sendq.empty?
now = Time.new
- if (now >= (@last_send + @sendfreq))
- # reset burst counter after @sendfreq has passed
+ if (now >= (@last_send + @sendq_delay))
+ # reset burst counter after @sendq_delay has passed
@burst = 0
debug "in spool, resetting @burst"
- elsif (@burst >= @maxburst)
+ elsif (@burst >= @sendq_burst)
# nope. can't send anything
return
end
@qmutex.synchronize do
- debug "(can send #{@maxburst - @burst} lines, there are #{@sendq.length} to send)"
- (@maxburst - @burst).times do
+ debug "(can send #{@sendq_burst - @burst} lines, there are #{@sendq.length} to send)"
+ (@sendq_burst - @burst).times do
break if @sendq.empty?
puts_critical(@sendq.shift)
end