this.challenges.splice(challToDelIdx, 1);
}
this.send("newchallenge", {
- data: Object.assign({ from: this.st.user.sid }, chall)
+ data: Object.assign(
+ // Temporarily add sender infos to display challenge on Discord.
+ { from: this.st.user.sid, sender: this.st.user.name }, chall)
});
// Add new challenge:
chall.from = {
const discordClient = new Discord.Client();
let discordChannel = null;
if (token.length > 0) {
- discordClient.login(token).then( () => {
+ discordClient.login(token);
+ discordClient.once("ready", () => {
discordChannel = discordClient.channels.cache.get(channel);
});
}
case "rematchoffer":
case "draw":
// "newgame" message can provide a page (corr Game --> Hall)
+ if (obj.code == "newchallenge") {
+ // Filter out targeted challenges and correspondance games:
+ if (!obj.data.to && obj.data.cadence.indexOf('d') < 0) {
+ const challMsg = (
+ (obj.data.sender || "@nonymous") + " : " +
+ "**" + obj.data.vname + "** " +
+ "[" + obj.data.cadence + "] "
+ );
+ if (!!discordChannel) discordChannel.send(challMsg);
+ else
+ // Log when running locally (dev, debug):
+ console.log(challMsg);
+ }
+ delete obj.data["sender"];
+ }
notifyRoom(
obj.page || page, obj.code, {data: obj.data}, obj.excluded);
- if (
- obj.code == "newchallenge" &&
- !obj.data.to && //filter out targeted challenges
- obj.data.cadence.indexOf('d') < 0 //and correspondance games
- ) {
- const challMsg = (
- "New challenge: **" + obj.data.vname + "** " +
- "[" + obj.data.cadence + "]"
- );
- if (!!discordChannel) discordChannel.send(challMsg);
- else
- // Log when running locally (dev, debug):
- console.log(challMsg);
- }
break;
case "rnewgame":