Created
April 9, 2012 15:22
-
-
Save misaka4e21/2344201 to your computer and use it in GitHub Desktop.
一個用ruby+cinch寫的irc機器人——mew
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
民國101年6月3日更新,六四特別版