php - 删除电报上带有特定单词的消息
问题描述
我写了一个机器人从电报组中删除一些单词。
function filter_messages() {
global $telegram;
$bad_words = [
'hello',
'hi'
];
$all_words = end( explode( ' ', $telegram->Text() ) );
if ( in_array( $all_words, $bad_words ) ) {
deletMessage();
}
}
当用户发送“你好”之类的消息时,它会起作用。机器人删除消息。但是当他发送“大家好”时,机器人不会删除该消息。
解决方案
function filter_messages() {
global $telegram;
$bad_words = [
'hello',
'hi'
];
//Make the array $badword to a (commaseparated) string
$badwords_to_string = implode(",", $bad_words);
//And then check if the any of the bad words in the telegramText exists
//based on that $telegram->Text() is a string
if (strpos($badwords_to_string, $telegram->Text()) !== false) {
deletMessage();
}
}
推荐阅读
- flutter - 无法从颤振中的模型类获取数据
- python - 如何将数据框转换为列表
- azure - AzurePipeline 错误:找不到与模板文件模式匹配的任何文件
- swift - SPM 与资源 + TestFlight
- python - django html中的if语句和for循环问题
- influxdb - 将数据从 CSV 文件导入到 InfluxDB
- python - 切片numpy数组取每n个元素
- python-3.6 - 如何从 python3.6 中的两个列表中删除公共元素?
- java - Bouncy Castle 的 CMSSignedData PEM 生成的数据导致解析问题
- javascript - JavaScript:函数创建数组作为返回对象的值