Commit 71ae841c authored by Imran Hussain's avatar Imran Hussain

Add more comments to try and be more helpful

parent e2910c89
// Welcomes to the default provided MWJS (Miliways-JavaScript) script.
// The API refeence can be found at https://projects.sucs.org/milliways/mw/blob/master/mwjs.rst
// This script comes with a very verbose debugmode
// set it to a integer to enable a level of debugging
// setting it to 0 disables it.
// This can be set within the talker by issuing the command ",debug"
var debugmode = 0;
//if we don't have any colour info then create space for it
// If we don't have any colour info then create space for it
if (mw.store["usercolours"] === undefined) {
mw.store["usercolours"] = "{}";
}
//dummy js dict/object for storing stuff
// Dummy js dict/object for storing stuff locally
var usercolours = {}; //local var used ++speedy
usercolours = JSON.parse(mw.store["usercolours"]); //grab the info from mw.store ++slow
var commands = {};
//all readable colours
// All readable colours using the old MW Colour codes
// MW now supports ANSI 256 colours codes - https://projects.sucs.org/milliways/mw/blob/master/colours.rst
var colourArray = ["kw","kr","ky","kg","kc","kb","km","kW","kR","kY","kG","kC","kB","kM","wr","wy","wg","wc","wb","wm","wK","wR","wY","wG","wC","wB","wM","ry","rg","rc","rb","rm","rK","rW","rY","rG","rC","rB","rM","yg","yc","yb","ym","yK","yW","yR","yG","yC","yB","yM","gc","gb","gm","gK","gW","gR","gY","gC","gB","gM","cb","cm","cK","cW","cR","cY","cG","cB","cM","bm","bK","bW","bR","bY","bG","bC","bM","mK","mW","mR","mY","mG","mC","mB","KW","KR","KY","KG","KC","KB","KM","WR","WY","WG","WC","WB","WM","RY","RG","RC","RB","RM","YG","YC","YB","YM","GC","GB","GM","CB","CM","BM"]
if (debugmode >= 1) {
......@@ -95,7 +103,7 @@ function replace(targetWord, newWord, text) {
// checks for word boundry (\b) or line end ($) at the end
// to stop parts of words being picked up when they shouldn't
// "gi" just says match every (g) and ignore case (i)
newSubTexts.push(element.replace(new RegExp("(^|\b)"+targetWord+"($|\b)","gi"),newWord));
newSubTexts.push(element.replace(new RegExp("(^|\b)"+targetWord+"($|\b)","gi"),newWord));
});
if (debugmode >= 2) {
mw.print("DEBUG: text after replace: " + newSubTexts);
......@@ -110,7 +118,7 @@ function replace(targetWord, newWord, text) {
//return text.replace(new RegExp(""+targetWord+"()","gi"), newWord);
}
// function to colour a word with a specifed colour
// function to colour a word with a specifed colour using the LEGACY colours
function colourWord(word, colour) {
return "\x1b" + colour + word + "\x1b--";
}
......@@ -161,7 +169,7 @@ function recolour() {
}
register("recolour",recolour,"Recolour a user. If you enter just a username, random colour is chosen if you enter a username followed by a space and then a colour that colour is used.");
//simple function to delete a user from the colours 'db'
// function to delete a user from the colours 'db'
function deleteColour() {
var userinput = mw.input();
delete usercolours[userinput];
......@@ -169,7 +177,7 @@ function deleteColour() {
}
register("deletecolour",deleteColour,"Delete a coloured username.");
// simple fuction to show all the colours assigned to users
// fuction to show all the colours assigned to users
function showcolours() {
var cusers = [];
for (var user in usercolours) {
......@@ -188,7 +196,6 @@ function handleEvent(event) {
// Loads of event types, see 'man mwjs'
switch(event.type) {
case "message_received":
// currently all message_received events have (only) data
msg = event.data;
if (debugmode >= 1) {
......@@ -217,7 +224,8 @@ function handleEvent(event) {
var newTimestamp = processUnixtime(msg.unixtime);
// highlight/colour people
// update the values so we can use them in the future as dreop in replacements
// update the values so we can use them in the future
// as dreop in replacements
msg.from_name = replace(msg.from_name,applyColours(msg.from_name),msg.from_name);
// if excluded_name isn't null then fill that in
if (msg.excluded_name != null) {
......@@ -304,8 +312,8 @@ function handleEvent(event) {
}
break;
default:
// leave the message alone if we don't have
// rules for it
// leave the message alone if we don't
// have rules for it
mw.print(newTimestamp + "ERORR Unknown msg type: " + msg.type + ' ' + msg.from_name + ': ' + msg.text);
break;
}
......@@ -315,6 +323,7 @@ function handleEvent(event) {
//stop handling message_recieved
break;
// handle talker join events
case "talker_join":
tje = event.data; //store the event data in tje
......@@ -332,9 +341,9 @@ function handleEvent(event) {
mw.exec("replay count 50");
}
//stop talker_join handling
break;
default:
if (debugmode >= 1) {
mw.print("Error! unhandeled event: " + JSON.stringify(event));
......@@ -343,5 +352,5 @@ function handleEvent(event) {
}
}
// push our eventhandler fuction to the list of funcs
// Push our eventhandler fuction to the list of funcs that handle events
mw.onevent.push(handleEvent);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment