bot6/bot.py

46 lines
1.5 KiB
Python
Raw Permalink Normal View History

#!./venv/bin/python3
2021-09-16 17:35:06 +00:00
#!/usr/bin/env python3
import ircstates, socket, ssl
2021-09-16 17:35:06 +00:00
from config import *
from stuff import stuff
from util import Util
from time import sleep
2021-09-16 17:35:06 +00:00
2021-09-16 17:35:06 +00:00
class bot:
server = ircstates.Server(config.server.name)
host = config.server.host
port = config.server.port
if __name__ == __module__ == "__main__":
2021-09-16 17:35:06 +00:00
@classmethod
def __init__(self):
if config.server.ssl:
with socket.create_connection((self.host, self.port)) as sock_raw:
ctx = ssl.create_default_context()
with ctx.wrap_socket(sock_raw, server_hostname=self.host) as sock:
try:
util = Util(config, sock)
stuff(self, sock)
except KeyboardInterrupt:
util.quit("^C")
except ircstates.server.ServerDisconnectedException:
sleep(3)
self.__init__()
else:
with socket.create_connection((self.host, self.port)) as sock:
try:
util = Util(config, sock)
stuff(self, sock)
except KeyboardInterrupt:
util.quit("^C")
except ircstates.server.ServerDisconnectedException:
sleep(3)
self.__init__()
print("starting bot...")
2021-09-16 17:35:06 +00:00
bot()