IRC Bot - 防洪(Python)
if data.find('PRIVMSG') != -1:
nick = data.split('!')[ 0 ].replace(':','')
text = ''
if data.count(text) >= 200:
sck.send('KICK ' + " " + chan + " :" 'flooding' + '\r\n')
我正在尝试为机器人编写洪水保护代码,如果用户输入超过 200 个字符,我希望它踢用户,我怎样才能使其能够读取其他行而不仅仅是第一行?上面的代码不起作用,它不会踢用户,但如果我将 sck.send()
更改为 sck.send('PRIVMSG ' + chan + " :" 'flooding ' + '\r\n')
它有效。
修复了踢球问题,代码现在可以运行,但它只读取第一行,不知道如果用户继续淹没频道,如何让它读取其他行。
if data.find('PRIVMSG') != -1:
nick = data.split('!')[ 0 ].replace(':','')
text = ''
if data.count(text) >= 200:
sck.send('KICK ' + " " + chan + " " + nick + " :" 'flooding' + '\r\n')
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')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我记得,冒号是IRC协议中的保留字符。也就是说,服务器消息中的第一个冒号表示用户提供的数据的开始(这也是昵称/频道名称中不允许使用“:”的原因)。因此,搜索第一个冒号并计算剩余字符串的长度就足够了。
此外,data.find('PRIVMSG') 非常不可靠。如果用户在常规频道对话中键入单词“PRIVMSG”怎么办?去查IRC RFC,它详细规定了PRIVMSGs的格式。
此外,你应该更具体一点。您面临的问题到底是什么?提取缺口?计算消息长度?正在连接 IRC?
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?