Skip to content

Commit cd3b30d

Browse files
committed
Remove loop from hookup command to avoid performance issues
1 parent 721b260 commit cd3b30d

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

plugins/hookup.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,21 @@
1212
glomps = ["glomps", "tackles", "tackle hugs", "sexually glomps", "takes a flying leap and glomps", "bear hugs"]
1313

1414
usrcache = []
15-
#glob_chan = chan
1615

17-
#@hook.command(autohelp=False)
16+
@hook.command(autohelp=False)
1817
def hookup(db, conn, chan):
1918
"""matches two users from the channel in a sultry scene."""
2019
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:
20+
results = db.execute("select name from seen_user where chan = :chan and time > :time", {"chan": chan, "time": times}).fetchall()
21+
if not results or len(results) < 2:
2322
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
23+
# Make sure the list of people is unique
24+
people = list(set(row[0] for row in results))
25+
random.shuffle(people)
26+
person1, person2 = people[:2]
3027
room = random.choice(rooms)
3128
weapon = random.choice(weapons)
32-
out = "{} used {} and did it with {} in the {}.".format(person1[0], weapon, person2[0], room)
29+
out = "{} used {} and did it with {} in the {}.".format(person1, weapon, person2, room)
3330
return out
3431

3532
@hook.command(autohelp=False)

0 commit comments

Comments
 (0)