Migrated from npm to yarn. Upgraded packages. Added rules code for removing role when agreeing to rules.

This commit is contained in:
chris062689 2018-02-27 19:19:14 -05:00
parent faba13149c
commit b5cf83a9fe
8 changed files with 1555 additions and 2316 deletions

View File

@ -4,8 +4,8 @@ FROM mhart/alpine-node:latest
WORKDIR /usr/src/app
# Install app dependencies
COPY package.json package-lock.json ./
RUN npm install
COPY package.json ./
RUN yarn install
# Bundle app source
COPY . .

View File

@ -17,13 +17,18 @@
"DISCORD_LOG_CHANNEL": {
"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": {
"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": {
"required": false,
"description": "Whether or not to load responses.js from the data directory."

2277
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -10,7 +10,7 @@
"license": "GPL-2.0+",
"dependencies": {
"checkenv": "^1.2.2",
"discord.js": "^10.0.1",
"discord.js": "^11.3.0",
"ip": "^1.1.5",
"logdna": "^1.2.3",
"node-schedule": "^1.2.3",

View File

@ -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.`);
}
});
};

View File

@ -26,7 +26,7 @@ process.on('uncaughtException', error => {
logger.error(`Unhandled exception: ${error.message}.`, error);
});
function findArray (haystack, arr) {
function findArray(haystack, arr) {
return arr.some(function (v) {
return haystack.indexOf(v) >= 0;
});
@ -41,6 +41,7 @@ client.on('ready', () => {
});
client.on('guildMemberAdd', (member) => {
member.addRole(process.env.DISCORD_RULES_ROLE);
state.stats.joins += 1;
});
@ -51,11 +52,12 @@ client.on('guildMemberRemove', (member) => {
// Output the stats for state.stats every 24 hours.
// Server is in UTC mode, 11:30 EST would be 03:30 UTC.
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.`);
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.`);
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.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.
state.stats.joins = 0;
state.stats.ruleAccepts = 0;
state.stats.leaves = 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}`);
// We want to make sure it's an actual command, not someone '...'-ing.
if (message.content.startsWith('.') && message.content.startsWith('..') === false) {
// Check if the channel is #rules, if so we want to follow a different logic flow.
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);
// Check by the name of the command.
@ -164,9 +179,8 @@ data.readWarnings();
data.readBans();
// Load custom responses
if (process.env.DATA_CUSTOM_RESPONSES)
{
data.readCustomResponses();
if (process.env.DATA_CUSTOM_RESPONSES) {
data.readCustomResponses();
}
client.login(process.env.DISCORD_LOGIN_TOKEN);

View File

@ -7,6 +7,7 @@ var State = function () {
this.bans = [];
this.stats = {
joins: 0,
ruleAccepts: 0,
leaves: 0,
warnings: 0
};

1520
yarn.lock Normal file

File diff suppressed because it is too large Load Diff