added updating of messages

This commit is contained in:
hydrabolt
2015-08-15 22:34:09 +01:00
parent 44a9844e0c
commit 5685c5f4ce
5 changed files with 208 additions and 4 deletions

View File

@@ -27,7 +27,81 @@ Commands[ "info" ] = {
}
}
Commands[ "" ]
Commands[ "loading" ] = {
oplevel:0,
fn: function(bot, params, message){
var progress = 0;
var currentMessage;
var bars = 20;
function getM(){
var before = progress;
var after = bars - progress;
var ret = "";
for(x=0; x < before; x++){
ret += "-";
}
ret += "**#**";
for(y=0; y < after; y++){
ret += "-";
}
return ret;
}
function doProg(){
if(progress === (bars + 1)){
progress = 0;
}
if(currentMessage){
bot.updateMessage(currentMessage, getM(), function(err, msg){
if(!err)
currentMessage = msg;
});
progress++;
}
}
bot.sendMessage(message.channel, getM(), function(err, message){
currentMessage = message;
setInterval(doProg, 200);
});
}
}
Commands[ "flashy" ] = {
oplevel:0,
fn: function(bot, params, message){
var phase = 0;
var msg;
var textToSay = getKey(params, "m", "FLASH");
var speed = parseInt( getKey(params, "s", "500") );
function change(){
if(msg){
var highlighting = ((phase % 2) === 0 ? "**" : "");
phase++;
bot.updateMessage(msg, highlighting + textToSay + highlighting, function(err, message){
if(!err){
msg = message;
}
});
}
}
bot.sendMessage(message.channel, textToSay, function(err, message){
msg = message;
setInterval(change, speed);
});
}
}
Commands[ "echo" ] = {
oplevel: 0,

View File

@@ -44,6 +44,27 @@ hydrabot.on( "disconnected", function( obj ) {
process.exit( 0 );
} );
hydrabot.on("messageDelete", function(message){
console.log(message);
})
hydrabot.on("messageUpdate", function(former, edit){
if(former.author.equals(this.user)){
return;
}
if(former){
var seconds = Math.round((Date.now() - former.time) / 1000);
var channel = former.channel;
hydrabot.sendMessage(channel, "**"+former.author.username + "** (edit from message "+seconds+" seconds ago):\n " + former.content);
}
})
hydrabot.on( "message", function( message ) {
// if the message doesn't begin with a valid command prefix exit