Skip to content

Commit

Permalink
added "split_messages" function
Browse files Browse the repository at this point in the history
heartbeat now supports multiple owners
"emoji_id" command added

bugfixes
  • Loading branch information
TheCataliasTNT2k committed Nov 26, 2023
1 parent ad666d9 commit 2e7ca15
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 59 deletions.
39 changes: 10 additions & 29 deletions general/news/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from PyDrocsid.command import add_reactions, optional_permissions, reply
from PyDrocsid.database import db, select
from PyDrocsid.discohook import DiscoHookError, MessageContent, load_discohook_link
from PyDrocsid.embeds import send_long_embed
from PyDrocsid.embeds import send_long_embed, split_message
from PyDrocsid.translations import t
from PyDrocsid.util import ZERO_WIDTH_WHITESPACE, RoleListConverter, attachment_to_file, check_message_send_permissions

Expand Down Expand Up @@ -296,12 +296,13 @@ async def news_send(self, ctx: Context, channel: TextChannel, *, discohook_url:

try:
for message in messages:
content: str | None = message.content
if content:
content = content.replace("@everyone", f"@{ZERO_WIDTH_WHITESPACE}everyone").replace(
"@here", f"@{ZERO_WIDTH_WHITESPACE}here"
)
await channel.send(content=content, embeds=message.embeds)
for msg in split_message(message.embeds, message.content):
content: str | None = msg[0]
if content:
content = content.replace("@everyone", f"@{ZERO_WIDTH_WHITESPACE}everyone").replace(
"@here", f"@{ZERO_WIDTH_WHITESPACE}here"
)
await ctx.author.send(content=content, embeds=msg[1])
if ctx.message.attachments:
await channel.send(
files=[await attachment_to_file(attachment) for attachment in ctx.message.attachments]
Expand Down Expand Up @@ -352,8 +353,8 @@ async def news_test(self, ctx: Context, *, discohook_url: str):

try:
for message in messages:
content: str | None = message.content
await ctx.author.send(content=content, embeds=message.embeds, allowed_mentions=AllowedMentions.none())
for msg in split_message(message.embeds, message.content):
await ctx.author.send(content=msg[0], embeds=msg[1])
if ctx.message.attachments:
await ctx.author.send(
files=[await attachment_to_file(attachment) for attachment in ctx.message.attachments],
Expand All @@ -365,23 +366,3 @@ async def news_test(self, ctx: Context, *, discohook_url: str):
raise CommandError(t.msg_could_not_be_sent_dm)

await add_reactions(ctx.message, "white_check_mark")

"""
files = [await attachment_to_file(attachment) for attachment in ctx.message.attachments]
content = ""
send_embed = Embed(title=t.news, description=message, colour=Colors.News)
send_embed.set_footer(text=t.sent_by(ctx.author, ctx.author.id), icon_url=ctx.author.display_avatar.url)
send_embed.colour = color if color is not None else Colors.News
if files and any(files[0].filename.lower().endswith(ext) for ext in ["jpg", "jpeg", "png", "gif"]):
send_embed.set_image(url="attachment://" + files[0].filename)
try:
await channel.send(content=content, embed=send_embed, files=files)
except (HTTPException, Forbidden):
raise CommandError(t.msg_could_not_be_sent)
else:
embed.description = t.msg_sent
await reply(ctx, embed=embed)"""
9 changes: 7 additions & 2 deletions general/utils/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
from random import random
from typing import Optional, Union

from discord import Embed, Member, User
from discord import Embed, Member, User, Emoji
from discord.ext import commands
from discord.ext.commands import CommandError, Context, guild_only, max_concurrency
from discord.utils import format_dt, snowflake_time

from PyDrocsid.async_thread import run_in_thread
from PyDrocsid.cog import Cog
from PyDrocsid.command import docs, reply
from PyDrocsid.converter import Color, UserMemberConverter
from PyDrocsid.converter import Color, UserMemberConverter, EmojiConverter
from PyDrocsid.translations import t
from PyDrocsid.util import measure_latency

Expand Down Expand Up @@ -103,3 +103,8 @@ async def suggest_role_color(self, ctx: Context, *avoid: Color):
embed = Embed(title="#" + color, color=int(color, 16))
embed.set_image(url=f"https://singlecolorimage.com/get/{color}/400x100")
await reply(ctx, embed=embed)

@commands.command()
async def emoji_id(self, ctx: Context, emoji: EmojiConverter):
emoji: Emoji
await ctx.reply(content=str(emoji.id))
50 changes: 26 additions & 24 deletions information/heartbeat/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from PyDrocsid.cog import Cog
from PyDrocsid.config import Config
from PyDrocsid.translations import t
from PyDrocsid.util import get_owner, send_editable_log
from PyDrocsid.util import send_editable_log, get_owners

from ...contributor import Contributor

Expand All @@ -28,44 +28,46 @@ def __init__(self):

@tasks.loop(seconds=20)
async def status_loop(self):
if (owner := get_owner(self.bot)) is None:
return
try:
await send_editable_log(
owner,
t.online_status,
t.status_description(Config.NAME, Config.VERSION),
t.heartbeat,
format_dt(now := utcnow(), style="D") + " " + format_dt(now, style="T"),
)
with open(Path("health"), "r") as f:
data = f.readlines()
if data and data[0].strip().isnumeric():
data[0] = str(int(datetime.now().timestamp())) + "\n"
else:
data = [str(int(datetime.now().timestamp())) + "\n"] + data
with open(Path("health"), "w+") as f:
f.writelines(data)
now = utcnow()
for owner in get_owners(self.bot):
try:
await send_editable_log(
owner,
t.online_status,
t.status_description(Config.NAME, Config.VERSION),
t.heartbeat,
format_dt(now, style="D") + " " + format_dt(now, style="T"),
)
with open(Path("health"), "r") as f:
data = f.readlines()
if data and data[0].strip().isnumeric():
data[0] = str(int(datetime.now().timestamp())) + "\n"
else:
data = [str(int(datetime.now().timestamp())) + "\n"] + data
with open(Path("health"), "w+") as f:
f.writelines(data)

except Forbidden:
pass
except Forbidden:
pass

async def on_ready(self):
if (owner := get_owner(self.bot)) is not None:
owners = get_owners(self.bot)
now = utcnow()
for owner in owners:
try:
await send_editable_log(
owner,
t.online_status,
t.status_description(Config.NAME, Config.VERSION),
t.logged_in,
format_dt(now := utcnow(), style="D") + " " + format_dt(now, style="T"),
format_dt(now, style="D") + " " + format_dt(now, style="T"),
force_resend=True,
force_new_embed=not self.initialized,
)
except Forbidden:
pass

if owner is not None:
if owners:
try:
self.status_loop.start()
except RuntimeError:
Expand Down
7 changes: 3 additions & 4 deletions moderation/message/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
create_discohook_link,
load_discohook_link,
)
from PyDrocsid.embeds import split_message
from PyDrocsid.translations import t
from PyDrocsid.types import GuildMessageable
from PyDrocsid.util import check_message_send_permissions, read_complete_message, read_normal_message
Expand Down Expand Up @@ -133,10 +134,8 @@ async def send_discohook(self, ctx: Context, channel: GuildMessageable, *, disco

try:
for message in messages:
content: str | None = message.content
for embed in message.embeds or [None]:
await channel.send(content=content, embed=embed)
content = None
for msg in split_message(message.embeds, message.content):
await channel.send(content=msg[0], embeds=msg[1])
except (HTTPException, Forbidden):
raise CommandError(t.msg_could_not_be_sent)

Expand Down
1 change: 1 addition & 0 deletions moderation/role_notifications/translations/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ rn_role_removed: Role {} has been removed from {}.
rn_ping_role: ping role
rn_ping_user: ping user
cannot_send: RoleNotifications cannot send messages to {}.
link_not_found: No matching link was found.

0 comments on commit 2e7ca15

Please sign in to comment.