Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

Commit

Permalink
3.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JsKingBoo committed Sep 24, 2017
1 parent 8a2d5be commit bae4180
Show file tree
Hide file tree
Showing 14 changed files with 358 additions and 9 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
### 3.1.0 - 2017-09-24
* Add Friend Code commands
* Add `config.js.example`
* Fix `meme.js` throwing an error

# 3.0.0 - 2017-09-06
* Initial release
* Initial release

13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@

## [Add SableyeBot to your server](https://discordapp.com/oauth2/authorize?&client_id=211522070620667905&scope=bot)

## Installation
SableyeBot requires NodeJS 8.0+. In order to run your own local copy of SableyeBot, you need to perform a few steps.

1. Download this repository.
2. Rename `config.js.example` to `config.js` and fill out the empty fields and/or change the default values.
3. Go to and download the [Pokemon-Showdown](https://github.com/Zarel/Pokemon-Showdown) repository. You only need three folders: `/sim`, `/data`, and `/mods`
4. In `/sim`, move `dex.js` and `dex-data.js` into the `/utils` folder of SableyeBot
5. Move `/data` and `/mods` to the root directory of SableyeBot
6. Go to and download the [Pokemon-Showdown-Client](https://github.com/Zarel/Pokemon-Showdown-Client) repository. You only need one folder: `/data`
7. Move `pokedex-mini.js` and `pokedex-mini-bw.js` into the SableyeBot `/data` folder.

If the steps above are performed correctly, you should be able to run `node index.js` and the bot will launch.

## Issues
If you encounter any bugs or need help, create an issue on the issue tracker. Please include:

Expand Down
10 changes: 8 additions & 2 deletions bot_events/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ const path = require('path');

const CommandManager = require(path.resolve(__dirname, '../utils/CommandManager.js'));
const Flag = require(path.resolve(__dirname, '../utils/Flag.js'));
const meme = require(path.resolve(__dirname, '../utils/meme.js'));
var meme;

try {
meme = require(path.resolve(__dirname, '../utils/meme.js'));
} catch (e) {
meme = () => {};
}

const cm = new CommandManager();
cm.init()
Expand Down Expand Up @@ -40,7 +46,7 @@ module.exports = function message(msg) {
}
msgContent = msgContent.join(" ").slice(cmd.length).split(",");

let commandOutput = cm.executeCommand(cmd, msgContent, flags, config.admins.includes(parseInt(msg.author.id)));
let commandOutput = cm.executeCommand(cmd, msgContent, flags, msg.author.id);

if (!commandOutput) {
return;
Expand Down
13 changes: 13 additions & 0 deletions commands/fc_commands/addfc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

module.exports = {
desc: "Register your friend code",
usage: '<friend code>, [Mii name]',
process: (msg, flags, authorId, fcm) => {
let miiName = (msg.length > 1 ? msg.splice(1).join(',').trim() : null);
let user = fcm.getUser(authorId);
let success = user.addFC(msg[0], miiName);
fcm.addUser(user);
return (success ? `Registered ${user.fc[user.fc.length - 1].fc} for ${authorId} as ${miiName}.` : `Error: could not add friend code.`);
}
};
21 changes: 21 additions & 0 deletions commands/fc_commands/addgame.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

module.exports = {
desc: "Add game information to your account.",
usage: '<abbreviated game>, <in-game name>, [TSV value]',
process: (msg, flags, authorId, fcm) => {
if (msg.length < 2) {
return null;
}

let user = fcm.getUser(authorId);
let game = msg[0].trim();
let ign = msg[1].trim();
let tsv = (msg.length > 2 ? msg[2].trim().slice(0, 4) : null);

let success = user.addGame(game, ign, tsv);
fcm.addUser(user);

return (success ? `Registered ${user.games[user.games.length - 1].game} for ${authorId} as ${user.games[user.games.length - 1].name}.` : `Error: could not add game information.`);
}
};
22 changes: 22 additions & 0 deletions commands/fc_commands/deletefc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

module.exports = {
desc: "Remove friend code.",
usage: '<friend code|friend code index>',
process: (msg, flags, authorId, fcm) => {
if (msg[0].length === 0) {
return null;
}

let user = fcm.getUser(authorId);
let fc = msg[0].replace(/\D/g, '').slice(0, 12);
if (fc.length < 12) {
fc = parseInt(fc);
}

user.removeFC(fc);
fcm.addUser(user);

return "Friend code removed."
}
};
18 changes: 18 additions & 0 deletions commands/fc_commands/deletegame.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

module.exports = {
desc: "Remove game.",
usage: '<game|game index>',
process: (msg, flags, authorId, fcm) => {
if (msg[0].length === 0) {
return null;
}
let user = fcm.getUser(authorId);
let game = msg[0].trim().toLowerCase();

let success = user.removeGame(game);
fcm.addUser(user);

return (success ? "Game entry removed." : "Error: could not remove game entry");
}
};
37 changes: 37 additions & 0 deletions commands/fc_commands/fc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict';

module.exports = {
desc: "Get friend code information of a user.",
longDesc: "Retrieve friend code information of a user along with a list of the games they own. If no Discord ID is provided, your information will be displayed. Discord ID is retrievable by enabling Developer Mode via Settings → Appearance → Advanced → Developer Mode. Once Developer Mode is activated, you can right click any user and select the \"Copy ID\" function to obtain another user's Discord ID.",
usage: '[Discord ID]',
process: (msg, flags, authorId, fcm) => {
let queryId = ((msg[0].length === 0 ? authorId : msg[0])+'').trim();
let user = fcm.getUser(queryId);

let sendMsg = [
`${queryId}:`
];

//FC data
sendMsg.push("Friend Code info:");
if (user.fc.length === 0) {
sendMsg.push(" - No friend code information found.");
} else {
for (let i = 0; i < user.fc.length; i++) {
sendMsg.push(` - [${i}] ${user.fc[i].fc} (Mii: ${user.fc[i].mii || "No name provided"})`);
}
}

//Game data
sendMsg.push("Owned games info:");
if (user.games.length === 0) {
sendMsg.push(" - No game information found.");
} else {
for (let i = 0; i < user.games.length; i++) {
sendMsg.push(` - [${i}] ${user.games[i].game} (Name: ${user.games[i].name}) (TSV: ${user.games[i].tsv || "Not known"})`);
}
}

return sendMsg;
}
};
26 changes: 26 additions & 0 deletions config.js.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

module.exports.token = '';
module.exports.admins = [130830896495329280];

module.exports.dexCommandPrefix = "//";
module.exports.botCommandPrefix = "//";
module.exports.helpCommand = "help";
module.exports.flagPrefix = "--";
module.exports.forcePM = 1500;
module.exports.maxMsgLength = 1950;
module.exports.maxPMs = 10;

module.exports.messageOptions = {
tts: false,
disableEveryone: true
};

module.exports.lokidb = './storage.json';
module.exports.avatar = 'avatar.png';
module.exports.defaultPresence = {
'status': 'online',
'game': `${module.exports.dexCommandPrefix}${module.exports.helpCommand}`
};

module.exports.defaultGen = 7;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sableyebot",
"version": "3.0.0",
"version": "3.1.0",
"description": "Competitive Pokemon discord bot",
"main": "index.js",
"scripts": {
Expand Down
27 changes: 24 additions & 3 deletions utils/CommandManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ const path = require('path');
const Commands = require('./Commands.js');
const Dex = require('./dex.js');
const Flag = require('./Flag.js');
const FCManager = require('./FCManager.js');

const BOT_CMD_DIR = path.resolve(__dirname, '../commands/bot_commands/');
const DEX_CMD_DIR = path.resolve(__dirname, '../commands/dex_commands/');
const FC_CMD_DIR = path.resolve(__dirname, '../commands/fc_commands/');

const fcm = new FCManager();
fcm.init();

class CommandManager {
constructor() {
Expand All @@ -19,7 +24,8 @@ class CommandManager {
async init() {
await Promise.all([
this.loadDirectory(BOT_CMD_DIR, Commands.BotCommand, config.botCommandPrefix),
this.loadDirectory(DEX_CMD_DIR, Commands.DexCommand, config.dexCommandPrefix)
this.loadDirectory(DEX_CMD_DIR, Commands.DexCommand, config.dexCommandPrefix),
this.loadDirectory(FC_CMD_DIR, Commands.FCCommand, config.fcCommandPrefix),
]);
}

Expand Down Expand Up @@ -48,8 +54,9 @@ class CommandManager {
});
}

executeCommand(cmd, msg = [], flags, isAdmin) {
executeCommand(cmd, msg = [], flags, authorId) {
let passDex = Dex;
let isAdmin = config.admins.includes(parseInt(authorId));

if (cmd === `${config.dexCommandPrefix}${config.helpCommand}` || cmd === `${config.botCommandPrefix}${config.helpCommand}`) {
let usedPrefix = cmd.slice(0, -1 * config.helpCommand.length);
Expand Down Expand Up @@ -87,7 +94,21 @@ class CommandManager {
}
}

let commandOutput = command.execute(msg, parsedFlags, passDex);
let commandOutput;
switch (command.commandType) {
case 'BotCommand':
commandOutput = command.execute(msg, parsedFlags);
break;
case 'DexCommand':
commandOutput = command.execute(msg, parsedFlags, passDex);
break;
case 'FCCommand':
commandOutput = command.execute(msg, parsedFlags, authorId, fcm);
break;
default:
commandOutput = command.execute(msg, parsedFlags);
}

let badOutput = false;
if (!commandOutput) {
badOutput = true;
Expand Down
15 changes: 15 additions & 0 deletions utils/Commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,21 @@ class BotCommand extends Command {
}
}

class FCCommand extends Command {
constructor(name, prefix, cmd) {
super(name, prefix, cmd);
this.commandType = 'FCCommand';
}

execute(msg = [], flags = this.options, authorId = -1, fcm = null) {
if (this.disabled) {
return;
}
return this.process(msg, flags, authorId, fcm);
}
}

module.exports.Command = Command;
module.exports.DexCommand = DexCommand;
module.exports.BotCommand = BotCommand;
module.exports.FCCommand = FCCommand;
Loading

0 comments on commit bae4180

Please sign in to comment.