如何解决将trello卡移至特定列表时如何发送消息
我目前正在制作一个机器人,该机器人会在卡片移至标题为Passed Applications
的列表时通知我。
我已经编写了代码,一旦将卡移动到特定列表,它基本上会发送一条消息,但是,它将随机发送一条消息,并在拔出并发送消息后的几分钟/几小时内拉出卡。
到目前为止,我所做的是:
trello.js
var Trello = require("node-trello"),EventEmitter = require("events").EventEmitter,extend = require("extend"),config,trello,timer,e;
module.exports = function(options) {
var defaults = {
pollFrequency: 1000 * 60,minId: 0,trello: {
key: "",token: "",boards: []
},start: true
};
e = new EventEmitter();
config = extend(true,defaults,options);
trello = new Trello(
process.env.TRELLO_API_KEY,process.env.TRELLO_OAUTH_TOKEN
);
if (config.start) {
process.nextTick(function() {
start(config.pollFrequency,true);
});
}
function start(frequency,immediate) {
if (timer) {
return;
}
frequency = frequency || config.pollFrequency;
timer = setInterval(poll,frequency);
if (immediate) {
poll();
}
}
function poll() {
config.trello.boards.forEach(function(boardId) {
getBoardActivity(boardId);
});
}
function getBoardActivity(boardId) {
trello.get("/1/boards/" + boardId + "/actions",function(err,resp) {
if (err) {
return e.emit("trelloError",err);
}
var boardActions = resp.reverse();
var actionId;
for (var ix in boardActions) {
actionId = parseInt(boardActions[ix].id,16);
if (actionId <= config.minId) {
continue;
}
var eventType = boardActions[ix].type;
e.emit(eventType,boardActions[ix],boardId);
}
config.minId = Math.max(config.minId,actionId);
e.emit("maxId",config.minId);
});
}
index.js
const conf = JSON.parse(fs.readFileSync("trelloconfig.json"));
let latestActivityID = fs.existsSync("./latestActivityID") ?
fs.readFileSync("./latestActivityID") :
0;
const eventEnabled = type =>
conf.enabledEvents.length > 0 ? conf.enabledEvents.includes(type) : true;
const TrelloEvents = require("./trello.js");
const events = new TrelloEvents({
pollFrequency: 60000,minId: latestActivityID,start: false,trello: {
boards: conf.boardIDs,key: process.env.TRELLO_API_KEY,token: process.env.TRELLO_OAUTH_TOKEN
}
});
client.on("ready",() => {
events.start();
console.log(`[STATUS CHANGE] ${client.user.username} is now online.`);
client.user.setActivity("Cookout Grill");
});
events.on("updateCard",(event,board) => {
if (event.data.old.hasOwnProperty("idList")) {
if (!eventEnabled(`cardListChanged`)) return;
if (event.data.listAfter.name === "Passed Applications") {
let robloxId = event.data.card.name.split(" | ")[0];
client.channels.get("730839109236424756").send(robloxId);
if (database.find(x => x.RobloxUser === robloxId)) {
let data = database.find(x => x.RobloxUser === robloxId);
const person = client.users.get(data.DiscordID);
let embed = new discord.RichEmbed()
.setThumbnail(
"https://www.roblox.com/bust-thumbnail/image?userId=" +
data.RobloxID +
"&width=420&height=420&format=png"
)
.setTitle("APPLICATION RESULTS | Passed")
.setColor("3ef72d")
.setFooter("Cookout Grill",client.user.avatarURL)
.setDescription(
"Greetings,**" +
data.RobloxUser +
"**!\n\nAfter extensive review by our Management Team,we have decided to accept your Trainee Application at Cookout Grill. We believe that your application showed that you’re ready to become a staff member at our establishment.\n\nWe would like to congratulate you on passing your Trainee Application. Your application met our critical expectations and requirements in order to pass.\n\nIn order to work your way up throughout the staff ranks,you must attend a training at [Cookout Grill’s Training Center](https://www.roblox.com/groups/5634772/Cookout-Grill#!/about) during the specific session times. If you’re unable to attend one of our designated sessions,feel free to schedule a private session with a member of our Management Team.\n\nWe wish you the best of luck in continuing throughout the staff ranks at Cookout Grill. If you have any further questions,please do not hesitate to create a ticket in our main Discord Server."
)
.addField("**NEW RANK**","`Trainee`");
person.send(embed);
roblox.message(
event.data.card.name.split(" | ")[1],"APPLICATION RESULTS | Passed","Greetings,**" +
data.RobloxUser +
"**!\n\nAfter extensive review by our Management Team,we have decided to accept your Trainee Application at Cookout Grill.\n\nWe would like to congratulate you on passing your Trainee Application. Your application met our critical expectations and requirements in order to pass.\n\nIn order to work your way up throughout the staff ranks,you must attend a training at Cookout Grill’s Training Center during the specific session times. If you’re unable to attend one of our designated sessions,feel free to schedule a private session with a member of our Management Team.\n\nWe wish you the best of luck in continuing throughout the staff ranks at Cookout Grill."
);
}
let embed2 = new discord.RichEmbed()
.setTitle(`Card list changed!`)
.setDescription(
`**CARD:** ${
event.data.card.name
} — **[CARD LINK](https://trello.com/c/${
event.data.card.shortLink
})**\n\n**EVENT:** Card moved to list __${
event.data.listAfter.name
}__ from list __${event.data.listBefore.name}__ by **[${
conf.realNames
? event.memberCreator.fullName
: event.memberCreator.username
}](https://trello.com/${event.memberCreator.username})**`
);
client.channels.get("730839109236424756").send(embed2);
Trello.addCommentToCard(
event.data.card.id,"User has been ranked.",function(error,trelloCard) {
console.log(error);
}
);
} else return;
} else return;
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。