OK, comments should work now
This commit is contained in:
144
action.js
144
action.js
@@ -47,13 +47,22 @@ for (const image of images) {
|
|||||||
|
|
||||||
// Prepare reply body.
|
// Prepare reply body.
|
||||||
const payload = github.context.payload;
|
const payload = github.context.payload;
|
||||||
const titleAndBody = payload.issue.title + '\n\n' + payload.issue.body;
|
const isComment = payload.comment !== undefined;
|
||||||
|
let titleAndBody;
|
||||||
|
let author;
|
||||||
|
if (isComment) {
|
||||||
|
titleAndBody = payload.comment.body;
|
||||||
|
author = payload.comment.user.login;
|
||||||
|
} else {
|
||||||
|
titleAndBody = payload.issue.title + '\n\n' + payload.issue.body;
|
||||||
|
author = payload.issue.user.login;
|
||||||
|
}
|
||||||
const quoteArray = [];
|
const quoteArray = [];
|
||||||
for (const line of titleAndBody.split('\n')) {
|
for (const line of titleAndBody.split('\n')) {
|
||||||
// Remove some speical chars to remove at mention spam possibilities.
|
// Remove some speical chars to remove at mention spam possibilities.
|
||||||
quoteArray.push('> ' + line.replace(/[@#]/g, ""));
|
quoteArray.push('> ' + line.replace(/[@#]/g, ""));
|
||||||
}
|
}
|
||||||
const replyBody = `Hi ${payload.issue.user.login},
|
const replyBody = `Hi ${author},
|
||||||
|
|
||||||
${quoteArray.join('\n').substring(0,40000)}
|
${quoteArray.join('\n').substring(0,40000)}
|
||||||
|
|
||||||
@@ -61,67 +70,69 @@ ${full_images.join('\n\n')}
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
// Label handling.
|
// Label handling.
|
||||||
const labels = new Set(payload.issue.labels.map(label => label.name));
|
if (!isComment) {
|
||||||
const newLabels = new Set();
|
const labels = new Set(payload.issue.labels.map(label => label.name));
|
||||||
const shabiWords = [
|
const newLabels = new Set();
|
||||||
'shabi',
|
const shabiWords = [
|
||||||
'shadiao',
|
'shabi',
|
||||||
'傻',
|
'shadiao',
|
||||||
'沙雕',
|
'傻',
|
||||||
'智障',
|
'沙雕',
|
||||||
'啥b',
|
'智障',
|
||||||
'stupid',
|
'啥b',
|
||||||
];
|
'stupid',
|
||||||
for (const word of shabiWords) {
|
];
|
||||||
if (new RegExp(word, 'i').test(titleAndBody)) {
|
for (const word of shabiWords) {
|
||||||
newLabels.add('you-are-stupid-argument');
|
if (new RegExp(word, 'i').test(titleAndBody)) {
|
||||||
break;
|
newLabels.add('you-are-stupid-argument');
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
const fuckMotherWords = [
|
||||||
const fuckMotherWords = [
|
'cnm',
|
||||||
'cnm',
|
'操你妈',
|
||||||
'操你妈',
|
'fuck.*\\b(mom|mum|mother)\\b',
|
||||||
'fuck.*\\b(mom|mum|mother)\\b',
|
'尼玛',
|
||||||
'尼玛',
|
'去你吗',
|
||||||
'去你吗',
|
]
|
||||||
]
|
for (const word of fuckMotherWords) {
|
||||||
for (const word of fuckMotherWords) {
|
if (new RegExp(word, 'i').test(titleAndBody)) {
|
||||||
if (new RegExp(word, 'i').test(titleAndBody)) {
|
newLabels.add('fuck-your-mother-argument');
|
||||||
newLabels.add('fuck-your-mother-argument');
|
break;
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
}
|
const motherDiedWords = [
|
||||||
const motherDiedWords = [
|
'nmsl',
|
||||||
'nmsl',
|
'你妈死',
|
||||||
'你妈死',
|
'司马',
|
||||||
'司马',
|
]
|
||||||
]
|
for (const word of motherDiedWords) {
|
||||||
for (const word of motherDiedWords) {
|
if (new RegExp(word, 'i').test(titleAndBody)) {
|
||||||
if (new RegExp(word, 'i').test(titleAndBody)) {
|
newLabels.add('your-mother-died-argument');
|
||||||
newLabels.add('your-mother-died-argument');
|
break;
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
}
|
const shitpostWords = [
|
||||||
const shitpostWords = [
|
'fuck',
|
||||||
'fuck',
|
'shit',
|
||||||
'shit',
|
'bitch',
|
||||||
'bitch',
|
'垃圾',
|
||||||
'垃圾',
|
'婊子',
|
||||||
'婊子',
|
'恶心',
|
||||||
'恶心',
|
'操你',
|
||||||
'操你',
|
];
|
||||||
];
|
for (const word of shitpostWords) {
|
||||||
for (const word of shitpostWords) {
|
if (new RegExp(word, 'i').test(titleAndBody)) {
|
||||||
if (new RegExp(word, 'i').test(titleAndBody)) {
|
newLabels.add('shitpost');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (newLabels.size > 0) {
|
||||||
newLabels.add('shitpost');
|
newLabels.add('shitpost');
|
||||||
break;
|
if (labels.has('not-shitpost')) {
|
||||||
}
|
labels.delete('not-shitpost');
|
||||||
}
|
newLabels.add('op-does-not-know-what-shit-is');
|
||||||
if (newLabels.size > 0) {
|
}
|
||||||
newLabels.add('shitpost');
|
|
||||||
if (labels.has('not-shitpost')) {
|
|
||||||
labels.delete('not-shitpost');
|
|
||||||
newLabels.add('op-does-not-know-what-shit-is');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,12 +146,15 @@ try {
|
|||||||
issue_number: payload.issue.number,
|
issue_number: payload.issue.number,
|
||||||
body: replyBody,
|
body: replyBody,
|
||||||
});
|
});
|
||||||
await octokit.issues.update({
|
if (!isComment) {
|
||||||
owner: 'cirosantilli',
|
// Update labels.
|
||||||
repo: payload.repository.name,
|
await octokit.issues.update({
|
||||||
issue_number: payload.issue.number,
|
owner: 'cirosantilli',
|
||||||
labels: Array.from([...labels, ...newLabels])
|
repo: payload.repository.name,
|
||||||
});
|
issue_number: payload.issue.number,
|
||||||
|
labels: Array.from([...labels, ...newLabels])
|
||||||
|
});
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user