문제

How to restrict command in the IRC bot written in Python?

For example I have:

data. = irc.recv(2048)

if data.find("^cmd",7) != -1:
    irc.send('PRIVMSG ' + channel + ' :' + 'do_something' + '\r\n')

But if any user write bla bla ^cmdblabla it will works too. I don't want it so how may I restrict it? Tried with len() but there is no chance to do it by this way. Seems that regexp also will not help for this.

올바른 솔루션이 없습니다

다른 팁

You need to write a tuple with the arguments allowed. For example:

commands = ("some_command", "other_command", "this_continues")

Then just:

if not command in commands:
    print("Unrecognized command.")

You have to parse the data before to get the command. Maybe like this:

command = data[:data.find(" ")]
# And here the code above

Hope it helps.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top