-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.py
92 lines (78 loc) · 2.6 KB
/
functions.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from datetime import datetime, timezone, timedelta
def reasons(embed, launch):
holdreason = launch.holdreason
failreason = launch.failreason
if holdreason:
embed.add_field(name="Holdreason", value=holdreason)
if failreason:
embed.add_field(name="Failreason", value=failreason)
if not (holdreason or failreason):
embed.add_field(name="Error", value="No reasons available")
return embed
def time_description(embed, launch):
launchtime_tz = launch.net
tz = launchtime_tz.tzname()
launchtime = launchtime_tz.replace(tzinfo=None)
title = str(launchtime) + ' ' + tz
if launch.missions:
description = launch.missions[0]['description']
if len(description) > 1000:
embed.add_field(name=title, value=description[:997]+'...', inline=False)
else:
embed.add_field(name=title, value=description, inline=False)
else:
embed.add_field(name=title, value="No description available.", inline=False)
return embed
def chop_microseconds(delta):
return delta - timedelta(microseconds=delta.microseconds)
def T_minus(launch):
launchtime = launch.net
utc = datetime.now(timezone.utc)
delta = chop_microseconds(launchtime - utc)
return delta - timedelta(microseconds=delta.microseconds)
def videourls(embed, launch):
streamurls = launch.vid_urls
if streamurls:
url = '\n'.join(streamurls)
else:
url = "No video available"
embed.add_field(name="Video", value=url)
return embed
def id(msg, obj):
id = obj.id
msg += "ID: {0}\n".format(id)
return msg
def familyid(msg, rocket):
id = rocket.family.id
msg += "Family ID: {0}\n".format(id)
return msg
def agencyid(msg, rocket):
id = rocket.family.agencies
msg += "Agency ID: {0}\n".format(id)
return msg
def padids(msg, rocket):
id = rocket.default_pads
msg += "Default pad IDs: {0}\n".format(id)
return msg
def rocketwikiurl(msg, rocket):
url = rocket.wiki_url
msg += "{0}\n".format(url)
return msg
def notify(msg, ctx):
roles = ctx.guild.roles
launchrole = None
for role in roles:
if role.name.lower() == 'launch notify':
launchrole = role
if launchrole:
msg += '{0}\n'.format(launchrole.mention)
else:
msg += 'No launch notify role found.\n'
return msg
def timelink(time):
time = time.replace(tzinfo=None)
hours = time.hour
minutes = time.minute
convertlink = 'https://www.thetimezoneconverter.com/?t={0}%3A{1}&tz=UTC'.format(hours, minutes)
text = '[{0}]({1})'.format(time, convertlink)
return text