mirror of
https://github.com/nexy7574/LCC-bot.git
synced 2024-09-19 18:16:34 +01:00
be less insulting
This commit is contained in:
parent
d330faab4d
commit
8951a2cc97
3 changed files with 55 additions and 8 deletions
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="dataSourceStorageLocal" created-in="PY-223.8836.43">
|
||||
<component name="dataSourceStorageLocal" created-in="PY-231.8770.66">
|
||||
<data-source name="main" uuid="28efee07-d306-4126-bf69-01008b4887e2">
|
||||
<database-info product="SQLite" version="3.39.2" jdbc-version="2.1" driver-name="SQLite JDBC" driver-version="3.39.2.0" dbms="SQLITE" exact-version="3.39.2" exact-driver-version="3.39">
|
||||
<identifier-quote-string>"</identifier-quote-string>
|
||||
|
|
|
@ -340,6 +340,15 @@ class Events(commands.Cog):
|
|||
await message.reply(file=file)
|
||||
if message.reference is not None and message.reference.cached_message is not None:
|
||||
if message.content.lower().strip() in ("what", "what?", "huh", "huh?", "?"):
|
||||
if f"{message.author.mention} said '" * 3 in message.reference.cached_message.content:
|
||||
await message.reply("You really are deaf aren't you.")
|
||||
elif not message.reference.cached_message.content:
|
||||
await message.reply(
|
||||
"Maybe *I* need to get my hearing checked, I have no idea what {} said.".format(
|
||||
message.reference.cached_message.author.mention
|
||||
)
|
||||
)
|
||||
else:
|
||||
text = "{0.author.mention} said %r, you deaf sod.".format(
|
||||
message.reference.cached_message
|
||||
)
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
import asyncio
|
||||
import textwrap
|
||||
import io
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import httpx
|
||||
from typing import Tuple
|
||||
|
||||
import discord
|
||||
|
@ -12,6 +16,37 @@ class StarBoardCog(commands.Cog):
|
|||
self.bot = bot
|
||||
self.lock = asyncio.Lock()
|
||||
|
||||
@staticmethod
|
||||
async def archive_image( starboard_message: discord.Message):
|
||||
async with httpx.AsyncClient(
|
||||
headers={
|
||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.69; Win64; x64) "
|
||||
"LCC-Bot-Scraper/0 (https://github.com/EEKIM10/LCC-bot)"
|
||||
}
|
||||
) as session:
|
||||
image = starboard_message.embeds[0].image
|
||||
if image and image.url:
|
||||
parsed = urlparse(image.url)
|
||||
filename = parsed.path.split("/")[-1]
|
||||
try:
|
||||
r = await session.get(image.url)
|
||||
except httpx.HTTPError:
|
||||
if image.proxy_url:
|
||||
r = await session.get(image.proxy_url)
|
||||
else:
|
||||
return
|
||||
|
||||
FS_LIMIT = starboard_message.guild.filesize_limit
|
||||
# if FS_LIMIT is 8mb, its actually 25MB
|
||||
if FS_LIMIT == 8 * 1024 * 1024:
|
||||
FS_LIMIT = 25 * 1024 * 1024
|
||||
if r.status_code == 200 and len(r.content) < FS_LIMIT:
|
||||
file = io.BytesIO(r.content)
|
||||
file.seek(0)
|
||||
embed = starboard_message.embeds[0].copy()
|
||||
embed.set_image(url="attachment://" + filename)
|
||||
await starboard_message.edit(embed=embed, file=discord.File(file, filename=filename))
|
||||
|
||||
async def generate_starboard_embed(self, message: discord.Message) -> discord.Embed:
|
||||
star_count = [x for x in message.reactions if str(x.emoji) == "\N{white medium star}"]
|
||||
if not star_count:
|
||||
|
@ -112,6 +147,7 @@ class StarBoardCog(commands.Cog):
|
|||
if channel and channel.can_send():
|
||||
msg = await channel.send(embed=await self.generate_starboard_embed(message))
|
||||
await entry.update(starboard_message=msg.id)
|
||||
self.bot.loop.create_task(self.archive_image(msg))
|
||||
else:
|
||||
await entry.delete()
|
||||
return
|
||||
|
@ -125,10 +161,12 @@ class StarBoardCog(commands.Cog):
|
|||
except discord.NotFound:
|
||||
msg = await channel.send(embeds=embeds)
|
||||
await entry.update(starboard_message=msg.id)
|
||||
self.bot.loop.create_task(self.archive_image(msg))
|
||||
except discord.HTTPException:
|
||||
pass
|
||||
else:
|
||||
await msg.edit(embeds=embeds)
|
||||
self.bot.loop.create_task(self.archive_image(msg))
|
||||
|
||||
@commands.message_command(name="Starboard Info")
|
||||
@discord.guild_only()
|
||||
|
|
Loading…
Reference in a new issue