forked from Kilvoctu/aiyabot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaiya.py
89 lines (78 loc) · 2.83 KB
/
aiya.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
import asyncio
import discord
import os
import sys
from core import settings
from core.logging import get_logger
from dotenv import load_dotenv
#start up initialization stuff
self = discord.Bot()
intents = discord.Intents.default()
intents.members = True
load_dotenv()
self.logger = get_logger(__name__)
#load extensions
# check files and global variables
settings.startup_check()
settings.files_check()
settings.old_api_check()
self.load_extension('core.settingscog')
self.load_extension('core.stablecog')
self.load_extension('core.upscalecog')
self.load_extension('core.identifycog')
self.load_extension('core.tipscog')
#stats slash command
@self.slash_command(name = 'stats', description = 'How many images has the bot generated?')
async def stats(ctx):
with open('resources/stats.txt', 'r') as f:
data = list(map(int, f.readlines()))
embed = discord.Embed(title='Art generated', description=f'I have created {data[0]} pictures!', color=settings.global_var.embed_color)
await ctx.respond(embed=embed)
@self.event
async def on_ready():
self.logger.info(f'Logged in as {self.user.name} ({self.user.id})')
await self.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name='drawing tutorials.'))
#because guilds are only known when on_ready, run files check for guilds
settings.guilds_check(self)
#feature to delete generations. give bot 'Add Reactions' permission (or not, to hide the ❌)
@self.event
async def on_message(message):
if message.author == self.user:
try:
if message.embeds[0].fields[1].name == 'took me':
await message.add_reaction('❌')
except(Exception,):
pass
@self.event
async def on_raw_reaction_add(ctx):
if ctx.emoji.name == '❌':
try:
message = await self.get_channel(ctx.channel_id).fetch_message(ctx.message_id)
if message.embeds:
if message.embeds[0].footer.text == f'{ctx.member.name}#{ctx.member.discriminator}':
await message.delete()
# this is for deleting generations in DMs
except(Exception,):
channel = await self.fetch_user(ctx.user_id)
message = await channel.fetch_message(ctx.message_id)
if message.embeds:
await message.delete()
@self.event
async def on_guild_join(guild):
print(f'Wow, I joined {guild.name}! Refreshing settings.')
settings.guilds_check(self)
async def shutdown(bot):
await bot.close()
try:
self.run(os.getenv('TOKEN'))
except KeyboardInterrupt:
self.logger.info('Keyboard interrupt received. Exiting.')
asyncio.run(shutdown(self))
except SystemExit:
self.logger.info('System exit received. Exiting.')
asyncio.run(shutdown(self))
except Exception as e:
self.logger.error(e)
asyncio.run(shutdown(self))
finally:
sys.exit(0)