mnet_admin.tcl 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. # MNET (Message Network) - Networked Broadcasting of Messages over IRC for Communities
  2. # Administration Script
  3. # Copyright (C) 2004 Paul-Dieter Klumpp
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. set admin_channels {"#messagenet" "#quad.dev" "#qwnet"}
  19. set mnet_admin_version "Mnet!1.012trylink"
  20. # allowcheck for admin commands..
  21. proc mnet:admin_allowed_channel {nick mask hand chan admin_channels} {
  22. global botnick botnet-nick lastbind
  23. putlog "mnet! = an admin command triggered triggered by $nick ($mask) in $chan"
  24. # the command must be from a channel of "ownchannels"
  25. putlog "mnet! = trying if $chan is an admin-channel"
  26. set found 0
  27. set proper_botnick [mnet:proper_botnick ${botnet-nick}]
  28. foreach _try_chan $admin_channels {
  29. if {[string compare -nocase ${chan} ${_try_chan}] == 0} {
  30. putlog "mnet! = channel: ${chan} is allowed to administrate mnet on this bot"
  31. set found 1
  32. } else {
  33. # putlog "mnet: = not in list: $chan"
  34. }
  35. }
  36. if {$found == 0} {
  37. putlog "mnet! = administration on ${chan} on this bot is not allowed"
  38. return 0
  39. }
  40. if {![isop ${nick} ${chan}]} {
  41. putlog "mnet! = allowed in ${chan}, but $nick is no op"
  42. mnet:put_nick ${nick} "Sorry $nick, you are not an administrator here."
  43. return 0
  44. }
  45. if {${nick} == ${botnick}} {
  46. # no recursion :)
  47. return 0
  48. }
  49. # got through all checks .. so it's an OK channel
  50. return 1
  51. }
  52. proc mnet:admin_check_addchannel {nick channel} {
  53. if {[botonchan ${channel}] == 1} {
  54. mnet:put_nick ${nick} "Mnet! I added myself to the channel ${channel}"
  55. putlog "Mnet! I added myself to the channel ${channel}"
  56. } else {
  57. mnet:put_nick ${nick} "Mnet! I tried to add myself to the channel ${value} - but failed! Pls check."
  58. putlog "Mnet! I tried to add myself to the channel ${value} - but failed! Pls check."
  59. }
  60. }
  61. proc mnet:admin_rehash {nick mask hand chan text} {
  62. global admin_channels botnet-nick
  63. set proper_botnick [mnet:proper_botnick ${botnet-nick}]
  64. set allowed [mnet:admin_allowed_channel $nick $mask $hand $chan $admin_channels]
  65. if {$allowed == 0} {
  66. return 0
  67. }
  68. # rehash the bot... be sure the scripts are coded correctly!! or the bot will DIE!
  69. rehash
  70. mnet:put_nick ${nick} "Mnet! \"${proper_botnick}\" has rehashed and thus reloaded the mnet.tcl"
  71. }
  72. proc mnet:admin_version {nick mask hand chan text} {
  73. global admin_channels botnet-nick mnet_admin_version mnet
  74. set proper_botnick [mnet:proper_botnick ${botnet-nick}]
  75. set allowed [mnet:admin_allowed_channel $nick $mask $hand $chan $admin_channels]
  76. if {$allowed == 0} {
  77. return 0
  78. }
  79. # tells version
  80. mnet:put_nick ${nick} "Mnet! \"${proper_botnick}\" Admin: $mnet_admin_version and Mnet is: $mnet(version)"
  81. }
  82. proc mnet:admin_channelinfo {nick mask hand chan text} {
  83. global admin_channels botnet-nick
  84. set proper_botnick [mnet:proper_botnick ${botnet-nick}]
  85. set allowed [mnet:admin_allowed_channel $nick $mask $hand $chan $admin_channels]
  86. if {$allowed == 0} {
  87. return 0
  88. }
  89. # tell channel infos
  90. set chanlist [channels]
  91. set chan_count [llength $chanlist]
  92. set output ""
  93. foreach _try_chan ${chanlist} {
  94. set userlist [chanlist ${_try_chan}]
  95. set usercount [llength ${userlist}]
  96. if {${usercount} == 0} {
  97. # no users! someone banned us!
  98. set output "${output}\00313${_try_chan} ${usercount}\003, "
  99. } elseif {${usercount} <= 3} {
  100. # toooo few users .. channel dead?
  101. set output "${output}\00304${_try_chan} ${usercount}\003, "
  102. } elseif {${usercount} <=5} {
  103. # puh .. a bit more..
  104. set output "${output}\00308${_try_chan} ${usercount}\003, "
  105. } else {
  106. # a healthy channel .. > 5 users
  107. set output "${output}\00303${_try_chan} ${usercount}\003, "
  108. }
  109. }
  110. mnet:put_nick ${nick} "Mnet! \"${proper_botnick}\" has \002${chan_count}\002 channels: ${output}"
  111. }
  112. proc mnet:admin_have_channelrecord {chan} {
  113. set channel_records [channels]
  114. foreach _try_chan $channel_records {
  115. if {${chan} == ${_try_chan}} {
  116. # found the channel in the records, go for it and return 1
  117. return 1
  118. } else {
  119. # putlog "mnet: = not in list: $chan"
  120. }
  121. }
  122. # not found till now? then return 0
  123. return 0
  124. }
  125. proc mnet:admin_trylink {nick mask hand chan text} {
  126. global admin_channels botnet-nick mnet_admin_version mnet
  127. set proper_botnick [mnet:proper_botnick ${botnet-nick}]
  128. set botslist [userlist b]
  129. foreach _try_bot $botslist {
  130. if {[islinked ${_try_bot}] == 0} {
  131. set _try [link ${_try_bot}]
  132. if {$_try == 1} {
  133. mnet:put_nick ${nick} "Mnet! \"${proper_botnick}\" tries to link to \"${_try_bot}\""
  134. utimer 5 "mnet:admin_trylink_test ${_try_bot} ${nick}"
  135. }
  136. } else {
  137. mnet:put_nick ${nick} "Mnet! \"${proper_botnick}\" \00303already linked\003 to \"${_try_bot}\" - good."
  138. }
  139. }
  140. return 0
  141. }
  142. proc mnet:admin_trylink_test {_try_bot nick} {
  143. global admin_channels botnet-nick mnet_admin_version mnet
  144. set proper_botnick [mnet:proper_botnick ${botnet-nick}]
  145. if {[islinked ${_try_bot}] == 1} {
  146. mnet:put_nick ${nick} "Mnet! \"${proper_botnick}\" \00309succeeded\003 to link to \"${_try_bot}\"! :)"
  147. } else {
  148. mnet:put_nick ${nick} "Mnet! \"${proper_botnick}\" \00304FAILED\003 to link to \"${_try_bot}\"! :("
  149. }
  150. }
  151. proc mnet:admin_reload {nick mask hand chan text} {
  152. global admin_channels botnet-nick
  153. set proper_botnick [mnet:proper_botnick ${botnet-nick}]
  154. set allowed [mnet:admin_allowed_channel $nick $mask $hand $chan $admin_channels]
  155. if {$allowed == 0} {
  156. return 0
  157. }
  158. set cmd "dummy"
  159. # reload config... be sure this script works or the bot will DIE!
  160. putlog "mnet! = reloading configs by admin"
  161. mnet:dcc_configload ${cmd} ${cmd} ${cmd}
  162. mnet:put_nick ${nick} "Mnet! \"${proper_botnick}\" Configs reload triggered."
  163. }
  164. proc mnet:admin {nick mask hand chan text} {
  165. global admin_channels botnet-nick mnet_admin_version mnet
  166. set proper_botnick [mnet:proper_botnick ${botnet-nick}]
  167. set allowed [mnet:admin_allowed_channel $nick $mask $hand $chan $admin_channels]
  168. if {$allowed == 0} {
  169. return 0
  170. }
  171. set tmp_cmd [lindex ${text} 0]
  172. set tmp_value [lindex ${text} 1]
  173. set cmd [string tolower [mnet:kill_spaces ${tmp_cmd}]]
  174. set value [string tolower [mnet:kill_spaces ${tmp_value}]]
  175. if {${cmd} == "add"} {
  176. # check $value ... if there
  177. if {${value} != ""} {
  178. # get channelrecord: ${value} if we don't have the record already:
  179. if {[mnet:admin_have_channelrecord ${value}] == 0} {
  180. channel add ${value}
  181. # save it
  182. savechannels
  183. # did it work?
  184. utimer 10 "mnet:admin_check_addchannel ${nick} ${value}"
  185. } else {
  186. mnet:put_nick ${nick} "Mnet! Can't add again - I already have the channel ${value}"
  187. putlog "Mnet! Can't add again - I already have the channel ${value}"
  188. }
  189. } else {
  190. mnet:put_nick ${nick} "Mnet! Can't add: no channel given"
  191. }
  192. return 0
  193. }
  194. if {${cmd} == "remove"} {
  195. # check $value ... if there
  196. if {${value} != ""} {
  197. # remove ${value} from bot, if we have a record for it.
  198. if {[mnet:admin_have_channelrecord ${value}] == 1} {
  199. channel remove ${value}
  200. savechannels
  201. mnet:put_nick ${nick} "Mnet! I removed the channelrecord: ${value}"
  202. putlog "Mnet! I removed the channelrecord: ${value}"
  203. } else {
  204. mnet:put_nick ${nick} "Mnet! Can't remove - I don't have that channelrecord: ${value}"
  205. putlog "Mnet! Can't remove - I don't have that channelrecord: ${value}"
  206. }
  207. } else {
  208. mnet:put_nick ${nick} "Mnet! Can't remove: no channel given"
  209. }
  210. return 0
  211. }
  212. if {${cmd} == "reload"} {
  213. # reload network configs, pointing to procedure
  214. mnet:admin_reload $nick $mask $hand $chan $text
  215. return 0
  216. }
  217. if {${cmd} == "channels"} {
  218. # tell channel infos, pointing to procedure
  219. mnet:admin_channelinfo $nick $mask $hand $chan $text
  220. return 0
  221. }
  222. if {${cmd} == "rehash"} {
  223. # rehash
  224. mnet:admin_rehash $nick $mask $hand $chan $text
  225. return 0
  226. }
  227. if {${cmd} == "version"} {
  228. # tells version
  229. mnet:admin_version $nick $mask $hand $chan $text
  230. return 0
  231. }
  232. # none of the above worked .. so we are here:
  233. mnet:put_nick ${nick} "mnet! possible commands are: add remove reload channels rehash version"
  234. mnet:put_nick ${nick} "mnet! use either \002!mnet_botnetnickname <command>\002 to admin a single bot or just \002!mnet_<command>\002 to admin ALL bots that listen to your words here."
  235. mnet:put_nick ${nick} "add #channelname || bot joins a channel"
  236. mnet:put_nick ${nick} "remove #channelname || bot parts a channel"
  237. mnet:put_nick ${nick} "reload || reloads the mnet_configs"
  238. mnet:put_nick ${nick} "channels || tells some channel-infos"
  239. mnet:put_nick ${nick} "rehash || rehashes the bot, reloads all botscripts"
  240. mnet:put_nick ${nick} "version || tells version"
  241. }
  242. # timer weil $botnet-nick nicht sofort von eggdrop gesetzt wird
  243. utimer 3 "mnet:admin_bindings"
  244. proc mnet:admin_bindings {} {
  245. global botnet-nick
  246. set proper_botnick [mnet:proper_botnick ${botnet-nick}]
  247. bind pub - !mnet_${proper_botnick} mnet:admin
  248. bind pub - !mnet_reload mnet:admin_reload
  249. bind pub - !mnet_channels mnet:admin_channelinfo
  250. bind pub - !mnet_rehash mnet:admin_rehash
  251. bind pub - !mnet_version mnet:admin_version
  252. bind pub - !mnet_trylink mnet:admin_trylink
  253. }
  254. putlog "mnet! = mnet adminscript loaded: $mnet_admin_version"