This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class AsyncLimiter extends TypedEmitter<{ limited: (wait: number) => void; }> { | |
private queue: Callback[] = []; | |
private tokens: number; | |
private executing = false; | |
private locked = false; | |
private last = 0; | |
constructor(readonly defaultTokens: number, readonly waitTime: number) { | |
super(); | |
this.tokens = +defaultTokens; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const metadata = Symbol.for("rate-limiter"); | |
const limiters = new Map<Fn | string | number, AsyncLimiter>(); | |
type Fn = (...args: any[]) => void; | |
export function limit(): MethodDecorator | |
export function limit(id: string | number): MethodDecorator | |
export function limit(tokens: number, wait?: number): MethodDecorator | |
export function limit(totalOrLimiter?: number | string, wait?: number): MethodDecorator { | |
// @ts-ignore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class AsyncLimiter extends TypedEmitter<{ limited: (duration: number) => void; }> { | |
private tokens: number; | |
private lock?: Promise<void>; | |
constructor(readonly defaultTokens: number, readonly ratelimitDuration: number) { | |
super(); | |
this.tokens = +defaultTokens; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.atomic.AtomicReference | |
class StringDB { | |
/** | |
* The key/value pairs in this database. | |
*/ | |
val entries: Map<String, Any> | |
get() = db.lines() | |
.filter { it.isNotBlank() } | |
.map { it.split("=") } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { gray, magenta } from "colors/safe" | |
import { join } from "path"; | |
import { format as fmt, loggers, transports as tps } from "winston"; | |
import DailyRotateFile from "winston-daily-rotate-file"; | |
export namespace LoggerFactory { | |
const transports = [ | |
new DailyRotateFile({ | |
filename: "combined-%DATE%.log", | |
dirname: join(process.cwd(), "logs") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.* | |
import java.util.concurrent.ThreadFactory | |
import java.util.concurrent.atomic.AtomicInteger | |
fun ThreadFactory(name: String, daemon: Boolean = false): ThreadFactory { | |
val group = System.getSecurityManager() | |
?.threadGroup | |
?: Thread.currentThread().threadGroup | |
return object : ThreadFactory { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.serialization.decodeFromString | |
import kotlinx.serialization.json.Json | |
import kotlinx.serialization.json.JsonObject | |
import kotlinx.serialization.json.decodeFromJsonElement | |
import java.nio.file.Paths | |
import kotlin.io.path.readText | |
object Config { | |
val json = Json {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val padding = " " | |
fun <V : Any> inspectValue(value: V?, prop: KProperty<*>? = null): String { | |
return when (value) { | |
null -> "null" | |
is String -> "\"$value\"" | |
is Number, is Boolean -> "$value" | |
is Pair<*, *> -> "${prop?.returnType?.name ?: value::class.name}(${inspectValue(value.first as Any, value::first)}, ${inspectValue(value.first as Any, value::second)})" | |
is Collection<*> -> "${prop?.returnType?.name ?: value::class.name}(${value.size})" | |
else -> { | |
val valueStr = value.toString() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
βοΈ Closed issue #18 in melike2d/lavalink | |
π£ Commented on #18 in melike2d/lavalink | |
βοΈ Closed issue #156 in MenuDocs/erela.js | |
βοΈ Closed issue #157 in MenuDocs/erela.js | |
βοΈ Opened issue #157 in MenuDocs/erela.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Kotlin 19 mins βββββββββββββββββββββ 100.0% |