-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathbot.py
executable file
·141 lines (127 loc) · 5.62 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
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
from discord.ext import commands
import logging, traceback, sys, discord
from datetime import date
from collections import Counter
import json
import datetime
import config
log = logging.getLogger('NekoBot')
log.setLevel(logging.INFO)
date = f"{date.today().timetuple()[0]}_{date.today().timetuple()[1]}_{date.today().timetuple()[2]}"
handler = logging.FileHandler(filename=f'NekoBot_{date}.log', encoding='utf-8', mode='w')
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
log.addHandler(handler)
startup_extensions = {
'modules.audio',
'modules.cardgame',
'modules.chatbot',
'modules.discordbots',
'modules.donator',
'modules.eco',
'modules.fun',
'modules.games',
'modules.general',
'modules.imgwelcome',
'modules.marriage',
'modules.mod',
'modules.nsfw',
'modules.reactions'
}
def _prefix_callable(bot, msg):
prefixes = ['n!', 'N!']
return commands.when_mentioned_or(*prefixes)(bot, msg)
class NekoBot(commands.AutoShardedBot):
def __init__(self):
super().__init__(command_prefix=_prefix_callable, #commands.when_mentioned_or('n!')
description="NekoBot",
pm_help=None,
shard_count=10,
shard_id=0,
status=discord.Status.dnd,
max_messages=5000,
help_attrs={'hidden': True})
self.counter = Counter()
for extension in startup_extensions:
try:
self.load_extension(extension)
except:
print("Failed to load {}.".format(extension), file=sys.stderr)
traceback.print_exc()
async def send_cmd_help(self, ctx):
if ctx.invoked_subcommand:
pages = await self.formatter.format_help_for(ctx, ctx.invoked_subcommand)
for page in pages:
await ctx.send(page)
else:
pages = await self.formatter.format_help_for(ctx, ctx.command)
for page in pages:
await ctx.send(page)
async def on_command_error(self, ctx, exception):
channel = self.get_channel(431987399581499403)
if isinstance(exception, commands.NoPrivateMessage):
return
elif isinstance(exception, commands.DisabledCommand):
return
elif isinstance(exception, discord.Forbidden):
return
elif isinstance(exception, discord.NotFound):
return
elif isinstance(exception, commands.CommandInvokeError):
em = discord.Embed(color=0xDEADBF,
title="Error",
description=f"Error in command {ctx.command.qualified_name}, "
f"[Support Server](https://discord.gg/q98qeYN)")
await channel.send(embed=discord.Embed(color=0xff6f3f,
title="Command Error").add_field(
name=f"Command: {ctx.command.qualified_name}",
value=f"```py\n{exception}```"))
await ctx.send(embed=em)
print('In {}:'.format(ctx.command.qualified_name), file=sys.stderr)
traceback.print_tb(exception.original.__traceback__)
print('{}: {}'.format(exception.original.__class__.__name__, exception.original), file=sys.stderr)
elif isinstance(exception, commands.BadArgument):
await self.send_cmd_help(ctx)
elif isinstance(exception, commands.MissingRequiredArgument):
await self.send_cmd_help(ctx)
elif isinstance(exception, commands.CheckFailure):
await ctx.send('You are not allowed to use that command.', delete_after=5)
elif isinstance(exception, commands.CommandOnCooldown):
await ctx.send('Command is on cooldown... {:.2f}s left'.format(exception.retry_after), delete_after=5)
elif isinstance(exception, commands.CommandNotFound):
return
else:
log.exception(type(exception).__name__, exc_info=exception)
await channel.send(embed=discord.Embed(color=0xff6f3f, title="Unknown Error", description=f"{exception}"))
async def on_message(self, message):
self.counter["messages_read"] += 1
if message.author.bot:
return
await self.process_commands(message)
async def close(self):
await super().close()
await self.close()
async def on_shard_ready(self, shard_id):
if not hasattr(self, 'uptime'):
self.uptime = datetime.datetime.utcnow()
print(f"Shard {shard_id} Connected...")
async def on_ready(self):
print(" _ _ _ \n"
" | | | | | | \n"
" _ __ ___| | _____ | |__ ___ | |_ \n"
" | '_ \ / _ \ |/ / _ \| '_ \ / _ \| __|\n"
" | | | | __/ < (_) | |_) | (_) | |_ \n"
" |_| |_|\___|_|\_\___/|_.__/ \___/ \__|\n"
" \n"
" ")
print("Ready OwO")
print(f"Shards: {self.shard_count}")
print(f"Servers {len(self.guilds)}")
print(f"Users {len(set(self.get_all_members()))}")
await self.change_presence(status=discord.Status.idle)
def run(self):
super().run(config.token)
def run_bot():
bot = NekoBot()
bot.run()
if __name__ == '__main__':
run_bot()