put special chars to prevent loopback flooding and use a config file

This commit is contained in:
vulpine 2020-11-25 11:04:24 -05:00
parent dfe6fdaf99
commit c405e2379f
3 changed files with 23 additions and 12 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
config.py
__pycache__
__pycache__/*

17
bot.py
View File

@ -10,14 +10,7 @@ from ircrobots import ConnectionParams
# im too lazy to import more stuffs :tm: # im too lazy to import more stuffs :tm:
from ircrobots.server import * from ircrobots.server import *
SERVERS = [ from config import *
("freenode", "chat.freenode.net", 6697, True),
("tilde", "irc.tilde.chat", 6697, True),
("technet","irc.technet.xi.ht", 6697, True),
("vulpineawoo","irc.wppnx.pii.at", 6697, True),
("alphachat","irc.alphachat.net", 6697, True),
("openirc","91.188.125.227",6668,False),
]
class Server(BaseServer): class Server(BaseServer):
@ -49,12 +42,12 @@ class Server(BaseServer):
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.isupport.network}") print(f"connected to {self.isupport.network}")
self.chan = "##xfnw" if self.name == "freenode" else "#xfnw" 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: if nick == self.nickname or (line.tags and "batch" in line.tags) or "\x0f\x0f\x0f\x0f" in text:
return return
for i in self.bot.servers: for i in 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))
@ -66,7 +59,7 @@ class Server(BaseServer):
async def bc(self,name,nick,msg): async def bc(self,name,nick,msg):
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,"<"+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]))
class Bot(BaseBot): class Bot(BaseBot):
def create_server(self, name: str): def create_server(self, name: str):
@ -76,7 +69,7 @@ bot = 0
async def main(): async def main():
bot = Bot() bot = Bot()
for name, host, port, ssl in SERVERS: for name, host, port, ssl in SERVERS:
params = ConnectionParams("xfnwRelay", host, port, ssl) params = ConnectionParams(NICKNAME, host, port, ssl)
await bot.add_server(name, params) await bot.add_server(name, params)
await bot.run() await bot.run()

13
config.py.example Normal file
View File

@ -0,0 +1,13 @@
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),
]
NICKNAME = 'testrelay'
CHANNEL = '#testrelay'
FNCHANNEL = '##testrelay'