Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
dorythecat committed Aug 29, 2024
2 parents 838892d + 92eec4d commit ba39e1a
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 59 deletions.
32 changes: 23 additions & 9 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ async def on_guild_join(guild: discord.Guild) -> None:
"We hope you enjoy this bot and all of its functions, and remember to always use it "
"with respect and consent from other users, and never for nefarious purposes!")


@bot.event
async def on_message(message: discord.Message) -> None:
# Check if the message is sent by the bot, we don't want an endless loop that ends on an error/crash, do we?
Expand Down Expand Up @@ -147,15 +148,28 @@ async def on_message(message: discord.Message) -> None:

content = ""
if message.reference: # Check if the message is a reply
content += f"**Replying to {message.reference.resolved.author.mention}:**\n"
content += (f"***Replying to {message.reference.resolved.author.mention} on "
f"{message.reference.resolved.jump_url}:***\n")
if message.reference.resolved.content:
content += f">>> {message.reference.resolved.content}"
# If we don't send this by itself, we'll get fucked over by the multi-line quote, sorry everyone :(
await webhook.send(content,
username=name,
avatar_url=image_url,
thread=message.channel if is_thread else discord.utils.MISSING)
content = ""
to_send = message.reference.resolved.content
if message.reference.resolved.mentions:
for mention in message.reference.resolved.mentions:
# This avoids people abusing mentions found in messages they are replying to
to_send = to_send.replace(mention.mention, f"@{mention.name}")
to_send = to_send.split('\n')
if to_send[0].startswith('***Replying to'):
for line in to_send[1:]:
if line.startswith('> '):
continue
to_send = to_send[(to_send.index(line) + 1):] # We add one to account for the blank line
break
for line in to_send:
if line.startswith('> '):
line = line[2:]
elif line.startswith('>>> '):
line = line[4:]
content += f"> {line}\n"
content += "\n"

if message.content:
# Check if censor, muffles, alt muffle, or sprinkles are active in data
Expand Down Expand Up @@ -186,7 +200,7 @@ async def on_message(message: discord.Message) -> None:
attachment_file = await attachment.to_file()
attachments.append(attachment_file)

# The message needs to either havbe content or attachments (or both) to be sent,
# The message needs to either have content or attachments (or both) to be sent,
# so we don't need to worry about sending empty messages and triggering 400 errors
await webhook.send(content,
username=name,
Expand Down
93 changes: 43 additions & 50 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,56 +93,49 @@ def write_tf(user: discord.User | discord.Member,
data[str(guild.id)] = {}
data[str(guild.id)]['blocked_channels'] = []
data[str(guild.id)]['blocked_users'] = []
if channel_id not in data[str(guild.id)]:
data[str(guild.id)][channel_id] = {
'transformed_by': transformed_by,
'into': into,
'image_url': image_url,
'claim': None,
'eternal': False,
'prefix': {
'active': False,
'contents': [],
'chance': 0
},
'suffix': {
'active': False,
'contents': [],
'chance': 0
},
'big': False,
'small': False,
'hush': False,
'backwards': False,
'censor': {
'active': False,
'contents': {}
},
'sprinkle': {
'active': False,
'contents': [],
'chance': 0
},
'muffle': {
'active': False,
'contents': [],
'chance': 0
},
'alt_muffle': {
'active': False,
'contents': [],
'chance': 0
},
'proxy_prefix': proxy_prefix,
'proxy_suffix': proxy_suffix,
'bio': None
}
else:
data[str(guild.id)][channel_id]['transformed_by'] = transformed_by
data[str(guild.id)][channel_id]['into'] = into
data[str(guild.id)][channel_id]['image_url'] = image_url
data[str(guild.id)][channel_id]['proxy_prefix'] = proxy_prefix
data[str(guild.id)][channel_id]['proxy_suffix'] = proxy_suffix
data[str(guild.id)][channel_id] = {
'transformed_by': transformed_by,
'into': into,
'image_url': image_url,
'claim': None,
'eternal': False,
'prefix': {
'active': False,
'contents': [],
'chance': 0
},
'suffix': {
'active': False,
'contents': [],
'chance': 0
},
'big': False,
'small': False,
'hush': False,
'backwards': False,
'censor': {
'active': False,
'contents': {}
},
'sprinkle': {
'active': False,
'contents': [],
'chance': 0
},
'muffle': {
'active': False,
'contents': [],
'chance': 0
},
'alt_muffle': {
'active': False,
'contents': [],
'chance': 0
},
'proxy_prefix': proxy_prefix,
'proxy_suffix': proxy_suffix,
'bio': None
}
else:
if transformed_by is not None and transformed_by != "":
data[str(guild.id)][channel_id]['transformed_by'] = transformed_by
Expand Down

0 comments on commit ba39e1a

Please sign in to comment.