Commit 2c9819b7 authored by Imran Hussain's avatar Imran Hussain

debugmode levels go up in verbosity + set the debugmode level from the talker

parent f8d4f8b3
......@@ -13,7 +13,7 @@ var commands = {};
//all readable colours
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) {
if (debugmode >= 1) {
//print out info about the mw obj
mw.print("DEBUG: mw object has: " + Object.getOwnPropertyNames(mw));
......@@ -32,13 +32,24 @@ function register(command, func, description) {
commands[command] = description;
}
// set debugmode level inside of mw
function setdebugmode(level) {
var userinput = mw.input("Please enter a debugmode level: ");
if (Number.isInteger(parseInt(userinput))) {
debugmode = parseInt(userinput);
} else {
mw.print("Not a valid input! Must be an int.")
}
}
register("debug",setdebugmode,"Set the debugmode level.");
// list all the colours, 1 per line
function colours() {
for (var i = 0, len = colourArray.length; i < len; i++) {
mw.print("\x1b" + colourArray[i] + " " + colourArray[i]);
}
}
//mw.command.listallcolours = colours;
register("listallcolours", colours, "List all the colours!");
// function to pad a number so if it's single digits it reutrns as 2
......@@ -121,7 +132,7 @@ function applyColours(word) {
//bullshit a new colour and store it
var colour = colourArray[Math.floor(Math.random()*colourArray.length)];
usercolours[word] = colour;
if (debugmode == 1) {
if (debugmode >= 1) {
mw.print(JSON.stringify(usercolours));
}
mw.store["usercolours"] = JSON.stringify(usercolours); //update the mw.store object
......@@ -146,7 +157,6 @@ function recolour() {
mw.store["usercolours"] = JSON.stringify(usercolours); //update the mw.store object
}
//mw.command.recolour = 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'
......@@ -165,12 +175,11 @@ function showcolours() {
}
mw.print(cusers);
}
mw.command.showcolours = showcolours;
register("showcolours",showcolours,"Show all users and their colours.");
// our core event handler
function handleEvent(event) {
if (debugmode == 1) {
if (debugmode >= 1) {
mw.print(JSON.stringify(event));
}
......@@ -180,7 +189,7 @@ function handleEvent(event) {
// currently all message_received events have (only) data
msg = event.data;
if (debugmode == 1) {
if (debugmode >= 1) {
mw.print("DEBUG: NEW MESSAGE of type: " + event.type);
mw.print("DEBUG: msg.text: " + msg.text);
mw.print("DEBUG: msg.unixtime: " + msg.unixtime);
......@@ -280,7 +289,6 @@ function handleEvent(event) {
} else {
mw.print(newTimestamp + "[" + msg.from_name + "]" + ": " + msg.text);
}
break;
case "mrod":
// handle kicking from the board
......@@ -309,7 +317,7 @@ function handleEvent(event) {
case "talker_join":
tje = event.data; //store the event data in tje
if (debugmode == 1) {
if (debugmode >= 1) {
mw.print("DEBUG: NEW MESSAGE of type: " + event.type);
mw.print("DEBUG: tje.quiet: " + tje.quiet);
mw.print("DEBUG: tje.user: " + tje.user);
......@@ -318,7 +326,7 @@ function handleEvent(event) {
}
//if it's us, then do a auto replay but not in debugmode
if (tje.user == mw.whoami() && !debugmode == 1) {
if (tje.user == mw.whoami() && !debugmode >= 1) {
mw.exec("replay count 50");
}
......@@ -326,7 +334,7 @@ function handleEvent(event) {
//stop talker_join handling
break;
default:
if (debugmode == 1) {
if (debugmode >= 1) {
mw.print("Error! unhandeled event: " + JSON.stringify(event));
}
return true;
......
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