Skip to content

Instantly share code, notes, and snippets.

View Zomatree's full-sized avatar
:fishsticks:

Angelo Kontaxis Zomatree

:fishsticks:
View GitHub Profile

Overview

messages can be sent with the components key to add buttons and other components (when discord brings them out), you can edit and add new buttons via editing the message, this is useful for the disabled key to stop people from clicking it.

Example Payload

{
    "content": "this is an example message for components",
    "components": [
        {"type": 1, "components": [
 {"type": 2, "style": 2, "label": "Button 1", "custom_id": "1"},
<!DOCTYPE HTML>
<html>
<head>
<meta charset='utf-8'>
<title>Hello, Zomatree</title>
<link rel="icon" type="image/png" href="images/icons/favicon.ico"/>
<script>
const transferToDDG = () => {
let content = document.querySelector('input.searchField').value;
window.open(`https://duckduckgo.com/?t=ffab&q=${content}`, '_self')
use bumpalo::Bump;
use std::fmt;
mod lifetimes {
use std::mem;
pub unsafe fn extend_lifetime<'a, 'b, T>(value: &'a T) -> &'b T {
mem::transmute(value)
}
use std::{any::Any, collections::HashMap};
trait VTable<G = ()> {
const NAME: &'static str;
fn table(&self) -> HashMap<&str, &'static dyn Any>;
fn get<T: 'static>(&self, name: &str) -> &T {
let table = self.table();
let any = table[name];
@Zomatree
Zomatree / serde.py
Last active December 28, 2022 22:49
from __future__ import annotations
from dataclasses import dataclass
from types import NoneType, UnionType
from typing import Annotated, Any, Callable, Generic, Iterable, TypeGuard, TypeVar, Union, cast, get_origin as _get_origin, get_args, Self
T = TypeVar("T")
# isistance doesnt allow the second paramter to be generic so we must get the origin, however typing.get_origin doesnt return the class if its not generic
# so we default back to the type ourself
@Zomatree
Zomatree / sql.ts
Created April 13, 2023 02:46
Type-safe sql parameters
type IsValid<Name> = Name extends `${infer _} ${infer _}`
? never
: Name;
type IsParameter<Part> = Part extends `\$${infer Parameter}`
? IsValid<Parameter>
: never;
type QueryParser<Query> = Query extends `${infer A}${' ' | '='}${infer B}`
? IsParameter<A> | QueryParser<B>
from __future__ import annotations
from typing import TYPE_CHECKING, Any, ClassVar, Generic, Literal, Self, TypeVar, Annotated, TypeVarTuple, get_args, overload, get_origin, reveal_type, cast
import asyncpg
T = TypeVar("T")
T_T = TypeVar("T_T", bound="Table", covariant=True)
T_OT = TypeVar("T_OT", bound="Table", covariant=True)
T_Ts = TypeVarTuple("T_Ts")
type StringFlags = "c" | "b" | "B";
type NumberFlags = "n"
type Resolve<T extends string> = (
T extends StringFlags ? [string] :
T extends NumberFlags ? [number] :
[] // ignore stuff like ">"
);
type Repeat<