我收到了ruby聊天機器人,如果在聊天過程中某個角色重複了五次或更多次,在第一次和第二次嘗試中,它會在第三次嘗試時警告用戶,用戶和第四個禁止了兩個小時的用戶,而且它目前正在如何在紅寶石中使用大寫字母方法
require_relative '../plugin'
class Flood
include Chatbot::Plugin
match /(.*)/, :method => :check_swear, :use_prefix => false
def initialize(bot)
super(bot)
@data = {}
end
def check_swear(user, message)
message = message.downcase
array = ["aaaaa", "ñññññ", "bbbbb", "ccccc", "ddddd", "eeeee", "fffff", "ggggg", "hhhhh", "iiiii", "jjjjj", "mmmmm", ".....", "*****", "?????", "!!!!!", "zzzzz", "kkkkkk", "ooooo", "nnnnn", "ppppp", "qqqqq", "rrrrr", "-----", "_____", "¨¨¨¨¨¨¨¨", "{{{{{", "}}}}}", "#####"]
array.each do |e|
if message.include? e
if(@data[user.name] and @data[user.name] == 3)
@client.send_msg "%s: [[Wiki_Freddy_Fazbear's_Pizza:Reglas_y_Lineamientos|Has sido advertido. Tendrás un ban de 2 horas.]] 4/3" % user.name
@client.ban user.name, "7200", "Ban automático por exceso de carácteres - Si crees que esto fué un error, contacta con un [[Wiki_Freddy_Fazbear%27s_Pizza:Administradores|moderador u Admin en su muro de mensajes]]."
@client.send_msg "!mods por si acaso consideran necesario más tiempo de ban."
@client.kick user.name
@data[user.name] = 0
elsif(@data[user.name] and @data[user.name] == 2)
@data[user.name] ||= 0
@data[user.name] += 1
@client.send_msg "%s: [[Wiki_Freddy_Fazbear's_Pizza:Reglas_y_Lineamientos|Por favor, no repitas carácteres, última advertencia antes de un ban.]] 3/3" % user.name
@client.kick user.name
elsif(@data[user.name] and @data[user.name] == 1)
@data[user.name] ||= 0
@data[user.name] += 1
@client.send_msg "%s: [[Wiki_Freddy_Fazbear's_Pizza:Reglas_y_Lineamientos|Por favor, no repitas carácteres, última advertencia antes de un kick]], 2/3" % user.name
else
@data[user.name] ||= 0
@data[user.name] += 1
@client.send_msg "%s: [[Wiki_Freddy_Fazbear's_Pizza:Reglas_y_Lineamientos|Por favor, no repitas carácteres]], 1/3" % user.name
end
end
end
end
end
現在,我需要去改變它,它是所有相同,除了它不具有5個以上的字符觸發,但如果消息中有5個或更多的單詞是大寫字母,有人可以幫助我嗎?
編輯:順便說一下,如果有人還可以幫助我,使之引發的不僅僅是在數組列表,但任何字符的字符,這將是真棒
@HolgerJust我試過這個https://gist.github.com/anonymous/44b7737b48a256f904add3f30cde08a3它沒有工作,我已經跑出想法:((關於標題,它應該如何命名,無論如何?) –
因此,我會被警告/禁止說:「除美元外還有其他美元,例如澳元,加拿大元,港幣和新西蘭元?」_? – Stefan