【发布时间】:2013-02-19 10:53:40
【问题描述】:
我的问题是第一组返回删除 $sub1 之前它可以用于字符串匹配,因此脚本不会继续。我已尝试将脚本的其余部分包含在第一组返回中,并且它可以工作,但是...我收到多条消息给用户和其他 2 组返回的通道。
无论如何都要修复它,使其不会向用户和频道发送多条消息 因为“foreach sub”中的每个 sub 都为 pm 用户和 pm 频道生成一行,根据数据库中匹配的数量,可以是 1 或 2 条消息到 200 条消息。
bind pubm - * bind_pubm
proc bind_pubm {nick uhost handle channel text} {
global SQL; sql:start
set regexp {^!sub (.*) *$}
if {[regexp -nocase -- $regexp $text -> subscription]} {
if {[string match -nocase *HDTV* $subscription] || [string match -nocase *S??E??* $subscription]} {
set return [mysqlsel $SQL(conn) "select sub from DB_Subs where category='TV'" -list]
foreach {sub} $return { ; # Lists all the subs in the DB for matching.
regsub -all -- {%} $sub "*" sub1 ; # Replaces % in SQL to * for the String match later.
}
if {[string match -nocase $sub1* $subscription]} { ; # Matches if a sub in the previous list matches the regexp subscription fromthe beginging of proc.
set return [mysqlsel $SQL(conn) "select user from DB_Subs where sub LIKE '[mysqlescape $sub]%' AND category='TV'" -list]
foreach line $return {
foreach {user} $line break
if {[onchan $user $beta]} { ; # If the user is on the channel it PM each user.
putnow "PRIVMSG $nick : Subscription found matching your request."
} else {
}
}
set return [mysqlsel $SQL(conn) "select count(DISTINCT user) from DB_Subs where sub LIKE '[mysqlescape $sub]%' AND category='TV'" -flatlist] ; # Counts the users for the Channel message.
foreach {users} $return break
putnow "PRIVMSG $beta :SUBSCRIPTION: $users Users With Subscriptions for $subscription"
} else {
}
} else {
}
}
}
很难解释我到底想要完成什么。
最终我想要达到的结果是......
- 通过正则表达式设置 $subscription
- 列出数据库中的所有子项
- 将数据库中 sub 中的所有 % 转换为 * 以用于以下匹配
- 尝试将 sub 与 $subscription 匹配
- 如果匹配,则继续下一个 SELECT
- 从数据库中选择所有“用户”,其中 sub 类似于 %sub%
- 然后向每个用户发送一条匹配选择的消息
- 最后一组返回计数匹配选择的用户数并向频道发送消息
使用多纳尔建议的解决方案后。一切似乎都表现得像它应该有的一个小问题。代码的 [string match -nocase [get_subscription $SQL(conn)]* $subscription] 部分没有将每个都保存为要检查的变量。哪一行首先出现,它改为使用并停止而不是完成列表以查看是否还有更多匹配项。某些条目以不同的方式添加,但应提供相同的结果。例如,一些条目被添加为 The.TV.Show.S01 或 The%TV%Show%S01 这意味着它应该匹配两个部分并获得准确的计数和用户。
【问题讨论】:
-
如果难以解释您要完成的工作,请发布几个不同的简短问题,每个问题都针对一个可理解的问题。以目前的形式,我不确定如何处理您的问题。
标签: mysql loops foreach tcl eggdrop