简体   繁体   English

使用PHP构建IRC机器人,需要一些帮助

[英]Building an IRC bot using PHP, need some help

I am using the a SmartIRC library for this. 我正在为此使用SmartIRC库。 What I need to be able to do is have the bot running and accepting commands from users, and also listening on a UDP socket. 我需要做的是让机器人运行并接受用户的命令,并在UDP套接字上侦听。 I get data sent through the UDP socket that I need to analyze, sort into MySQL tables and such. 我通过需要分析的UDP套接字发送数据,并整理到MySQL表等中。 I need that UDP data to be available to my BOT. 我需要UDP数据可用于我的BOT。

So the problem is, whenever I open a UDP socket it listens to all the data in a 'while' loop. 所以问题是,每当我打开UDP套接字时,它都会在“ while”循环中侦听所有数据。 So it means that the IRC bot itself is un-functional until the loop is over and closed. 因此,这意味着IRC漫游器本身在循环结束并关闭之前无法运行。 I thought about using some kind of a multi-threading solution, but I am not sure how. 我曾考虑使用某种多线程解决方案,但不确定如何使用。 I need to find some way to spawn a new thread of the UDP socket, and send that data to my currently running bot. 我需要找到某种方式来产生UDP套接字的新线程,并将该数据发送到当前正在运行的机器人。 ah, no clue. 啊,没有头绪。

Any ideas? 有任何想法吗? Hopefully I explained it enough so you guys can understand what the hell I want. 希望我能解释得足够多,以便你们可以理解我到底想要什么。

Thanks! 谢谢!

I'm not sure why you're listening for data in a while loop. 我不确定为什么要在while循环中监听数据。 When I have used SmartIRC in the past I use $irc->registerActionhandler() for the user commands and then call $irc->listen( ) , that way the library handles it all for you. 过去使用SmartIRC时,我将$irc->registerActionhandler()用于用户命令,然后调用$irc->listen( ) ,这样库将为您处理所有$irc->listen( )

Some good examples of using SmartIRC can be found here , hopefully they will help you. 可以在此处找到一些使用SmartIRC的好示例,希望它们会对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM