Skip to content

Commit d31940a

Browse files
removed t! email, fixed bugs, def getemail implemented
1 parent 87ec965 commit d31940a

File tree

2 files changed

+11
-40
lines changed

2 files changed

+11
-40
lines changed

README.md

Lines changed: 0 additions & 17 deletions
This file was deleted.

main.py

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
# friend honked my car? he isnt logged on at all possibly because vehicle list is set to 0 which brings the first in the list?
55
# Implement a function to consistently refresh cache.json so we have up to date creds?
66
# Sometimes Vehicle error when sending command; teslapy.VehicleError: Meta slave not woken up within 60 seconds; issue is bot will not read anythiing else during those 60s
7+
#freezes on t! test if not loged in, maybe waiting for timeout
78

89
#TODO: QOL LIST
910
#maybe t! email with no argument returns what email you have it set to for ease of access?
1011

12+
1113
with open('tokens.json', 'r') as openfile:
1214
tokens = json.load(openfile)
1315

@@ -20,6 +22,12 @@ async def on_ready(self):
2022
print('Logged on as {0}!'.format(self.user))
2123

2224
async def on_message(self, message):
25+
26+
def getEmail(passid):
27+
with open('emails.json', 'r') as openfile:
28+
emailDictionary = json.load(openfile)
29+
return emailDictionary[str(passid)]
30+
2331
print('Message from {0.author}: {0.content}'.format(message))
2432

2533
if message.content.startswith('t! help'):
@@ -28,15 +36,13 @@ async def on_message(self, message):
2836
embed.set_thumbnail(url="https://cdn.mos.cms.futurecdn.net/xz4NVQhHaHShErxar7YLn.jpg")
2937
embed.add_field(name="t! test", value="pulls up data about your tesla")
3038
embed.add_field(name="t! login", value="logs you into tesla, must do t! email first")
31-
embed.add_field(name="t! email [email]", value="binds an email to your discord user id")
39+
embed.add_field(name="t! setup", value="setup your account with us")
3240
embed.add_field(name="t! logout", value="logs you out")
3341
embed.add_field(name="t! debugid", value="tells you your id, email, and token")
3442
await message.channel.send(embed=embed)
3543

3644
if message.content.startswith('t! test'):
37-
with open('emails.json', 'r') as openfile:
38-
emailDictionary = json.load(openfile)
39-
vehicles = teslapy.Tesla(emailDictionary[str(client.user.id)]).vehicle_list()
45+
vehicles = teslapy.Tesla(getEmail(client.user.id)).vehicle_list()
4046
await message.channel.send(vehicles[0])
4147

4248
if message.content.startswith('t! login'):
@@ -81,22 +87,6 @@ def urlcheck(m):
8187
teslapy.Tesla(emailDictionary[str(client.user.id)]).logout()
8288
if not teslapy.Tesla(emailDictionary[str(client.user.id)]).authorized:
8389
await message.channel.send('Successful logout')
84-
85-
if message.content.startswith('t! email'):
86-
text = message.content
87-
email = text.split()[-1]
88-
if(email=="email"):
89-
await message.channel.send('empty field for email. try: t! email [your email]')
90-
return
91-
with open('emails.json', 'r') as openfile:
92-
emailDictionary = json.load(openfile)
93-
emailDictionary2={client.user.id:email}
94-
emailDictionary.update(emailDictionary2)
95-
json_object= json.dumps(emailDictionary)
96-
with open("emails.json", "w") as outfile:
97-
outfile.write(json_object)
98-
await message.channel.send('Email has been set')
99-
10090
# TODO: This function will implement the user setting up their email process and logging in
10191
if message.content.startswith('t! setup'):
10292
await message.channel.send('Welcome to the setup process. \n')
@@ -123,7 +113,7 @@ def emailCheck(message):
123113

124114
with open('emails.json', 'r') as openfile:
125115
emailDictionary = json.load(openfile)
126-
emailDictionary2={client.user.id:email.content}
116+
emailDictionary2={str(client.user.id):email.content}
127117
emailDictionary.update(emailDictionary2)
128118
json_object= json.dumps(emailDictionary)
129119
with open("emails.json", "w") as outfile:
@@ -136,7 +126,6 @@ def emailCheck(message):
136126
await message.channel.send('Setup process has been cancelled.')
137127
return
138128

139-
140129
if message.content.startswith('t! debugid'):
141130
await message.channel.send(client.user.id)
142131
with open('emails.json', 'r') as openfile:
@@ -153,7 +142,6 @@ def emailCheck(message):
153142
vehicles[0].sync_wake_up()
154143
vehicles[0].command('HONK_HORN')
155144

156-
157145
client = MyClient()
158146
client.run(tokens['discordToken'])
159147
# TODO: Integrate where on bot close, it will terminate the teslapy session (but this is a per user session?)

0 commit comments

Comments
 (0)