This repository has been archived by the owner on Oct 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
134 lines (96 loc) · 3.25 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
import logging
import discord
from discord.ext import commands
import helpers.tokens as t
from helpers import descriptions as desc, checks, settings
bot = commands.Bot(command_prefix='!', description=desc.main, pm_help=True)
@bot.event
async def on_ready():
log.info(bot.user.name + ' logged in')
await bot.change_status(game=discord.Game(name=settings.now_playing))
@bot.event
async def on_message(message):
if message.author is bot.user:
return
swear = bot.get_cog('Swear')
spam = bot.get_cog('SpamFilter')
if swear is not None:
await swear.message(message)
if spam is not None:
await spam.message(message)
await bot.process_commands(message)
@bot.event
async def on_command(command, ctx):
if ctx.subcommand_passed is not None:
cmd = "{0.name} {1.subcommand_passed}".format(command, ctx)
else:
cmd = command.name
try:
log.info("#{1.message.channel.name}: {1.message.author.name} called `!{0}`".format(cmd, ctx))
except AttributeError:
log.info("PM: {1.message.author.name} called `!{0}`".format(cmd, ctx))
stats = bot.get_cog('Stats')
if stats is not None:
await stats.on_command_p(command.name)
@bot.command(hidden=True)
@checks.is_dev()
async def reload(*, module: str):
"""
Reloads a module.
:param module: Module to be reloaded, cogs.general -> from cogs folder general module
"""
module = module.strip()
try:
bot.unload_extension(module)
bot.load_extension(module)
except Exception as e:
await bot.say('\U0001f52b')
await bot.say('{}: {}'.format(type(e).__name__, e))
else:
await bot.say('\U0001f44c')
@bot.command(hidden=True)
@checks.is_dev()
async def load(*, module: str):
"""
Loads a module.
:param module: Module to be loaded, cogs.general -> from cogs folder general module
"""
module = module.strip()
try:
bot.load_extension(module)
except Exception as e:
await bot.say('\U0001f52b')
await bot.say('{}: {}'.format(type(e).__name__, e))
else:
await bot.say('\U0001f44c')
@bot.command(hidden=True)
@checks.is_dev()
async def unload(*, module: str):
"""Unloads a module."""
module = module.strip()
try:
bot.unload_extension(module)
except Exception as e:
await bot.say('\U0001f52b')
await bot.say('{}: {}'.format(type(e).__name__, e))
else:
await bot.say('\U0001f44c')
if __name__ == '__main__':
log = logging.getLogger()
log.setLevel(logging.INFO)
console = logging.StreamHandler()
log_file = logging.FileHandler('log.log', 'w', 'utf-8')
console.setLevel(logging.INFO)
log_file.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s', "%d.%m.%Y %H:%M:%S")
console.setFormatter(formatter)
log_file.setFormatter(formatter)
log.addHandler(log_file)
log.addHandler(console)
for extension in settings.extensions:
try:
bot.load_extension(extension)
log.info('{} loaded'.format(extension))
except Exception as e:
log.warning('Failed to load extension {}\n{}: {}'.format(extension, type(e).__name__, e))
bot.run(t.token)