126 lines
3.8 KiB
Python
Executable File
126 lines
3.8 KiB
Python
Executable File
#!/usr/local/bin/python
|
|
from discord.ext import commands
|
|
import core_utils
|
|
import discord
|
|
import os
|
|
import random
|
|
|
|
intents = discord.Intents.default()
|
|
intents.message_content = True
|
|
intents.members = True
|
|
bot = commands.Bot(command_prefix="!", intents=intents)
|
|
bot.remove_command("help")
|
|
|
|
cogfiles = [
|
|
f"cogs.{filename[:-3]}"
|
|
for filename in os.listdir("/app/cogs/")
|
|
if filename.endswith(".py")
|
|
]
|
|
|
|
for cogfile in cogfiles:
|
|
bot.load_extension(cogfile)
|
|
|
|
|
|
@bot.event
|
|
async def on_ready():
|
|
print(f"{bot.user.name} has connected to Discord!")
|
|
game = discord.Game("Type !help")
|
|
await bot.change_presence(
|
|
status=discord.Status.online,
|
|
activity=discord.Activity(
|
|
type=discord.ActivityType.listening, name="type !help"
|
|
),
|
|
)
|
|
|
|
if os.getenv("DRAGON_ENV") == "prod":
|
|
# for guild in bot.guilds:
|
|
# await bot.register_commands(guild_id=guild.id, force=True)
|
|
await bot.get_channel(152921472304676865).send("I have reconnected")
|
|
# else:
|
|
# # force register commands in test server on launch
|
|
# await bot.register_commands(guild_id=826547484632678450, force=True)
|
|
|
|
|
|
@bot.listen("on_message")
|
|
async def fix_cdn_url(ctx):
|
|
# Ignore images
|
|
videos = ["mp4", "mov"]
|
|
if any(x in ctx.content for x in videos) and "media.discordapp.net" in ctx.content:
|
|
await ctx.delete()
|
|
await ctx.channel.send(
|
|
"%s said:\n\n%s"
|
|
% (
|
|
ctx.author.mention,
|
|
ctx.content.replace("media.discordapp.net", "cdn.discordapp.com"),
|
|
)
|
|
)
|
|
return
|
|
|
|
|
|
@bot.listen("on_message")
|
|
async def he_just_like_me(ctx):
|
|
if ctx.guild.id in core_utils.my_guilds:
|
|
phrases = ["he just like me", "hjlm", "frfr"]
|
|
if any(x in ctx.content for x in phrases):
|
|
await ctx.reply("https://imgur.com/V3k729v")
|
|
|
|
|
|
@bot.listen("on_message")
|
|
async def did_you_mean(ctx):
|
|
if ctx.message.author.id != core_utils.my_id:
|
|
message = ctx.content
|
|
command = ctx.content.split()[0][1:]
|
|
|
|
command_map = {"ask": "wolfram"}
|
|
if message.startswith("!"):
|
|
if command in command_map.keys():
|
|
command = command_map[command]
|
|
await ctx.reply("Did you mean /%s?" % command)
|
|
|
|
|
|
@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.event
|
|
async def on_command_completion(ctx):
|
|
channel = bot.get_channel(826547484632678453)
|
|
embed = discord.Embed(colour=discord.Color.green(), title="Command Executed")
|
|
embed.add_field(name="Command:", value=f"`{ctx.command}`")
|
|
embed.add_field(name="User:", value=f"`{ctx.author}`", inline=False)
|
|
embed.add_field(name="Channel:", value=f"{ctx.channel} **( <#{ctx.channel.id}> )**")
|
|
embed.add_field(
|
|
name="Link to Message:",
|
|
value="**(** [%s](%s) **)**" % (ctx.channel, ctx.message.jump_url),
|
|
)
|
|
embed.add_field(name="Server:", value=f"{ctx.guild} **( <#{ctx.channel.id}> )**")
|
|
if ctx.message.author.id != core_utils.my_id:
|
|
await channel.send(embed=embed)
|
|
|
|
|
|
bot.run(os.getenv("token"))
|