|
4 | 4 | from __future__ import annotations |
5 | 5 |
|
6 | 6 | import asyncio |
| 7 | +import functools |
7 | 8 | import logging |
8 | 9 | import os |
| 10 | +import ssl |
9 | 11 | import threading |
10 | 12 | from typing import Self |
11 | 13 |
|
12 | 14 | import commands |
13 | 15 | import discord |
14 | | -import ib3.auth |
15 | 16 | import irc.bot |
16 | 17 | import irc.client |
17 | | -import irc.strings |
| 18 | +import irc.connection |
18 | 19 | from ircrelay import formatting |
19 | 20 |
|
20 | 21 |
|
21 | | -class IRCBot(ib3.auth.SASL, irc.bot.SingleServerIRCBot): |
| 22 | +class IRCBot(irc.bot.SingleServerIRCBot): |
22 | 23 | """The IRC bot class. This is the class that runs the entire IRC side of the bot |
23 | 24 | The class to start the entire IRC bot |
24 | 25 |
|
@@ -58,25 +59,42 @@ def __init__( |
58 | 59 | username: str, |
59 | 60 | password: str, |
60 | 61 | ) -> None: |
61 | | - |
62 | 62 | self.loop = loop |
| 63 | + self.username = username |
| 64 | + self.password = password |
| 65 | + self.join_channel_list = channels |
| 66 | + |
| 67 | + # SSL context setup |
| 68 | + context = ssl.create_default_context() |
| 69 | + factory = irc.connection.Factory( |
| 70 | + wrapper=functools.partial(context.wrap_socket, server_hostname=server) |
| 71 | + ) |
| 72 | + |
| 73 | + # Pass the correct server info and password |
63 | 74 | super().__init__( |
64 | | - server_list=[(server, port)], |
| 75 | + server_list=[ |
| 76 | + (server, port, password) |
| 77 | + ], # Ensure this has the correct password |
65 | 78 | realname=username, |
66 | 79 | nickname=username, |
67 | | - ident_password=password, |
68 | | - channels=channels, |
| 80 | + connect_factory=factory, |
69 | 81 | ) |
70 | | - self.join_channel_list = channels |
71 | | - self.username = username |
72 | | - self.password = password |
| 82 | + |
| 83 | + # Reconnect handler if disconnected |
73 | 84 | self._on_disconnect = self.reconnect_from_disconnect |
74 | 85 |
|
75 | 86 | def exit_irc(self: Self) -> None: |
76 | 87 | """Instatly kills the IRC thread""" |
77 | 88 | # pylint: disable=protected-access |
78 | 89 | os._exit(1) |
79 | 90 |
|
| 91 | + def start_bot(self: Self) -> None: |
| 92 | + """Start the bot and handle SASL authentication.""" |
| 93 | + self.connection.set_rate_limit(1) # Be nice to server |
| 94 | + self.connection.username = self.username |
| 95 | + self.connection.sasl_login = self.username |
| 96 | + self.start() # Starts the IRC bot's main loop |
| 97 | + |
80 | 98 | def reconnect_from_disconnect( |
81 | 99 | self: Self, connection: irc.client.ServerConnection, event: irc.client.Event |
82 | 100 | ) -> None: |
|
0 commit comments