m4pl1mp/plugins/tcpac_plugin.py

33 lines
1.6 KiB
Python
Raw Permalink Normal View History

2022-07-27 13:22:10 +00:00
# -*- coding: utf-8 -*- ############################################################################# SOF
2022-06-25 20:34:18 +00:00
from irc3.plugins.command import command
from irc3.plugins.cron import cron
import irc3
import socket
2022-07-27 13:22:10 +00:00
#########################################################################################################
2022-06-25 20:34:18 +00:00
@irc3.plugin
class Plugin:
2022-07-27 13:22:10 +00:00
#########################################################################################################
2022-06-25 20:34:18 +00:00
def __init__(self, bot):
self.bot = bot
2022-07-27 13:22:10 +00:00
#####################################################################################################
2022-06-25 20:34:18 +00:00
@command(permission='view')
def tcpac(self, mask, target, args):
2022-07-27 13:22:10 +00:00
"""tcpac - the irc version of `cat file - | nc tcp.ac 9999`, usage: ?tcpac message
2022-06-25 20:34:18 +00:00
%%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]
2022-07-27 13:22:10 +00:00
delmsg=s.split(',')[0].split('":"')[1][:-1]
txtmsg=s.split(',')[1].split('":"')[1][:-2]
msg=f"{mask.nick}: tcp.ac service - url to share -> txt: {txtmsg}"
2022-06-25 20:34:18 +00:00
self.bot.privmsg(target,msg)
2022-07-27 13:22:10 +00:00
msg=f"{mask.nick}: tcp.ac service - url to admin -> del: {delmsg}"
2022-06-25 20:34:18 +00:00
self.bot.privmsg(mask.nick,msg)
2022-07-27 13:22:10 +00:00
#####################################################################################################
##################################################################################################### EOF