我的问题是,第一个返回的字符串匹配中可以使用它之前,它将丢弃$ sub1,所以脚本不会继续。我已经尝试在第一次设置的回报中包含脚本的其余部分,并且它可以工作,但是...我向用户获取了多条消息,而其他2个设置返回了该通道。Mysqltcl foreach循环tcl
无论如何修复它,以便它不会将多条消息发送给用户和频道 ,因为“foreach子”中的每个子项都为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 {
}
}
}
它很难解释什么是试图完成。
最终的结果我尝试达到是...
从正则表达式,设置$认购
列出所有潜艇的DB
隐蔽内的所有%子的内数据库为*为符合以下
尝试匹配子到$认购
如果他们匹配,则继续下一个SELECT
从DB中选择所有的“USERS”,其中子是%sub%
然后向每个用户发送与选择相匹配的消息
上次设置的返回数计数匹配选择和发送消息通道
使用Donal提出的解决方案后。一切似乎都像一个小问题一样表现出来。代码中的[字符串匹配-nocase [get_subscription $ SQL(conn)] * $ subscription]部分不会将每个值都保存为要检查的变量。首先使用哪一行代替,然后停止而不是完成列表以查看是否有更多匹配。某些条目以不同方式添加,但应提供相同的结果。例如一些条目被添加为The.TV.Show.S01或%TV%显示%S01 这意味着它应该匹配两个部分并获得准确的数量和用户。
2013-03-05
Maphex
+0
如果很难解释你想要完成什么,请发布几个不同的*短*问题,每个问题都只涉及一个可理解的问题。在目前的形式下,我不确定如何处理您的问题。 –
2013-03-05 09:45:03