Skip to content

Instantly share code, notes, and snippets.

@Yui-Koi
Yui-Koi / utils.py
Created October 11, 2025 06:16
personal utility
from __future__ import annotations
import asyncio, functools, inspect
from typing import Awaitable, Callable, TypeVar, cast
R = TypeVar("R")
F = TypeVar("F", bound=Callable[..., object])
ExceptionTypes = type[Exception] | tuple[type[Exception], ...]
PropagateTypes = type[BaseException] | tuple[type[BaseException], ...]
@Yui-Koi
Yui-Koi / lmarena_parser.py
Last active October 1, 2025 05:54
Supposed to be a scraper, but i couldn’t stop chasing happy‑path purity and it collapsed into a rule based transducer. accidental elegance >>> intended mediocrity (ノ´ヮ`)ノ*:・゚✧
import os
import argparse
import json
from enum import Enum, auto
from dataclasses import dataclass, asdict
from itertools import starmap
from copy import deepcopy
from typing import (
List, Tuple, Dict, Union, Optional, Iterable, Callable,
TypeVar, Generic, NamedTuple, cast
@Yui-Koi
Yui-Koi / streamfind.py
Created August 26, 2025 08:46
brain: just use os.walk with a for loop. it's simple. me: no. it must be lazy, functional, and beautiful. So I made this. A file finder that aggressively avoids for loops and try/except blocks in favor of pure, unadulterated iterator magic. Pass it a path and as many filter functions as you want. It'll do the rest. Have fun~ (ノ´ヮ`)ノ*:・゚✧
import os
import itertools
from typing import Iterator, Iterable, Callable, Union, List, Tuple
Predicate = Callable[[os.DirEntry], bool]
Sorter = Callable[[Iterable[os.DirEntry]], List[os.DirEntry]]
# predicates
no_ext = lambda e: '.' not in e.name
not_hidden = lambda e: not e.name.startswith('.')
@Yui-Koi
Yui-Koi / voice-support.py
Last active October 11, 2025 06:17
Implementation of voice messages with monkey patching & mixin classes. Use at your own risk I'm not gonna be maintaining it. It's so late at night and I spent way too long on this. Docs probably tomorrow or never
import discord
import aiofiles
import io
import array
import base64
from discord.ext import commands
from pydub import AudioSegment
from typing import Union, Any, Optional, Tuple
class VoiceMessage(discord.Message):
@Yui-Koi
Yui-Koi / cog_helper.py
Last active August 10, 2023 07:22
This function is a helper method within a Python Discord bot that performs actions on cogs (modules containing commands) or all cogs.
# Define a helper function that performs an action on a cog or all cogs
async def _cog_action(self, ctx: commands.Context, action: Literal["load", "unload", "reload"], cog: Optional[str] = None) -> None:
"""
Perform an action on a cog or all cogs.
Parameters:
ctx (commands.Context): The Discord command context.
action (Literal["load", "unload", "reload"]): The action to perform (load, unload, or reload).
cog (Optional[str]): The specific cog name to perform the action on. If None, the action will be applied to all cogs.
@Yui-Koi
Yui-Koi / Boolean transformer.py
Created April 7, 2023 09:53
A discordpy boolean transformer for application command choices
class BooleanTransformer(app_commands.Transformer):
@property
def choices(self) -> List[app_commands.Choice]:
return [app_commands.Choice(name="True", value="True"), app_commands.Choice(name="False", value="False")]
async def transform(self, interaction: discord.Interaction, value: str) -> bool:
return {"True": True, "False": False}[value] 
@app_commands.command(name="test", description='Test bool')
@app_commands.describe(option="Bool test")