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

format and nextcord

This commit is contained in:
igna 2021-09-07 14:22:54 +00:00
parent 3eaac0148d
commit 84c5276076
3 changed files with 679 additions and 645 deletions

120
bot.py
View file

@ -3,6 +3,8 @@
# © lambda#0987 <lambda@lambda.dance> # © lambda#0987 <lambda@lambda.dance>
# SPDX-License-Identifier: AGPL-3.0-or-later # SPDX-License-Identifier: AGPL-3.0-or-later
import sys
import asyncio
import base64 import base64
import logging import logging
import traceback import traceback
@ -17,74 +19,78 @@ logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO) logger.setLevel(logging.INFO)
# SelectorEventLoop on windows doesn't support subprocesses lol # SelectorEventLoop on windows doesn't support subprocesses lol
import asyncio
import sys
if sys.platform == 'win32': if sys.platform == 'win32':
loop = asyncio.ProactorEventLoop() loop = asyncio.ProactorEventLoop()
asyncio.set_event_loop(loop) asyncio.set_event_loop(loop)
class Bot(Bot): class Bot(Bot):
startup_extensions = ( startup_extensions = (
'cogs.emote', 'cogs.emote',
'cogs.meta', 'cogs.meta',
'bot_bin.debug', 'bot_bin.debug',
'bot_bin.misc', 'bot_bin.misc',
'bot_bin.systemd', 'bot_bin.systemd',
'jishaku', 'jishaku',
) )
def __init__(self, **kwargs): def __init__(self, **kwargs):
with open('data/config.py', encoding='utf-8') as f: with open('data/config.py', encoding='utf-8') as f:
config = eval(f.read(), {}) config = eval(f.read(), {})
super().__init__(config=config, **kwargs) super().__init__(config=config, **kwargs)
# allow use of the bot's user ID before ready() # allow use of the bot's user ID before ready()
token_part0 = self.config['tokens']['discord'].partition('.')[0].encode() token_part0 = self.config['tokens']['discord'].partition('.')[
self.user_id = int(base64.b64decode(token_part0 + b'=' * (3 - len(token_part0) % 3))) 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))
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))
def main(): def main():
import sys import sys
if len(sys.argv) == 1: if len(sys.argv) == 1:
shard_count = None shard_count = None
shard_ids = None shard_ids = None
elif len(sys.argv) < 3: elif len(sys.argv) < 3:
print('Usage:', sys.argv[0], '[<shard count> <hyphen-separated list of shard IDs>]', file=sys.stderr) print(
sys.exit(1) 'Usage:', sys.argv[0], '[<shard count> <hyphen-separated list of shard IDs>]', file=sys.stderr)
else: sys.exit(1)
shard_count = int(sys.argv[1]) else:
shard_ids = list(map(int, sys.argv[2].split('-'))) shard_count = int(sys.argv[1])
shard_ids = list(map(int, sys.argv[2].split('-')))
Bot( Bot(
intents=discord.Intents( intents=nextcord.Intents(
guilds=True, guilds=True,
# we hardly need DM support but it's helpful to be able to run the help/support commands in DMs # we hardly need DM support but it's helpful to be able to run the help/support commands in DMs
messages=True, messages=True,
# we don't need DM reactions because we don't ever paginate in DMs # we don't need DM reactions because we don't ever paginate in DMs
guild_reactions=True, guild_reactions=True,
emojis=True, emojis=True,
# everything else, including `members` and `presences`, is implicitly false. # everything else, including `members` and `presences`, is implicitly false.
), ),
# the least stateful bot you will ever see 😎 # the least stateful bot you will ever see 😎
chunk_guilds_at_startup=False, chunk_guilds_at_startup=False,
member_cache_flags=discord.MemberCacheFlags.none(), member_cache_flags=nextcord.MemberCacheFlags.none(),
# disable message cache # disable message cache
max_messages=None, max_messages=None,
shard_count=shard_count,
shard_ids=shard_ids,
).run()
shard_count=shard_count,
shard_ids=shard_ids,
).run()
if __name__ == '__main__': if __name__ == '__main__':
main() main()

File diff suppressed because it is too large Load diff

View file

@ -1,49 +1,53 @@
{ {
'description': 'description':
'Emote Manager lets you manage custom server emotes effortlessly.\n\n' 'Emote Manager lets you manage custom server emotes effortlessly.\n\n'
'NOTE: Most commands will be unavailable until both you and the bot have the ' 'NOTE: Most commands will be unavailable until both you and the bot have the '
'"Manage Emojis" permission.', '"Manage Emojis" permission.',
# a channel ID to invite people to when they request help with the bot # a channel ID to invite people to when they request help with the bot
# the bot must have Create Instant Invite permissions for this channel # the bot must have Create Instant Invite permissions for this channel
# if set to None, the support command will be disabled # if set to None, the support command will be disabled
'support_server_invite_channel': None, 'support_server_invite_channel': None,
'prefixes': ['em/'], 'prefixes': ['em/'],
'tokens': { 'tokens': {
'discord': 'sek.rit.token', 'discord': 'sek.rit.token',
}, },
'ignore_bots': { 'ignore_bots': {
'default': True, 'default': True,
'overrides': { 'overrides': {
'channels': [ 'channels': [
], ],
'guilds': [ 'guilds': [
], ],
}, },
}, },
'copyright_license_file': 'data/short-license.txt', 'copyright_license_file': 'data/short-license.txt',
'socks5_proxy_url': None, # required for connecting to the EC API over a Tor onion service # required for connecting to the EC API over a Tor onion service
'use_socks5_for_all_connections': False, # whether to use socks5 for all HTTP operations (other than discord.py) 'socks5_proxy_url': None,
'user_agent': 'EmoteManagerBot (https://github.com/iomintz/emote-manager-bot)', # whether to use socks5 for all HTTP operations (other than discord.py)
'ec_api_base_url': None, # set to None to use the default of https://ec.emote.bot/api/v0 'use_socks5_for_all_connections': False,
'http_head_timeout': 10, # timeout for the initial HEAD request before retrieving any images (up this if using Tor) 'user_agent': 'EmoteManagerBot (https://github.com/iomintz/emote-manager-bot)',
'http_read_timeout': 60, # timeout for retrieving an image # set to None to use the default of https://ec.emote.bot/api/v0
'ec_api_base_url': None,
# timeout for the initial HEAD request before retrieving any images (up this if using Tor)
'http_head_timeout': 10,
'http_read_timeout': 60, # timeout for retrieving an image
# emotes that the bot may use to respond to you # emotes that the bot may use to respond to you
# If not provided, the bot will use '❌', '✅' instead. # If not provided, the bot will use '❌', '✅' instead.
# #
# You can obtain these ones from the discordbots.org server under the name "tickNo" and "tickYes" # You can obtain these ones from the discordbots.org server under the name "tickNo" and "tickYes"
# but I uploaded them to my test server # but I uploaded them to my test server
# so that both the staging and the stable versions of the bot can use them # so that both the staging and the stable versions of the bot can use them
'response_emojis': { 'response_emojis': {
'success': { # emotes used to indicate success or failure 'success': { # emotes used to indicate success or failure
False: '<:error:478164511879069707>', False: '<:error:478164511879069707>',
True: '<:success:478164452261363712>' True: '<:success:478164452261363712>'
}, },
}, },
} }