~aleteoryx/ntalk

ref: 690dffab9173ec59359b5988728f15458cf7fb71 ntalk/clairen.py -rwxr-xr-x 1.4 KiB
690dffabAleteoryx hopefully fix glob portability a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/env python

import botlib
from time import sleep

NAME = "clairen"

# used for focus simulation
# i is just the iterator in the current download, k is the length
# k - i - 1 is how many messages there are after the current message, or its depth
# the chances of missing a message, using the direct address, etc, depend on this
i = k = depth = 0

last16 = []

### "AI" ###

def log_hi(nick):
	global last16
	last16[-1][0] = 'hi'

def direct_address(nick, words, pwords):
	print(words, pwords)
	if is_hi(words, pwords):
		log_hi(nick)
	elif is_gm(words, pwords):
		log_gm(nick)
	else:
		huh(nick)

def gossip(nick, line):
	pass

def chatting(nick, line):
	pass


def handle_msg(nick, words, pwords):
	global NAME, last16

	last16 += [('msg', nick, words, pwords)]
	if nick == NAME:
		return

	# things that can be of the form "<word> clairen"
	nocomma = ['hi', 'hey', 'o/', 'hello', 'thanks', 'ty', 'tysm']

	if botlib.strip_direct_address(NAME, nocomma, words, pwords):
		direct_address(nick, words, pwords)
	elif NAME in pwords:	# "gossip" is messages mentioning us
		gossip(nick, words, pwords)
	else:
		chatting(nick, words, pwords)

def handle_action(line):
	global last16
	last16 += None


### BOOT ###

botlib.parse_args()

while True:
	sleep(5)
	writeln(f"SKIP {botlib.lastmsg}")
	lines = botlib.readmany()

	for i, line in enumerate(lines):
		depth = k - i - 1
		botlib.handle_line(line, handle_msg, handle_action)