EmoteManager/cogs/meta.py

67 lines
2.2 KiB
Python
Raw Normal View History

2021-07-11 03:03:32 +00:00
# © lambda#0987 <lambda@lambda.dance>
# SPDX-License-Identifier: AGPL-3.0-or-later
2018-07-31 23:02:44 +00:00
2018-08-10 13:01:15 +00:00
import contextlib
2021-09-07 14:47:30 +00:00
import nextcord
from nextcord.ext import commands
2018-07-31 23:02:44 +00:00
2021-03-17 06:06:57 +00:00
import utils
2021-09-07 14:47:30 +00:00
2019-03-14 00:19:14 +00:00
class Meta(commands.Cog):
2021-09-07 14:47:30 +00:00
# TODO does this need to be configurable?
INVITE_DURATION_SECONDS = 60 * 60 * 3
MAX_INVITE_USES = 5
def __init__(self, bot):
self.bot = bot
self.support_channel = None
self.task = bot.loop.create_task(self.cache_invite_channel())
def cog_unload(self):
self.task.cancel()
async def cache_invite_channel(self):
self.support_channel = ch = await self.bot.fetch_channel(self.bot.config['support_server_invite_channel'])
return ch
@commands.command()
async def support(self, context):
"""Directs you to the support server."""
ch = self.support_channel or await self.cache_invite_channel()
reason = f'Created for {context.author} (ID: {context.author.id})'
invite = await ch.create_invite(
max_age=self.INVITE_DURATION_SECONDS,
max_uses=self.MAX_INVITE_USES,
reason=reason,
)
try:
await context.author.send(f'Official support server invite: {invite}')
except nextcord.Forbidden:
with contextlib.suppress(nextcord.HTTPException):
await context.message.add_reaction(utils.SUCCESS_EMOJIS[True])
with contextlib.suppress(nextcord.HTTPException):
await context.send('Unable to send invite in DMs. Please allow DMs from server members.')
else:
try:
await context.message.add_reaction('📬')
except nextcord.HTTPException:
with contextlib.suppress(nextcord.HTTPException):
await context.send('📬')
2021-09-09 11:24:28 +00:00
@commands.command(aliases=['inv']) # https://discordapi.com/permissions.html
2021-09-07 14:47:30 +00:00
async def invite(self, context):
"""Gives you a link to add me to your server."""
2021-09-09 11:24:28 +00:00
await context.send('<%s>' % nextcord.utils.oauth_url(self.bot.user.id, permissions=nextcord.Permissions(permissions=1074056256)))
2021-09-07 14:47:30 +00:00
2020-07-07 00:15:47 +00:00
2018-07-31 23:02:44 +00:00
def setup(bot):
2021-09-07 14:47:30 +00:00
bot.add_cog(Meta(bot))
2018-08-10 13:01:15 +00:00
2021-09-07 14:47:30 +00:00
if not bot.config.get('support_server_invite_channel'):
bot.remove_command('support')