开发者

IRC Bot - flood protection (python)

  if data.find('PRIVMSG') != -1:
     nick = data.split('!')[ 0 ].replace(':','')
     text = ''
     if data.count(text) >= 200:
        sck.send('KICK ' + " " + chan + " :" 'flooding' + '\r\n')

I'm trying to code a flood protection for the bot, I want it to kick a user if he enters more then 200 characters, how can I make it so it can read the other lines instead of just the first line? and the code above doesn't work, it doesnt kick the user but if I change the sck.send() to sck.send('PRIVMSG ' + chan + " :" 'flooding' + '\r\n') it works.

fixed the kicking problem, and the code works now, but it only reads the first line开发者_运维技巧, not sure how to make it read the other lines if the user keeps flooding the channel.

  if data.find('PRIVMSG') != -1:
     nick = data.split('!')[ 0 ].replace(':','')
     text = ''
     if data.count(text) >= 200:
        sck.send('KICK ' + " " + chan + " " + nick + " :" 'flooding' + '\r\n')


As far as I remember, the colon is a reserved character in the IRC protocol. That is, the first colon in a server message denotes the start of user-supplied data (that's also why ":" is not allowed in nicks/channel names). Hence, it suffices to search for the first colon and calculate the length of the remaining string.

Furthermore, data.find('PRIVMSG') is pretty unreliable. What if a user types the word "PRIVMSG" in regular channel conversation? Go look up the IRC RFC, it specifies the format of PRIVMSGs in detail.

Besides, you should be a little more specific. What exactly is the problem you're facing? Extracting the nick? Calculating the message length? Connecting to IRC?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜