diff --git a/proposal/commands.py b/proposal/commands.py index 257a59a..d35934b 100644 --- a/proposal/commands.py +++ b/proposal/commands.py @@ -8,52 +8,19 @@ from main import my_bot # 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}") + """ Says hello to nice people """ + 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") +@my_bot.on_channel("#fun", "#play") def cmd_fun(msg): - """ Give some fun, but only on authorized channels """ - my_bot.send(msg.to, "Fun is allowed only here") + """ Gives 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) +@my_bot.users("Breizh") def breizh_is_always_right(msg): - """ Agree every message from Breizh """ + """ Agrees 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!") - - - diff --git a/proposal/dynamic.py b/proposal/dynamic.py new file mode 100644 index 0000000..535a518 --- /dev/null +++ b/proposal/dynamic.py @@ -0,0 +1,37 @@ +# Import the relevant bot and libraries +from main import my_bot +import uuid + +# Setup some global vars +vip_nicks = {"Darks"} +vip_channel = uuid.uuid4() + +# Create a "private" function to handle the VIP channel +@my_bot.command("!vip") +def cmd_vip(msg): + if msg.author not in vip_nicks: + my_bot.send(msg.to, "Sorry but you're not a VIP. This command is for VIPs only.") + return + + # No arguments, give the channel name as private message + if msg == "": + my_bot.send(msg.author, f"The VIP channel is #{vip_channel}") + # If message was send in a public channel, send a reminder + if msg.to.beginswith("#"): + my_bot.send(msg.to, "Check you private messages, {msg.author}.") + + # Parse args + match(msg.text.split()): + case ["invite", nick]: + vip_nicks.add(nick) + my_bot.send(msg.to, f"{nick} is now a VIP.") + case ["exclude", nick]: + try: + vip_nicks.remove(nick) + my_bot.send(msg.to, f"{nick} is no longer a VIP.") + except KeyError: + my_bot.send(msg.to, f"{nick} not found in the VIPs.") + case ["list"]: + my_bot.send(msg.to, "VIPs are " + ", ".join(vip_nicks) + ".") + case _, : + my_bot.send(msg.to, "Invalid command. Valid ones are: `invite `, `exclude `, `list`.") \ No newline at end of file diff --git a/proposal/help.py b/proposal/help.py new file mode 100644 index 0000000..b2e7caf --- /dev/null +++ b/proposal/help.py @@ -0,0 +1,9 @@ +# Import the relevant bot +from main import my_bot + + +# Register a command to display help +# This uses the internal `help` method of class Bot +@my_bot.command("!help") +def help(msg): + my_bot.send(msg.to, my_bot.help()) diff --git a/proposal/history.py b/proposal/history.py new file mode 100644 index 0000000..b343ebb --- /dev/null +++ b/proposal/history.py @@ -0,0 +1,35 @@ +# 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!") diff --git a/proposal/main.py b/proposal/main.py index 268968f..ae4db80 100644 --- a/proposal/main.py +++ b/proposal/main.py @@ -15,5 +15,8 @@ my_bot = Bot( def cmd_pong(msg): my_bot.send(msg.to, "Pong!") -# Or import them from another file -from commands import * +# Or import them from another file(s) +import commands +import dynamic +import help +import history