Skip to content

Commit

Permalink
Extensible embed replacement system
Browse files Browse the repository at this point in the history
  • Loading branch information
nfaltermeier committed May 5, 2023
1 parent 8bfaaf3 commit 98844e1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import minecraft
import excuse
import markov
import twitter
import embeds
import autogen_buildtime

logging.basicConfig(level=logging.INFO)
Expand Down Expand Up @@ -52,7 +52,7 @@ async def on_message(message: discord.Message):
await excuse.on_message(message)
await markov.on_message(message)
await faces.on_message(message, client, config)
await twitter.on_message(message, config)
await embeds.on_message(message, config)
if await roll.on_message(message):
return

Expand Down
9 changes: 8 additions & 1 deletion src/config.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,11 @@ face_dims = [
# Max total pixels for a face image to have, set to -1 to disable
face_max_pixels = 2_000_000

enforce_vxtwitter = True
enforce_embeds = True
embeds = {
"twitter.com": "vxtwitter.com",
"tiktok.com": "vxtiktok.com",
"www.tiktok.com": "www.vxtiktok.com",
"instagram.com": "ddinstagram.com",
"www.instagram.com": "www.ddinstagram.com",
}
23 changes: 23 additions & 0 deletions src/embeds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import discord

async def on_message(message: discord.Message, conf):
if conf.enforce_embeds:
for base, replacement in conf.embeds.items():
test = f'https://{base}'
test_len = len(test)
i = message.content.find(test)
if i == -1:
test = f'http://{base}'
test_len = len(test)
i = message.content.find(test)
if i != -1:
space = message.content.find(" ", i)
if space == -1:
space = len(message.content)
url = f'https://{replacement}{message.content[i + test_len: space]}'
if i == 0 and space == len(message.content):
await message.channel.send(f'{message.author.mention} (🤡) sent: {url}')
await message.delete()
else:
await message.edit(suppress=True)
await message.reply(url)
20 changes: 0 additions & 20 deletions src/twitter.py

This file was deleted.

0 comments on commit 98844e1

Please sign in to comment.