aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml10
-rw-r--r--package.json2
-rw-r--r--send.sh77
-rw-r--r--test.js161
4 files changed, 248 insertions, 2 deletions
diff --git a/.travis.yml b/.travis.yml
index f5a9455..59d3cb3 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,3 +1,11 @@
language: node_js
node_js:
-- "node" \ No newline at end of file
+- "node"
+after_success:
+ - wget https://raw.githubusercontent.com/k3rn31p4nic/travis-ci-discord-webhook/master/send.sh
+ - chmod +x send.sh
+ - ./send.sh success $WEBHOOK_URL
+after_failure:
+ - wget https://raw.githubusercontent.com/k3rn31p4nic/travis-ci-discord-webhook/master/send.sh
+ - chmod +x send.sh
+ - ./send.sh failure $WEBHOOK_URL \ No newline at end of file
diff --git a/package.json b/package.json
index 948a14c..bc8baa9 100644
--- a/package.json
+++ b/package.json
@@ -4,7 +4,7 @@
"description": "A chat bot for discord written in discord.js.",
"main": "src/bot.js",
"scripts": {
- "test": "node bot_discord.js"
+ "test": "node test.js"
},
"repository": {
"type": "git",
diff --git a/send.sh b/send.sh
new file mode 100644
index 0000000..2f8004c
--- /dev/null
+++ b/send.sh
@@ -0,0 +1,77 @@
+#!/bin/bash
+
+if [ -z "$2" ]; then
+ echo -e "WARNING!!\nYou need to pass the WEBHOOK_URL environment variable as the second argument to this script.\nFor details & guide, visit: https://github.com/k3rn31p4nic/travis-ci-discord-webhook" && exit
+fi
+
+echo -e "[Webhook]: Sending webhook to Discord...\\n";
+
+case $1 in
+ "success" )
+ EMBED_COLOR=3066993
+ STATUS_MESSAGE="Passed"
+ AVATAR="https://travis-ci.org/images/logos/TravisCI-Mascot-blue.png"
+ ;;
+
+ "failure" )
+ EMBED_COLOR=15158332
+ STATUS_MESSAGE="Failed"
+ AVATAR="https://travis-ci.org/images/logos/TravisCI-Mascot-red.png"
+ ;;
+
+ * )
+ EMBED_COLOR=0
+ STATUS_MESSAGE="Status Unknown"
+ AVATAR="https://travis-ci.org/images/logos/TravisCI-Mascot-1.png"
+ ;;
+esac
+
+AUTHOR_NAME="$(git log -1 "$TRAVIS_COMMIT" --pretty="%aN")"
+COMMITTER_NAME="$(git log -1 "$TRAVIS_COMMIT" --pretty="%cN")"
+COMMIT_SUBJECT="$(git log -1 "$TRAVIS_COMMIT" --pretty="%s")"
+COMMIT_MESSAGE="$(git log -1 "$TRAVIS_COMMIT" --pretty="%b")"
+
+if [ "$AUTHOR_NAME" == "$COMMITTER_NAME" ]; then
+ CREDITS="$AUTHOR_NAME authored & committed"
+else
+ CREDITS="$AUTHOR_NAME authored & $COMMITTER_NAME committed"
+fi
+
+if [[ $TRAVIS_PULL_REQUEST != false ]]; then
+ URL="https://github.com/$TRAVIS_REPO_SLUG/pull/$TRAVIS_PULL_REQUEST"
+else
+ URL=""
+fi
+
+TIMESTAMP=$(date --utc +%FT%TZ)
+WEBHOOK_DATA='{
+ "username": "",
+ "avatar_url": "https://travis-ci.org/images/logos/TravisCI-Mascot-1.png",
+ "embeds": [ {
+ "color": '$EMBED_COLOR',
+ "author": {
+ "name": "Job #'"$TRAVIS_JOB_NUMBER"' (Build #'"$TRAVIS_BUILD_NUMBER"') '"$STATUS_MESSAGE"' - '"$TRAVIS_REPO_SLUG"'",
+ "url": "https://travis-ci.org/'"$TRAVIS_REPO_SLUG"'/builds/'"$TRAVIS_BUILD_ID"'",
+ "icon_url": "'$AVATAR'"
+ },
+ "title": "'"$COMMIT_SUBJECT"'",
+ "url": "'"$URL"'",
+ "description": "'"${COMMIT_MESSAGE//$'\n'/ }"\\n\\n"$CREDITS"'",
+ "fields": [
+ {
+ "name": "Commit",
+ "value": "'"[\`${TRAVIS_COMMIT:0:7}\`](https://github.com/$TRAVIS_REPO_SLUG/commit/$TRAVIS_COMMIT)"'",
+ "inline": true
+ },
+ {
+ "name": "Branch/Tag",
+ "value": "'"[\`$TRAVIS_BRANCH\`](https://github.com/$TRAVIS_REPO_SLUG/tree/$TRAVIS_BRANCH)"'",
+ "inline": true
+ }
+ ],
+ "timestamp": "'"$TIMESTAMP"'"
+ } ]
+}'
+
+(curl --fail --progress-bar -A "TravisCI-Webhook" -H Content-Type:application/json -H X-Author:k3rn31p4nic#8383 -d "$WEBHOOK_DATA" "$2" \
+ && echo -e "\\n[Webhook]: Successfully sent the webhook.") || echo -e "\\n[Webhook]: Unable to send webhook."
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..da32b11
--- /dev/null
+++ b/test.js
@@ -0,0 +1,161 @@
+/****************************************
+ *
+ * AleeBot: Made for discord servers
+ * Copyright (C) 2018 AleeCorp
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * *************************************/
+const Discord = require('discord.js');
+const economy = require('discord-eco');
+const moment = require('moment');
+const client = new Discord.Client({
+ disableEveryone: true
+});
+const abVersion = '2.8.0';
+const prefix = 'ab:';
+const fs = require('fs');
+
+const log = message => {
+
+ console.log(`[${moment().format('YYYY-MM-DD HH:mm:ss')}] ${message}`);
+
+};
+
+console.log('AleeBot: Copyright (C) 2018 AleeCorp');
+console.log('This program comes with ABSOLUTELY NO WARRANTY; for details type `show w\'.');
+console.log ('This is free software, and you are welcome to redistribute it');
+console.log ('under certain conditions; type `show c\' for details.\n')
+
+if (process.argv.indexOf("--debug") == -1) {
+ console.log("Running AleeBot without --debug command line flag. Debug output disabled.\n");
+} else {
+ console.log('[!] Entering debug mode...')
+ client.on('debug', function(info) {
+ log(info);
+ });
+ client.on('warn', function(info) {
+ log(info);
+ });
+}
+
+client.commands = new Discord.Collection();
+client.aliases = new Discord.Collection();
+
+fs.readdir('./commands', (err, files) => {
+ if (err) console.error(err);
+ log(`[!] Attempting to load a total of ${files.length} commands into the memory.`);
+ files.forEach(file => {
+ try {
+ const command = require(`./commands/${file}`);
+ log(`[!] Attempting to load the command "${command.help.name}".`);
+ client.commands.set(command.help.name, command);
+ command.conf.aliases.forEach(alias => {
+ client.aliases.set(alias, command.help.name);
+ log(`[!] Attempting to load "${alias}" as an alias for "${command.help.name}"`);
+ });
+ }
+ catch (err) {
+ log('[X] An error has occured trying to load a command. Here is the error.');
+ console.log(err.stack);
+ }
+ });
+ log('[>] Command Loading complete!');
+ console.log('\n');
+});
+
+
+client.on('ready', () => {
+ log('[>] AleeBot is now ready!');
+ log(`[i] Logged in as ${client.user.tag}`);
+ log(`[i] Bot ID: ${client.user.id}`);
+ log(`[i] Token: ${config.abtoken}`);
+ log('[i] Running version ' + abVersion + ` and in ${client.guilds.size} guilds`);
+
+ client.setInterval(function() {
+ const games = [
+ 'AleeBot ' + abVersion + ' | ' + config.prefix + 'help',
+ 'Annoying Alee',
+ 'Coding stuff',
+ 'Drawing shapes',
+ 'Fighting AstralMod',
+ ];
+
+ client.user.setPresence({
+ status: 'online',
+ afk: false,
+ game: {
+ type: 0,
+ name: games[Math.floor(Math.random() * games.length)],
+ },
+ });
+ }, 200000);
+ client.user.setStatus('online');
+});
+
+client.on('guildCreate', guild => {
+
+ log(`[i] New guild joined: ${guild.name} (id: ${guild.id}). This guild has ${guild.memberCount} members!`);
+
+});
+
+
+client.on('guildDelete', guild => {
+
+ log(`[i] I have been removed from: ${guild.name} (id: ${guild.id})`);
+
+});
+
+
+client.on('message', (msg) => {
+ if (msg.author.bot) return;
+ if (!msg.content.startsWith(prefix)) return;
+ const args = msg.content.slice(prefix.length).trim().split(/ +/g);
+ const command = args.shift();
+ let cmd;
+
+ if (client.commands.has(command)) {
+ cmd = client.commands.get(command);
+ } else if (client.aliases.has(command)) {
+ cmd = client.commands.get(client.aliases.get(command));
+ }
+
+ if (cmd) {
+ if (cmd.conf.guildOnly == true) {
+ if (!msg.channel.guild) {
+ return msg.channel.createMessage('This command can only be ran in a guild.');
+ }
+ }
+ try {
+ cmd.run(client, msg, args);
+ }
+ catch (e) {
+ console.error(e);
+ }
+ }
+});
+
+process.on('unhandledRejection', function(err, p) {
+
+log("[X | UNCAUGHT PROMISE] " + err.stack);
+
+});
+
+process.on('uncaughtException', function (exception) {
+ log(exception);
+});
+
+client.on("error", error => {
+ log(error);
+});