-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlivecheck.py
76 lines (61 loc) · 2.08 KB
/
livecheck.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
75
76
import discord
import random, cfg, twitch_stuff
import asyncio, logging, datetime
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
handler = logging.FileHandler('discordbot.log', mode='w')
formatter = logging.Formatter('''%(asctime)s -
%(name)s - %(levelname)s - %(message)s''')
handler.setFormatter(formatter)
logger.addHandler(handler)
TOKEN = cfg.D_TOKEN
twitchid = twitch_stuff.get_user_id('emongg')
print(twitchid)
if twitchid==False:
print('no id')
have_id = False
else:
have_id = True
if have_id:
live_check = twitch_stuff.get_status(twitchid)
client = discord.Client()
async def check_live():
global live_check
while True:
currentDT = str(datetime.datetime.now())
try:
new_check = twitch_stuff.get_status(twitchid)
except:
continue
if new_check == True:
if live_check == False:
try:
logger.info('posting message at ' + currentDT)
message = "@everyone emongg is live https://twitch.tv/emongg"
await client.send_message(discord.Object(id='422170422516121612'), message)
except:
logger.exception('error posting message: ')
elif live_check == True:
logger.info('still live as of ' + currentDT)
pass
else:
print('something broke. live_check = ', live_check)
live_check = new_check
elif new_check == False:
logger.info('not live as of ' + currentDT)
live_check = new_check
pass
else:
print('something broke. new_check = ', new_check)
await asyncio.sleep(60)
@client.event
async def on_ready():
await client.change_presence(game=discord.Game(name="\"Life? Don't talk to me about life.\""))
print("Logged in as " + client.user.name)
try:
if have_id:
print('creating loop')
client.loop.create_task(check_live())
client.run(TOKEN)
except:
logger.exception("message:")