Add command aliases and better help
This commit is contained in:
parent
59fb327773
commit
89077db935
28
fun_cmnds.py
28
fun_cmnds.py
|
@ -1,14 +1,24 @@
|
|||
from irc_api import api
|
||||
from irc_api.api import auto_help
|
||||
|
||||
from random import randint, choice
|
||||
|
||||
@api.every(30, desc="Fait apparaître un canard de manière aléatoire")
|
||||
def pop_duck(bot):
|
||||
if randint(1, 10) == 1:
|
||||
ducks = ("Coin coin ! 🦆", "Couac ! 🦆")
|
||||
bot.nb_ducks += 1
|
||||
bot.send("#glados", choice(ducks))
|
||||
if randint(1, 10) == 1 and bot.nb_ducks > 1:
|
||||
bot.send("#glados", "Le canard est parti…")
|
||||
bot.nb_ducks -= 1
|
||||
|
||||
|
||||
@api.channel("#glados")
|
||||
@api.on(lambda m: "blague" in m.text.lower())
|
||||
def fun(bot, msg):
|
||||
bot.send(msg.to, "Mais je suis nuuuullle en blagues euh.")
|
||||
|
||||
|
||||
@api.user("Shadow15510")
|
||||
@api.on(lambda m: "glados" in m.text.lower())
|
||||
def agree(bot, msg):
|
||||
bot.send(msg.to, "Ouaip ! Complètement d'accord avec toi !")
|
||||
@api.command("pan", desc="Tirer sur un canard")
|
||||
def fire(bot, msg):
|
||||
if bot.nb_ducks > 0:
|
||||
bot.nb_ducks -= 1
|
||||
bot.send("#glados", "Touché !")
|
||||
else:
|
||||
bot.send("#glados", "Euh va check ta vue stp…")
|
||||
|
|
|
@ -55,7 +55,3 @@ def wiki(bot, msg, text: str, limit: int=1):
|
|||
bot.send(msg.to, f"{len(response[1])} résultat{('', 's')[limit > 1]} pour la recherche : '{text}'.")
|
||||
for name, link in zip(response[1], response[3]):
|
||||
bot.send(msg.to, f" {name} : {link}")
|
||||
|
||||
@api.every(5)
|
||||
def foo(bot):
|
||||
bot.send("#glados", "foo called")
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import logging
|
||||
import re
|
||||
from functools import wraps
|
||||
from irc_api.irc import IRC, History
|
||||
from threading import Thread
|
||||
import time
|
||||
|
@ -9,12 +8,14 @@ import time
|
|||
PREFIX = ""
|
||||
|
||||
|
||||
def command(name, desc=""):
|
||||
def command(name, alias=(), desc=""):
|
||||
if not alias or not name in alias:
|
||||
alias += (name,)
|
||||
def decorator(func):
|
||||
return Command(
|
||||
name=name,
|
||||
func=func,
|
||||
events=[lambda m: m.text.startswith(PREFIX + name)],
|
||||
events=[lambda m: True in [m.text.startswith(PREFIX + cmd) for cmd in alias]],
|
||||
desc=desc,
|
||||
cmnd_type=1
|
||||
)
|
||||
|
@ -215,7 +216,7 @@ class Bot:
|
|||
else:
|
||||
self.callbacks[command.name] = command
|
||||
|
||||
if add_to_help:
|
||||
if add_to_help and command.cmnd_type == 1:
|
||||
self.commands_help[command.name] = command
|
||||
|
||||
def add_commands(self, *commands, **kwargs):
|
||||
|
@ -243,7 +244,7 @@ class Bot:
|
|||
self.callbacks.pop(command_name)
|
||||
|
||||
|
||||
@command("aide")
|
||||
@command("aide", alias=("aide", "help", "doc", "assistance"))
|
||||
def auto_help(bot, msg, fct_name: str=""):
|
||||
"""Aide des commandes disponibles."""
|
||||
if fct_name and fct_name in bot.commands_help.keys():
|
||||
|
|
6
main.py
6
main.py
|
@ -21,14 +21,16 @@ from secrets import USER, PASSWORD
|
|||
LOG_FORMAT = "%(asctime)s [%(levelname)s] <%(filename)s> %(funcName)s: %(message)s"
|
||||
logging.basicConfig(format=LOG_FORMAT, level=logging.DEBUG)
|
||||
|
||||
class MyBot(api.Bot):
|
||||
nb_ducks = 0
|
||||
|
||||
glados = api.Bot(
|
||||
|
||||
glados = MyBot(
|
||||
(USER, PASSWORD),
|
||||
('irc.planet-casio.com', 6697),
|
||||
["#glados"],
|
||||
gv4_cmnds, fcmnds,
|
||||
prefix="!",
|
||||
limit=50
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue