m4pl1mp/plugins/tcpac_plugin.py
2022-06-25 15:34:18 -05:00

29 lines
822 B
Python

# -*- coding: utf-8 -*-
from irc3.plugins.command import command
from irc3.plugins.cron import cron
import irc3
import socket
@irc3.plugin
class Plugin:
def __init__(self, bot):
self.bot = bot
@command(permission='view')
def tcpac(self, mask, target, args):
"""tcpac
%%tcpac <message>...
"""
msg=' '.join(args['<message>'])
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect(("tcp.ac", 9999))
s.sendall(bytes(msg.encode()))
data = s.recv(1024)
response=f'{data!r}'
response=response.replace('\\n',' - ').replace("b'","")[:-1]
msg=f"{mask.nick}: {response.split()[0]}"
self.bot.privmsg(target,msg)
msg=f"{response}"
self.bot.privmsg(mask.nick,msg)