-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlive.py
75 lines (61 loc) · 2.32 KB
/
live.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
#!/bin/python3 -u
import discord
import os
from dotenv import load_dotenv
from discord.ext import commands
import twitch
import asyncio
load_dotenv()
helix = twitch.Helix(os.getenv('twitch_client'), os.getenv('twitch_secret'))
client = commands.Bot(command_prefix='+123+')
@client.event
async def on_ready():
print('Live started on bot {0.user}'.format(client))
async def twitch_live():
await client.wait_until_ready()
twitch_channel = client.get_channel(int(os.getenv('twitch_channel')))
try:
while 1:
await asyncio.sleep (60)
users_file = open("twitch_users.log", "r")
users = users_file.readlines()
users_file.close()
users = [x.replace('\n', '') for x in users]
live_file = open("twitch_live.log", "r")
live = live_file.readlines()
live_file.close()
live = [x.replace('\n', '') for x in live]
i=0
twitch_chans = []
disc_ids = []
for user in users:
if i:
i=0
twitch_chans.append(user)
else:
i=1
disc_ids.append(user)
i=0
for chan in twitch_chans:
user = helix.user(chan)
if user.is_live:
if user.display_name not in live:
await twitch_channel.send(str("<@!" + disc_ids[i] + "> is live now: **" + user.stream.title + "**\n" + "https://www.twitch.tv/" + user.display_name))
live_file = open("twitch_live.log", "a")
live_file.write(str(user.display_name + "\n"))
live_file.close()
i=i+1
live_file = open("twitch_live.log", "r")
live = live_file.readlines()
live_file.close()
live = [x.replace('\n', '') for x in live]
live_file = open("twitch_live.log", "w")
for lve in live:
live_user = helix.user(lve)
if live_user.is_live:
live_file.write(str(live_user.display_name + "\n"))
live_file.close()
except:
client.loop.create_task(twitch_live())
client.loop.create_task(twitch_live())
client.run(os.getenv('TOKEN'))