Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

!! / !bang? #34

Open
asottile opened this issue Oct 14, 2020 · 4 comments
Open

!! / !bang? #34

asottile opened this issue Oct 14, 2020 · 4 comments

Comments

@asottile
Copy link
Member

1:05 MetaBytez: Do you have a command !! that just repeats the last bot command 
Kappa
1:05 MetaBytez: Or maybe !bang
@Preocts
Copy link

Preocts commented Jan 30, 2022

Would you two be open to me taking a stab at this one?

@asottile
Copy link
Member Author

iirc this is hard / not really feasible since every message is dispatched independently and asynchronously

@Preocts
Copy link

Preocts commented Jan 30, 2022

I was poking around and the add_alias() function caught my muse. Would appear if an alias !bang and !! were made of the most recent command successfully found that you'd have part of the desired outcome. I may have missed some I/O but it looked to me like commands are only held in memory so this call felt very inexpensive.

twitch-chat-bot/bot/data.py

Lines 113 to 116 in 50341c3

def add_alias(cmd: str, *aliases: str) -> None:
for alias in aliases:
COMMANDS[alias] = COMMANDS[cmd]
SECRET_CMDS.add(alias)

How to handle keeping message permissions from being skipped, that all commands are stripped of extra bangs, and the command pattern doesn't presently match !! were where I stopped.

command = f'!{cmd_match["cmd"].lstrip("!").lower()}'

COMMAND_PATTERN_RE = re.compile(r'!+\w+')

(either way, neat implementation and I learned a few things digging through it which was my primary goal!)

@asottile
Copy link
Member Author

the aliasing system is for command names and probably wouldn't work or help for command values -- it's also meant to be ~immutable after process startup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants