Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ability to read raid info from raid boss image #40

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added eng.traineddata
Binary file not shown.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
"dependencies": {
"discord.js": "^11.1.0",
"mocha": "^3.5.0",
"mysql": "^2.14.0"
"moment": "^2.18.1",
"mysql": "^2.14.0",
"opencv": "^6.0.0",
"request": "^2.81.0",
"tesseract.js": "^1.0.10"
},
"devDependencies": {
"eslint": "^4.3.0"
Expand Down
45 changes: 39 additions & 6 deletions src/chatcommands/egg.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const raidimage = require('./raidimage');
const CONSTANTS = require('./../constants');

const usage = 'Command usage: **!egg tier# minutesLeft location details**';
Expand Down Expand Up @@ -34,13 +35,47 @@ const egg = (data, message) => {
let reply = '';

const msgSplit = message.content.toLowerCase().split(' ');
if (!msgSplit || msgSplit.length < 4) {
const imageUrls = message.attachments
.filter((elem, index, arr) => elem.height && elem.width && elem.url)
.map((elem, index, arr) => elem.url);
if ((!imageUrls || imageUrls.length == 0) && (!msgSplit || msgSplit.length < 4)) {
reply = 'Sorry, incorrect format.\n'+usage;
message.channel.send(reply);
return reply;
}

const tier = parseInt(msgSplit[1]);
if ((!imageUrls || imageUrls.length == 0)) {
const tier = parseInt(msgSplit[1]);
const minutesLeft = parseInt(msgSplit[2]);
var detail = null;
if (minutesLeft && !isNaN(minutesLeft)) {
detail = message.content.substring(message.content.indexOf(minutesLeft.toString()) + minutesLeft.toString().length + 1);
}
return createReply(data, message, tier, minutesLeft, detail)
} else {
return new Promise((resolve, reject) => {
raidimage.raidEggUrl(imageUrls[0])
.then(result => {
if (result.tier && result.gym && result.minutesLeft) {
resolve(createReply(data, message, result.tier, result.minutesLeft, result.gym));
} else {
if (!result.tier) {
reply = 'Raid tier could not be found';
} else if (!result.gym) {
reply = 'Gym name could not be found';
} else if (!result.minutesLeft) {
reply = 'Time remaining could not be found';
}
message.channel.send(reply);
reject(reply);
}
});
});

}
};

const createReply = (data, message, tier, minutesLeft, detail) => {
let reply = '';
if (isNaN(tier) || tier < 1 || tier > 5) {
reply = 'Sorry incorrect format. Ensure tier is a number between 1 and 5, use format:\n' + usage;
message.channel.send(reply);
Expand All @@ -61,7 +96,6 @@ const egg = (data, message) => {
else tierEmoji = 'normalraid';

const channelName = message.channel.name;
const minutesLeft = parseInt(msgSplit[2]);
if (isNaN(minutesLeft) || minutesLeft < 1 || minutesLeft > 120) {
reply = 'Raid not processed, ensure minutes remaining is a integer between 1 and 120.\n'+usage;
message.channel.send(reply);
Expand All @@ -73,7 +107,6 @@ const egg = (data, message) => {
var twelveHrDate = format_time(date); //calc the friendly 12h date string for the UI

//location information of raid
var detail = message.content.substring(message.content.indexOf(minutesLeft.toString()) + minutesLeft.toString().length + 1);
detail = removeTags(detail).replace('\'', '\'\''); //sanitize html and format for insertion into sql;
if (!detail) {
reply = 'Raid not processed, no location details. Use format:\n'+usage;
Expand Down Expand Up @@ -115,4 +148,4 @@ const egg = (data, message) => {

module.exports = (data) => ( (message) => {
return egg(data, message);
});
});
41 changes: 37 additions & 4 deletions src/chatcommands/raid.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const raidimage = require('./raidimage');
const pokemonInfo = require('../../data/pokemon.json');
const CONSTANTS = require('./../constants');

Expand Down Expand Up @@ -35,12 +36,46 @@ const raid = (data, message) => {
let reply = '';

const msgSplit = message.content.toLowerCase().split(' ');
if (!msgSplit || msgSplit.length < 4) {
const imageUrls = message.attachments
.filter((elem, index, arr) => elem.height && elem.width && elem.url)
.map((elem, index, arr) => elem.url);
if ((!imageUrls || imageUrls.length == 0) && (!msgSplit || msgSplit.length < 4)) {
reply = 'Sorry, incorrect format.\n'+usage;
message.channel.send(reply);
return reply;
}
let boss = CONSTANTS.standardizePokemonName(msgSplit[1].toLowerCase());
if ((!imageUrls || imageUrls.length == 0)) {
var minutesLeft = parseInt(msgSplit[2]);
var detail = null;
if (minutesLeft && !isNaN(minutesLeft)) {
detail = message.content.substring(message.content.indexOf(minutesLeft.toString()) + minutesLeft.toString().length + 1);
}
return createReply(data, message, msgSplit[1], minutesLeft, detail)
} else {
return new Promise((resolve, reject) => {
raidimage.raidBossUrl(imageUrls[0])
.then(result => {
if (result.pokemon && result.gym && result.minutesLeft) {
resolve(createReply(data, message, result.pokemon, result.minutesLeft, result.gym));
} else {
if (!result.pokemon) {
reply = 'Raid Boss name could not be found';
} else if (!result.gym) {
reply = 'Gym name could not be found';
} else if (!result.minutesLeft) {
reply = 'Time remaining could not be found';
}
message.channel.send(reply);
reject(reply);
}
});
});
}
}

const createReply = (data, message, pokemon, minutesLeft, detail) => {
let reply = '';
let boss = CONSTANTS.standardizePokemonName(pokemon.toLowerCase());

if (!pokemonInfo[boss.toUpperCase()]) {
reply = 'Sorry, boss not found. Please make sure to type the exact name of the raid boss and DO NOT USE THE @ tag.\n'+usage;
Expand Down Expand Up @@ -73,7 +108,6 @@ const raid = (data, message) => {
}

const channelName = message.channel.name;
const minutesLeft = parseInt(msgSplit[2]);
if (isNaN(minutesLeft) || minutesLeft < 1 || minutesLeft > 120) {
reply = 'Raid not processed, ensure minutes remaining is a integer between 1 and 120.\n'+usage;
message.channel.send(reply);
Expand All @@ -94,7 +128,6 @@ const raid = (data, message) => {
*/

//location information of raid
var detail = message.content.substring(message.content.indexOf(minutesLeft.toString()) + minutesLeft.toString().length + 1);
detail = removeTags(detail).replace('\'', '\'\''); //sanitize html and format for insertion into sql;
if (!detail) {
reply = 'Raid not processed, no location details. Use format: !raid [bossName] [minutesRemaining] [location details]';
Expand Down
Loading