-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
75 lines (62 loc) · 2.41 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import random
import time
import cat_api
import os
import discord
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
BOT_OWNER_ID = os.getenv('BOT_OWNER_ID')
client = discord.Client()
dead = False
async def change_avatar():
print("changing avatar")
await client.user.edit(avatar=cat_api.get_image_as_bytes())
async def change_avatar_threading():
print('starting change avatar thread!')
while not client.is_ready:
pass
print('c.a.t. client is ready')
while not dead:
await change_avatar()
time.sleep(5*60)
print('change avatar thread killed')
@client.event
async def on_ready():
print(f'{client.user} with id "{client.user.id}" has connected to Discord!')
for guild in client.guilds:
print(f'{client.user} has connected to the guild: {guild.name} (id: "{guild.id}")')
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content == 'cat!':
response = cat_api.get_url()
print(f'User "{message.author}" used command "cat!" in channel "{message.channel}" (Guild: "{message.guild.id}" => "{message.guild}")')
await message.channel.send(response)
elif message.content == 'kill_bot' and str(message.author.id) == str(BOT_OWNER_ID):
print(f'User "{message.author}" called command "kill_bot" in channel "{message.channel}" (Guild: "{message.guild.id}" => "{message.guild}")')
responses = [
'Shutting down...',
'Master, it\'s getting so dark',
'*dies*',
f'I can\'t let you do that ~~Dave~~ *{message.author.display_name}*...',
'bleh *dies*',
'This won\'t be the last time, you see me!',
'If it weren\'t for these meddling bot owners, I would have survived',
'This won\'t be the last, you see of me!',
'I\'ll be back!'
]
response = random.choice(responses)
print(f'sending response: "{response}"')
await message.channel.send(response)
print(f'response: "{response}" sent')
await client.logout()
print(f'Bot logged out')
await client.close()
print(f'Bot terminated')
dead = True
elif message.content == 'change_avatar' and str(message.author.id) == str(BOT_OWNER_ID):
await change_avatar()
await message.channel.send('boop!')
client.run(TOKEN)