以 twitch 为例,禁止在 IRC 频道中登录

Ban logs in IRC channels, on the example of twitch

我正在 Python + Sockets 中编写一个机器人来同时收集多个 twitch 频道上的日志。实际上,消息本身没有问题,但我想收集禁止/超时日志以获得更广泛的功能,代码:

IRC = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
IRC.connect ((SERVER, PORT))
IRC.send (f "PASS {PASSWORD} \ n" .encode ('utf-8'))
IRC.send (f "NICK {NICKNAME} \ n" .encode ('utf-8'))
IRC.send (f "JOIN {CHANNEL} \ n" .encode ('utf-8'))

while True:
     response = IRC.recv (1024) .decode ('utf-8')
     if response == "PING: tmi.twitch.tv \ r \ n":
         IRC.send ("PONG: tmi.twitch.tv \ r \ n" .encode ('utf-8'))

     print (response)
     time.sleep (.5)

在这个(尚未完成的)表格中,他收集消息,但不收集禁令等

您是否考虑过偶然设置 Twitch-IO?如果您设置一个仅连接到您的聊天并配置日志记录的机器人,它将自动记录到一个文件,如下所示:

from twitchio.ext import commands
import logging

logging.basicConfig(filename='irclog.txt', encoding='utf-8', level=logging.DEBUG)

bot = commands.Bot(token="irc token", nickname="your username", prefix="doesn't really matter, can be anything", initial_channels=["your channel"])

@bot.event
async def event_ready():
    print("Bot ready, beginning logging")

bot.run()

希望对您有所帮助!