Skip to content

Instantly share code, notes, and snippets.

@jeffallen
Last active November 13, 2025 08:55
Show Gist options
  • Select an option

  • Save jeffallen/07b47e513a1fb62814ee69796773251b to your computer and use it in GitHub Desktop.

Select an option

Save jeffallen/07b47e513a1fb62814ee69796773251b to your computer and use it in GitHub Desktop.
import irc.bot
import irc.strings
import ssl
class BasicIRCBot(irc.bot.SingleServerIRCBot):
def __init__(self, channel, nickname, password, server, port=6697):
# Create SSL context
ssl_context = ssl.create_default_context()
# Pass server_hostname to wrap_socket
factory = irc.connection.Factory(wrapper=lambda sock: ssl_context.wrap_socket(sock, server_hostname=server))
super().__init__([(server, port, password)], nickname, nickname, connect_factory=factory)
self.channel = channel
self.password = password
def on_welcome(self, connection, event):
# Some networks require NickServ authentication after connecting
if self.password:
# NickServ authentication (Libera.Chat style)
connection.privmsg("NickServ", f"IDENTIFY {self.password}")
print(f"Sent NickServ IDENTIFY for {connection.get_nickname()}")
connection.join(self.channel)
print(f"Joined {self.channel}")
def on_join(self, connection, event):
nick = event.source.nick
if nick == connection.get_nickname():
connection.privmsg(self.channel, f"Hello! I am {nick}")
print(f"Joined channel: {self.channel}")
def on_pubmsg(self, connection, event):
message = event.arguments[0]
nick = event.source.nick
print(f"<{nick}> {message}")
if irc.strings.lower(message) == "!hello":
connection.privmsg(self.channel, f"Hello, {nick}!")
if __name__ == "__main__":
channel = "#jom"
nickname = "jombot"
password = "botme" # Replace with your NickServ or SASL password
server = "irc.exoscale.ch"
port = 6697
bot = BasicIRCBot(channel, nickname, password, server, port)
bot.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment