Spaces:
Runtime error
Runtime error
File size: 2,388 Bytes
7cc32a6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | import discord
from discord.ext import commands
import aiohttp
bot_embed_color = 0x4548A8
class Roleplay(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
async def _fetch_waifu(self, endpoint: str) -> str | None:
"""Fetch an image URL from waifu.pics for the given endpoint."""
url = f"https://api.waifu.pics/sfw/{endpoint}"
try:
async with aiohttp.ClientSession() as session:
async with session.get(url, timeout=10) as resp:
if resp.status != 200:
return None
data = await resp.json()
return data.get("url")
except Exception:
return None
@commands.hybrid_command(name="pat", aliases=["patting"])
async def pat(self, ctx: commands.Context, mentioned_member: discord.Member):
"""Pat someone"""
image_url = await self._fetch_waifu("pat")
em = discord.Embed(
description=f"**{ctx.author.mention} _pats_ {mentioned_member.mention}**",
color=bot_embed_color,
)
if image_url:
em.set_image(url=image_url)
await ctx.reply(embed=em)
@commands.hybrid_command(name="kiss", aliases=["kissing", "kisss"])
async def kiss(self, ctx: commands.Context, mentioned_member: discord.Member):
"""Kiss someone"""
image_url = await self._fetch_waifu("kiss")
em = discord.Embed(
description=f"**{ctx.author.mention} _kisses_ {mentioned_member.mention}**",
color=bot_embed_color,
)
if image_url:
em.set_image(url=image_url)
await ctx.reply(embed=em)
@commands.hybrid_command(name="highfive", aliases=["hfive", "hfv"])
async def highfive(self, ctx: commands.Context, mentioned_member: discord.Member):
"""Give someone a high five"""
image_url = await self._fetch_waifu("highfive")
if not image_url:
image_url = await self._fetch_waifu("hug")
em = discord.Embed(
description=f"**{ctx.author.mention} _gives a high five to_ {mentioned_member.mention}**",
color=bot_embed_color,
)
if image_url:
em.set_image(url=image_url)
await ctx.reply(embed=em)
async def setup(bot: commands.Bot):
await bot.add_cog(Roleplay(bot)) |