forked from hyamanieu/bot_hic
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.py
76 lines (54 loc) · 2.15 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
import os
import discord
import structlog
from dotenv import load_dotenv
from os.path import join, dirname
from discord.ext import commands
log = structlog.get_logger()
dotenv_path = join(dirname(__file__), '.env')
if os.path.exists(dotenv_path):
log.info('loading environment')
load_dotenv(dotenv_path)
TOKEN = os.getenv('BOT_TOKEN')
BOT_PREFIX = os.getenv('BOT_PREFIX', '!')
log.info('starting bot', prefix=BOT_PREFIX)
intents = discord.Intents.all()
bot = commands.Bot(command_prefix=BOT_PREFIX, case_insensitive=True, intents=intents)
@bot.event
async def on_ready():
log.info('bot logged in', user=bot.user.name)
EXTENSIONS = [
'extensions.utils',
'extensions.help',
'extensions.admin',
'extensions.team',
'extensions.poll',
'extensions.welcome',
'extensions.auto_message'
]
for extension in EXTENSIONS:
log.info('loading extension', name=extension)
await bot.load_extension(extension)
# stream = discord.Streaming(name='Hacking Industry Camp',url='https://www.twitch.tv/alsacedigitale')
# await bot.change_presence(activity=stream)
await post_version_message()
log.info('bot ready')
async def post_version_message():
SCALINGO_APP = os.getenv('APP')
SCALINGO_CONTAINER_VERSION = os.getenv('CONTAINER_VERSION')
if SCALINGO_CONTAINER_VERSION and SCALINGO_APP:
await bot_log_message(f"{SCALINGO_APP} a démarré en version {SCALINGO_CONTAINER_VERSION}")
async def bot_log_message(*args, **kwargs):
BOT_LOG_CHANNEL_ID = os.getenv('BOT_LOG_CHANNEL_ID')
try:
if BOT_LOG_CHANNEL_ID:
BOT_LOG_CHANNEL_ID = int(BOT_LOG_CHANNEL_ID)
bot_log_channel = discord.utils.get(bot.get_all_channels(), id=BOT_LOG_CHANNEL_ID)
if bot_log_channel:
await bot_log_channel.send(*args, **kwargs)
else:
log.warning(f'Could not find bot log channel with id {BOT_LOG_CHANNEL_ID}')
except Exception as e:
log.error('Could not post message to bot log channel', exc_info=e)
if __name__ == "__main__":
bot.run(TOKEN, reconnect=True, root_logger=structlog.get_logger())