Skip to content

Instantly share code, notes, and snippets.

@trueharuu
trueharuu / numToWords.ts
Last active October 18, 2022 00:11
num to word
function arr(x: any) {
return Array.from(x);
}
function num(x: any) {
return Number(x) || 0;
}
function str(x: any) {
return String(x);
}
function isEmpty(xs: any) {
@trueharuu
trueharuu / pylon-spotify.ts
Created January 23, 2021 00:52
Get info on a song on Spotify using Pylon and Slash Commands
export async function api(
url: string,
type: 'json' | 'text' | 'buffer' = 'json'
) {
const a = await fetch(url);
switch (type) {
case 'buffer':
return await a.arrayBuffer();
case 'text':
return await a.text();
/*
no :)
*/
export const colorStrings: Record<string, string> = {
aliceblue: '#f0f8ff',
antiquewhite: '#faebd7',
aqua: '#00ffff',
aquamarine: '#7fffd4',
azure: '#f0ffff',
beige: '#f5f5dc',
bisque: '#ffe4c4',
black: '#000000',
blanchedalmond: '#ffebcd',
export function getKeyDepth(key: string, object: object) {
const keyLine = JSON.stringify(object, null, 1)
.split("\n")
.find((v) => v.includes(key));
if (!keyLine) return undefined;
const spaces = keyLine.match(/^ +/);
if (!spaces) return 0
return spaces[0].length
}
export class FunctionMap<T> {
private items: Array<() => T>;
private self: typeof FunctionMap = FunctionMap;
constructor(items: Array<[string, T]>) {
this.items = items.map(([k, v]) => this.self.toFunction(k, v));
}
static toFunction<T>(key: string, value: T) {
const wrap = {
[key]: () => value
}
@trueharuu
trueharuu / reddit.ts
Last active June 27, 2022 04:32
Pylon Reddit System
import * as config from '../modules/config';
const content = "sex!"
const group = config.CLIENT.INTERACTION_COMMANDS;
const subreddit_storage = new pylon.KVNamespace('subreddits');
let subreddits = [];
let firstTime = true;
const interval = config.REDDIT.INTERVAL;
const channel_id = config.CHANNEL.REDDIT;
const REDDIT_COMMAND = config.CLIENT.INTERACTION_COMMANDS;
type Constructor<U extends Array<unknown>> = new (...args: U) => unknown;
type Keys<T, M = any> = keyof {
[P in keyof T as T[P] extends M ? P : never]: T[P];
};
export class Ops<T = {}> {
public mem: T = {} as never;
public define<K extends string, U>(
key: K,
@trueharuu
trueharuu / a.ts
Last active December 6, 2022 17:40
/* eslint-disable @typescript-eslint/ban-types */
export interface Struct<Static, Instance> {
self: Static & (new () => Instance);
build(): Static & (new () => Instance);
impl<U>(
builder: (constructor: Static) => U
): Struct<Static & ToStatic<Instance, U>, Instance & U>;
impl_static<U>(
builder: (self: Static & (new () => Instance)) => U
): Struct<Static & U, Instance>;
bot_autodifficulty_threshold_high 5.0
bot_autodifficulty_threshold_low 5.0
bot_defer_to_human_goals 0
bot_defer_to_human_items 0
bot_difficulty 3
bot_quota 9
bot_allow_grenades 0
sv_auto_adjust_bot_difficulty 0
sv_bots_get_easier_each_win 0
sv_bots_get_harder_after_each_wave 1