1
0
Fork 0
mirror of https://github.com/uhIgnacio/EmoteManager.git synced 2024-08-15 02:23:13 +00:00
EmoteManager/bot.py

97 lines
2.8 KiB
Python
Raw Normal View History

2018-07-30 03:48:58 +00:00
#!/usr/bin/env python3
2020-05-12 23:55:08 +00:00
2021-07-11 03:03:32 +00:00
# © lambda#0987 <lambda@lambda.dance>
# SPDX-License-Identifier: AGPL-3.0-or-later
2018-07-30 03:48:58 +00:00
2021-09-07 14:22:54 +00:00
import sys
import asyncio
import base64
2018-07-30 05:15:38 +00:00
import logging
2018-07-30 05:26:06 +00:00
import traceback
2018-07-30 05:15:38 +00:00
2021-09-07 14:15:53 +00:00
import nextcord
2019-09-05 22:39:46 +00:00
from bot_bin.bot import Bot
2018-07-30 03:48:58 +00:00
from discord.ext import commands
2018-07-30 05:15:38 +00:00
logging.basicConfig(level=logging.WARNING)
2019-06-04 03:08:44 +00:00
logging.getLogger('discord').setLevel(logging.INFO)
2018-07-30 05:15:38 +00:00
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
2021-05-19 21:26:51 +00:00
# SelectorEventLoop on windows doesn't support subprocesses lol
if sys.platform == 'win32':
2021-09-07 14:22:54 +00:00
loop = asyncio.ProactorEventLoop()
asyncio.set_event_loop(loop)
2021-05-19 21:26:51 +00:00
2019-09-05 22:39:46 +00:00
class Bot(Bot):
2021-09-07 14:22:54 +00:00
startup_extensions = (
'cogs.emote',
'cogs.meta',
'bot_bin.debug',
'bot_bin.misc',
'bot_bin.systemd',
'jishaku',
)
def __init__(self, **kwargs):
with open('data/config.py', encoding='utf-8') as f:
config = eval(f.read(), {})
super().__init__(config=config, **kwargs)
# allow use of the bot's user ID before ready()
token_part0 = self.config['tokens']['discord'].partition('.')[
0].encode()
self.user_id = int(base64.b64decode(
token_part0 + b'=' * (3 - len(token_part0) % 3)))
def process_config(self):
"""Load the emojis from the config to be used when a command fails or succeeds
We do it this way so that they can be used anywhere instead of requiring a bot instance.
"""
super().process_config()
import utils.misc
default = ('', '')
utils.SUCCESS_EMOJIS = utils.misc.SUCCESS_EMOJIS = (
self.config.get('response_emojis', {}).get('success', default))
2018-08-22 15:27:35 +00:00
2020-06-02 00:51:06 +00:00
def main():
2021-09-07 14:22:54 +00:00
import sys
if len(sys.argv) == 1:
shard_count = None
shard_ids = None
elif len(sys.argv) < 3:
print(
'Usage:', sys.argv[0], '[<shard count> <hyphen-separated list of shard IDs>]', file=sys.stderr)
sys.exit(1)
else:
shard_count = int(sys.argv[1])
shard_ids = list(map(int, sys.argv[2].split('-')))
Bot(
intents=nextcord.Intents(
guilds=True,
# we hardly need DM support but it's helpful to be able to run the help/support commands in DMs
messages=True,
# we don't need DM reactions because we don't ever paginate in DMs
guild_reactions=True,
emojis=True,
# everything else, including `members` and `presences`, is implicitly false.
),
# the least stateful bot you will ever see 😎
chunk_guilds_at_startup=False,
member_cache_flags=nextcord.MemberCacheFlags.none(),
# disable message cache
max_messages=None,
shard_count=shard_count,
shard_ids=shard_ids,
).run()
2020-06-02 00:51:06 +00:00
2018-07-30 03:48:58 +00:00
if __name__ == '__main__':
2021-09-07 14:22:54 +00:00
main()