dragon-bot/app/bot.py
Luke R 83ac1077b0
All checks were successful
Build and push / changes (push) Successful in 3s
Build and push / Lint-Python (push) Successful in 10s
Build and push / Build-and-Push-Docker (push) Successful in 3m1s
Build and push / sync-argocd-app (push) Successful in 2s
Build and push / post-failure-to-discord (push) Has been skipped
Build and push / post-success-to-discord (push) Successful in 10s
Adding shitpost for 🅱️sustoms
2025-05-08 13:18:33 -07:00

129 lines
3.8 KiB
Python
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/local/bin/python
from discord.ext import commands
import core_utils
import discord
import os
import random
import requests
import requests_cache
requests_cache.install_cache(
"request-cache", backend="sqlite", expire_after=300, allowable_methods=("GET",)
)
intents = discord.Intents.default()
intents.message_content = True
intents.members = True
intents.reactions = True
bot = commands.Bot(intents=intents)
cogfiles = [
f"cogs.{filename[:-3]}"
for filename in os.listdir("/app/cogs/")
if filename.endswith(".py")
]
for cogfile in cogfiles:
bot.load_extension(cogfile)
welcome_blurb = requests.get(core_utils.json_endpoint + "roles.json").json()
@bot.event
async def on_ready():
print(f"{bot.user.name} has connected to Discord!")
if os.getenv("DRAGON_ENV") == "prod":
# await bot.get_channel(152921472304676865).send("I have reconnected")
# Waiting-room in zoid's server
channel_id = 1026281775984549958
message_id = 1099374735428681758
# Testing
# channel_id = 932476007439552522
# message_id = 1236011522572943382
# message = await bot.get_channel(channel_id).send(blurb)
# Update the message on_ready to match the content we always want to be there
message = await bot.get_channel(channel_id).fetch_message(message_id)
await message.edit(content=welcome_blurb["welcome_message"])
@bot.event
async def on_raw_reaction_add(payload):
guild = bot.get_guild(payload.guild_id)
role_map = welcome_blurb["role_map"]
if payload.channel_id == 1026281775984549958:
role = discord.utils.get(guild.roles, name=role_map[payload.emoji.name])
member = guild.get_member(payload.user_id)
await member.add_roles(role)
@bot.listen("on_message")
async def convert_heic_to_jpg(ctx):
from cmagick import cmagick
import time
import tempfile
if ctx.attachments:
for attachment in ctx.attachments:
if attachment.filename.lower().endswith(("heic", "tiff")):
source_file = "/tmp/source"
source_file, file_path = tempfile.mkstemp()
jpg_file = f"/tmp/{time.time()}.jpg"
await attachment.save(fp=file_path)
cmagick.convert(file_path, jpg_file)
try:
await ctx.delete()
except Exception:
pass
await ctx.channel.send(
f"{ctx.author.mention} uplodaed a file that discord cant natively embed, so I converted it to a jpg:\n{ctx.content}",
file=discord.File(jpg_file),
)
os.remove(file_path)
return
@bot.listen("on_message")
async def reply_with_the_word_cum(ctx):
if ctx.author.id == bot.user.id:
return
if random.randint(1, 1000) == 1:
await ctx.reply("cum")
@bot.listen("on_message")
async def reply_with_bustoms(ctx):
if ctx.author.id == bot.user.id:
return
if ctx.channel.id == 932476007439552522 and "customs" in ctx.content.lower():
await ctx.reply("I think you mean 🅱ustoms")
@bot.listen("on_message")
async def fix_social_media_links(ctx):
headers = {"Cache-Control": "no-store"}
correct_domains = requests.get(
core_utils.json_endpoint + "social_media_domains.json", headers=headers
).json()
if ctx.author.id == bot.user.id:
return
for k in correct_domains.keys():
if ctx.content.startswith(k) or ctx.content.startswith(f"www.{k}.com"):
await ctx.channel.send(
f"{ctx.author.mention} said:\n{ctx.content.replace(k, f'https://{correct_domains[k]}.com').split('?')[0]}",
)
await ctx.delete()
return
bot.run(os.getenv("discord_token"))