make the support command dynamically create invites to reduce raids
This commit is contained in:
parent
05bcf4a412
commit
7dd40ce0e5
26
cogs/meta.py
26
cogs/meta.py
|
@ -7,6 +7,10 @@ import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
|
||||||
class Meta(commands.Cog):
|
class Meta(commands.Cog):
|
||||||
|
# TODO does this need to be configurable?
|
||||||
|
INVITE_DURATION_SECONDS = 60 * 60 * 3
|
||||||
|
MAX_INVITE_USES = 5
|
||||||
|
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
|
@ -28,17 +32,29 @@ class Meta(commands.Cog):
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def support(self, context):
|
async def support(self, context):
|
||||||
"""Directs you to the support server."""
|
"""Directs you to the support server."""
|
||||||
|
ch = self.bot.get_channel(self.bot.config['support_server_invite_channel'])
|
||||||
|
if ch is None:
|
||||||
|
await context.send('This command is temporarily unavailable. Try again later?')
|
||||||
|
return
|
||||||
|
|
||||||
|
invite = await ch.create_invite(max_age=self.INVITE_DURATION_SECONDS, max_uses=self.MAX_INVITE_USES)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await context.author.send(self.bot.config['support_server_invite'])
|
await context.author.send(f'Official support server invite: {invite}')
|
||||||
with contextlib.suppress(discord.HTTPException):
|
|
||||||
await context.message.add_reaction('📬') # TODO make this emoji configurable too
|
|
||||||
except discord.Forbidden:
|
except discord.Forbidden:
|
||||||
with contextlib.suppress(discord.HTTPException):
|
with contextlib.suppress(discord.HTTPException):
|
||||||
await context.message.add_reaction(utils.SUCCESS_EMOJIS[True])
|
await context.message.add_reaction(utils.SUCCESS_EMOJIS[True])
|
||||||
await context.send('Unable to send invite in DMs. Please allow DMs from server members.')
|
with contextlib.suppress(discord.HTTPException):
|
||||||
|
await context.send('Unable to send invite in DMs. Please allow DMs from server members.')
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
await context.message.add_reaction('📬')
|
||||||
|
except discord.HTTPException:
|
||||||
|
with contextlib.suppress(discord.HTTPException):
|
||||||
|
await context.send('📬')
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(Meta(bot))
|
bot.add_cog(Meta(bot))
|
||||||
|
|
||||||
if not bot.config.get('support_server_invite'):
|
if not bot.config.get('support_server_invite_channel'):
|
||||||
bot.remove_command('support')
|
bot.remove_command('support')
|
||||||
|
|
|
@ -4,7 +4,10 @@
|
||||||
'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.',
|
||||||
|
|
||||||
'support_server_invite': 'https://discord.gg/some-invite',
|
# 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
|
||||||
|
# if set to None, the support command will be disabled
|
||||||
|
'support_server_invite_channel': None,
|
||||||
|
|
||||||
'cogs': (
|
'cogs': (
|
||||||
'cogs.emote',
|
'cogs.emote',
|
||||||
|
@ -27,7 +30,7 @@
|
||||||
'user_agent': 'EmoteManagerBot (https://github.com/bmintz/emote-manager-bot)',
|
'user_agent': 'EmoteManagerBot (https://github.com/bmintz/emote-manager-bot)',
|
||||||
|
|
||||||
# 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
|
||||||
|
|
Loading…
Reference in New Issue