Class: Unibanner::Bot
- Inherits:
-
Object
- Object
- Unibanner::Bot
- Defined in:
- lib/unibanner/bot_class.rb
Instance Attribute Summary collapse
-
#geckos ⇒ Object
readonly
Returns the value of attribute geckos.
-
#irc ⇒ Object
Returns the value of attribute irc.
-
#local_host ⇒ Object
readonly
Returns the value of attribute local_host.
-
#log ⇒ Object
readonly
Returns the value of attribute log.
-
#network ⇒ Object
readonly
Returns the value of attribute network.
-
#nick ⇒ Object
readonly
Returns the value of attribute nick.
-
#oper_name ⇒ Object
readonly
Returns the value of attribute oper_name.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#sock ⇒ Object
Returns the value of attribute sock.
-
#ssl ⇒ Object
readonly
Returns the value of attribute ssl.
Instance Method Summary collapse
-
#initialize(network, hsh) ⇒ Bot
constructor
Create a new bot.
-
#quit(msg) ⇒ Object
Allow Bot.quit(msg) to actually cause the irc connection to /quit.
-
#start ⇒ nil
Start the IRC connection.
Constructor Details
#initialize(network, hsh) ⇒ Bot
Create a new bot
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/unibanner/bot_class.rb', line 89 def initialize(network, hsh) @network = network @server = hsh["server"] # network::server: irc.server.tld @ssl = hsh["ssl"] # network::ssl: true/false @port = hsh["port"] # network::port: 0000 @local_host = hsh["local_host"] # network::local_host: 0.0.0.0 @nick = hsh["nick"] # network::nick: nickname @geckos = hsh["geckos"] # network::geckos: Real Name @prefix = hsh["prefix"] # network::prefix: ! @oper_name = hsh["oper_name"] # network::oper_name: opername @oper_pass = hsh["oper_pass"] # network::oper_pass: PASSWORD @channels = hsh["channels"] # network::channels: [channel1,channel2] @perform = hsh["perform"] # network::perform: ['COMMAND arg1 arg2', 'COMMAND2 arg1 arg2'] Unibanner::Logger.new(self) @log = Unibanner::Logger[self] @log_level = hsh["log_level"] @log.level = @log_level @irc = ::IRCSocket.new(@server, @port, @ssl, @local_host) end |
Instance Attribute Details
#geckos ⇒ Object (readonly)
Returns the value of attribute geckos.
83 84 85 |
# File 'lib/unibanner/bot_class.rb', line 83 def geckos @geckos end |
#irc ⇒ Object
Returns the value of attribute irc.
82 83 84 |
# File 'lib/unibanner/bot_class.rb', line 82 def irc @irc end |
#local_host ⇒ Object (readonly)
Returns the value of attribute local_host.
83 84 85 |
# File 'lib/unibanner/bot_class.rb', line 83 def local_host @local_host end |
#log ⇒ Object (readonly)
Returns the value of attribute log.
84 85 86 |
# File 'lib/unibanner/bot_class.rb', line 84 def log @log end |
#network ⇒ Object (readonly)
Returns the value of attribute network.
83 84 85 |
# File 'lib/unibanner/bot_class.rb', line 83 def network @network end |
#nick ⇒ Object (readonly)
Returns the value of attribute nick.
83 84 85 |
# File 'lib/unibanner/bot_class.rb', line 83 def nick @nick end |
#oper_name ⇒ Object (readonly)
Returns the value of attribute oper_name.
83 84 85 |
# File 'lib/unibanner/bot_class.rb', line 83 def oper_name @oper_name end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
83 84 85 |
# File 'lib/unibanner/bot_class.rb', line 83 def port @port end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
83 84 85 |
# File 'lib/unibanner/bot_class.rb', line 83 def prefix @prefix end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
83 84 85 |
# File 'lib/unibanner/bot_class.rb', line 83 def server @server end |
#sock ⇒ Object
Returns the value of attribute sock.
82 83 84 |
# File 'lib/unibanner/bot_class.rb', line 82 def sock @sock end |
#ssl ⇒ Object (readonly)
Returns the value of attribute ssl.
83 84 85 |
# File 'lib/unibanner/bot_class.rb', line 83 def ssl @ssl end |
Instance Method Details
#quit(msg) ⇒ Object
Allow Bot.quit(msg) to actually cause the irc connection to /quit
112 113 114 |
# File 'lib/unibanner/bot_class.rb', line 112 def quit(msg) @irc.quit(msg) end |
#start ⇒ nil
Start the IRC connection
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/unibanner/bot_class.rb', line 118 def start @irc.connect if @irc.connected? @irc.nick "#{@nick}" @irc.user "#{@nick}", 0, "*", "#{@geckos}" while line = irc.read @log.incoming line # Join Channels after MOTD if line.include? 'ING' @irc.pong('0') end if line.split[1] == "376" Thread.new { @irc.oper @oper_name, @oper_pass @channels.each do |channel| @irc.join channel end @perform.each do |line| @irc.write line end } end # 0 1 2 ------------------3------------------- # :kojo.electrocode.net 340 unibanner :[email protected] if line.split[1] == "340" user_ip = line.split[3].gsub(/.*@(.*)/, '\1') @log.info "Got #{user_ip} back from /USERIP. Submitting to blacklist." reply = Unibanner::Functions.send2BL(user_ip) @log.info "Unibanner::Functions.send2BL(#{user_ip}) returned '#{reply}'" @irc.zline("BLACKLISTED[5,6]: fngate spam / unicode spam", "#{user_ip} 7d") end if line.split[1] == "433" @log.error "#{self.network}: 433, Nickname in use, can't connect" ::Unibanner::Bots.die("Nickname in use, Can't connect") end # unicode characters used by the spammers # spam_pattern = /(\uFE13|\u04BB|\u0501|\u0D20|\u222A|\u217E|\u1EFF){1,}/ spam_pattern = Regexp.new('(\ufe68|\u205f|\u0422|\u2009|\u04bb|\u1952|\u217c|\u2004|\u217f|\u1d20|\u03bf|\u0456|\u217d|\u2c9f|\u2024|\u0435|\uff03|\uff0f|\u03f3|\ufe57|\u2216|\u2170|\u1959|\u13df|\u0251|\u222a|\u0441|\u0430|\u2001|\u200a|\u217e|\u0443|\u2005|\u2002|\u0455|\u2000|\u2215|\u2044|\u03f2|\u043e|\u0d20|\u0261|\u1971|\u0501|\u2007|\u0392|\uff0e|\u13a1|\u0458|\u202f|\ufe55|\u15b4|\u1d21|\u2006|\u2cad|\u0440|\u2574|\u16ec|\u13da|\u13a2)') # message pattern nick_pattern = Regexp.new(':(?<nick>.*)!(?<user>.+)\@(?<host>\S+) PRIVMSG (?<channel>\#\S+) :(?<msg>.*)') # Run a /USERIP on the nick that matched the spam text if line.force_encoding('utf-8') =~ nick_pattern @log.info "matched on nick pattern" irc_msg = Regexp.last_match if irc_msg["msg"].force_encoding('utf-8') =~ spam_pattern @log.info "matched on spam pattern" @irc.userip(irc_msg["nick"]) end end end end return nil end |