Python - 将文件中的行写入 IRC 缓冲区
好的,所以我正在尝试为 XCHAT 编写一个 Python 脚本,它允许我输入“/hookcommand filename”,然后将该文件逐行打印到我的 irc 缓冲区中。
编辑:这是我现在所拥有的
__module_name__ = "scroll.py"
__module_version__ = "1.0"
__module_description__ = "script to scroll contents of txt file on irc"
import xchat, random, os, glob, string
def gg(ascii):
ascii = glob.glob("F:\irc\as\*.txt")
for textfile in ascii:
f = open(textfile, 'r')
def gg_cb(word, word_eol, userdata):
ascii = gg(word[0])
xchat.command("msg %s %s"%(xchat.get_info('channel'), ascii))
return xchat.EAT_ALL
xchat.hook_command("gg", gg_cb, help="/gg filename to use")
Ok, so I am trying to write a Python script for XCHAT that will allow me to type "/hookcommand filename" and then will print that file line by line into my irc buffer.
EDIT: Here is what I have now
__module_name__ = "scroll.py"
__module_version__ = "1.0"
__module_description__ = "script to scroll contents of txt file on irc"
import xchat, random, os, glob, string
def gg(ascii):
ascii = glob.glob("F:\irc\as\*.txt")
for textfile in ascii:
f = open(textfile, 'r')
def gg_cb(word, word_eol, userdata):
ascii = gg(word[0])
xchat.command("msg %s %s"%(xchat.get_info('channel'), ascii))
return xchat.EAT_ALL
xchat.hook_command("gg", gg_cb, help="/gg filename to use")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,你的第一个问题是你在定义它之前引用了一个变量 ascii:
尝试这样做:
接下来,你打开 glob 返回的每个文件...只是对它们不做任何事情。我不会给你这个代码:请尝试自己弄清楚它在做什么或没有做什么。提示:xchat 界面是一个额外的复杂性。首先尝试让它在普通 Python 中运行,然后将其连接到 xchat。
很可能还有其他问题 - 我不知道 xchat api。
当您说“不工作”时,请尝试准确说明它是如何不工作的。有错误信息吗?它做错事了吗?你尝试了什么?
Well, your first problem is that you're referring to a variable ascii before you define it:
Try making that:
Next, you're opening each file returned by glob... only to do absolutely nothing with them. I'm not going to give you the code for this: please try to work out what it's doing or not doing for yourself. One tip: the xchat interface is an extra complication. Try to get it working in plain Python first, then connect it to xchat.
There may well be other problems - I don't know the xchat api.
When you say "not working", try to specify exactly how it's not working. Is there an error message? Does it do the wrong thing? What have you tried?