Permalink
Browse files

小优化.

  • Loading branch information...
1 parent 860d99f commit 2e8a2ea900df1838add967ba92c80ab56b0ce84a @sevk committed May 22, 2010
Showing with 42 additions and 46 deletions.
  1. +15 −16 Dic.rb
  2. +27 −30 irc.rb
View
@@ -75,7 +75,7 @@ def unescapeHTML
$_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'
+Help = '我是 kk-irc-bot ㉿ s 新手资料 g google d define `new 取论坛新贴 `deb 包查询 `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
Ver='v0.27' unless defined?(Ver)
UserAgent="kk-bot/#{Ver} (X11; U; Linux i686; en-US; rv:1.9.1.2) Gecko/20090810 Ubuntu/9.10 (karmic) kk-bot/#{Ver}"
@@ -85,7 +85,7 @@ def unescapeHTML
Http_re= /http:\/\/\S+[^\s*]/
-Minsaytime= 4
+Minsaytime= 5
puts "Min say time=#{Minsaytime}"
$min_next_say = Time.now
$Lsay=Time.now; $Lping=Time.now
@@ -96,8 +96,8 @@ def unescapeHTML
$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 = /ub/i
+#$tiList=/ub|deb|ux|ix|win|beta|py|ja|qq|dn|pr|qt|tk|ed|re|rt/i
+$urlList=$tiList = /ub|linux/i
def URLDecode(str)
#str.gsub(/%[a-fA-F0-9]{2}/) { |x| x = x[1..2].hex.chr }
@@ -118,7 +118,7 @@ def guess_charset(str)
s = str.gsub(/[\x0-\x7f]/,'')
return nil if s.bytesize < 4
while s.bytesize < 25
- s = s + s
+ s << s
end
return guess(s)
end
@@ -483,7 +483,7 @@ def getGoogle(word,flg)
tmp = $2.to_s + " > " + $3.to_s.gsub(/&amp;.*/i,'')
tmp += ' ⋙ SEE ALSO ' + $1.to_s if rand(10)>5 and $1.to_s.size > 2
when /专业气象台|比价仅作信息参考/
- tmp = html.match(/>网页<.+?(搜索用时|>网页<\/b>)(.*?)(搜索结果|Google 主页)/)[2]
+ tmp = html.match(/resultStats.*?\/nobr>(.*?)(class=hd>搜索结果|Google\s+主页)/i)[1]
when /calc_img\.gif(.*?)Google 计算器详情/i #是计算器
tmp = '<' +$1.to_s + ' Google 计算器' #(.*?)<li>
else
@@ -492,9 +492,7 @@ def getGoogle(word,flg)
#p;puts html.match(/搜索用时(.*?)搜索结果<\/h2>(.*?)网页快照/i)[0]
if matched or html =~ /搜索用时(.*?)搜索结果<\/h2>(.*?)网页快照/i
if !matched
- #puts ' tmp=' + $2.to_s
tmp =$2.gsub(/<cite>.+<\/cite>/,' ' + url_mini)
- #puts ' tmp1=' + tmp1.to_s
tmp1=$1
end
tmp.gsub!(/(.+?)您的广告/,'')
@@ -507,20 +505,20 @@ def getGoogle(word,flg)
case word
when /^tq|tq$|天气$|tianqi$/i
#puts '天气过滤' + tmp.to_s
+ tmp.gsub!(/.*?<table class="ts std">/i,'')
tmp.gsub!(/alt="/,'>')
tmp.gsub!(/"?\s?title=|right/,'<')
tmp.gsub!(/\s\/\s/,"\/")
tmp.gsub!(//, '' )
tmp.gsub!(/今日\s+/, ' 今日' )
tmp.gsub!(/<\/b>/, ' ')
tmp.gsub!(/添加到(.*?)当前:/,' ')
- tmp.gsub!(/相关搜索.*?\-/,'天气- ')
+ tmp.gsub!(/相关搜索.*?\-/,' ')
#tmp.gsub!(/北京市专业气象台(.*)/, '' )
tmp=tmp.match(/.+?°C.+?°C.+?°C/)[0]
- tmp.gsub!(/°C/,'°C ')
+ tmp.gsub!(/°C/,' ')
end
tmp.gsub!(/(.*秒))|\s+/i,' ')
- #~ puts html
if tmp.bytesize > 30 || word =~ /^.?13.{9}$/ || tmp =~ /小提示/ then
re=tmp
else
@@ -767,18 +765,19 @@ def ge name
begin
url = 'http://packages.ubuntu.com/search?&searchon=names&suite=all&section=all&keywords=' + name.strip
#url = 'http://packages.debian.org/search?suite=all&arch=any&searchon=names&keywords=' + name.strip
- p url
+ #p url
#page = agent.get(url)
page = agent.get_file(url)
#return nil if page.class != Mechanize::Page
rescue Exception => e
- p e.message
+ #p e.message
return e.message[0,60] + ' . IN getdeb'
end
- s = page.match(/resultlink".+?:(.+?)<br>(.+?): /mi)[1..2].join ','
- p s
+ s = page.split(/<\/h2>/im)[1]
+ s = s.match(/.*resultlink".+?:(.+?)<br>(.+?): .*<h2>/mi)[1..2].join ','
s = s.gsub!(/\s+/,' ')
- s.gsub!(/<.*?>/,'').unescapeHTML
+ s.gsub!(/<.*?>/,'')
+ s.unescapeHTML
end
alias get_deb_info ge
View
@@ -190,13 +190,13 @@ def sayDic(dic,from,to,s='')
end
Thread.exit if re.bytesize < 2
- b7=from if b7
+ b7=from if not b7
if sto =~ /notice/i
- notice(to, "#{b7}:\0039 #{c}\017\0037 #{re}",9)
+ notice(to, "#{b7}:\0039 #{c}\017\0037 #{re}",10)
else
- msg(to, "#{b7}:\0039 #{c}\017\0037 #{re}",9)
+ msg(to, "#{b7}:\0039 #{c}\017\0037 #{re}",10)
end
- msg(from,"#{b7}:\0039 #{c}\017\0037 #{re}",0) if tellSender
+ msg(from,"#{b7}:\0039 #{c}\017\0037 #{re}",9) if tellSender
end #Thread
end
@@ -215,9 +215,8 @@ def check_code(s)
p s
if s =~ /^:(.+?)!(.+?)@(.+?)\sPRIVMSG\s(.+?)\s:(.*)$/i#需要提示
from=b1=$1;name=b2=$2;ip=b3=$3;to=b4=$4;say=$5.to_s.untaint
+ send "PRIVMSG #{((b4==@nick)? from: to)} :#{from}:say #{say} in #{tmp} ? But we use #{@charset} !" if $need_Check_code
send "Notice #{from} :请使用 #{@charset} 字符编码".utf8_to_gb
- return 'matched err charset, but not need check code' if $need_Check_code < 1
- send "PRIVMSG #{((b4==@nick)? from: to)} :#{from}:said #{say} in #{tmp} ? But we use #{@charset} !"
return 'matched err charset'
end
end
@@ -439,7 +438,7 @@ def check_dic(s,from,to)
end
end
}
- @ti.priority = 30
+ @ti.priority = 50
#@ti.join
when /ed2k/i
msg(to,geted2kinfo(url),0)
@@ -449,7 +448,7 @@ def check_dic(s,from,to)
msg to,"#{IpLocationSeeker.new.seek($1)} #{$1}",0
when /^`tr?\s(.+?)\s?(\d?)\|?$/i #baidu_tran
sayDic(101,from,to,$1)
- when /^`deb\s(.*)$/i #aptitude show
+ when /^`?deb\s(.*)$/i #aptitude show
sayDic('deb',from,to,$1)
when /^`?s\s(.*)$/i #TXT search
sayDic(6,from,to,$1)
@@ -482,18 +481,18 @@ def check_dic(s,from,to)
sayDic(40,from,to,$1)
when /^`?d(ef(ine)?)?\s(.*?)$/i#define:
sayDic(1,from,to,'define:' + $3.to_s.strip)
- when /^`?b\s(.*?)$/i # 百度
+ when /^`b\s(.*?)$/i # 百度
sayDic(2,from,to,$1)
when /^`?a\s(.*?)$/i #查某人ip
sayDic(22,from,to,$1)
when /^`?f\s(.*?)$/i #查某人的老乡
sayDic(23,from,to,$1)
when /^`?(大家好(...)?|hi( all)?.?|hello)$/i
$otherbot_said=false
- do_after_sec(to,from + ', hi .',10,18) if rand(10) > 4
+ do_after_sec(to,from + ', ',10,18) if rand(10) > 4
when /^`?((有人(...)?(吗|不|么|否)((...)?|\??))|test.{0,6}|测试(中)?(.{1,5})?)$/i #有人吗?
$otherbot_said=false
- do_after_sec(to,from + ', hello .',10,18)
+ do_after_sec(to,from + ', ...',10,18)
when /^`?(bu|wo|ni|ta|shi|ru|zen|hai|neng|shen|shang|wei|guo|qing|mei|xia|zhuang|geng|zai)\s(.+)$/i #拼音
return nil if s =~ /[^,.?\s\w]/ #只能是拼音或标点
return nil if s.bytesize < 12
@@ -559,25 +558,23 @@ def check_irc_event(s)
$_time= t - Time.mktime(t.year,t.month,t.day,$_hour,$_min,$_sec)
puts Time.now.to_s.pink
end
- #if !@Motded
- #376 End of /MOTD
- if pos == 376
- #@Motded = true
- p 'Motded'
- $min_next_say=Time.now
- File.open(ARGV[0]).each { |line|
- if line =~ /pass/
- eval line
- break
- end
- }
- send "PRIVMSG nickserv :id #{$pass}"
- $pass = nil
- $bot_on = $bot_on1
- $min_next_say = Time.now
- do_after_sec(@channel,nil,7,11)
- end
- #end
+ #376 End of /MOTD
+ if pos == 376
+ #@Motded = true
+ p 'Motded'
+ $min_next_say=Time.now
+ File.open(ARGV[0]).each { |line|
+ if line =~ /pass/
+ eval line
+ break
+ end
+ }
+ send "PRIVMSG nickserv :id #{$pass}"
+ $pass = nil
+ $bot_on = $bot_on1
+ $min_next_say = Time.now
+ do_after_sec(@channel,nil,7,11)
+ end
if !@Named
case pos
when 353

0 comments on commit 2e8a2ea

Please sign in to comment.