diff options
author | romangraef <romangraef@loves.dicksinhisan.us> | 2018-11-03 18:21:43 +0100 |
---|---|---|
committer | romangraef <romangraef@loves.dicksinhisan.us> | 2018-11-03 18:21:43 +0100 |
commit | 5052d209791919139e12eefa1210caf540e66183 (patch) | |
tree | ffcb8a36a4a66602413dfd5656dd11373d18c7eb | |
download | twitch-demonetarisiert-1.0.0.tar.gz twitch-demonetarisiert-1.0.0.tar.bz2 twitch-demonetarisiert-1.0.0.zip |
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | demonetarisiert/__init__.py | 20 | ||||
-rw-r--r-- | demonetarisiert/__main__.py | 4 | ||||
-rw-r--r-- | demonetarisiert/config.py | 10 | ||||
-rw-r--r-- | demonetarisiert/irc.py | 39 | ||||
-rw-r--r-- | requirements.txt | 2 |
6 files changed, 77 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f2c4ddd --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +config/ +venv/ diff --git a/demonetarisiert/__init__.py b/demonetarisiert/__init__.py new file mode 100644 index 0000000..7e203c6 --- /dev/null +++ b/demonetarisiert/__init__.py @@ -0,0 +1,20 @@ +from threading import Thread +from time import sleep + +from .config import config +from .irc import Client + +connection = Client() + + +def send_msg(): + connection.ready.wait() + while True: + connection.connection.privmsg("#" + config.channel, "#familyfriendly, bitte!") + sleep(300) + + +def main(): + t = Thread(target=send_msg) + t.start() + connection.setup() diff --git a/demonetarisiert/__main__.py b/demonetarisiert/__main__.py new file mode 100644 index 0000000..c7c70d0 --- /dev/null +++ b/demonetarisiert/__main__.py @@ -0,0 +1,4 @@ +from . import main + +if __name__ == '__main__': + main() diff --git a/demonetarisiert/config.py b/demonetarisiert/config.py new file mode 100644 index 0000000..b6e7fbd --- /dev/null +++ b/demonetarisiert/config.py @@ -0,0 +1,10 @@ +from configlib import BaseConfig + + +class Config(BaseConfig): + name: str + password: str + channel: str + + +config = Config.get_instance() diff --git a/demonetarisiert/irc.py b/demonetarisiert/irc.py new file mode 100644 index 0000000..b1c24ad --- /dev/null +++ b/demonetarisiert/irc.py @@ -0,0 +1,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) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..62ba3b9 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +irc +https://github.com/romangraef/configlib/archive/master.zip |