-
Notifications
You must be signed in to change notification settings - Fork 1
/
pileborg.py
74 lines (60 loc) · 1.67 KB
/
pileborg.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from chatty import create
import config, time
import functions as fun
from bot import bot as b
from tornado.ioloop import PeriodicCallback, IOLoop
# This is an unnecessary function that checks a file that contains the current song
# playing on stream for changes and then sends it to the chat.
def nowplaying():
global np, t, tprev, npprev
np = fun.now_playing()
t = time.time()
if(t-tprev)>15.0:
if np:
if not np == npprev:
chat.message("Now Playing: " + fun.removeNonAscii(np))
npprev = np
tprev = time.time()
def addmoney():
global chat, ph
users = chat.get_users()
##ADD MONEY
ph.add_money_to_users(users)
def sendchat():
global chats, chat
if len(chats) == 0:
chats = config.CHATMESSAGES[:]
chat.message(chats.pop(0))
if __name__ == "__main__":
tprev = time.time()
npprev = fun.now_playing()
chats = config.CHATMESSAGES[:]
if npprev is not None:
print("Now playing: " + npprev)
else:
print("Song not playing.")
chat = create(config)
ph = b(chat)
# Tell chat to authenticate with the beam server. It'll throw
# a chatty.errors.NotAuthenticatedError if it fails.
chat.authenticate(config.CHANNEL)
# Listen for incoming messages.
chat.on("message", ph.filtermessage)
# Send Now playing to chat when song changes
PeriodicCallback(
lambda: nowplaying(),
1000
).start()
# Add money to viewers after user defined seconds
PeriodicCallback(
lambda: addmoney(),
ph.moneyupdate * 1000
).start()
# Send predetermined chat messages
if (config.CHATTIMER > 0) and (len(config.CHATMESSAGES) > 0):
PeriodicCallback(
lambda: sendchat(),
config.CHATTIMER * 1000
).start()
# Start the tornado event loop.
IOLoop.instance().start()