summaryrefslogtreecommitdiff
path: root/demonetarisiert/irc.py
blob: b1c24adfbafee6d0f90daeb743f6ffeeb939e7d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from threading import Event as TEvent

from irc.client import SimpleIRCClient, ServerConnection, Event

from .config import config

SERVER = "irc.chat.twitch.tv"
PORT = 6667
CHANNEL = "#" + config.channel
NICK = config.name


class Client(SimpleIRCClient):
    def __init__(self):
        super().__init__()
        self.ready = TEvent()

    def setup(self):
        self.connect(SERVER, PORT, NICK, password=config.password)
        self.start()

    def on_endofmotd(self, conn: ServerConnection, event: Event):
        print('Well, we are done here.')
        conn.join(CHANNEL)

    def on_motd(self, conn: ServerConnection, event: Event):
        print("Motd: " + event.arguments[0])

    def on_pubmsg(self, conn: ServerConnection, event: Event):
        if event.arguments[0] == 'test123':
            conn.privmsg(CHANNEL, '#familyfriendly, bitte!')

    def on_endofnames(self, conn: ServerConnection, event: Event):
        self.ready.set()

    def _dispatcher(self, conn: ServerConnection, event: Event):
        if event.type != 'all_raw_messages':
            print(event)
        super(Client, self)._dispatcher(conn, event)