forked from GamesDoneQuick/donation-tracker
-
Notifications
You must be signed in to change notification settings - Fork 1
/
irc.py
38 lines (28 loc) · 1.09 KB
/
irc.py
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
# IRC related functionality
import ssl
import irc.bot
import irc.connection
class TwitchAnnouncer(irc.bot.SingleServerIRCBot):
"""Class to announce messages to a Twitch channel."""
def __init__(self, username, token, channel):
self.token = token
self.channel = '#' + channel
# Create IRC bot connection
ssl_factory = irc.connection.Factory(wrapper=ssl.wrap_socket)
server = 'irc.chat.twitch.tv'
port = 443
irc.bot.SingleServerIRCBot.__init__(self, [(server, port, 'oauth:' + token)], username, username,
connect_factory=ssl_factory)
def send_message(self, message):
"""Send a message or list of messages to the channel.
:param message:
:return:
"""
self._connect()
self.connection.join(self.channel)
if isinstance(message, (list, tuple)):
for m in message:
self.connection.privmsg(self.channel, m)
else:
self.connection.privmsg(self.channel, message)
self.connection.disconnect()