~aleteoryx/ntalk

9a0915a59d59af94635c479c933b005bd512c1c9 — Aleteoryx 22 days ago 1aa5d39
add a new command
2 files changed, 76 insertions(+), 9 deletions(-)

M botlib.py
M dee.py
M botlib.py => botlib.py +2 -2
@@ 22,11 22,11 @@ def usage():

### "AI" ###

def split_list(words, pwords):
def split_list(words, pwords, fillers):
	terms = []
	acc = []
	for i in range(len(words)):
		if len(acc) == 0 and pwords[i] in ('and', 'or'):
		if len(acc) == 0 and pwords[i].lower() in fillers:
			continue
		if words[i][-1] == ',':
			acc.append(words[i].rstrip(','))

M dee.py => dee.py +74 -7
@@ 46,7 46,7 @@ def handle_msg(nick, line, words, pwords):

	if cmd == 'help':
		help(nick)
	elif cmd not in ('roll', 'pick', 'shuf', 'shuffle'):
	elif cmd not in ('roll', 'pick', 'shuf', 'shuffle', 'do', 'don\'t', 'should', 'are'):
		send(f'{nick}, I don\'t know how to do that! My help is at {MAN}')
	elif len(pwords) < 1:
		send(f'{nick}, {cmd} what?')


@@ 56,6 56,28 @@ def handle_msg(nick, line, words, pwords):
		pick(nick, words, pwords)
	elif cmd in ('shuf', 'shuffle'):
		shuf(nick, words, pwords)
	elif cmd == 'do':
		if pwords[0].lower() == 'i':
			do_i(nick, words[1:], pwords[1:])
		elif pwords[:2] == ['you', 'think']:
			dyt(nick)
		else:
			send(f'{nick}, do what?')
	elif cmd == 'should':
		if pwords[0].lower() == 'i':
			do_i(nick, words[1:], pwords[1:])
		else:
			dyt(nick)
	elif cmd == 'don\'t':
		if pwords[0].lower() == 'i':
			dyt(nick)
		elif pwords[:2] == ['you', 'think']:
			dyt(nick)
		else:
			send(f'{nick}, don\'t what?')
	elif cmd == 'are':
		dyt(nick)
		


def handle_action(line, words, pwords):


@@ 64,16 86,61 @@ def handle_action(line, words, pwords):

### CHOICES, CHOICES ###

def pick(nick, words, pwords):
	terms = botlib.split_list(words, pwords)
	picked = choice(terms)
	send(f'{nick}, how about {" ".join(picked)}?')
def pick(nick, words, pwords, ignore=['or']):
	formats = [
		'my sources tell me {} is the best option.',
		'how about {}?',
		'I\'ve got a good feeling about {}.',
		'if I *had* to pick, I\'d say {}.',
		'signs point to {}.',
		'{}!',
		'try {}... if you dare!',
		'a terrible fate will befall you! ...unless you pick {}!',
		'after extensive deliberation, I think {} is the only option',
		'nothing ventured, nothing gained! try {}.',
	]

	terms = botlib.split_list(words, pwords, ignore)
	picked = " ".join(choice(terms)).rstrip('?')
	reply = choice(formats).format(picked)
	send(f'{nick}, {reply}')

def shuf(nick, words, pwords):
	terms = botlib.split_list(words, pwords)
	terms = botlib.split_list(words, pwords, ['and'])
	shuffle(terms)
	send(f'{nick}: {", ".join(map(" ".join, terms))}')

def do_i(nick, words, pwords):
	if 'or' not in pwords:
		dyt(nick)
	else:
		for word in words:
			if word.endswith(','):
				pick(nick, words, pwords, ['or', 'do', 'should', 'i'])
				break
		else:
			dyt(nick)

def dyt(nick):
	replies = [
		'yes',
		'yeah!',
		'absolutely!',
		'sure',
		'signs point to yes',
		'totally!',
		'no',
		'nah',
		'signs point to no',
		'never in a million years!',
		'maybe',
		'dunno',
		'not sure',
		'ask again later'
	]

	send(f'{nick}, {choice(replies)}')


### DICE ###



@@ 170,7 237,7 @@ def dice(nick, words, pwords):

	result = nick

	terms = botlib.split_list(words, pwords)
	terms = botlib.split_list(words, pwords, ['and'])
	print(f'{terms=}')
	for term in terms:
		try: