Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/discordie'
Browse files Browse the repository at this point in the history
Conflicts:
	Readme.md
  • Loading branch information
Thomas Moore committed Sep 4, 2016
2 parents c5d188d + 441a578 commit 14b1f3a
Show file tree
Hide file tree
Showing 50 changed files with 1,202 additions and 714 deletions.
8 changes: 8 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"parser": "babel-eslint",
"extends": "airbnb",
"rules": {
"indent": ["error", "tab"],
"react/jsx-indent-props": ["error", "tab"],
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
.env
npm-debug.log
.DS_Store
designs
78 changes: 0 additions & 78 deletions .jscsrc

This file was deleted.

10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM dkarchmervue/fluent-ffmpeg

# Quick NPM Installs
ADD ./package.json /app/package.json
RUN cd /app && npm install

# Add our App
ADD . /app

WORKDIR /app
2 changes: 2 additions & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
web: ./node_modules/.bin/babel-node --presets es2015 -- ./server.js
worker: ./node_modules/.bin/babel-node --presets es2015 -- ./bot.js
12 changes: 7 additions & 5 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,26 @@ Next you'll want to clone this and then add a `.env` file to the root of the clo
DISCORD_TOKEN=
LEAGUE_APIKEY=
LEAGUE_LOCATION=
TWITTER_CONSUMER_KEY=
TWITTER_CONSUMER_SECRET=
TWITTER_ACCESS_TOKEN=
TWITTER_ACCESS_TOKEN_SECRET=
```

You'll want to fill these in with your own values.

Once that's all sorted you can then run `npm install` to install the dependencies for the bot and webserver.

When that's all sorted you should be able to run `npm run start:bot` to start the bot or `npm run start:web` to start the websever on http://localhost:5000. For making the bot join a server you'll want to login as the user the bot will act as first and then join the server first (an easier way should be on the way soon!).
When that's all sorted you should be able to run `npm run start:bot` to start the bot or `npm run start:web` to start the websever on http://localhost:5000.

### Bot Modules

Each command the bot uses is it's own file in `/modules` if you're adding new modules you'll want to create new files (and folders if you're grouping a group of commands) for them. To then add or remove a command from the bot you'll want to modify `bot.js` either adding/removing the require statement & the function within `bot.on(message)`.

### Contributing

I'll gladly accept any help or pointers you want to give, if you're going to do a pull request it'll be nice if you can follow the eslint for the javascript. It's pretty much just airbnb's javascript guide with tabs instead of spaces.
I try to keep to [Airbnb's Javascript Standards](https://github.com/airbnb/javascript) where possible using the [.eslintrc](https://github.com/tomopagu/disbott/blob/discordie/.eslintrc) file in the root of disbott. I'm happy to have any help or suggestions where possible, just stick a PR on the Repo!

#### Why the disbott rather than disbot

Funny story, I broke the first disbot user. For some reason it remains connected to discord but remains unresponsive to any message whatsoever. I can't send anything as that user when logged into the discord client myself. No idea on the reason why for it still.

If you do happen to know why, please let me know!
Funny story, I broke the first disbot user. For some reason it remained connected to discord but remains unresponsive to any message whatsoever. I couldn't send anything as that user when logged into the discord client myself. This was way before the bots we have today so disbot probably could work but the disbott name has kinda stuck.
134 changes: 67 additions & 67 deletions bot.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Config } from './config';

import _ from 'underscore';
import S from 'string';
import DiscordClient from 'discord.io';
import Discordie from 'discordie';
const client = new Discordie({ autoReconnect: true });

// Modules
import { about, help, info, ping } from './modules/utils';
import * as util from './modules/utils';

import league from './modules/lol/index';

Expand All @@ -14,91 +13,92 @@ import soundFileupload from './modules/sound/modules/fileupload';

import management from './modules/management/index';

import poll from './modules/poll/index';

import { messagecountCommand, messageCountLog } from './modules/messagecount';

import remindme from './modules/remindme/index';
import remindmeCommand from './modules/remindme/command';

import lastseen from './modules/lastseen/index';
import lastseenCommand from './modules/lastseen/command';
// import lastseen from './modules/lastseen/index';
// import lastseenCommand from './modules/lastseen/command';

import twitter from './modules/twitter/index';

import { chunder } from './modules/silly';

var bot = new DiscordClient({
token: Config.discord.token,
});

bot.sendMessages = function (ID, messageArr, interval) {
var callback = [];
var resArr = [];
var len = messageArr.length;
typeof (arguments[2]) === 'function' ? callback = arguments[2] : callback = arguments[3];
if (typeof (interval) !== 'number') interval = 1000;

function _sendMessages() {
setTimeout(function () {
if (messageArr[0]) {
bot.sendMessage({
to: ID,
message: messageArr.shift(),
}, function (res) {
resArr.push(res);
if (resArr.length === len) if (typeof (callback) === 'function') callback(resArr);
});

_sendMessages();
}
}, interval);
}
export function bot() {
client.connect({
token: Config.discord.token,
});

_sendMessages();
};
client.Dispatcher.on('GATEWAY_READY', () => {
console.log('Connected as: ' + client.User.id + ' - ' + client.User.username); // eslint-disable-line

bot.connect();
client.User.setGame({
name: '@disbott help for cmd!',
});

bot.on('ready', function () {
console.log(bot.username + ' - (' + bot.id + ')');
bot.setPresence({
game: 'Hacking Simulator 2k16',
// Start the logging functions
remindme(client);
// lastseen(client);
});

// Start the logging function
remindme(bot);
lastseen(bot);
});
client.Dispatcher.on('MESSAGE_CREATE', e => {
messageCountLog(e);

bot.on('message', function (user, userID, channelID, message, rawEvent) {
var wasMentioned = _.findWhere(rawEvent.d.mentions, { id: bot.id });
const wasMentioned = client.User.isMentioned(e.message);

if (wasMentioned && userID !== bot.id) {
message = S(message).chompLeft('<@' + bot.id + '> ').s;
if (wasMentioned && e.message.author.id !== client.User.id) {
const message = e.message.content.replace(`<@${client.User.id}> `, '');

try {
ping(bot, channelID, message);
help(Config, bot, channelID, message);
about(Config, bot, channelID, message);
info(Config, bot, channelID, message);
try {
util.ping(e, message);
util.help(e, message);
util.about(e, message);
util.info(e, message);
util.deleteMessages(e, message);

// kill(bot, channelID, message);
// kill(client, channelID, message);

chunder(bot, channelID, message);
chunder(e, message);

league(bot, user, userID, channelID, message);
league(e, message);

sound(Config, bot, channelID, message, rawEvent);
sound(client, e, message);

management(Config, bot, channelID, message, rawEvent);
management(e, message);

remindmeCommand(bot, user, userID, channelID, message);
lastseenCommand(bot, user, userID, channelID, message);
poll(e, message);

twitter(bot, channelID, message);
} catch (e) {
console.log(e);
remindmeCommand(e, message);

messagecountCommand(e, message);

// lastseenCommand(client, user, userID, channelID, message);

twitter(e, message);
} catch (error) {
console.log(error); // eslint-disable-line
}
}
}

// soundFileupload is a little different to other commands so it has to be put here
// Currently it'll accept any mp3, I'd like it to only be mp3's dm'd to it
soundFileupload(bot, channelID, rawEvent);
});
// soundFileupload is a little different to other commands so it has to be put here
// Currently it'll accept any mp3 messaged to it
soundFileupload(e);
});

client.Dispatcher.on('VOICE_CHANNEL_JOIN', e => {
util.userHasJoinedVoiceChannel(e);
});

client.Dispatcher.on('DISCONNECTED', e => {
console.log(e); // eslint-disable-line
});
}

export function botDisconnect() {
client.disconnect();
}

bot();
5 changes: 3 additions & 2 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
require('dotenv').config();

export var Config = {
export const Config = {
discord: {
token: process.env.DISCORD_TOKEN,
testerToken: process.env.DISBOTT_TESTER_TOKEN,
},
league: {
apikey: process.env.LEAGUE_APIKEY,
Expand All @@ -12,7 +13,7 @@ export var Config = {
consumer_key: process.env.TWITTER_CONSUMER_KEY,
consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
access_token: process.env.TWITTER_ACCESS_TOKEN,
access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET
access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET,
},
domain: 'https://disbott.pagu.co',
};
3 changes: 0 additions & 3 deletions modules-todo.md

This file was deleted.

14 changes: 7 additions & 7 deletions modules/lol/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import lolGetSetSummoner from './modules/get-set-summoner';
import lolCurrentGameInfo from './modules/current-game';
import lolRankedStats from './modules/ranked-stats';

export default function league(bot, user, userID, channelID, message) {
message = message.toLowerCase();
lolSetSummoner(bot, user, userID, channelID, message);
lolGetSetSummoner(bot, user, userID, channelID, message);
lolCurrentGameInfo(bot, user, userID, channelID, message);
lolRankedStats(bot, user, userID, channelID, message);
};
export default function league(e, message) {
const lcmessage = message.toLowerCase();
lolSetSummoner(e, lcmessage);
lolGetSetSummoner(e, lcmessage);
lolCurrentGameInfo(e, lcmessage);
lolRankedStats(e, lcmessage);
}
Loading

0 comments on commit 14b1f3a

Please sign in to comment.