-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.py
executable file
·85 lines (66 loc) · 2.55 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
#!/usr/bin/env python
"""TVP bot discord."""
from datetime import datetime
from nextcord.ext import commands, tasks
from itertools import cycle
import config
import nextcord
import sqlite3
import os
import sys
bot = commands.Bot(command_prefix=config.PREFIX,
intents=nextcord.Intents.all())
status = cycle(['.help', 'https://www.thevenusproject.com',
'https://designing-the-future.org'])
@bot.event
async def on_ready():
change_status.start()
current_time = datetime.now().strftime("%H:%M:%S")
print(f'✅ {current_time} Бот запущен')
global base, cur
base = sqlite3.connect(config.DB_NAME)
cur = base.cursor()
if base:
current_time = datetime.now().strftime("%H:%M:%S")
print(f'✅ {current_time} DB connected')
@bot.command(aliases=['l'])
@commands.has_permissions(administrator=True)
async def load(ctx, ext):
"""Подключает модуль к боту."""
bot.load_extension(f'cogs.{ext}')
current_time = datetime.now().strftime("%H:%M:%S")
print(f'✅ {current_time} {ext} loaded')
await ctx.send(f'✅ {ctx.author.mention} `{ext}` is loaded')
@bot.command(aliases=['u'])
@commands.has_permissions(administrator=True)
async def unload(ctx, ext):
"""Отключает модуль от бота."""
bot.unload_extension(f'cogs.{ext}')
current_time = datetime.now().strftime("%H:%M:%S")
print(f'✅ {current_time} {ext} unloaded')
await ctx.send(f'✅ {ctx.author.mention} `{ext}` is unloaded')
@bot.command(aliases=['r'])
@commands.has_permissions(administrator=True)
async def reload(ctx, ext):
"""Перезагружает модуль бота."""
bot.unload_extension(f'cogs.{ext}')
bot.load_extension(f'cogs.{ext}')
current_time = datetime.now().strftime("%H:%M:%S")
print(f'✅ {current_time} {ext} reloaded')
await ctx.send(f'✅ {ctx.author.mention} `{ext}` is reloaded')
for filename in os.listdir('./cogs'):
if filename.endswith('.py'):
bot.load_extension(f'cogs.{filename[:-3]}')
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.errors.MissingPermissions):
msg = f'Sorry {ctx.message.author.mention}, you do not have permissions to do that!'
await ctx.send(msg)
print(ctx.command.name + " was invoked incorrectly.")
print(error)
@tasks.loop(seconds=30)
async def change_status():
await bot.change_presence(activity=nextcord.Game(next(status)))
bot.run(config.TOKEN)
# Вывод логов бота в консоль heroku
sys.stdout.flush()