60 lines
1.8 KiB
Python
60 lines
1.8 KiB
Python
# Import the relevant bot
|
|
from main import my_bot
|
|
|
|
|
|
# Register a free response to a message
|
|
# Here we reply to people mentionning the bot
|
|
# Note that this is a simple exemple that can bug if
|
|
# bot's name is included in a word (ex "Bobsleigh")
|
|
@my_bot.on(lambda m: my_bot.nick in m.text)
|
|
def hello(msg):
|
|
my_bot.send(msg.to, f"What's up, {m.author}")
|
|
|
|
# Register a command on specific channels
|
|
@my_bot.on_channel("#fun", "#play")
|
|
@my_bot.command("!fun")
|
|
def cmd_fun(msg):
|
|
""" Give some fun, but only on authorized channels """
|
|
my_bot.send(msg.to, "Fun is allowed only here")
|
|
|
|
# Register a command on specific users
|
|
@my_bot.users("Breizh")
|
|
@my_bot.on(lambda m: True)
|
|
def breizh_is_always_right(msg):
|
|
""" Agree every message from Breizh """
|
|
my_bot.send(msg.to, "I agree what Breizh said.")
|
|
|
|
# Create commands using message history
|
|
@my_bot.on_channel("#duck_hunting")
|
|
@my_bot.command("!new")
|
|
def cmd_duck(msg):
|
|
my_bot.send(msg.to, "Hey, here's a duck!")
|
|
|
|
@my_bot.on_channel("#duck_hunting")
|
|
@my_bot.on(lambda m: m.text.lower == "pan!")
|
|
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 "pan!" in m.lower():
|
|
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!")
|
|
|
|
|
|
|