36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
|
# Import the relevant bot
|
||
|
from main import my_bot
|
||
|
|
||
|
|
||
|
# Register commands using message history
|
||
|
@my_bot.command("!new")
|
||
|
@my_bot.on_channel("#duck_hunting")
|
||
|
def cmd_duck(msg):
|
||
|
""" Sends a duck, then congrats the first to shoot it """
|
||
|
my_bot.send(msg.to, "Hey, here's a duck!")
|
||
|
|
||
|
@my_bot.on(lambda m: m.text.lower() == "pan!")
|
||
|
@my_bot.on_channel("#duck_hunting")
|
||
|
def resp_duck(msg):
|
||
|
# Retreive index of last duck sent
|
||
|
index = None
|
||
|
for i, m in enumerate(reversed(my_bot.history)):
|
||
|
if m.author == my_bot.nick and m.to == "#duck_hunting" \
|
||
|
and m.text = "Hey, here's a duck!":
|
||
|
index = i
|
||
|
break
|
||
|
|
||
|
# If no duck found :(
|
||
|
if index is None:
|
||
|
my_bot.send(msg.to, "Where did you see a duck, idiot?")
|
||
|
return
|
||
|
|
||
|
# Check if there was replies from other users since the last duck
|
||
|
for m in my_bot.history[-i:-2]:
|
||
|
if m.text.lower() == "pan!":
|
||
|
my_bot.send(msg.to, f"{m.author} was quickier than you, looser!")
|
||
|
return
|
||
|
|
||
|
# User was the quickiest, congrats!
|
||
|
my_bot.send(msg.to, f"Congrats {msg.author}, you are the winner!")
|