Compare commits
No commits in common. "main" and "main" have entirely different histories.
71
bot.py
71
bot.py
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import asyncio, random
|
import asyncio
|
||||||
|
|
||||||
from irctokens import build, Line
|
from irctokens import build, Line
|
||||||
from ircrobots import Bot as BaseBot
|
from ircrobots import Bot as BaseBot
|
||||||
|
@ -25,8 +25,9 @@ class Server(BaseServer):
|
||||||
reader, writer = await transport.connect(
|
reader, writer = await transport.connect(
|
||||||
params.host,
|
params.host,
|
||||||
params.port,
|
params.port,
|
||||||
tls =params.tls,
|
tls =params.tls,
|
||||||
bindhost =params.bindhost)
|
tls_verify=params.tls_verify,
|
||||||
|
bindhost =params.bindhost)
|
||||||
|
|
||||||
self._reader = reader
|
self._reader = reader
|
||||||
self._writer = writer
|
self._writer = writer
|
||||||
|
@ -40,37 +41,15 @@ class Server(BaseServer):
|
||||||
async def line_read(self, line: Line):
|
async def line_read(self, line: Line):
|
||||||
print(f"{self.name} < {line.format()}")
|
print(f"{self.name} < {line.format()}")
|
||||||
if line.command == "001":
|
if line.command == "001":
|
||||||
print(f"connected to {self.name}")
|
print(f"connected to {self.isupport.network}")
|
||||||
self.chan = FNCHANNEL if self.name in ["freenode","libera"] else CHANNEL
|
self.chan = FNCHANNEL if self.name == "freenode" else CHANNEL
|
||||||
await self.send(build("JOIN", [self.chan]))
|
await self.send(build("JOIN", [self.chan]))
|
||||||
if line.command == "PRIVMSG" and line.params.pop(0) == self.chan:
|
if line.command == "PRIVMSG" and line.params.pop(0) == self.chan:
|
||||||
text = line.params[0].replace("\1ACTION","*").replace("\1","")
|
text = line.params[0].replace("\1ACTION","*").replace("\1","")
|
||||||
nick = line.source.split('!')[0]
|
nick = line.source.split('!')[0]
|
||||||
if nick == self.nickname or (line.tags and "batch" in line.tags) or "\x0f\x0f\x0f\x0f" in text:
|
if nick == self.nickname or (line.tags and "batch" in line.tags) or "\x0f\x0f\x0f\x0f" in text:
|
||||||
return
|
return
|
||||||
if self.disconnected:
|
for i in self.bot.servers:
|
||||||
return
|
|
||||||
if nick.lower() in self.users and self.users[nick.lower()].account in ADMINS:
|
|
||||||
if text[:len(self.nickname)+2].lower() == f'{self.nickname}: '.lower():
|
|
||||||
args = text[len(self.nickname)+2:].split(' ')
|
|
||||||
if args[0] == 'connect' and len(args) > 4:
|
|
||||||
await self.bot.add_server(args[1],ConnectionParams(NICKNAME,args[2],args[3]))
|
|
||||||
await self.send(build("PRIVMSG",[self.chan,"Connected to {} :3".format(args[1])]))
|
|
||||||
return
|
|
||||||
if args[0] == 'unlink' and len(args) > 1:
|
|
||||||
await self.bot.servers[args[1]].disconnect()
|
|
||||||
del self.bot.servers[args[1]]
|
|
||||||
await self.send(build("PRIVMSG",[self.chan,"Unlinked {} :S".format(args[1])]))
|
|
||||||
return
|
|
||||||
for i in random.sample(list(self.bot.servers),len(self.bot.servers)):
|
|
||||||
asyncio.create_task(self.bot.servers[i].ac(self.name,args))
|
|
||||||
return
|
|
||||||
for npn in NOPING:
|
|
||||||
offset = 1
|
|
||||||
for loc in find_all_indexes(text.lower(), npn.lower()):
|
|
||||||
text = text[:loc+offset]+"\u200c"+text[loc+offset:]
|
|
||||||
offset += 1
|
|
||||||
for i in random.sample(list(self.bot.servers),len(self.bot.servers)):
|
|
||||||
asyncio.create_task(self.bot.servers[i].bc(self.name,nick,text))
|
asyncio.create_task(self.bot.servers[i].bc(self.name,nick,text))
|
||||||
#await self.send(build("PRIVMSG ##xfnw :ine and boat ",[text]))
|
#await self.send(build("PRIVMSG ##xfnw :ine and boat ",[text]))
|
||||||
if line.command == "INVITE":
|
if line.command == "INVITE":
|
||||||
|
@ -81,46 +60,16 @@ class Server(BaseServer):
|
||||||
if self.disconnected or name == self.name or "chan" not in list(dir(self)):
|
if self.disconnected or name == self.name or "chan" not in list(dir(self)):
|
||||||
return
|
return
|
||||||
await self.send(build("PRIVMSG",[self.chan,"\x0f\x0f\x0f\x0f<"+nick[:1]+"\u200c"+nick[1:]+"@"+name+"> "+msg]))
|
await self.send(build("PRIVMSG",[self.chan,"\x0f\x0f\x0f\x0f<"+nick[:1]+"\u200c"+nick[1:]+"@"+name+"> "+msg]))
|
||||||
async def ac(self,name,args):
|
|
||||||
if self.disconnected or "chan" not in list(dir(self)):
|
|
||||||
return
|
|
||||||
nargs = []
|
|
||||||
isComb = False
|
|
||||||
for arg in args:
|
|
||||||
if arg[0] == ':':
|
|
||||||
isComb = True
|
|
||||||
nargs.append(arg[1:])
|
|
||||||
continue
|
|
||||||
if isComb:
|
|
||||||
nargs[-1] += ' '+arg
|
|
||||||
else:
|
|
||||||
nargs.append(arg)
|
|
||||||
await self.send(build(nargs[0],[self.chan]+nargs[1:]))
|
|
||||||
|
|
||||||
class Bot(BaseBot):
|
class Bot(BaseBot):
|
||||||
def create_server(self, name: str):
|
def create_server(self, name: str):
|
||||||
return Server(self, name)
|
return Server(self, name)
|
||||||
|
|
||||||
|
bot = 0
|
||||||
|
|
||||||
def find_all_indexes(input_str, search_str):
|
|
||||||
l1 = []
|
|
||||||
length = len(input_str)
|
|
||||||
index = 0
|
|
||||||
while index < length:
|
|
||||||
i = input_str.find(search_str, index)
|
|
||||||
if i == -1:
|
|
||||||
return l1
|
|
||||||
l1.append(i)
|
|
||||||
index = i + 1
|
|
||||||
return l1
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
bot = Bot()
|
bot = Bot()
|
||||||
for name, host, port in SERVERS:
|
for name, host, port, ssl in SERVERS:
|
||||||
params = ConnectionParams(NICKNAME, host, port)
|
params = ConnectionParams(NICKNAME, host, port, ssl)
|
||||||
await bot.add_server(name, params)
|
await bot.add_server(name, params)
|
||||||
|
|
||||||
await bot.run()
|
await bot.run()
|
||||||
|
|
|
@ -1,20 +1,13 @@
|
||||||
|
|
||||||
# name hostname port tls
|
|
||||||
SERVERS = [
|
SERVERS = [
|
||||||
("tilde", "irc.tilde.chat.invalid", 6697),
|
("freenode", "chat.freenode.net.invalid", 6697, True),
|
||||||
("technet","irc.technet.xi.ht.invalid", 6697),
|
("tilde", "irc.tilde.chat.invalid", 6697, True),
|
||||||
("vulpineawoo","foxes.are.allowed.org.invalid", 6697),
|
("technet","irc.technet.xi.ht.invalid", 6697, True),
|
||||||
("alphachat","irc.alphachat.net.invalid", 6697),
|
("vulpineawoo","irc.wppnx.pii.at.invalid", 6697, True),
|
||||||
|
("alphachat","irc.alphachat.net.invalid", 6697, True),
|
||||||
]
|
]
|
||||||
|
|
||||||
NICKNAME = 'testrelay'
|
NICKNAME = 'testrelay'
|
||||||
CHANNEL = '#testrelay'
|
CHANNEL = '#testrelay'
|
||||||
FNCHANNEL = '##testrelay'
|
FNCHANNEL = '##testrelay'
|
||||||
|
|
||||||
# nickserv accounts of people who can run admin commands
|
|
||||||
ADMINS=['jess']
|
|
||||||
|
|
||||||
# strings to break for preventing pings
|
|
||||||
# unlikely to be useful unless you are on both sides of the relay on the same client
|
|
||||||
NOPING=['MIF']
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user