Compare commits

...

19 Commits
main ... main

Author SHA1 Message Date
xfnw 7e1206a3fc breaking change, support ircrobots >= 0.6
tls option in config is no longer required
2022-08-26 08:08:10 -04:00
xfnw e82956fd4a Revert "overwriting connect no longer needed"
This reverts commit bd18b48b26.
2021-09-12 12:45:39 -04:00
xfnw bd18b48b26 overwriting connect no longer needed 2021-07-10 19:25:52 -04:00
vulpine ebd6f4b7d0
remove freenode, andrew lee is a bad boy 2021-05-20 22:12:20 -04:00
xfnw d83a06dfa8 another ## net 2021-05-11 14:57:21 -04:00
vulpine 1f4848887b do not propogate pings for people on the NOPING list 2021-01-22 15:56:58 -05:00
vulpine 6629984913 randomize network order so one network does not get priority 2021-01-18 21:28:20 -05:00
vulpine 1e3dc7f675 support last long colon params in admin commands 2021-01-09 16:17:59 -05:00
vulpine a065098578 oops, apperently bool(String) always returns true lol 2020-12-30 18:07:42 -05:00
vulpine 1479da33be allow connecting to nonexistant servers 2020-12-30 11:42:04 -05:00
vulpine 3ba295d33e connect to new servers without restarting 2020-12-29 10:54:13 -05:00
vulpine 02a16fc38f allow manual reconnections to previously-dead networks 2020-12-26 18:05:03 -05:00
vulpine 9776d910c0 Merge branch 'main' of github.com:xfnw/relay into main 2020-12-23 16:23:41 -05:00
vulpine 99d3be7dfa admin commands to send to all servers, eg remote bans 2020-12-23 16:20:27 -05:00
vulpine 228369c64c installation guide 2020-11-25 20:46:31 -05:00
vulpine e44186fbf1 put special chars to prevent loopback flooding and use a config file 2020-11-25 20:46:31 -05:00
vulpine 5e2b7ea6ce insert a zero-width-non-joiner so people will not ping themself on every message 2020-11-25 20:46:31 -05:00
vulpine 9a0db80afc allow some connections to be disconnected without effecting other connections
dont send to disconnected
2020-11-25 20:46:22 -05:00
lickthecheese a5a9825965 dont send messages while not connected lol 2020-11-25 20:46:22 -05:00
2 changed files with 73 additions and 15 deletions

71
bot.py
View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3
import asyncio
import asyncio, random
from irctokens import build, Line
from ircrobots import Bot as BaseBot
@ -25,9 +25,8 @@ class Server(BaseServer):
reader, writer = await transport.connect(
params.host,
params.port,
tls =params.tls,
tls_verify=params.tls_verify,
bindhost =params.bindhost)
tls =params.tls,
bindhost =params.bindhost)
self._reader = reader
self._writer = writer
@ -41,15 +40,37 @@ class Server(BaseServer):
async def line_read(self, line: Line):
print(f"{self.name} < {line.format()}")
if line.command == "001":
print(f"connected to {self.isupport.network}")
self.chan = FNCHANNEL if self.name == "freenode" else CHANNEL
print(f"connected to {self.name}")
self.chan = FNCHANNEL if self.name in ["freenode","libera"] else CHANNEL
await self.send(build("JOIN", [self.chan]))
if line.command == "PRIVMSG" and line.params.pop(0) == self.chan:
text = line.params[0].replace("\1ACTION","*").replace("\1","")
nick = line.source.split('!')[0]
if nick == self.nickname or (line.tags and "batch" in line.tags) or "\x0f\x0f\x0f\x0f" in text:
return
for i in self.bot.servers:
if self.disconnected:
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))
#await self.send(build("PRIVMSG ##xfnw :ine and boat ",[text]))
if line.command == "INVITE":
@ -60,16 +81,46 @@ class Server(BaseServer):
if self.disconnected or name == self.name or "chan" not in list(dir(self)):
return
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):
def create_server(self, name: str):
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():
bot = Bot()
for name, host, port, ssl in SERVERS:
params = ConnectionParams(NICKNAME, host, port, ssl)
for name, host, port in SERVERS:
params = ConnectionParams(NICKNAME, host, port)
await bot.add_server(name, params)
await bot.run()

View File

@ -1,13 +1,20 @@
# name hostname port tls
SERVERS = [
("freenode", "chat.freenode.net.invalid", 6697, True),
("tilde", "irc.tilde.chat.invalid", 6697, True),
("technet","irc.technet.xi.ht.invalid", 6697, True),
("vulpineawoo","irc.wppnx.pii.at.invalid", 6697, True),
("alphachat","irc.alphachat.net.invalid", 6697, True),
("tilde", "irc.tilde.chat.invalid", 6697),
("technet","irc.technet.xi.ht.invalid", 6697),
("vulpineawoo","foxes.are.allowed.org.invalid", 6697),
("alphachat","irc.alphachat.net.invalid", 6697),
]
NICKNAME = 'testrelay'
CHANNEL = '#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']