#!/usr/local/bin/python from discord.ext import commands import core_utils import discord import os intents = discord.Intents.default() intents.message_content = True intents.members = True intents.reactions = True bot = commands.Bot(command_prefix="!", 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) import requests_cache requests_cache.install_cache(expire_after=300) @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 # for testing, bot-testing server's channel # channel_id = 932476007439552522 # message_id = 1114045480129806361 blurb = """If you're here to game, please react to this message with one of the following emojis to be granted the appropriate role: 🚀 for Star Citizen 🦖 for ARK 🔫 for Tarkov 🐀 for Darktide or Vermintide 🪖 for Battlefield or Battlebit 😈 for Baulder's Gate Otherwise, let your friend know you're here to shitpost """ # 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=blurb) @bot.event async def on_raw_reaction_add(payload): guild = bot.get_guild(payload.guild_id) role_map = { "🦖": "ARK Gamers", "🔫": "Tarkov Gamers", "🐀": "Dorktide Gamers", "🪖": "Battlefielders", "🚀": "Star Citizens", "⚙️": "Lethal Gamers", } 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 = "/tmp/%s.jpg" % time.time() await attachment.save(fp=file_path) img = cmagick.convert(file_path, jpg_file) try: await ctx.delete() except Exception: pass await ctx.channel.send( "%s said:\n%s" % (ctx.author.mention, ctx.content), file=discord.File(jpg_file), ) os.remove(file_path) return @bot.listen("on_message") async def annoy_jason(ctx): if ctx.author.id == 83012791983673344 and "twitter.com" in ctx.content: # my author id for testing # if ctx.author.id == core_utils.my_id and "twitter.com" in ctx.content: await ctx.reply( "https://tenor.com/view/oomfie-klee-genshin-impact-smook-smokingissad-gif-21571907" ) return @bot.listen("on_message") async def fix_tiktok_links(ctx): if "https://www.tiktok.com" in ctx.content: await ctx.channel.send( "%s said:\n%s" % ( ctx.author.mention, ctx.content.replace("tiktok", "vxtiktok"), ) ) await ctx.delete() return @bot.event async def on_message(ctx): if str(bot.user.id) in ctx.content: import wolframalpha client = wolframalpha.Client(os.getenv("wolfram_token")) query = " ".join(ctx.content.split()[1:]) try: res = client.query(query) return await ctx.reply(next(res.results).text) except Exception as e: print(e) return await ctx.reply("Sorry, I'm unable to answer that") bot.run(os.getenv("discord_token"))