将 Python 随机模块与 XCHAT IRC 脚本结合使用
我正在尝试将列表中的随机项目打印到我的 XCHAT 频道消息中。到目前为止,我只能打印列表中的随机项目,但不能打印任何特定文本。
示例用法为:“/ran blahblahblah”以产生频道消息所需的效果,例如“blahblahblah [随机项目]”
__module_name__ = "ran.py"
__module_version__ = "1.0"
__module_description__ = "script to add random text to channel messages"
import xchat
import random
def ran(message):
message = random.choice(['test1', 'test2', 'test3', 'test4', 'test5'])
return(message)
def ran_cb(word, word_eol, userdata):
message = ''
message = ran(message)
xchat.command("msg %s %s"%(xchat.get_info('channel'), message))
return xchat.EAT_ALL
xchat.hook_command("ran", ran_cb, help="/ran to use")
I'm trying to print random items from a list into my XCHAT channel messages. So far I've only been able to print the random items from my list alone, but not with any specific text.
Example usage would be: "/ran blahblahblah" to produce the desired effect of a channel message such as "blahblahblah [random item]"
__module_name__ = "ran.py"
__module_version__ = "1.0"
__module_description__ = "script to add random text to channel messages"
import xchat
import random
def ran(message):
message = random.choice(['test1', 'test2', 'test3', 'test4', 'test5'])
return(message)
def ran_cb(word, word_eol, userdata):
message = ''
message = ran(message)
xchat.command("msg %s %s"%(xchat.get_info('channel'), message))
return xchat.EAT_ALL
xchat.hook_command("ran", ran_cb, help="/ran to use")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不允许调用者指定可供选择的参数。
您需要从命令中获取选择。
word
是通过命令发送的单词列表,word[0]
是命令本身,因此只能从 1 及更远的位置复制。You don't allow the caller to specify the arguments to choose from.
You need to get the choices from the command.
word
is a list of the words sent through the command,word[0]
is the command itself so only copy from 1 and further.