Skip to content

Instantly share code, notes, and snippets.

@Artoria2e5
Last active March 7, 2016 05:25
Show Gist options
  • Save Artoria2e5/d92f23e5c576dbb0f371 to your computer and use it in GitHub Desktop.
Save Artoria2e5/d92f23e5c576dbb0f371 to your computer and use it in GitHub Desktop.
white-album bot
from __future__ import division, print_function, unicode_literals
import random
import string
import pangu
import re
def w_expand(lst):
return sum([a[1] for i in range(a[0])] for a in lst)
sentences = w_expand([
(1, '你为什么会那么熟练啊!你到底[ACTION#0@0]了多少次[ACTION#0@1?]!'),
(1, '是我,是我先,明明都是我先来的!'),
(2, '是我,是我先,明明都是我先来的……[ACTION#0@0]也好,[ACTION#1@0]也好,还是[ACTION#2@0][ACTION#2@1]也好'),
(1, '为什么会变成这样呢……第一次有了喜欢的[THING#0@0]。有了能[ACTION#0@0]的[ACTION#0@1]。两件快乐事情重合在一起。' +
'而这两份快乐,又给我带来更多的快乐。得到的,本该是像梦境一般幸福的时间……但是,为什么,会变成这样呢……'),\
(1, '我即使是死了,钉在在棺材里了,也要在墓里,用这腐朽的声带喊出:[S:XCLAIM#0@0]'),
(4, '[S#0@0]'),
])
people = ['SB', 'Linus Torvalds', 'RMS', 'vczh', 'Arthur2e5']
things = ['人', '电脑', '跳蛋']
features = ['HiDPI', 'SVG', 'UPnP']
actions = w_expand([
# weight, (verb, choices...)
# todo write something proper
(1, ('亲吻', people)),
(1, ('commit', ['code', 'changeset'])),
(3, ('拥抱', people)),
(1, ('捕捉', people)),
(4, ('支持', features)),
(1, ('搞坏', features + things)),
(1, ('谈笑风生')),
(1, ('推倒')),
(1, ('怒斥', ['记者'])),
])
def get_action(action_len = 0):
global actions
return random.choice(filter(lambda a:len(a) == action_len + 1, actions))
def quack(opt, L = sentences):
# this is shit
L1 = [a[-1] == '!' for a in L] if opt == 'XCLAIM' else L
return fill(random.choice(L1), L)
def fill(s, L):
# kill loop
L = [a for a in L if a != s]
fields = dict()
for i in [a[1:-1] for a in re.findall(r'\[[^\]]\]+', s)]:
(comp, arg) = i.split('@')
fields[comp] = max(fields[comp], arg)
for comp, argn in fields.items():
thing = None
(typ, num) = comp.split('#')
if ':' in typ:
(typ, opt) = typ.split(':')
opt = opt.split('-')
else:
opt = []
if typ == 'S':
fields[comp] = quack(opt, L)
elif typ == 'ACTION':
fields[comp] = get_action(num)
for ....
elif typ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment