Advertisement
IceKirby

ReplaceWords Mod

Jul 27th, 2012
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.51 KB | None | 0 0
  1. //this script has all the current scripts merged together into one neat package
  2. //report bugs to Crystal Moogle
  3. //feel free to use it, edit it, improve it, do whatever.
  4. //lot of stuff "borrowed" from main scripts and stackoverflow~ :3
  5. //commands found by using ~commandlist
  6. //currently needs 2.0.05 to fix channel links
  7. //this mod adds a ~replacetext feature, that changes and highlight a word to another
  8. var auth_symbol = {
  9. "0": "",
  10. "1": "+",
  11. "2": "+",
  12. "3": "+",
  13. "4": ""
  14. //change these to what you have set yourself and more if needed using the format "x": "symbol",
  15. }
  16. var auth_style = {
  17. "0": "<b>",
  18. "1": "<i><b>",
  19. "2": "<i><b>",
  20. "3": "<i><b>",
  21. "4": "<b>"
  22. //change this to the style you have set, only start tags are needed
  23. }
  24.  
  25.  
  26. /* ReplaceWords Code */
  27. var message_replace = {
  28. "sux": "is awesome",
  29. "llama": "Llama Llama Duck",
  30. "brb": "Be right back",
  31. "afk": "Away from Keyboard"
  32. } // Replaces the word at the left for the word at the right
  33. var replace_color = "blue"; //Changes the color of a replace text
  34. /* ReplaceWords Code */
  35.  
  36.  
  37. var commandsymbol = "~" //change this if you want to use another symbol. Make sure it is 1 character still and if you use "!" or "/" that it doesn't conflict with existing scripts
  38. var stalkwords = [] // add stalkwords for you to be pinged format is ["word1","word2"], obviously you can add more than 2
  39. var hilight = "BACKGROUND-COLOR: #ffcc00" //change this if you want a different hilight colour when pinged (leave background there unless you want a different style)
  40. var fontcolour = "#000000" //change this for different font colours
  41. var fonttype = "" //this changes the font type of your text, leave it blank for default
  42. var fontstyle = "" //this changes the style of the font (bold/italics/etc), start tags only are needed.
  43. var fontsize = 3 //this changes the font size of your text, 3 is default
  44. var greentext = '#789922' //changes the text when someone quotes with ">" at the start
  45. //var punctuation = [".", ",", "\"", "'", "&", ";", ":"] //list of common punctuation, increase or decrease as you see fit. No longer needed with the new way of doing enriched text, will probably remove after more testing is done on the new method
  46. var flash = true //turns flashes on/off (probably best to use ~flash on/off though)
  47. //these things below shouldn't be touched unless you know what you're doing~
  48. function init() {
  49. if (sys.getVal('etext') === "true") {
  50. etext = "true"
  51. } else {
  52. etext = "false"
  53. }
  54. if (sys.getVal('tgreentext') === "true") {
  55. tgreentext = "true"
  56. } else {
  57. tgreentext = "false"
  58. }
  59.  
  60.  
  61. /* ReplaceWords Code */
  62. if (sys.getVal('treplacetext') === "true") {
  63. replace_enabled = "true"
  64. } else {
  65. replace_enabled = "false"
  66. }
  67. /* ReplaceWords Code */
  68.  
  69.  
  70. if (sys.getVal('stalkwords') !== "") {
  71. var nstalkwords = sys.getVal('stalkwords').split(",")
  72. stalkwords = nstalkwords.concat(stalkwords)
  73. stalkwords = eliminateDuplicates(stalkwords)
  74. }
  75. }
  76.  
  77. function eliminateDuplicates(arr) { //stolen from http://dreaminginjavascript.wordpress.com/2008/08/22/eliminating-duplicates/
  78. var i,
  79. len = arr.length,
  80. out = [],
  81. obj = {};
  82. for (i = 0; i < len; i++) {
  83. obj[arr[i]] = 0;
  84. }
  85. for (i in obj) {
  86. out.push(i);
  87. }
  88. return out;
  89. }
  90. if (client.ownId() !== -1) {
  91. init()
  92. }
  93. client.network().playerLogin.connect(function () {
  94. script.awayFunction()
  95. init()
  96. })
  97. poScript = ({
  98. awayFunction: function () {
  99. if (sys.getVal("idle") === "true") {
  100. client.goAway(true)
  101. } else {
  102. client.goAway(false)
  103. }
  104. },
  105. tagEnd: function (string) {
  106. newstring = string.replace(/</g, "</")
  107. return newstring
  108. },
  109. html_escape: function (text) {
  110. var m = String(text);
  111. if (m.length > 0) {
  112. var amp = "&am" + "p;";
  113. var lt = "&l" + "t;";
  114. var gt = "&g" + "t;";
  115. return m.replace(/&/g, amp).replace(/</g, lt).replace(/>/g, gt);
  116. } else {
  117. return "";
  118. }
  119. },
  120. htmlLinks: function (text) {
  121. var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
  122. var found = text.match(exp)
  123. var newtext
  124. var newfound
  125. for (x in found) {
  126. newfound = found[x].replace(/\//g, sys.md5('/'))
  127. newfound = newfound.replace(/_/g, sys.md5('_'))
  128. text = text.replace(found[x], newfound)
  129. newtext = ("<a href ='" + newfound + "'>" + newfound + "</a>").replace(/&amp;/gi, "&")
  130. text = text.replace(newfound, newtext)
  131. }
  132.  
  133.  
  134. /* ReplaceWords Code */
  135. if (replace_enabled == "true") {
  136. var reg;
  137. for (var x in message_replace) {
  138. reg = new RegExp(x, "gi");
  139. text = text.replace(reg, '<font color="' + replace_color + '">' + message_replace[x] + '</font>');
  140. }
  141. }
  142. /* ReplaceWords Code */
  143.  
  144.  
  145. if (etext == "true") {
  146. text = this.enrichedText(text)
  147. }
  148. var expt = new RegExp(sys.md5('/'), "g")
  149. if (text.search(expt) != -1) {
  150. text = text.replace(expt, "/")
  151. }
  152. expt = new RegExp(sys.md5('_'), "g")
  153. if (text.search(expt) != -1) {
  154. text = text.replace(expt, "_")
  155. }
  156. return text
  157. },
  158. enrichedText: function (text) {
  159. var expi = new RegExp("/(\\S+)/(?![^\\s<]*>)")
  160. text = text.replace(expi, "<i>$1</i>")
  161. var expii = new RegExp("\\\\(\\S+)\\\\(?![^\\s<]*>)")
  162. text = text.replace(expii, "<i>$1</i>")
  163. var expb = new RegExp("\\*(\\S+)\\*(?![^\\s<]*>)")
  164. text = text.replace(expb, "<b>$1</b>")
  165. var expu = new RegExp("_(\\S+)_(?![^\\s<]*>)")
  166. text = text.replace(expu, "<u>$1</u>")
  167. return text
  168. },
  169. sendMessage: function (message, channel) {
  170. if (channel === undefined) {
  171. channel = client.currentChannel()
  172. }
  173. client.printChannelMessage(message, channel, false)
  174. return;
  175. },
  176. beforeChannelMessage: function (message, channel, html) {
  177. var chan = channel
  178. var pos = message.indexOf(': ');
  179. if (pos != -1) {
  180. if (client.id(message.substring(0, pos)) == -1) {
  181. return;
  182. }
  183. var id = client.id(message.substring(0, pos))
  184. if (client.isIgnored(id)) {
  185. return;
  186. }
  187. var playname = message.substring(0, pos)
  188. var playmessage = this.html_escape(message.substr(pos + 2))
  189. var msg = playmessage.split(' ')
  190. var link, linkplaceholder
  191. /*for (x in msg) {
  192. var msgnew = "",
  193. otherend = ""
  194. var msgl = msg[x].length
  195. var nmsgl = msg[x].length
  196. var start = msg[x][0]
  197. var end = msg[x][parseInt(msgl - 1)]
  198. for (y in punctuation) {
  199. if (start == punctuation[y]) {
  200. start = msg[x][1]
  201. msgl = msgl - 1
  202. }
  203. if (end == punctuation[y]) {
  204. end = msg[x][parseInt(nmsgl - 2)]
  205. otherend = punctuation[y]
  206. msgl = msgl - 1
  207. }
  208. }
  209. if (((start == "*" && end == "*" && msgl > 2) || ((start == "/" || start == "\\") && (end == "/" || end == "\\") && msgl > 2) || (start == "_" && end == "_" && msgl > 2)) && etext === "true") {
  210. var modifier, endmodifier, newmsg
  211. if (start == "*") {
  212. modifier = "<b>"
  213. endmodifier = "</b>"
  214. }
  215. if (start == "/" || start == "\\") {
  216. modifier = "<i>"
  217. endmodifier = "</i>"
  218. }
  219. if (start == "_") {
  220. modifier = "<u>"
  221. endmodifier = "</u>"
  222. }
  223. var i = msg[x].lastIndexOf(end)
  224. if (i >= 0) {
  225. newmsg = msg[x].substring(0, i) + endmodifier + (otherend == undefined ? "" : otherend)
  226. }
  227. msgnew = newmsg.replace(start, modifier)
  228. playmessage = playmessage.replace(msg[x], msgnew)
  229. }
  230. }*/
  231. var colour = client.color(id)
  232. if (colour === "#000000") {
  233. var clist = ['#5811b1', '#399bcd', '#0474bb', '#f8760d', '#a00c9e', '#0d762b', '#5f4c00', '#9a4f6d', '#d0990f', '#1b1390', '#028678', '#0324b1'];
  234. colour = clist[src % clist.length];
  235. }
  236. var ownName = this.html_escape(client.ownName())
  237. if (playmessage.toLowerCase().indexOf(ownName.toLowerCase()) != -1 && playname !== ownName && flash !== false) {
  238. var name = new RegExp("\\b" + ownName + "\\b", "i")
  239. newplaymessage = playmessage.replace(name, "<span style='" + hilight + "'>" + client.ownName() + "</span>")
  240. if (newplaymessage !== playmessage) {
  241. playmessage = newplaymessage.replace(newplaymessage, "<i> " + newplaymessage + "</i><ping/>")
  242. }
  243. }
  244. for (x in stalkwords) {
  245. var stalk = new RegExp("\\b" + stalkwords[x] + "\\b", "i")
  246. var stalks = playmessage.match(stalk)
  247. if (playmessage.toLowerCase().search(stalk) != -1 && playname !== client.ownName() && flash !== false) {
  248. newplaymessage = playmessage.replace(stalk, "<span style='" + hilight + "'>" + stalks + "</span>")
  249. if (newplaymessage !== playmessage) {
  250. playmessage = newplaymessage.replace(newplaymessage, "<i> " + newplaymessage + "</i><ping/>")
  251. }
  252. }
  253. }
  254. if (playmessage.substr(0, 4) == "&gt;" && tgreentext === "true") {
  255. playmessage = "<font color = '" + greentext + "'>" + playmessage + "</font>"
  256. } else {
  257. playmessage = "<font color = '" + fontcolour + "'>" + playmessage
  258. }
  259. var symbolLength = 0
  260. for (x in auth_symbol) {
  261. if (x > symbolLength) {
  262. symbolLength = x
  263. }
  264. }
  265. var auth = client.auth(id)
  266. if (auth > symbolLength) {
  267. auth = 0
  268. }
  269.  
  270. playmessage = client.channel(chan).addChannelLinks(playmessage)
  271. playmessage = this.htmlLinks(playmessage)
  272. client.printChannelMessage("<font face ='" + fonttype + "'><font size = " + fontsize + "><font color='" + colour + "'><timestamp/> " + auth_symbol[auth] + auth_style[auth] + playname.replace(/±/gi, "[bot]") + ": </font>" + this.tagEnd(auth_style[auth]) + fontstyle + playmessage + this.tagEnd(fontstyle), chan, true)
  273. sys.stopEvent()
  274. }
  275. },
  276. beforeSendMessage: function (message, channel) {
  277. if (message[0] == commandsymbol) {
  278. var command, commandData
  279. var pos = message.indexOf(' ');
  280. if (pos != -1) {
  281. command = message.substring(1, pos).toLowerCase();
  282. commandData = message.substr(pos + 1);
  283. } else {
  284. command = message.substr(1).toLowerCase();
  285. }
  286. if (command == "commandlist" || command == "commandslist") {
  287. sys.stopEvent()
  288. this.sendMessage("*** Client Commands ***")
  289. this.sendMessage(commandsymbol + "etext on/off: Allows you to turn Enriched text on/off")
  290. this.sendMessage(commandsymbol + "greentext on/off: Allows you to turn greentext on/off")
  291. this.sendMessage(commandsymbol + "idle on/off: Allows you to turn auto-idle on/off")
  292. this.sendMessage(commandsymbol + "goto channel: Allows you to switch to that channel (joins if you're not in that channel)")
  293. this.sendMessage(commandsymbol + "stalkwords: Allows you to view your current stalkwords")
  294. this.sendMessage(commandsymbol + "[add/remove]stalkword: Allows you to add/remove stalkwords")
  295. this.sendMessage(commandsymbol + "flash on/off: Allows you to turn flashes on/off")
  296. }
  297. if (command == "etext") {
  298. sys.stopEvent()
  299. if (commandData == "on") {
  300. etext = "true"
  301. sys.saveVal('etext', true)
  302. this.sendMessage("+ClientBot: You turned Enriched text on!")
  303. return;
  304. }
  305. if (commandData == "off") {
  306. etext = "false"
  307. sys.saveVal('etext', false)
  308. this.sendMessage("+ClientBot: You turned Enriched text off!")
  309. return;
  310. }
  311. this.sendMessage("+ClientBot: Please use on/off")
  312. }
  313. if (command == "greentext") {
  314. sys.stopEvent()
  315. if (commandData == "on") {
  316. tgreentext = "true"
  317. sys.saveVal('tgreentext', true)
  318. this.sendMessage("+ClientBot: You turned greentext on!")
  319. return;
  320. }
  321. if (commandData == "off") {
  322. tgreentext = "false"
  323. sys.saveVal('tgreentext', false)
  324. this.sendMessage("+ClientBot: You turned greentext off!")
  325. return;
  326. }
  327. this.sendMessage("+ClientBot: Please use on/off")
  328. }
  329.  
  330. /* ReplaceWords Code */
  331. if (command == "replacetext") {
  332. sys.stopEvent()
  333. if (commandData == "on") {
  334. replace_enabled = "true"
  335. sys.saveVal('treplacetext', true)
  336. this.sendMessage("+ClientBot: You turned replacetext on!")
  337. return;
  338. }
  339. if (commandData == "off") {
  340. replace_enabled = "false"
  341. sys.saveVal('treplacetext', false)
  342. this.sendMessage("+ClientBot: You turned replacetext off!")
  343. return;
  344. }
  345. this.sendMessage("+ClientBot: Please use on/off")
  346. }
  347. /* ReplaceWords Code */
  348.  
  349.  
  350. if (command == "idle") {
  351. sys.stopEvent()
  352. if (commandData == "on") {
  353. client.goAway(true)
  354. sys.saveVal('idle', true)
  355. this.sendMessage("+ClientBot: You turned auto-idling on!")
  356. return;
  357. }
  358. if (commandData == "off") {
  359. client.goAway(false)
  360. sys.saveVal('idle', false)
  361. this.sendMessage("+ClientBot: You turned auto-idling off!")
  362. return;
  363. }
  364. this.sendMessage("+ClientBot: Please use on/off")
  365. }
  366. if (command == "goto") {
  367. sys.stopEvent()
  368. var channela = commandData
  369. var channels = client.channelNames()
  370. for (x in channels) {
  371. if (channela === channels[x].toLowerCase()) {
  372. channela = channels[x]
  373. if (!client.hasChannel(client.channelId(channela))) {
  374. client.join(channela)
  375. return;
  376. }
  377. client.activateChannel(channela)
  378. return;
  379. }
  380. }
  381. this.sendMessage("+ClientBot: That is not a channel!")
  382. }
  383. if (command == "stalkwords") {
  384. sys.stopEvent()
  385. this.sendMessage("+ClientBot: Your stalkwords are: " + stalkwords)
  386. }
  387. if (command == "addstalkword") {
  388. sys.stopEvent()
  389. var nstalkwords = commandData
  390. if (nstalkwords.search(/, /g) !== -1 || nstalkwords.search(/ ,/g) !== -1) {
  391. nstalkwords = nstalkwords.replace(/, /g, ",").replace(/ ,/g, ",")
  392. }
  393. nstalkwords = nstalkwords.split(",")
  394. stalkwords = eliminateDuplicates(nstalkwords.concat(stalkwords))
  395. sys.saveVal('stalkwords', stalkwords.toString())
  396. this.sendMessage("+ClientBot: You added " + commandData + " to your stalkwords!")
  397. }
  398. if (command == "removestalkword") {
  399. sys.stopEvent()
  400. commandData = commandData.toLowerCase()
  401. for (x in stalkwords) {
  402. if (stalkwords[x].toLowerCase() === commandData) {
  403. stalkwords.splice(x, 1)
  404. sys.saveVal('stalkwords', stalkwords.toString())
  405. this.sendMessage("+ClientBot: You removed " + commandData + " from your stalkwords!")
  406. return;
  407. }
  408. }
  409. this.sendMessage("+ClientBot: " + commandData + " is not a stalkword!")
  410. }
  411. if (command == "flash" || command == "flashes") {
  412. sys.stopEvent()
  413. if (commandData == "on") {
  414. flash = true
  415. this.sendMessage("+ClientBot: You turned flashes on!")
  416. return;
  417. } else {
  418. flash = false
  419. this.sendMessage("+ClientBot: You turned flashes off!")
  420. return;
  421. }
  422. }
  423. if (command == "eval") {
  424. sys.stopEvent()
  425. eval(commandData)
  426. }
  427. if (command == "evalp") {
  428. sys.stopEvent()
  429. var bindChannel = channel;
  430. try {
  431. var res = eval(commandData);
  432. this.sendMessage("Got from eval: " + res, bindChannel);
  433. } catch (err) {
  434. this.sendMessage("Error in eval: " + err, bindChannel);
  435. }
  436. return;
  437. }
  438. }
  439. },
  440. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement