Skip to content

Commit

Permalink
Shipping Command (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
jadc authored Apr 16, 2024
1 parent 9667823 commit afb71b2
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cogs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .starboard import setup_starboard
from .faq import setup_faq
from .votedelete import setup_votedelete
from .ship import setup_ship

import asyncio
from aiohttp import ClientSession
Expand All @@ -23,4 +24,5 @@ async def setup_all_cogs(bot, guilds, client=None):
setup_starboard(bot, guilds),
setup_faq(bot, guilds),
setup_votedelete(bot, guilds),
setup_ship(bot, guilds)
)
56 changes: 56 additions & 0 deletions cogs/ship.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import json

import discord
from discord.ext import commands
from discord import app_commands


class Ship(commands.Cog, name="ship"):
def __init__(self):
super().__init__()
self.thresholds = {}

async def cog_load(self):
await super().cog_load()
print("Ship Cog Loaded")

async def load_data(self):
with open("data/ship-thresholds.json", "r", encoding="utf-8") as f:
self.thresholds = json.load(f)

def get_slogan(self, compat) -> tuple[str, str]:
for threshold, data in self.thresholds.items():
if compat >= int(threshold):
return data["message"], data["image"]
return ("", "")

@app_commands.command(
name="ship", description="Calculates the compatibility between two people"
)
async def ship(
self,
intr: discord.Interaction,
first_user: discord.User,
second_user: discord.User,
):
if first_user.id == second_user.id:
await intr.response.send_message("No narcissism allowed.", ephemeral=True)
return

compat = (first_user.id + second_user.id) % 101
slogan, image = self.get_slogan(compat)

embed = discord.Embed(
type="rich",
title=f"{first_user.display_name} and {second_user.display_name} are {compat}% compatible!",
description=slogan,
)
embed.set_thumbnail(url=image)

await intr.response.send_message(embed=embed)


async def setup_ship(bot, guilds):
cog = Ship()
await cog.load_data()
await bot.add_cog(cog, guilds=guilds)
26 changes: 26 additions & 0 deletions data/ship-thresholds.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"95": {
"message": "TRUE LOVE!!!",
"image": "https://cdn.discordapp.com/emojis/1090118781818388481.webp"
},
"75": {
"message": "Lovely!",
"image": "https://cdn.discordapp.com/emojis/1132861877647589376.webp"
},
"50": {
"message": "Okay!",
"image": "https://cdn.discordapp.com/emojis/1066954556753330236.webp"
},
"25": {
"message": "Many fish in the sea...",
"image": "https://cdn.discordapp.com/emojis/1086538148252745768.gif"
},
"10": {
"message": "Yikes...",
"image": "https://cdn.discordapp.com/emojis/1097261807548256256.webp"
},
"0": {
"message": "...",
"image": "https://cdn.discordapp.com/emojis/1039832025194041354.webp"
}
}

0 comments on commit afb71b2

Please sign in to comment.