In addition to the issues @zondo has pointed out (i.e. PEP 8, some better operators, and the string features), I would also like to point out a few things.
1) Variable names
Variables names such as
temp are to be avoided. A much better name for this variable would be something like
^ Note: non PEP 8 camelCasing used to be consistent with existing code as posted. Obviously you would make this
message_stack when fixing that issue.
In your code, it should be noted, that lines 17 - 19 inclusive (shown below for brevity) introduce some (probably?) undesired behaviour...
if "PING" in line:
Consider that a user in the chat says "
PING". Your bot will replace it with
PONG and send the message back to the room.
This would be particularly bad given that this if-statement occurs before the banned words checking code (and
break's out of the loop). Users can now use bad words to their heart's content, provided they include the word "PING" (in uppercase) in their message! Furthermore, the bot will repeat these bad words back to the room!! (This is how security bugs get created)
Note, if you do end up implementing an
!add command to insert items into
banned_set, PLEASE ensure you have successfully protected your adding code from injection!
3) Decide your case-consistency and stick with it.
On line 23 you include a call to
message.lower() (the result of which is not stored anywhere). Then on line 26 your compare
message to a lower-case command string (
"!guitars"). Do you want
"!Guitars" to work just like
"!guitars"? If so, you may want to make
message lowercase before you split it (as you're already doing for the bad-words check).
Furthermore, with your current logic the message "I've just added the !guitars command to my bot" will trigger the same response as just saying "!guitars". This is because your current logic (using the
in operator,) disregards the position of the command string within the message.