Skip to content

Commit

Permalink
chore: remove junk
Browse files Browse the repository at this point in the history
  • Loading branch information
eesoymilk committed May 19, 2024
1 parent bc47798 commit 9db3f25
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 137 deletions.
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
TOKEN=<your_bot_token_here>
MONGODB_CONNECTION_STR=<your_mongodb_connection_string_here>
OPENAI_API_KEY=<your_openai_api_key_here>
10 changes: 0 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,6 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

# - name: Copy docker-compose.yml to Kamatera
# run: |
# echo "${{ secrets.KAMATERA_KEY }}" > private_key.pem
# chmod 600 private_key.pem
# scp -o StrictHostKeyChecking=no \
# -i private_key.pem \
# -P ${{ env.KAMATERA_PORT }} \
# ./docker-compose.yml \
# ${{ env.KAMATERA_USER }}@${{ secrets.KAMATERA_HOST }}:${{ env.KAMATERA_PATH }}

deploy:
needs: build-and-push
runs-on: ubuntu-latest
Expand Down
51 changes: 16 additions & 35 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,21 @@

log = get_lumberjack(__name__)
initial_extensions = (
'extensions.help',
'extensions.inspect',
'extensions.emoji_kitchen',
'extensions.waifu',
'extensions.listeners',
'extensions.reaction_poll',
'extensions.soy_commands',
'extensions.chatbot',
'extensions.admin',
"extensions.help",
"extensions.inspect",
"extensions.emoji_kitchen",
"extensions.waifu",
"extensions.listeners",
"extensions.reaction_poll",
"extensions.soy_commands",
"extensions.chatbot",
"extensions.admin",
)

# TODO: more flexible command prefix


def _prefix_callable(bot: Bot, msg: Message):
user_id = bot.user.id
base = [f'<@!{user_id}> ', f'<@{user_id}> ']
if msg.guild is None:
base.append('!')
base.append('?')
else:
base.extend(bot.prefixes.get(msg.guild.id, ['?', '!']))
return base


class Soybot(Bot):

def __init__(self, *args, **kwargs):
activity = Game(name='Your Mom')
activity = Game(name="🥛 Drinking Soymilk 🥛")
intents = Intents(
guilds=True,
members=True,
Expand All @@ -55,11 +41,7 @@ def __init__(self, *args, **kwargs):
reactions=True,
message_content=True,
)
super().__init__(
intents=intents,
activity=activity,
**kwargs
)
super().__init__(intents=intents, activity=activity, **kwargs)

async def setup_hook(self):
self.bot_app_info = await self.application_info()
Expand All @@ -70,9 +52,9 @@ async def setup_hook(self):
for ext in initial_extensions:
try:
await self.load_extension(ext)
log.info(f'{ext} loaded')
log.info(f"{ext} loaded")
except Exception as e:
log.exception(f'Failed to load extension {ext}.')
log.exception(f"Failed to load extension {ext}: {e}")

self.tree.on_error = self.on_app_command_error
await self.tree.set_translator(SoybotTranslator())
Expand All @@ -82,13 +64,12 @@ def owner(self) -> User:
return self.bot_app_info.owner

async def on_app_command_error(
self,
intx: Interaction,
err: AppCommandError
self, intx: Interaction, err: AppCommandError
):
if isinstance(err, CommandOnCooldown):
await intx.response.send_message(
f'冷卻中...\n請稍後**{str(round(err.retry_after, 1)).rstrip("0").rstrip(".")}**秒再試',
ephemeral=True)
ephemeral=True,
)
else:
log.exception(err)
21 changes: 8 additions & 13 deletions extensions/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,35 @@
from utils import get_lumberjack, cd_but_soymilk

log = get_lumberjack(__name__)
help_attributes = {
'aliases': ['h', 'helps'],
'cooldown': cd_but_soymilk
}
help_attributes = {"aliases": ["h", "helps"], "cooldown": cd_but_soymilk}


class SoyHelp(MinimalHelpCommand):
async def send_bot_help(self, mapping: dict[Cog, list[Command]]):
embed = Embed(title='Help')
embed = Embed(title="Help")
for cog, commands in mapping.items():
filtered = await self.filter_commands(commands, sort=True)
command_signatures = [
self.get_command_signature(c) for c in filtered
]
if command_signatures:
cog_name = getattr(cog, 'qualified_name', 'No Category')
cog_name = getattr(cog, "qualified_name", "No Category")
embed.add_field(
name=cog_name,
value='\n'.join(command_signatures),
inline=False
value="\n".join(command_signatures),
inline=False,
)

channel = self.get_destination()
await channel.send(embed=embed)

async def send_command_help(self, command: Command):
embed = Embed(title=self.get_command_signature(command))
embed.add_field(name='Help', value=command.help)
embed.add_field(name="Help", value=command.help)
alias = command.aliases
if alias:
embed.add_field(
name='Aliases',
value=', '.join(alias),
inline=False
name="Aliases", value=", ".join(alias), inline=False
)

channel = self.get_destination()
Expand All @@ -56,7 +51,7 @@ def __init__(self, bot: Bot):
bot.help_command.command_attrs = help_attributes
bot.help_command.cog = self

def cog_unload(self):
async def cog_unload(self):
self.bot.help_command = self._original_help_command


Expand Down
72 changes: 36 additions & 36 deletions extensions/waifu.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,34 @@
log = get_lumberjack(__name__)


class WaifuGroup(Group, name='waifu'):
BASE_URL = 'https://api.waifu.im/'
class WaifuGroup(Group, name="waifu"):
BASE_URL = "https://api.waifu.im/"

SFW_CHOICES = [
Choice(name=opt, value=tag)
for opt, tag in {
'waifu-sfw_maid': 'maid',
'waifu-sfw_waifu': 'waifu',
'waifu-sfw_marin-kitagawa': 'marin-kitagawa',
'waifu-sfw_mori-calliope': 'mori-calliope',
'waifu-sfw_raiden-shogun': 'raiden-shogun',
'waifu-sfw_oppai': 'oppai',
'waifu-sfw_selfies': 'selfies',
'waifu-sfw_uniform': 'uniform',
'waifu-sfw_kamisato-ayaka': 'kamisato-ayaka',
"waifu-sfw_maid": "maid",
"waifu-sfw_waifu": "waifu",
"waifu-sfw_marin-kitagawa": "marin-kitagawa",
"waifu-sfw_mori-calliope": "mori-calliope",
"waifu-sfw_raiden-shogun": "raiden-shogun",
"waifu-sfw_oppai": "oppai",
"waifu-sfw_selfies": "selfies",
"waifu-sfw_uniform": "uniform",
"waifu-sfw_kamisato-ayaka": "kamisato-ayaka",
}.items()
]

NSFW_CHOICES = [
Choice(name=opt, value=tag)
for opt, tag in {
'waifu-nsfw_hentai': 'hentai',
'waifu-nsfw_milf': 'milf',
'waifu-nsfw_oral': 'oral',
'waifu-nsfw_paizuri': 'paizuri',
'waifu-nsfw_ecchi': 'ecchi',
'waifu-nsfw_ass': 'ass',
'waifu-nsfw_ero': 'ero',
"waifu-nsfw_hentai": "hentai",
"waifu-nsfw_milf": "milf",
"waifu-nsfw_oral": "oral",
"waifu-nsfw_paizuri": "paizuri",
"waifu-nsfw_ecchi": "ecchi",
"waifu-nsfw_ass": "ass",
"waifu-nsfw_ero": "ero",
}.items()
]

Expand All @@ -56,35 +56,35 @@ async def _fetch(
) -> dict:
params = dict()
if is_nsfw:
params |= {'is_nsfw': 'true'}
params |= {"is_nsfw": "true"}
if tag is not None:
params |= {'included_tags': tag}
params |= {"included_tags": tag}
url = f'{urljoin(self.BASE_URL, "/search")}?{urlencode(params)}'
async with cs.get(url) as resp:
data = await resp.json()

image = data['images'][0]
image = data["images"][0]
return image

def _get_embed_view(self, title: str, image: dict) -> tuple[Embed, View]:
tags = [t['name'] for t in image['tags']]
tags = [t["name"] for t in image["tags"]]
embed = (
Embed(
title=title,
description=''.join([f'#{t}' for t in tags]),
color=Color.from_str(image['dominant_color']),
timestamp=datetime.fromisoformat(image['uploaded_at']),
description="".join([f"#{t}" for t in tags]),
color=Color.from_str(image["dominant_color"]),
timestamp=datetime.fromisoformat(image["uploaded_at"]),
)
.set_image(
url=image['url'],
url=image["url"],
)
.set_footer(text='uploaded at')
.set_footer(text="uploaded at")
)
view = View().add_item(
Button(
style=ButtonStyle.link,
url=image['source'],
label='查看圖源',
url=image["source"],
label="查看圖源",
)
)

Expand All @@ -101,27 +101,27 @@ async def _run(
tag = tag.value
title = await intx.translate(tag)
else:
title = await intx.translate(_T('random', shared=True))
title = await intx.translate(_T("random", shared=True))

bot: Soybot = intx.client
image = await self._fetch(bot.cs, tag=tag)
embed, view = self._get_embed_view(title, image)
await intx.followup.send(embed=embed, view=view)
except (KeyError, AttributeError) as err:
log.exception(err)
await intx.followup.send(await intx.translate('error'))
await intx.followup.send(await intx.translate("error"))

@ac.command(name='waifu-sfw')
@ac.describe(tag='tag')
@ac.command(name="waifu-sfw")
@ac.describe(tag="tag")
@ac.choices(tag=SFW_CHOICES)
@ac.checks.dynamic_cooldown(cd_but_soymilk)
async def sfw_coro(
self, intx: Interaction, tag: Optional[Choice[str]] = None
):
await self._run(intx, tag, False)

@ac.command(name='waifu-nsfw')
@ac.describe(tag='tag')
@ac.command(name="waifu-nsfw")
@ac.describe(tag="tag")
@ac.choices(tag=NSFW_CHOICES)
@ac.checks.dynamic_cooldown(cd_but_soymilk)
async def nsfw_coro(
Expand All @@ -130,7 +130,7 @@ async def nsfw_coro(
# manually check if the channel is nsfw due to discord limitation
if not intx.channel.nsfw:
return await intx.response.send_message(
await intx.translate('no_horny'), ephemeral=True
await intx.translate("no_horny"), ephemeral=True
)
await self._run(intx, tag, True)

Expand Down
Loading

0 comments on commit 9db3f25

Please sign in to comment.