improve examples/simple.py, add examples/sasl.py
This commit is contained in:
parent
d310dad471
commit
6c14fed785
2 changed files with 34 additions and 5 deletions
29
examples/sasl.py
Normal file
29
examples/sasl.py
Normal 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())
|
|
@ -1,13 +1,11 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from irctokens import build, Line
|
from irctokens import build, Line
|
||||||
|
from ircrobots import Bot as BaseBot
|
||||||
from ircrobots.bot import Bot as BaseBot
|
from ircrobots import ConnectionParams, Server
|
||||||
from ircrobots.server import ConnectionParams, Server
|
|
||||||
|
|
||||||
SERVERS = [
|
SERVERS = [
|
||||||
("freenode", "chat.freenode.net"),
|
("freenode", "chat.freenode.invalid")
|
||||||
("tilde", "ctrl-c.tilde.chat")
|
|
||||||
]
|
]
|
||||||
|
|
||||||
class Bot(BaseBot):
|
class Bot(BaseBot):
|
||||||
|
@ -25,6 +23,8 @@ async def main():
|
||||||
for name, host in SERVERS:
|
for name, host in SERVERS:
|
||||||
params = ConnectionParams("BitBotNewTest", host, 6697, True)
|
params = ConnectionParams("BitBotNewTest", host, 6697, True)
|
||||||
await bot.add_server(name, params)
|
await bot.add_server(name, params)
|
||||||
|
|
||||||
await bot.run()
|
await bot.run()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
|
Loading…
Reference in a new issue