Python - 将文件中的行写入 IRC 缓冲区

发布于 2024-10-17 17:18:01 字数 648 浏览 5 评论 0原文

好的,所以我正在尝试为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暗地喜欢 2024-10-24 17:18:01

好吧,你的第一个问题是你在定义它之前引用了一个变量 ascii:

ascii = gg(ascii)

尝试这样做:

ascii = gg(word[0])

接下来,你打开 glob 返回的每个文件...只是对它们不做任何事情。我不会给你这个代码:请尝试自己弄清楚它在做什么或没有做什么。提示:xchat 界面是一个额外的复杂性。首先尝试让它在普通 Python 中运行,然后将其连接到 xchat。

很可能还有其他问题 - 我不知道 xchat api。

当您说“不工作”时,请尝试准确说明它是如何不工作的。有错误信息吗?它做错事了吗?你尝试了什么?

Well, your first problem is that you're referring to a variable ascii before you define it:

ascii = gg(ascii)

Try making that:

ascii = gg(word[0])

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文