2020-04-01 16:36:53 +02:00
|
|
|
import asyncio
|
|
|
|
|
|
|
|
from irctokens import build, Line
|
2020-04-02 19:17:17 +02:00
|
|
|
from ircrobots import Bot as BaseBot
|
2020-04-21 21:39:51 +02:00
|
|
|
from ircrobots import Server as BaseServer
|
|
|
|
from ircrobots import ConnectionParams
|
2020-04-01 16:36:53 +02:00
|
|
|
|
|
|
|
SERVERS = [
|
2020-04-02 19:17:17 +02:00
|
|
|
("freenode", "chat.freenode.invalid")
|
2020-04-01 16:36:53 +02:00
|
|
|
]
|
|
|
|
|
2020-04-21 21:39:51 +02:00
|
|
|
class Server(BaseServer):
|
|
|
|
async def line_read(self, line: Line):
|
|
|
|
print(f"{self.name} < {line.format()}")
|
2020-04-01 16:36:53 +02:00
|
|
|
if line.command == "001":
|
2020-04-21 21:39:51 +02:00
|
|
|
print(f"connected to {self.isupport.network}")
|
|
|
|
await self.send(build("JOIN", ["#testchannel"]))
|
|
|
|
async def line_send(self, line: Line):
|
|
|
|
print(f"{self.name} > {line.format()}")
|
2020-04-01 16:36:53 +02:00
|
|
|
|
2020-04-21 21:39:51 +02:00
|
|
|
class Bot(BaseBot):
|
|
|
|
def create_server(self, name: str):
|
|
|
|
return Server(self, name)
|
2020-04-02 00:06:08 +02:00
|
|
|
|
2020-04-01 16:36:53 +02:00
|
|
|
async def main():
|
|
|
|
bot = Bot()
|
|
|
|
for name, host in SERVERS:
|
|
|
|
params = ConnectionParams("BitBotNewTest", host, 6697, True)
|
|
|
|
await bot.add_server(name, params)
|
2020-04-02 19:17:17 +02:00
|
|
|
|
2020-04-01 16:36:53 +02:00
|
|
|
await bot.run()
|
2020-04-02 19:17:17 +02:00
|
|
|
|
2020-04-01 16:36:53 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
asyncio.run(main())
|