Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

小优化.

  • Loading branch information...
commit 860d99fb01739938d27a171cb3d0f80783dd3e0b 1 parent 3dd52e2
sevk authored
Showing with 43 additions and 58 deletions.
  1. +9 −18 Dic.rb
  2. +0 −1  ipwry.rb
  3. +32 −37 irc.rb
  4. +2 −2 irc_user.rb
27 Dic.rb
View
@@ -73,6 +73,7 @@ def unescapeHTML
#todo http://netkiller.hikz.com/book/linux/ linux资料查询
$old_feed_date = nil unless defined?$old_feed_date
$_time=86400 if not defined?$_time
+$kick_info = '请勿Flood,超过4行贴至 http://code.bulix.org 图片帖至 http://kimag.es'
Help = '我是 kk-irc-bot ㉿ s 新手资料 g google d define `new 取论坛新贴 `b baidu tt google翻译 `t 词典 > x=1+2;x+=1 计算x的值 `a 查某人地址 `f 查老乡 `host 查域名 `i 机器人源码. 末尾加入|重定向,如 g ubuntu | nick'
Delay_do_after = 4 unless defined? Delay_do_after
@@ -91,12 +92,12 @@ def unescapeHTML
puts "$SAFE= #$SAFE"
NoFloodAndPlay=/\-ot|arch|fire/i
-$botlist=/bot|fity|badgirl|crazyghost|iphone|\^?[Ou]_[ou]|MadGirl/i
+$botlist=/bot|fity|badgirl|pocoyo.?.?|iphone|\^?[Ou]_[ou]|MadGirl/i
$botlist_Code=/badgirl|\^?[Ou]_[ou]/i
$botlist_ub_feed=/crazyghost|\^?[Ou]_[ou]/i
$botlist_title=/GiGi|\^?[Ou]_[ou]/i
-$tiList=/ub|deb|ux|ix|win|goo|beta|py|ja|lu|qq|dot|dn|li|pr|qt|tk|ed|re|rt/i
-$urlList=$tiList
+#$tiList=/ub|deb|ux|ix|win|goo|beta|py|ja|lu|qq|dot|dn|li|pr|qt|tk|ed|re|rt/i
+$urlList=$tiList = /ub/i
def URLDecode(str)
#str.gsub(/%[a-fA-F0-9]{2}/) { |x| x = x[1..2].hex.chr }
@@ -200,7 +201,7 @@ def get_Atom_n(url= 'http://forum.ubuntu.org.cn/feed.php',not_re = true)
#取ubuntu.org.cn的 feed.
def get_feed(url= 'http://forum.ubuntu.org.cn/feed.php',not_re = true)
begin
- Timeout.timeout(12) {
+ Timeout.timeout(15) {
$tmp = RSS::Parser.parse(url)
}
#rescue Timeout::Error => e
@@ -340,7 +341,7 @@ def gettitle(url,proxy=nil)
p e.message
if $!.message == 'Connection reset by peer'
sleep 0.5
- return Timeout.timeout(10){gettitle(url,true)}
+ return Timeout.timeout(11){gettitle(url,true)}
else
return e.message[0,60] + ' . IN title'
end
@@ -556,6 +557,7 @@ def getGoogle(word,flg)
#ed2k
def geted2kinfo(url)
url.match(/^:\/\/\|(\w+?)\|(\S+?)\|(.+?)\|.*$/)
+ return if $1 == 'server'
$ti = "#{URLDecode($2.to_s)} , #{ '%.2f' % ($3.to_f / 1024**3)} GB"
$ti.gsub!(/.*\]\./,'')
"#{unescapeHTML($ti)}"
@@ -749,13 +751,7 @@ def osod
page = agent.get_file(url)
rescue Exception => e
#p e.message
- if $!.message == 'Connection reset by peer'
- #p 'Connection reset by peer'
- sleep 0.5
- return Timeout.timeout(10){gettitle(url,true)}
- else
- return e.message[0,60] + ' . IN osod'
- end
+ return e.message[0,60] + ' . IN osod'
end
s = page.match(/span class="e2">(.*?)<select name='selectmonth'>/mi)[1]
s = s.gsub!(/\s+/,' ')
@@ -777,12 +773,7 @@ def ge name
#return nil if page.class != Mechanize::Page
rescue Exception => e
p e.message
- if $!.message == 'Connection reset by peer'
- sleep 0.5
- return Timeout.timeout(10){gettitle(url,true)}
- else
- return e.message[0,60] + ' . IN getdeb'
- end
+ return e.message[0,60] + ' . IN getdeb'
end
s = page.match(/resultlink".+?:(.+?)<br>(.+?): /mi)[1..2].join ','
p s
1  ipwry.rb
View
@@ -10,7 +10,6 @@
class IpLocationSeeker
def initialize()
fQQwry='./QQWry.Dat'
-
#@datafile = File.open(fQQwry,"r:utf-8")
@datafile = File.open(fQQwry,"rb")
@first_index_pos,@last_index_pos = @datafile.read(8).unpack('L2')
69 irc.rb
View
@@ -37,7 +37,6 @@ def initialize(server, port, nick, channel, charset, pass, user)
@nick = nick
@str_user= user
@channel = channel
- #@channel = Ch.new
charset='UTF-8' if charset =~ /utf\-?8/i
@charset = charset
puts "$saytitle = #{$saytitle}" #是否读取url title
@@ -47,7 +46,7 @@ def initialize(server, port, nick, channel, charset, pass, user)
#kick踢出
def kick(s)
- send "kick #@channel #{s} 大段内容请贴到http://pastebin.ca 或 http://paste.ubuntu.org.cn"
+ send "kick #@channel #{s} #$kick_info"
end
#/mode #ubuntu-cn +q *!*@1.1.1.0
@@ -63,7 +62,7 @@ def autoban(chan,s,time=50)
def ping
$Lping = Time.now
- send "PING LAG1982067890"
+ send "PING LAG1982067890",false
end
#发送notice消息
def notice(who,sSay,delay=4)
@@ -83,7 +82,7 @@ def say(s)
end
#发送tcp数据,如果长度大于460 就自动截断.
- def send(s)
+ def send(s,add_tim_chr=true)
s.gsub!(/\s+/,' ')
if s.bytesize > 450
s.chop!.chop! while s.bytesize > 450
@@ -97,9 +96,9 @@ def send(s)
#非utf-8的聊天室就直接截断了
s=Iconv.conv("#{@charset}//IGNORE","UTF-8//IGNORE",s[0,450])
end
- s+=' ...'
+ s += ' ...'
else
- s+= Time.now.ch
+ s += Time.now.ch if add_tim_chr
end
@irc.send("#{s.strip}\n", 0)
$Lsay = Time.now
@@ -121,7 +120,7 @@ def sayDic(dic,from,to,s='')
direction = ''
tellSender = false
pub =true #默认公共消息
- pub =true if dic == 5
+ #pub =true if dic == 5
if s=~/(.*?)\s?([#|>])\s?(.*?)$/i #消息重定向
words=$1;direction=$2;b7=$3
@@ -188,15 +187,14 @@ def sayDic(dic,from,to,s='')
c == "" ? re= getTQFromName(from) : re= getTQ(c)
when 99 then re = Help ;c=''
when 101 then re = dictcn(c);c=''
- #when 101 then re = getBaidu_tran(c);c=''
end
Thread.exit if re.bytesize < 2
b7=from if b7
if sto =~ /notice/i
- notice(to, "#{b7}:\0039 #{c}\017\0037 #{re}",8)
+ notice(to, "#{b7}:\0039 #{c}\017\0037 #{re}",9)
else
- msg(to, "#{b7}:\0039 #{c}\017\0037 #{re}",7)
+ msg(to, "#{b7}:\0039 #{c}\017\0037 #{re}",9)
end
msg(from,"#{b7}:\0039 #{c}\017\0037 #{re}",0) if tellSender
@@ -282,8 +280,8 @@ def check_msg(s)
else
autoban to,"#{nick}!*@*"
end
- msg(a4,"#{a1}:KAO,谁说话这么快, 大段内容请贴到 http://pastebin.ca 或 http://paste.ubuntu.org.cn",0)
- notice(nick,"#{a1}: ... 大段内容请贴到 http://pastebin.ca 或 http://paste.ubuntu.org.cn",5)
+ msg(a4,"#{a1}:KAO,谁说话这么快,#$kick_info",0)
+ notice(nick,"#{a1}: ... #$kick_info",5)
return nil
end
@@ -431,18 +429,17 @@ def check_dic(s,from,to)
@ti=Thread.start {
$ti= gettitle(url)
if $ti
- #if $ti =~ $tiList || url =~ $urlList
- tmp = $ti.gsub(/_|\.|\s+|Ubuntu中文论坛.+?查看主题/,'')
- if s =~ /#{Regexp::escape tmp[tmp.size/2-4,8]}/i#已经发了就不说了
- puts "已经发了标题 #{tmp[tmp.size/2-4,8]}"
- else
- $ti.gsub!(/Ubuntu中文论坛 • 登录/,'对不起,感觉是个水贴')
- msg(to,"⇪ title: #{$ti}",0)
- end
- #end
+ return if $ti !~ $tiList and url !~ $urlList
+ tmp = $ti.gsub(/_|\.|\s+|Ubuntu中文论坛.+?查看主题/,'')
+ if s.include? tmp #已经发了就不说了
+ puts "已经发了标题 #{tmp}"
+ else
+ $ti.gsub!(/Ubuntu中文论坛 • 登录/,'对不起,感觉是个水贴')
+ msg(to,"⇪ title: #{$ti}",0)
+ end
end
}
- @ti.priority = 40
+ @ti.priority = 30
#@ti.join
when /ed2k/i
msg(to,geted2kinfo(url),0)
@@ -464,14 +461,11 @@ def check_dic(s,from,to)
w=$2.to_s.strip
return if w =~/这|那|的|哪/
sayDic(1,from,to,"define:#{w} |")
- when /^(.*?)[\s:,](.+)是什么[\??]?$/i #是什么
- if $1
- return
- else
- w = $2.to_s.strip
- return if w =~/这|那|的|哪/
- sayDic(1,from,to,"define:#{w} |")
- end
+ when /^(.*?)?[:,]?(.+)是什么(\?|...)?$/i #是什么
+ w = $1.delete '`'
+ return if w =~ /^(.+)[:,]/
+ return if w =~ /这|那|的|哪/
+ sayDic(1,from,to,"define:#{w} |")
when /^`ims\s(.*?)$/i #IMS查询
puts 'IMS ' + s
sayDic(21,from,to,$1)
@@ -538,7 +532,7 @@ def check_irc_event(s)
@irc.send "PONG :#{$1}\n", 0
when /LAG1982067890/i #LAG
$lag=Time.now - $Lping
- puts "LAG = #{$lag}" if $lag > 3
+ puts "LAG = #{$lag}" if $lag > 3 and $lag < 20
when /^(:.+?)!(.+?)@(.+?)\s(.+?)\s.+\s:(.+)$/i #all mesg from nick
from=$1;name=$2;ip=$3;to=$4;sSay=$5
if $ignore_nick =~ Regexp.new(from+'!',Regexp::IGNORECASE)
@@ -752,18 +746,18 @@ def renew_Readline_complete(w)
#检测用户输入,实现IRC客户端功能.
def iSend()
loop do
- sleep 0.28
+ sleep 0.29
s = Readline.readline('[' + @channel + '] ', true)
#s = Readline.readline('', true)
next if !s
#lock.synchronize do
case s
when /^:q\s?(.*)?$/i #:q退出
+ myexit ;
+ @exit = true
send 'quit optimize' + $1
sleep 1
p 'quit...'
- @exit = true
- myexit ;
exit
when /^\/msg\s(.+?)\s(.+)$/i
who = $1;s=$2
@@ -854,9 +848,10 @@ def timer_start
timer_daily
n+=1
next if n%2 ==0
- saveu if n%8 ==0
- next unless (8..24) === Time.now.hour
- say_new($channel) if $need_say_feed > 0
+ saveu if n%9 ==0
+ if (8..24).include? Time.now.hour
+ say_new($channel) if $need_say_feed > 0
+ end
end
end
end
4 irc_user.rb
View
@@ -2,8 +2,8 @@
# coding: utf-8
#51070540@qq.com ; sevkme@gmail.com
-$maxfloodme = 71.0 #70
-$maxflood = 33.3 #37
+$maxfloodme = 72.0 #70
+$maxflood = 33.4 #37
$initFlood = 83.0 #83
$maxNamed = 200
Please sign in to comment.
Something went wrong with that request. Please try again.