From f940db796ac0b71f1ce0dabedd439e4cf20d4142 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Mon, 9 Nov 2015 20:08:00 -0800 Subject: [PATCH] Add shibe.py --- plugins/shibe.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 plugins/shibe.py diff --git a/plugins/shibe.py b/plugins/shibe.py new file mode 100644 index 0000000..8122a2f --- /dev/null +++ b/plugins/shibe.py @@ -0,0 +1,51 @@ +from random import choice, random, randint +import time + +from util import hook + +COLORS = ['03','04','06','07','08','09','10','11','12','13'] + +#Shibe generation code borrowed from aji + +class pvec: + def __init__(self, num): + self.v = [1.0] * num + self.norm() + def norm(self): + s = sum(self.v) + self.v = [x / s for x in self.v] + def pick(self): + r = random() * sum(self.v) # sum should always be 1, but meh + s = 0 + for i, x in enumerate(self.v): + s += x + if r < s: + break + def calc(j, x): + fac = (1 - 3.5 / (abs(i - j) + 4.5)) + return x * fac + self.v = [calc(j, x) for j, x in enumerate(self.v)] + self.norm() + return i + +spvec = pvec(40) +for i in range(10): + spvec.pick() + +last_color = '00' + +def gen_prefix(): + global last_color + + color = choice(COLORS) + while color == last_color: + color = choice(COLORS) + + last_color = color + return ' ' * spvec.pick() + '\3' + color + +@hook.command("shibe") +def shibeify(inp): + return "%s%s" %\ + (gen_prefix(), inp) +