-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunwar.tcl
More file actions
260 lines (216 loc) · 6.44 KB
/
Copy pathfunwar.tcl
File metadata and controls
260 lines (216 loc) · 6.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# funwar.tcl
#
# This script was created to post fun clan wars/matches for the two multiplayer
# games RTCW and ET in channels periodically and with the commands below. The
# matches are retrieved from tables in postreSQL databases.
#
# Usage:
# !et post ET matches
# !rtcw post RTCW matches
# !funwars post ET and RTCW matches
#
# Enable for a channel with: .chanset #channel +funwar
# Disable for a channel with: .chanset #channel -funwar
#
# See https://github.com/hwipl/eggdrop-scripts for the latest version and
# additional information including the license (MIT).
# tested versions, might run on earlier versions
package require Tcl 8.6
package require eggdrop 1.8.4
# postgres sql
package require tdbc::postgres
namespace eval ::funwar {
# channel flag for enabling/disabling
setudef flag funwar
# sql server address, username and password
variable sqlServer "eggdroppostgres"
variable sqlUser "eggdrop"
variable sqlPassword "eggdropPassword"
# ET database and table on sql server
variable sqlDbnameEt "postgres"
variable sqlTblnameEt "test.funmatch"
# RTCW database and table on sql server
variable sqlDbnameRtcw "postgres"
variable sqlTblnameRtcw "test.funmatch"
# crontab style definition of how often funwars are posted in channels
# format:
# "MIN HOUR DAY MONTH YEAR"
# examples:
# "20,50 * * * *" post at minute 20 and 50 of every hour
# "*/10 * * * *" post every ten minutes
variable autoCron "20,50 * * * *"
# trigger configuration for ET, RTCW and both
variable triggerEt "!et"
variable triggerRtcw "!rtcw"
variable triggerBoth "!funwars"
# output configuration
variable outputHeader "*** Funwars: ***"
variable outputHeader2 "Game: Date/Time: XonX: Clantag: IRC:"
variable outputFooter "*** end of funwars list ***"
}
# post the funwar header in the channel
proc ::funwar::postHeader {chan} {
variable outputHeader
variable outputHeader2
set fmt "%-7s %-20s %-6s %-12s %-12s"
set lineHeader [format $fmt {*}$outputHeader2]
puthelp "PRIVMSG $chan :$outputHeader"
puthelp "PRIVMSG $chan :$lineHeader"
}
# post a funwar line in the channel
proc ::funwar::post {game id date time xonx clantag irc www server org chan } {
set fmt "%-7s %-20s %-6s %-12s %-12s"
set outputBody [format $fmt $game $date/$time $xonx $clantag $irc]
puthelp "PRIVMSG $chan :$outputBody"
}
# post the funwar footer in the channel
proc ::funwar::postFooter {chan} {
variable outputFooter
puthelp "PRIVMSG $chan :$outputFooter"
}
# get rows from sql table
proc ::funwar::sqlGet {server user password dbname tblname order limit} {
# connect to data base
# add -sslmode require if you want to enforce ssl
tdbc::postgres::connection create db -host $server -database $dbname \
-user $user -password $password
# query table in data base
set columns "id,date,time,xonx,clantag,irc,www,server,org"
set top "FETCH FIRST $limit ROWS ONLY"
set queryStr "SELECT $columns FROM $tblname ORDER BY $order DESC $top"
set query [db prepare $queryStr]
# collect all rows and return them
set rows ""
$query foreach row {
lappend rows $row
}
$query close
db close
return $rows
}
# query db, parse everything and post in channels
proc ::funwar::sqlParsedb {server user password dbname tblname order chan \
game limit command} {
# query rows from table in database
set rows [sqlGet $server $user $password $dbname $tblname $order \
$limit]
if {$rows == ""} {
return
}
if { $command != "noheader" } {
# post header in every given channel
foreach channel $chan {
postHeader $channel
}
}
# parse earch row and post them in channels
foreach row $rows {
set id [dict get $row id]
set date [dict get $row date]
set time [dict get $row time]
set xonx [dict get $row xonx]
set clantag [dict get $row clantag]
set irc [dict get $row irc]
set www [dict get $row www]
set server [dict get $row server]
set org [dict get $row org]
foreach channel $chan {
# post row in every given channel
post $game $id $date $time $xonx $clantag $irc $www \
$server $org $channel
}
}
if { $command != "nofooter" } {
# post footer in every given channel
foreach channel $chan {
postFooter $channel
}
}
}
# helper for posting rtcw entries
proc ::funwar::postRtcw {chan limit command} {
variable sqlServer
variable sqlUser
variable sqlPassword
variable sqlDbnameRtcw
variable sqlTblnameRtcw
set order "id"
set game "RTCW"
sqlParsedb $sqlServer $sqlUser $sqlPassword $sqlDbnameRtcw \
$sqlTblnameRtcw $order $chan $game $limit $command
}
# helper for posting et entries
proc ::funwar::postEt {chan limit command} {
variable sqlServer
variable sqlUser
variable sqlPassword
variable sqlDbnameEt
variable sqlTblnameEt
set order "id"
set game "ET"
sqlParsedb $sqlServer $sqlUser $sqlPassword $sqlDbnameEt \
$sqlTblnameEt $order $chan $game $limit $command
}
# handle the !rtcw trigger
proc ::funwar::rtcw { nick host hand chan arg } {
# check channel flag if enabled in this channel
if {![channel get $chan funwar]} {
return 0
}
set limit "10"
set command ""
postRtcw $chan $limit $command
return 1
}
# handle the !et trigger
proc ::funwar::et { nick host hand chan arg } {
# check channel flag if enabled in this channel
if {![channel get $chan funwar]} {
return 0
}
set limit "10"
set command ""
postEt $chan $limit $command
return 1
}
# handle the !funwars trigger
proc ::funwar::both { nick host hand chan arg } {
# check channel flag if enabled in this channel
if {![channel get $chan funwar]} {
return 0
}
set limit "3"
set command "nofooter"
postRtcw $chan $limit $command
set command "noheader"
postEt $chan $limit $command
return 1
}
# handle cron auto posting
proc ::funwar::auto { min hour day month year } {
# determine list of channels to post in based on channel flag
set autoChannels ""
foreach botChan [channels] {
# only use channels the bot is on and have the flag enabled
if {![botonchan $botChan] || ![channel get $botChan funwar]} {
continue
}
lappend autoChannels $botChan
}
if {$autoChannels == ""} {
# no channels to post in
return
}
set limit "3"
set command "nofooter"
postRtcw $autoChannels $limit $command
set command "noheader"
postEt $autoChannels $limit $command
}
namespace eval ::funwar {
bind pub - $triggerEt ::funwar::et
bind pub - $triggerRtcw ::funwar::rtcw
bind pub - $triggerBoth ::funwar::both
bind cron - $autoCron ::funwar::auto
putlog "Loaded funwars.tcl"
}