This commit is contained in:
igna 2021-09-07 14:47:30 +00:00
parent 84c5276076
commit 35f019a490
3 changed files with 101546 additions and 101544 deletions

View File

@ -127,7 +127,7 @@ class Emotes(commands.Cog):
You can use it like this:
`add :thonkang:` (if you already have that emote)
`add rollsafe https://image.noelshack.com/fichiers/2017/06/1486495269-rollsafe.png`
`add speedtest <https://cdn.nextcordapp.com/emojis/379127000398430219.png>`
`add speedtest <https://cdn.discord.com/emojis/379127000398430219.png>`
With a file attachment:
`add name` will upload a new emote using the first attachment as the image and call it `name`
@ -204,7 +204,7 @@ class Emotes(commands.Cog):
@staticmethod
def format_emote_filename(filename):
"""format a filename to an emote name as nextcord does when you upload an emote image"""
"""format a filename to an emote name as discord does when you upload an emote image"""
left, sep, right = posixpath.splitext(filename)[0].rpartition('-')
return (left or right).replace(' ', '')
@ -270,7 +270,7 @@ class Emotes(commands.Cog):
name = f'{name}.{"gif" if emote.animated else "png"}'
# place some level of trust on nextcord's CDN to actually give us images
# place some level of trust on discord's CDN to actually give us images
data = await self.fetch_safe(str(emote.url), validate_headers=False)
if type(data) is str: # error case
await context.send(f'{emote}: {data}')

View File

@ -3,72 +3,74 @@
import contextlib
import discord
from discord.ext import commands
import nextcord
from nextcord.ext import commands
import utils
class Meta(commands.Cog):
# TODO does this need to be configurable?
INVITE_DURATION_SECONDS = 60 * 60 * 3
MAX_INVITE_USES = 5
# 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 __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()
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
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()
@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,
)
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 discord.Forbidden:
with contextlib.suppress(discord.HTTPException):
await context.message.add_reaction(utils.SUCCESS_EMOJIS[True])
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('📬')
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('📬')
@commands.command(aliases=['inv'])
async def invite(self, context):
"""Gives you a link to add me to your server."""
permissions = discord.Permissions()
permissions.update(**dict.fromkeys((
'read_messages',
'send_messages',
'add_reactions',
'external_emojis',
'manage_emojis',
'embed_links',
'attach_files',
), True))
@commands.command(aliases=['inv'])
async def invite(self, context):
"""Gives you a link to add me to your server."""
permissions = nextcord.Permissions()
permissions.update(**dict.fromkeys((
'read_messages',
'send_messages',
'add_reactions',
'external_emojis',
'manage_emojis',
'embed_links',
'attach_files',
), True))
await context.send('<%s>' % nextcord.utils.oauth_url(self.bot.user.id, permissions))
await context.send('<%s>' % discord.utils.oauth_url(self.bot.user.id, permissions))
def setup(bot):
bot.add_cog(Meta(bot))
bot.add_cog(Meta(bot))
if not bot.config.get('support_server_invite_channel'):
bot.remove_command('support')
if not bot.config.get('support_server_invite_channel'):
bot.remove_command('support')

File diff suppressed because it is too large Load Diff