Migrated from npm to yarn. Upgraded packages. Added rules code for removing role when agreeing to rules.
This commit is contained in:
parent
faba13149c
commit
b5cf83a9fe
|
@ -4,8 +4,8 @@ FROM mhart/alpine-node:latest
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
# Install app dependencies
|
# Install app dependencies
|
||||||
COPY package.json package-lock.json ./
|
COPY package.json ./
|
||||||
RUN npm install
|
RUN yarn install
|
||||||
|
|
||||||
# Bundle app source
|
# Bundle app source
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
13
env.json
13
env.json
|
@ -17,13 +17,18 @@
|
||||||
"DISCORD_LOG_CHANNEL": {
|
"DISCORD_LOG_CHANNEL": {
|
||||||
"description": "The unique ID for the channel the bot will output logs to."
|
"description": "The unique ID for the channel the bot will output logs to."
|
||||||
},
|
},
|
||||||
|
"DISCORD_RULES_CHANNEL": {
|
||||||
|
"description": "The unique ID for the channel that the bot will manage rules from."
|
||||||
|
},
|
||||||
|
"DISCORD_RULES_TRIGGER": {
|
||||||
|
"description": "Text that will trigger and indicate the user has read the rules."
|
||||||
|
},
|
||||||
|
"DISCORD_RULES_ROLE": {
|
||||||
|
"description": "The unique ID for the role that the bot will *remove* when the user accepts the rules."
|
||||||
|
},
|
||||||
"DISCORD_LOGIN_TOKEN": {
|
"DISCORD_LOGIN_TOKEN": {
|
||||||
"description": "The login token of the bot."
|
"description": "The login token of the bot."
|
||||||
},
|
},
|
||||||
"CANARY_WEBHOOK_URL": {
|
|
||||||
"required": false,
|
|
||||||
"description": "The URL for the webhook to trigger canary builds."
|
|
||||||
},
|
|
||||||
"DATA_CUSTOM_RESPONSES": {
|
"DATA_CUSTOM_RESPONSES": {
|
||||||
"required": false,
|
"required": false,
|
||||||
"description": "Whether or not to load responses.js from the data directory."
|
"description": "Whether or not to load responses.js from the data directory."
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -10,7 +10,7 @@
|
||||||
"license": "GPL-2.0+",
|
"license": "GPL-2.0+",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"checkenv": "^1.2.2",
|
"checkenv": "^1.2.2",
|
||||||
"discord.js": "^10.0.1",
|
"discord.js": "^11.3.0",
|
||||||
"ip": "^1.1.5",
|
"ip": "^1.1.5",
|
||||||
"logdna": "^1.2.3",
|
"logdna": "^1.2.3",
|
||||||
"node-schedule": "^1.2.3",
|
"node-schedule": "^1.2.3",
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
const request = require('request');
|
|
||||||
const logger = require('../logging.js');
|
|
||||||
|
|
||||||
exports.roles = ['Admins', 'Moderators'];
|
|
||||||
exports.command = function (message) {
|
|
||||||
// Read the URL endpoint from config.
|
|
||||||
var webhookUrl = process.env.CANARY_WEBHOOK_URL;
|
|
||||||
if (!webhookUrl) {
|
|
||||||
message.channel.sendMessage('Failed to start the canary build due to a missing Webhook URL.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send a POST request to the URL endpoint to trigger the build.
|
|
||||||
request.post({ url: webhookUrl, json: true, body: {
|
|
||||||
"ref": "refs/heads/master"
|
|
||||||
}}, function (error, response, body) {
|
|
||||||
if (!error && response.statusCode == 200) {
|
|
||||||
message.channel.sendMessage(`Canary build has been started.`);
|
|
||||||
} else {
|
|
||||||
logger.error(error);
|
|
||||||
message.channel.sendMessage(`Failed to start the canary build due to an error.`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
|
@ -26,7 +26,7 @@ process.on('uncaughtException', error => {
|
||||||
logger.error(`Unhandled exception: ${error.message}.`, error);
|
logger.error(`Unhandled exception: ${error.message}.`, error);
|
||||||
});
|
});
|
||||||
|
|
||||||
function findArray (haystack, arr) {
|
function findArray(haystack, arr) {
|
||||||
return arr.some(function (v) {
|
return arr.some(function (v) {
|
||||||
return haystack.indexOf(v) >= 0;
|
return haystack.indexOf(v) >= 0;
|
||||||
});
|
});
|
||||||
|
@ -41,6 +41,7 @@ client.on('ready', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('guildMemberAdd', (member) => {
|
client.on('guildMemberAdd', (member) => {
|
||||||
|
member.addRole(process.env.DISCORD_RULES_ROLE);
|
||||||
state.stats.joins += 1;
|
state.stats.joins += 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -51,11 +52,12 @@ client.on('guildMemberRemove', (member) => {
|
||||||
// Output the stats for state.stats every 24 hours.
|
// Output the stats for state.stats every 24 hours.
|
||||||
// Server is in UTC mode, 11:30 EST would be 03:30 UTC.
|
// Server is in UTC mode, 11:30 EST would be 03:30 UTC.
|
||||||
schedule.scheduleJob({ hour: 3, minute: 30 }, function () {
|
schedule.scheduleJob({ hour: 3, minute: 30 }, function () {
|
||||||
logger.info(`Here are today's stats for ${(new Date()).toLocaleDateString()}! ${state.stats.joins} users have joined, ${state.stats.leaves} users have left, ${state.stats.warnings} warnings have been issued.`);
|
logger.info(`Here are today's stats for ${(new Date()).toLocaleDateString()}! ${state.stats.joins} users have joined, ${state.stats.ruleAccepts} users have accepted the rules, ${state.stats.leaves} users have left, ${state.stats.warnings} warnings have been issued.`);
|
||||||
state.logChannel.sendMessage(`Here are today's stats for ${(new Date()).toLocaleDateString()}! ${state.stats.joins} users have joined, ${state.stats.leaves} users have left, ${state.stats.warnings} warnings have been issued.`);
|
state.logChannel.sendMessage(`Here are today's stats for ${(new Date()).toLocaleDateString()}! ${state.stats.joins} users have joined, ${state.stats.ruleAccepts} users have accepted the rules, ${state.stats.leaves} users have left, ${state.stats.warnings} warnings have been issued.`);
|
||||||
|
|
||||||
// Clear the stats for the day.
|
// Clear the stats for the day.
|
||||||
state.stats.joins = 0;
|
state.stats.joins = 0;
|
||||||
|
state.stats.ruleAccepts = 0;
|
||||||
state.stats.leaves = 0;
|
state.stats.leaves = 0;
|
||||||
state.stats.warnings = 0;
|
state.stats.warnings = 0;
|
||||||
});
|
});
|
||||||
|
@ -73,8 +75,21 @@ client.on('message', message => {
|
||||||
|
|
||||||
logger.verbose(`${message.author.username} ${message.author} [Channel: ${message.channel.name} ${message.channel}]: ${message.content}`);
|
logger.verbose(`${message.author.username} ${message.author} [Channel: ${message.channel.name} ${message.channel}]: ${message.content}`);
|
||||||
|
|
||||||
// We want to make sure it's an actual command, not someone '...'-ing.
|
// Check if the channel is #rules, if so we want to follow a different logic flow.
|
||||||
if (message.content.startsWith('.') && message.content.startsWith('..') === false) {
|
if (message.channel.id === process.env.DISCORD_RULES_CHANNEL) {
|
||||||
|
if (message.content.includes(process.env.DISCORD_RULES_TRIGGER)) {
|
||||||
|
// We want to remove the 'Unauthorized' role from them once they agree to the rules.
|
||||||
|
logger.verbose(`${message.author.username} ${message.author} has accepted the rules, removing role ${process.env.DISCORD_RULES_ROLE}.`);
|
||||||
|
state.stats.ruleAccepts += 1;
|
||||||
|
|
||||||
|
message.member.removeRole(process.env.DISCORD_RULES_ROLE, 'Accepted the rules.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the message in the channel to force a cleanup.
|
||||||
|
message.delete();
|
||||||
|
return;
|
||||||
|
} else if (message.content.startsWith('.') && message.content.startsWith('..') === false) {
|
||||||
|
// We want to make sure it's an actual command, not someone '...'-ing.
|
||||||
let cmd = message.content.split(' ')[0].slice(1);
|
let cmd = message.content.split(' ')[0].slice(1);
|
||||||
|
|
||||||
// Check by the name of the command.
|
// Check by the name of the command.
|
||||||
|
@ -164,9 +179,8 @@ data.readWarnings();
|
||||||
data.readBans();
|
data.readBans();
|
||||||
|
|
||||||
// Load custom responses
|
// Load custom responses
|
||||||
if (process.env.DATA_CUSTOM_RESPONSES)
|
if (process.env.DATA_CUSTOM_RESPONSES) {
|
||||||
{
|
data.readCustomResponses();
|
||||||
data.readCustomResponses();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
client.login(process.env.DISCORD_LOGIN_TOKEN);
|
client.login(process.env.DISCORD_LOGIN_TOKEN);
|
||||||
|
|
|
@ -7,6 +7,7 @@ var State = function () {
|
||||||
this.bans = [];
|
this.bans = [];
|
||||||
this.stats = {
|
this.stats = {
|
||||||
joins: 0,
|
joins: 0,
|
||||||
|
ruleAccepts: 0,
|
||||||
leaves: 0,
|
leaves: 0,
|
||||||
warnings: 0
|
warnings: 0
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue