2018-07-30 03:48:58 +00:00
|
|
|
|
#!/usr/bin/env python3
|
2020-05-12 23:55:08 +00:00
|
|
|
|
|
|
|
|
|
# © 2018–2020 io mintz <io@mintz.cc>
|
|
|
|
|
#
|
|
|
|
|
# Emote Manager is free software: you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# Emote Manager is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
# along with Emote Manager. If not, see <https://www.gnu.org/licenses/>.
|
2018-07-30 03:48:58 +00:00
|
|
|
|
|
2020-06-03 21:21:41 +00:00
|
|
|
|
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
|
|
|
|
|
2018-07-30 03:48:58 +00:00
|
|
|
|
import discord
|
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)
|
|
|
|
|
|
2019-09-05 22:39:46 +00:00
|
|
|
|
class Bot(Bot):
|
2019-08-30 21:46:35 +00:00
|
|
|
|
startup_extensions = (
|
|
|
|
|
'cogs.emote',
|
|
|
|
|
'cogs.meta',
|
2020-06-02 00:51:06 +00:00
|
|
|
|
'cogs.stats',
|
2019-09-05 22:39:46 +00:00
|
|
|
|
'bot_bin.debug',
|
|
|
|
|
'bot_bin.misc',
|
2019-08-30 21:46:35 +00:00
|
|
|
|
'jishaku',
|
|
|
|
|
)
|
|
|
|
|
|
2018-07-30 04:34:27 +00:00
|
|
|
|
def __init__(self, **kwargs):
|
2020-05-13 00:12:56 +00:00
|
|
|
|
with open('data/config.py') as f:
|
2019-08-30 21:46:35 +00:00
|
|
|
|
config = eval(f.read(), {})
|
2018-08-01 02:05:23 +00:00
|
|
|
|
|
2019-08-30 21:46:35 +00:00
|
|
|
|
super().__init__(config=config, **kwargs)
|
2020-06-03 21:21:41 +00:00
|
|
|
|
# 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)))
|
2018-08-22 15:27:35 +00:00
|
|
|
|
|
2019-09-19 21:14:18 +00:00
|
|
|
|
def process_config(self):
|
2018-08-22 15:27:35 +00:00
|
|
|
|
"""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.
|
|
|
|
|
"""
|
2019-09-19 21:14:18 +00:00
|
|
|
|
super().process_config()
|
2018-08-22 15:27:35 +00:00
|
|
|
|
import utils.misc
|
|
|
|
|
default = ('❌', '✅')
|
|
|
|
|
utils.SUCCESS_EMOJIS = utils.misc.SUCCESS_EMOJIS = (
|
|
|
|
|
self.config.get('response_emojis', {}).get('success', default))
|
|
|
|
|
|
2020-06-02 03:38:33 +00:00
|
|
|
|
def load_extensions(self):
|
|
|
|
|
super().load_extensions()
|
|
|
|
|
if self.config.get('systemd'):
|
|
|
|
|
self.load_extension('cogs.systemd')
|
|
|
|
|
|
2020-06-02 00:51:06 +00:00
|
|
|
|
def main():
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
kwargs = dict(guild_subscriptions=False, request_offline_members=False)
|
|
|
|
|
|
2020-06-19 03:56:27 +00:00
|
|
|
|
if len(sys.argv) < 3:
|
|
|
|
|
print('Usage:', sys.argv[0], '<shard count> <hyphen-separated list of shard IDs>', file=sys.stderr)
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
shard_count = int(sys.argv[1])
|
|
|
|
|
shard_ids = list(map(int, sys.argv[2].split('-')))
|
|
|
|
|
Bot(**kwargs, 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__':
|
2020-06-02 00:51:06 +00:00
|
|
|
|
main()
|