Skip to content

Instantly share code, notes, and snippets.

@misaka4e21
Created April 9, 2012 15:22
Show Gist options
  • Save misaka4e21/2344201 to your computer and use it in GitHub Desktop.
Save misaka4e21/2344201 to your computer and use it in GitHub Desktop.
一個用ruby+cinch寫的irc機器人——mew
#!/usr/bin/env ruby
#coding=utf-8
require 'cinch'
def get_reply(cmd,params,nick)
case cmd
when "tiaoxi"
if params=="" then
return "各位注意:此用户(#{nick})因传播黄色信息依法被消失(依据刑诉法73条)。请各位谅解。公安部国内安全保卫大队。"
else
return "#{params}已被#{nick}調戲。"
end
when "loveBy"
if params=="this" then
return "人家纔不喜歡你呢!"
elsif params=="cst"
return "打倒cst反動派!刪貼刪會員!"
end
when "kill"
if params==nick
return "你想自殺嗎?"
else
return "#{params}已被#{nick}殺死。"
end
end
end
class Cmd
include Cinch::Plugin
prefix lambda{|m| Regexp.new("^"+Regexp.escape(m.bot.nick+":"))}
match /([a-zA-Z_]+)\((.*)\)$/,method: :cmd
def cmd(m)
md=/^mew:([a-zA-Z_]+)\((.*?)\)$/.match(m.message)
m.reply(get_reply(md[1],md[2],m.user.nick)) if not md.nil?
end
end
bot = Cinch::Bot.new do
configure do |c|
c.server = "irc.freenode.org"
c.channels = ["#linuxbar"]
c.nick = "mew"
c.plugins.plugins=[Cmd]
@datas={}
@xiaoba=[]
end
on :message, /mew:我要(當|当)吧主/ do |m|
m.reply "#{m.user.nick}:吧主是我的!"
end
on :message, /mew:我要(当|當)小吧主/ do |m|
@xiaoba << m.user.nick
m.reply "吧务团队:永久吧主mew,临时吧主火车头,小吧主#{@xiaoba.to_s},永久小黑屋cst。"
end
on :message, /mew:(.*?)。$/ do |m|
md=/mew:(.*?)。$/.match(m.message)
if not md.nil? then
m.reply "難道#{md[1]}?"
end
end
on :message, /mew:難道(.*?)?$/ do |m|
m.reply "是的。"
end
end
bot.start
@misaka4e21
Copy link
Author

民國101年6月3日更新,六四特別版

#!/usr/bin/env ruby
#coding=utf-8

require 'cinch'

$xiaoba=[]

def process(msg,nick)
  case msg
    when /我要(当|當)小吧主/
      $xiaoba << nick
      "吧务团队:永久吧主mew,临时吧主火车头,小吧主#{$xiaoba.to_s},永久小黑屋cst。"
    when /我要(当|當)吧主/
      "反了你了?"
    when /kill\((?<object>.*?)\)/
      md=$~
      if md[:object].nil? or md[:object].empty?
        "你想自殺嗎?"
      else
        "#{md[:object]}已被#{nick}殺死。"
      end
    when /tiaoxi\((?<object>.*?)\)/
      md=$~
      if md[:object].nil? or md[:object].empty?
        "各位注意:此用户(#{nick})因传播黄色信息依法被消失(依据刑诉法73条)。请各位谅解。公安部国内安全保卫大队。"
      else
        "#{md[:object]}已被#{nick}調戲。"
      end
    when /(難|难)道.*??/
      "是的。"
    when /(.*?)。/
      "難道#{$~[1]}?"
    when /loveBy\((.*?)\)/
      case $~[1]
        when "this"
          "纔不喜歡你呢!"
        when "cst"
          "打倒cst反動派!刪貼刪會員!"
        else
          "Ade mein liebes Schätzelein"
      end
    when "help()"
      "如何使用?自己探索啦!"
    when /weather.*?/
      "250攝氏度,槍林彈雨,東風21級(別忘了還給諸葛亮)。"
    when "meng()"
      "cst最討厭了~"
    when /fsck\((.*?)\)/
      md=$~
      "fsck.ext5: #{md[1]}: 文件系統已經清理。"
    when "allahu akbar!"
      "bomb!"
    when "you.fuck()"
      "(fuck you) ;; Long live LISP!"
    when /你的著作.*/
      "簡介:為什麼一向恩愛的cst和mew竟然大打出手,cst的重量級投訴究竟是什麼內容,Ponohano是否真的插足二人的生活?老w的GLinux——本事件的導火索,代碼到底在哪裡?mew到底是民主鬥士,還是獨裁者?敬請觀看Linux版《Mein Kampf》,mew第三人稱自傳:《先吧主 mew,我們的元首——Linux吧7.2事件真相》"
    when /你的孩子.*/
      "mew05001和cst~cst~"
    when /六四/
      "二十三年了。"
  end
end

bot = Cinch::Bot.new do
  configure do |c|
    c.server = "irc.freenode.org"
    c.channels = ["#linuxbar"]
    $nick = c.nick = "mew"
  end

  on :message, /^mew_*:\s*(.*)$/ do |m|
    msg=/^mew_*:\s*(.*)$/.match(m.message)[1]
    m.reply "#{m.user.nick}: "+process(msg,m.user.nick)
  end
end

bot.start

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment