howgay
This commit is contained in:
parent
9b083e1c61
commit
3e1f1ee82e
3 changed files with 83 additions and 1 deletions
|
@ -9,8 +9,9 @@ import { source } from "./commands/source";
|
||||||
import { sql } from "./commands/sql";
|
import { sql } from "./commands/sql";
|
||||||
import { help } from "./commands/help";
|
import { help } from "./commands/help";
|
||||||
import { moderateMessage } from "./modules/moderate";
|
import { moderateMessage } from "./modules/moderate";
|
||||||
|
import { howgay } from "./commands/howgay";
|
||||||
|
|
||||||
export const commands: Command[] = [forgejoDown, minky, source, sql, help];
|
export const commands: Command[] = [forgejoDown, minky, source, sql, help, howgay];
|
||||||
export const bot = new Telegraf(config.token);
|
export const bot = new Telegraf(config.token);
|
||||||
|
|
||||||
bot.on(message("text"), async (ctx) => {
|
bot.on(message("text"), async (ctx) => {
|
||||||
|
|
19
src/commands/howgay.ts
Normal file
19
src/commands/howgay.ts
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import { Context } from "telegraf";
|
||||||
|
import { Command, CommandTypes } from "../utils/types";
|
||||||
|
import { seededRandom } from "../utils/seededRandom";
|
||||||
|
|
||||||
|
async function handler(ctx: Context, args: string[]) {
|
||||||
|
await ctx.reply(
|
||||||
|
`🏳️🌈 ${ctx.from.first_name} is ${(seededRandom(ctx.from.id.toString() + "hg") * 100).toFixed(2).toString()}% gay`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const howgay: Command = {
|
||||||
|
name: "howgay",
|
||||||
|
aliases: ["gay", "hg"],
|
||||||
|
description: "Check how gay you or someone is",
|
||||||
|
type: CommandTypes.Fun,
|
||||||
|
modOnly: false,
|
||||||
|
ownerOnly: false,
|
||||||
|
handler
|
||||||
|
};
|
62
src/utils/seededRandom.ts
Normal file
62
src/utils/seededRandom.ts
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
// adapted from https://github.com/davidbau/seedrandom/blob/released/lib/alea.js
|
||||||
|
//
|
||||||
|
// A port of an algorithm by Johannes Baagøe <baagoe@baagoe.com>, 2010
|
||||||
|
// http://baagoe.com/en/RandomMusings/javascript/
|
||||||
|
// https://github.com/nquinlan/better-random-numbers-for-javascript-mirror
|
||||||
|
// Original work is under MIT license -
|
||||||
|
|
||||||
|
// Copyright (C) 2010 by Johannes Baagøe <baagoe@baagoe.org>
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
export function seededRandom(seed: string) {
|
||||||
|
let n = 0xefc8249d;
|
||||||
|
|
||||||
|
function mash(data: string) {
|
||||||
|
data = String(data);
|
||||||
|
for (let i = 0; i < data.length; i++) {
|
||||||
|
n += data.charCodeAt(i);
|
||||||
|
let h = 0.02519603282416938 * n;
|
||||||
|
n = h >>> 0;
|
||||||
|
h -= n;
|
||||||
|
h *= n;
|
||||||
|
n = h >>> 0;
|
||||||
|
h -= n;
|
||||||
|
n += h * 0x100000000; // 2^32
|
||||||
|
}
|
||||||
|
return (n >>> 0) * 2.3283064365386963e-10; // 2^-32
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply the seeding algorithm from Baagoe.
|
||||||
|
let s0 = mash(" ");
|
||||||
|
let s1 = mash(" ");
|
||||||
|
let s2 = mash(" ");
|
||||||
|
|
||||||
|
s0 -= mash(seed);
|
||||||
|
if (s0 < 0) s0++;
|
||||||
|
|
||||||
|
s1 -= mash(seed);
|
||||||
|
if (s1 < 0) s1++;
|
||||||
|
|
||||||
|
s2 -= mash(seed);
|
||||||
|
if (s2 < 0) s2++;
|
||||||
|
|
||||||
|
const t = 2091639 * s0 + 2.3283064365386963e-10; // 2^-32
|
||||||
|
return t - (t | 0);
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue