improve examples/simple.py, add examples/sasl.py

This commit is contained in:
jesopo 2020-04-02 18:17:17 +01:00
parent d310dad471
commit 6c14fed785
2 changed files with 34 additions and 5 deletions

29
examples/sasl.py Normal file
View file

@ -0,0 +1,29 @@
import asyncio
from irctokens import build, Line
from ircrobots import Bot as BaseBot
from ircrobots import ConnectionParams, SASLUserPass, Server
class Bot(BaseBot):
async def line_read(self, server: Server, line: Line):
print(f"{server.name} < {line.format()}")
async def line_send(self, server: Server, line: Line):
print(f"{server.name} > {line.format()}")
async def main():
bot = Bot()
sasl_params = SASLUserPass("myusername", "invalidpassword")
params = ConnectionParams(
"MyNickname",
host = "chat.freenode.invalid",
port = 6697,
ssl = True,
sasl = sasl_params)
await bot.add_server("freenode", params)
await bot.run()
if __name__ == "__main__":
asyncio.run(main())

View file

@ -1,13 +1,11 @@
import asyncio
from irctokens import build, Line
from ircrobots.bot import Bot as BaseBot
from ircrobots.server import ConnectionParams, Server
from ircrobots import Bot as BaseBot
from ircrobots import ConnectionParams, Server
SERVERS = [
("freenode", "chat.freenode.net"),
("tilde", "ctrl-c.tilde.chat")
("freenode", "chat.freenode.invalid")
]
class Bot(BaseBot):
@ -25,6 +23,8 @@ async def main():
for name, host in SERVERS:
params = ConnectionParams("BitBotNewTest", host, 6697, True)
await bot.add_server(name, params)
await bot.run()
if __name__ == "__main__":
asyncio.run(main())