2023-03-09 22:01:10 +00:00
|
|
|
import json
|
2023-04-05 10:10:18 +00:00
|
|
|
import os
|
2023-03-09 22:01:10 +00:00
|
|
|
|
|
|
|
import discord
|
2019-03-02 23:40:43 +00:00
|
|
|
from discord.ext import commands
|
|
|
|
from discord.ext.commands import Cog
|
2023-03-09 22:01:10 +00:00
|
|
|
|
|
|
|
from robocop_ng.helpers.checks import check_if_collaborator
|
2024-03-02 08:56:41 +00:00
|
|
|
from robocop_ng.helpers.invites import add_invite
|
2019-03-02 23:40:43 +00:00
|
|
|
|
2020-04-20 22:05:32 +00:00
|
|
|
|
2019-03-02 23:40:43 +00:00
|
|
|
class Invites(Cog):
|
|
|
|
def __init__(self, bot):
|
|
|
|
self.bot = bot
|
|
|
|
|
|
|
|
@commands.command()
|
|
|
|
@commands.guild_only()
|
|
|
|
@commands.check(check_if_collaborator)
|
|
|
|
async def invite(self, ctx):
|
2023-04-05 10:10:18 +00:00
|
|
|
welcome_channel = self.bot.get_channel(self.bot.config.welcome_channel)
|
2019-03-02 23:40:43 +00:00
|
|
|
author = ctx.message.author
|
2019-03-03 14:12:30 +00:00
|
|
|
reason = f"Created by {str(author)} ({author.id})"
|
2020-04-20 22:05:32 +00:00
|
|
|
invite = await welcome_channel.create_invite(
|
|
|
|
max_age=0, max_uses=1, temporary=True, unique=True, reason=reason
|
|
|
|
)
|
2019-03-03 14:12:30 +00:00
|
|
|
|
2024-03-02 08:56:41 +00:00
|
|
|
add_invite(self.bot, invite.id, invite.url, 1, invite.code)
|
2019-03-02 23:40:43 +00:00
|
|
|
|
|
|
|
await ctx.message.add_reaction("🆗")
|
|
|
|
try:
|
|
|
|
await ctx.author.send(f"Created single-use invite {invite.url}")
|
|
|
|
except discord.errors.Forbidden:
|
2020-04-20 22:05:32 +00:00
|
|
|
await ctx.send(
|
|
|
|
f"{ctx.author.mention} I could not send you the \
|
|
|
|
invite. Send me a DM so I can reply to you."
|
|
|
|
)
|
2019-03-02 23:40:43 +00:00
|
|
|
|
|
|
|
|
2022-05-24 18:35:42 +00:00
|
|
|
async def setup(bot):
|
|
|
|
await bot.add_cog(Invites(bot))
|