Last active
January 26, 2017 10:07
-
-
Save yangshun/fbb8ad519739f3d6030c4a88d8379143 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Name animater | |
var name = 'Yang.Shun.Tay.'; | |
setInterval(function () { | |
name = name.substring(1) + name.charAt(0); | |
var flags = (1 << 0) | (1 << 1); | |
MtpApiManager.invokeApi('account.updateProfile', { | |
flags: flags, | |
first_name: name, | |
last_name: '' | |
}).then(function (user) { | |
$scope.error = {} | |
AppUsersManager.saveApiUser(user) | |
}); | |
}, 2000); | |
// Fake setTyping | |
setInterval(function () { | |
// Karen | |
MtpApiManager.invokeApi('messages.setTyping', { | |
peer: AppPeersManager.getInputPeerByID('30461908'), | |
action: {_: 'sendMessageTypingAction'} | |
})['catch'](function (error) { | |
error.handled = true | |
}); | |
// Li Kai | |
MtpApiManager.invokeApi('messages.setTyping', { | |
peer: AppPeersManager.getInputPeerByID('175097875'), | |
action: {_: 'sendMessageTypingAction'} | |
})['catch'](function (error) { | |
error.handled = true | |
}); | |
// Yang Shun | |
MtpApiManager.invokeApi('messages.setTyping', { | |
peer: AppPeersManager.getInputPeerByID('70259901'), | |
action: {_: 'sendMessageTypingAction'} | |
})['catch'](function (error) { | |
error.handled = true | |
}); | |
}, 2500); | |
var sent = {}; | |
// Reply with message when user typing | |
console.log('update.user_id typing', update.user_id); | |
var INTERVAL = 30 * 60 * 1000; // 30 minutes between each greeting | |
if (!sent[update.user_id] || (Date.now() - sent[update.user_id]) > INTERVAL) { | |
console.log('will reply to', update.user_id); | |
MtpApiManager.invokeApi('messages.sendMessage', { | |
flags: 128, | |
peer: AppPeersManager.getInputPeerByID(update.user_id), | |
message: 'Hello there (:', | |
random_id: [nextRandomInt(0xFFFFFFFF), nextRandomInt(0xFFFFFFFF)], | |
reply_to_msg_id: 0, | |
entities: [] | |
}); | |
sent[update.user_id] = Date.now(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment