-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
158 lines (133 loc) · 4.33 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import os
import keep_alive
import discord
from discord.ext import commands
import asyncio
from datetime import datetime
TOKEN = os.environ['DISCORD_TOKEN']
client = commands.Bot(command_prefix=['k*', 'K*'], help_command=None, case_insensitive=True)
THIS_FOLDER = os.path.dirname(os.path.abspath(__file__))
COG_FOLDER = os.path.join(THIS_FOLDER, 'cogs')
# cdDict is a cache that stores a list of the user id's of users who are on cd for a command
cdDict = {
'help': [],
'anime': [],
#'manga': [],
'animeme': [],
'blackjack': [],
'daily': [],
'balance': [],
'_02': [],
'chika': [],
'nam': [],
'ayaya': [],
'pog': [],
'uwu': [],
'sus': [],
'eject': [],
'pfp': [],
'flip': [],
'roll': [],
'invite': [],
'support': [],
'waifu': [],
'cry': [],
'bully': [],
'setprofile': [],
'osu': [],
'serverdropadd': [],
'serverdropremove': [],
'stats': [],
'calcmode': []
}
# Commands
@client.command(hidden=True)
@commands.is_owner()
async def load(ctx, extension):
client.load_extension(f'cogs.{extension}')
@client.command(hidden=True)
@commands.is_owner()
async def unload(ctx, extension):
client.unload_extension(f'cogs.{extension}')
@client.command(hidden=True)
@commands.is_owner()
async def reload(ctx, extension=None):
embed=discord.Embed(
title='Cog Reload Status:',
color=0xff0000
)
status = ''
if extension is None:
# reload all cogs
# cog_unload_event is a custom event to signal a ClientSession must be closed in that cog
client.dispatch('cog_unload_event')
for fileName in os.listdir(COG_FOLDER):
if fileName.endswith('.py'):
extension = fileName[:-3]
try:
client.unload_extension(f'cogs.{extension}')
client.load_extension(f'cogs.{extension}')
status += '✅`{}`\n'.format(extension)
except:
status += '❌`{}`\n'.format(extension)
else:
# reload the specified cog
if extension == 'redditbot' or extension == 'fun':
client.dispatch('cog_unload_event')
try:
client.unload_extension(f'cogs.{extension}')
client.load_extension(f'cogs.{extension}')
status = '✅`{}`'.format(extension)
except:
status = '❌`{}`'.format(extension)
# send report
embed.add_field(name='\u2800', value=status, inline=False)
embed.timestamp = datetime.utcnow()
await ctx.send(embed=embed)
@client.command(hidden=True)
@commands.is_owner()
async def count(ctx):
serverCnt = len(client.guilds)
memberCnt = 0
for guild in client.guilds:
memberCnt += guild.member_count - 1
await ctx.send(f'Watching over {memberCnt} users in {serverCnt} servers.')
embed=discord.Embed(
title='Bot Statistics',
description=f'Chilling with {memberCnt} users\nWatching {serverCnt} servers',
color=0xff0000
)
serverStr = ''
for server in client.guilds:
serverStr += f'{server}\n'
embed.add_field(name='Server List', value=serverStr, inline=False)
await ctx.send(embed=embed)
# begin by loading all cogs
for fileName in os.listdir(COG_FOLDER):
if fileName.endswith('.py'):
client.load_extension(f'cogs.{fileName[:-3]}')
# Events
@client.event
async def on_ready():
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name='k*help'), status=discord.Status.online)
print("KurisuBot is online.")
# Error Handling (Event)
@client.event
async def on_command_error(ctx, error):
#print(f'Error: {error}')
# Cooldown Errors
if isinstance(error, commands.CommandOnCooldown):
#print(ctx.command)
user = ctx.message.author
userId = user.id
com = str(ctx.command).lower()
if userId not in cdDict[com]:
cdDict[com].append(userId)
secondsLeft = round(error.retry_after)
if com != 'daily':
# the cdDict for daily is for the on cooldown error message
await ctx.send(f'{user.mention}, this command is on a `{secondsLeft} second` cooldown')
await asyncio.sleep(secondsLeft)
cdDict[com].remove(userId)
keep_alive.keep_alive()
client.run(TOKEN)