Skip to content

Commit 9e5e0a9

Browse files
authored
Updates the IRC authentication method to no longer need ib3 (#1282)
This changes the IRC authentication to be done using the IRC package instead of the ib3 packages.
1 parent 6a4b4e8 commit 9e5e0a9

5 files changed

Lines changed: 63 additions & 38 deletions

File tree

Pipfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ flake8-variables-names = "==0.0.6"
2020
gino = "==1.0.1"
2121
gitpython = "==3.1.44"
2222
hypothesis = "==6.131.9"
23-
ib3 = "==0.2.0"
2423
inflect = "==7.3.1"
25-
irc = "==20.1.0"
24+
irc = "==20.5.0"
2625
isort = "==6.0.1"
2726
munch = "==4.0.0"
2827
typing_extensions = "==4.8.0"

Pipfile.lock

Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

techsupport_bot/bot.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,22 +1042,30 @@ async def can_run(
10421042
# IRC Stuff
10431043

10441044
async def start_irc(self: Self) -> None:
1045-
"""Starts the IRC connection in a seperate thread"""
1046-
irc_config = self.file_config.api.irc
1045+
"""Starts the IRC bot in a separate thread."""
10471046
main_loop = asyncio.get_running_loop()
1047+
irc_config = self.file_config.api.irc
10481048

1049-
irc_bot = ircrelay.IRCBot(
1049+
# Create the bot instance
1050+
irc_bot = ircrelay.relay.IRCBot(
10501051
loop=main_loop,
10511052
server=irc_config.server,
10521053
port=irc_config.port,
10531054
channels=irc_config.channels,
10541055
username=irc_config.name,
10551056
password=irc_config.password,
10561057
)
1058+
10571059
self.irc = irc_bot
10581060

1059-
irc_thread = threading.Thread(target=irc_bot.start)
1061+
def run_in_thread() -> None:
1062+
"""Run the IRC bot in a separate thread."""
1063+
irc_bot.start_bot()
1064+
1065+
# Start the bot in a new thread
10601066
await self.logger.send_log(
1061-
message="Logging in to IRC", level=LogLevel.INFO, console_only=True
1067+
message="Logging into IRC", level=LogLevel.INFO, console_only=True
10621068
)
1063-
irc_thread.start()
1069+
1070+
bot_thread = threading.Thread(target=run_in_thread)
1071+
bot_thread.start()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
"""Allows python to find the irc packages"""
22

33
from .formatting import *
4-
from .irc import *
4+
from .relay import *
Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,22 @@
44
from __future__ import annotations
55

66
import asyncio
7+
import functools
78
import logging
89
import os
10+
import ssl
911
import threading
1012
from typing import Self
1113

1214
import commands
1315
import discord
14-
import ib3.auth
1516
import irc.bot
1617
import irc.client
17-
import irc.strings
18+
import irc.connection
1819
from ircrelay import formatting
1920

2021

21-
class IRCBot(ib3.auth.SASL, irc.bot.SingleServerIRCBot):
22+
class IRCBot(irc.bot.SingleServerIRCBot):
2223
"""The IRC bot class. This is the class that runs the entire IRC side of the bot
2324
The class to start the entire IRC bot
2425
@@ -58,25 +59,42 @@ def __init__(
5859
username: str,
5960
password: str,
6061
) -> None:
61-
6262
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
6374
super().__init__(
64-
server_list=[(server, port)],
75+
server_list=[
76+
(server, port, password)
77+
], # Ensure this has the correct password
6578
realname=username,
6679
nickname=username,
67-
ident_password=password,
68-
channels=channels,
80+
connect_factory=factory,
6981
)
70-
self.join_channel_list = channels
71-
self.username = username
72-
self.password = password
82+
83+
# Reconnect handler if disconnected
7384
self._on_disconnect = self.reconnect_from_disconnect
7485

7586
def exit_irc(self: Self) -> None:
7687
"""Instatly kills the IRC thread"""
7788
# pylint: disable=protected-access
7889
os._exit(1)
7990

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+
8098
def reconnect_from_disconnect(
8199
self: Self, connection: irc.client.ServerConnection, event: irc.client.Event
82100
) -> None:

0 commit comments

Comments
 (0)