-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbot.py
62 lines (53 loc) · 1.64 KB
/
bot.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
import discord, boto3, config
client = discord.Client()
ec2 = boto3.resource('ec2')
instance = ec2.Instance(config.instance_id)
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------------')
@client.event
async def on_message(message):
if message.content.lower() == "stop":
if turnOffInstance():
await message.channel.send('AWS Instance stopping')
else:
await message.channel.send('Error stopping AWS Instance')
elif message.content.lower() == "start":
if turnOnInstance():
await message.channel.send('AWS Instance starting')
else:
await message.channel.send('Error starting AWS Instance')
elif message.content.lower() == "state":
if getInstanceState():
await message.channel.send('AWS Instance state is: ' + getInstanceState())
elif message.content.lower() == "reboot":
if rebootInstance():
await message.channel.send('AWS Instance rebooting')
else:
await message.channel.send('Error rebooting AWS Instance')
elif message.content.lower() == "test":
await message.channel.send('Thanks, Jace. Helps alot.')
def turnOffInstance():
try:
instance.stop()
return True
except:
return False
def turnOnInstance():
try:
instance.start()
return True
except:
return False
def getInstanceState():
return instance.state['Name']
def rebootInstance():
try:
instance.reboot()
return True
except:
return False
client.run(config.discord_key)