I am writing a bot for my discord server in ruby which I want to kind of act as a profanity filter. For that I read a list of "bad words" from a text file and store them into an array. Whenever a user sends a message (in a channel the bot is listening to), the bot then checks if that message includes one or more of these bad words. To do that I use the following code:
badWords.each { |badword|
if content.downcase.include? badword
puts badword
bot.send_message(event.channel.id, "Sorry #{event.user.name}, this message made my profanity senses tingle!")
bot.send_message(344559522003812354, "PROFANITY WARNING!!\n user: #{event.user.name}\n message: #{event.content}\n Please check if it is a cause for a warning. Use !?warn to give the user a warning.")
event.message.delete
respond = true
end
}
Now my problem is that the if-statement only returns true if the bad word in the content of the message matches the last one in the array. If it matches any other element of the array it always returns false.
I have already checked that the content of the message as well as every element of the array are all valid strings. Several ruby documentations haven't brought me any closer to a solution, either.
I'm not at a loss for words - I have enough of those in my text file - but I'm out of ideas where to look to even understand what the problem is. Is there any functionality of Array.each that I am misunderstanding?
Thank you all in advance for your help.
Aucun commentaire:
Enregistrer un commentaire