-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
58 lines (48 loc) · 1.87 KB
/
main.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
import asyncio
from datetime import datetime, timedelta
from discord import DiscordEvents
from dotenv import load_dotenv
from game_fetcher import fetch_game_data
import os
DEBUG = False
def game_endtime(input_datetime: str) -> str:
'''Returns the ISO formatted datetime string of when the game finishes'''
original_datetime = datetime.fromisoformat(input_datetime)
game_duration = int(os.environ.get('GAME_DURATION_HOURS'))
new_datetime = original_datetime + timedelta(hours=game_duration)
return new_datetime.isoformat()
async def main():
load_dotenv()
discord_token = os.environ.get('DISCORD_TOKEN')
guild_id = os.environ.get('GUILD_ID')
channel_id = os.environ.get('CHANNEL_ID')
bot_id = os.environ.get('BOT_ID')
if DEBUG:
print(discord_token)
print(guild_id)
print(channel_id)
print(bot_id)
bot = DiscordEvents(discord_token, bot_id)
event_data = await fetch_game_data()
if DEBUG:
print(f'GAME DATA: {event_data}')
await bot.delete_guild_events(guild_id)
for i in range(len(event_data)):
event = event_data[i]
if 'CUSTOM_EVENT_NAME' in os.environ:
event_name = os.environ.get('CUSTOM_EVENT_NAME')
else:
event_name = f'GAME DAY {i+1}'
event_link = await bot.create_guild_event(
guild_id=guild_id,
event_name=event_name,
event_description=f'{event.team1} vs. {event.team2}',
event_start_time=event.time,
event_end_time=game_endtime(event.time),
event_metadata={'location': event.location},
)
if len(event_link) > 0:
print(event_link)
if int(os.environ.get('SEND_ANNOUNCEMENTS')) == 1:
await bot.send_guild_message(channel_id, event_link)
asyncio.run(main())