Skip to content

Commit b01878d

Browse files
authored
Merge pull request CloudBotIRC#140 from linuxdaemon/gonzobot+hookup-fix
Fix + general cleanup for hookup.py
2 parents 5f13b96 + 0bd42f8 commit b01878d

4 files changed

Lines changed: 129 additions & 25 deletions

File tree

data/bite.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"templates": [
3+
"{action} {user}'s {bodypart}"
4+
],
5+
"parts": {
6+
"action": [
7+
"bites",
8+
"nips",
9+
"nibbles",
10+
"chomps",
11+
"licks",
12+
"teases",
13+
"chews",
14+
"gums",
15+
"tastes"
16+
],
17+
"bodypart": [
18+
"cheeks",
19+
"ear lobes",
20+
"nipples",
21+
"nose",
22+
"neck",
23+
"toes",
24+
"fingers",
25+
"butt",
26+
"taint",
27+
"thigh",
28+
"grundle",
29+
"tongue",
30+
"calf",
31+
"nurses",
32+
"nape"
33+
]
34+
}
35+
}

data/glomp.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
glomps
2+
tackles
3+
tackle hugs
4+
sexually glomps
5+
takes a flying leap and glomps
6+
bear hugs

data/hookup.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"templates": [
3+
"{user1} used {weapon} and did it with {user2} in the {room}."
4+
],
5+
"parts": {
6+
"weapon": [
7+
"a candlestick",
8+
"an axe",
9+
"a pistol",
10+
"rope",
11+
"gloves",
12+
"a horseshoe",
13+
"a knife",
14+
"a baseball bat",
15+
"a chalice",
16+
"a dumbbell",
17+
"a wrench",
18+
"a trophy",
19+
"a pipe",
20+
"garden shears"
21+
],
22+
"room": [
23+
"courtyard",
24+
"guest house",
25+
"observatory",
26+
"theatre",
27+
"drawing room",
28+
"garage",
29+
"spa",
30+
"master bedroom",
31+
"studio",
32+
"pool",
33+
"arcade",
34+
"beach house",
35+
"surf shop",
36+
"kitchen",
37+
"ballroom",
38+
"conservatory",
39+
"billiard room",
40+
"library",
41+
"study",
42+
"hallway",
43+
"lounge",
44+
"dining room",
45+
"cellar"
46+
]
47+
}
48+
}

plugins/hookup.py

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,62 @@
1+
import codecs
2+
import json
3+
import os
14
import random
25
import time
36

47
from cloudbot import hook
8+
from cloudbot.util.textgen import TextGenerator
59

6-
rooms = ["courtyard", "guest house", "observatory", "theatre", "drawing room", "garage", "spa", "master bedroom", "studio", "pool", "arcade", "beach house", "surf shop", "kitchen", "ballroom", "conservatory", "billiard room", "library", "study", "hallway", "lounge", "dining room", "cellar"]
7-
weapons = ["a candlestick","an axe", "a pistol", "rope", "gloves", "a horseshoe", "a knife", "a baseball bat", "a chalice", "a dumbbell", "a wrench", "a trophy", "a pipe", "garden shears"]
10+
hookups = {}
11+
bites = {}
12+
glomps = []
813

9-
bitesyns = ["bites", "nips", "nibbles", "chomps", "licks", "teases", "chews", "gums", "tastes"]
10-
bodyparts = ["cheeks", "ear lobes", "nipples", "nose", "neck", "toes", "fingers", "butt", "taint", "thigh", "grundle", "tongue", "calf", "nurses", "nape"]
1114

12-
glomps = ["glomps", "tackles", "tackle hugs", "sexually glomps", "takes a flying leap and glomps", "bear hugs"]
15+
@hook.on_start
16+
def load_data(bot):
17+
hookups.clear()
18+
glomps.clear()
19+
bites.clear()
1320

14-
usrcache = []
15-
#glob_chan = chan
21+
with codecs.open(os.path.join(bot.data_dir, "hookup.json"), encoding="utf-8") as f:
22+
hookups.update(json.load(f))
1623

17-
#@hook.command(autohelp=False)
18-
def hookup(db, conn, chan):
24+
with codecs.open(os.path.join(bot.data_dir, "glomp.txt"), encoding="utf-8") as f:
25+
lines = (line.strip() for line in f if not line.startswith("//"))
26+
glomps.extend(filter(None, lines))
27+
28+
with codecs.open(os.path.join(bot.data_dir, "bite.json"), encoding="utf-8") as f:
29+
bites.update(json.load(f))
30+
31+
32+
@hook.command(autohelp=False)
33+
def hookup(db, chan):
1934
"""matches two users from the channel in a sultry scene."""
2035
times = time.time() - 86400
21-
people = db.execute("select name from seen_user where chan = :chan and time > :time", {"chan": chan, "time": times}).fetchall()
22-
if not people:
36+
results = db.execute("select name from seen_user where chan = :chan and time > :time", {"chan": chan, "time": times}).fetchall()
37+
if not results or len(results) < 2:
2338
return "something went wrong"
24-
person1 = people[random.randint(0,len(people) - 1)]
25-
person2 = people[random.randint(0,len(people) - 1)]
26-
loop = 0
27-
while person1 == person2 or loop < 5:
28-
person2 = people[random.randint(0, len(people) -1 )]
29-
loop = loop + 2
30-
room = random.choice(rooms)
31-
weapon = random.choice(weapons)
32-
out = "{} used {} and did it with {} in the {}.".format(person1[0], weapon, person2[0], room)
33-
return out
39+
# Make sure the list of people is unique
40+
people = list(set(row[0] for row in results))
41+
random.shuffle(people)
42+
person1, person2 = people[:2]
43+
variables = {
44+
'user1': person1,
45+
'user2': person2,
46+
}
47+
generator = TextGenerator(hookups['templates'], hookups['parts'], variables=variables)
48+
return generator.generate_string()
49+
3450

3551
@hook.command(autohelp=False)
3652
def bite(text, chan, action):
3753
"""bites the specified nick somewhere random."""
3854
if not text:
3955
return "please tell me who to bite."
4056
name = text.split(' ')[0]
41-
bite = random.choice(bitesyns)
42-
body = random.choice(bodyparts)
43-
out = "{} {}'s {}.".format(bite, name, body)
44-
action(out, chan)
57+
generator = TextGenerator(bites['templates'], bites['parts'], variables={'user': name})
58+
action(generator.generate_string(), chan)
59+
4560

4661
@hook.command(autohelp=False)
4762
def glomp(text, chan, action):

0 commit comments

Comments
 (0)