Skip to content

Commit

Permalink
Run eslint and pretteir on project
Browse files Browse the repository at this point in the history
  • Loading branch information
Matan Kushner committed Dec 12, 2017
1 parent 2be00cc commit d5f8cde
Show file tree
Hide file tree
Showing 10 changed files with 4,893 additions and 4,422 deletions.
9,098 changes: 4,776 additions & 4,322 deletions package-lock.json

Large diffs are not rendered by default.

23 changes: 13 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,23 @@
"precommit": "lint-staged"
},
"lint-staged": {
"*.js": [
"npm run lint",
"prettier --write",
"git add"
]
"*.js": ["npm run lint", "prettier --write", "git add"]
},
"eslintConfig": {
"parserOptions": {
"ecmaVersion": 8
"ecmaVersion": 8,
"ecmaFeatures": {
"experimentalObjectRestSpread": true
}
},
"extends": [
"eslint:recommended",
"plugin:flowtype/recommended"
]
"rules": {
"no-console": "off"
},
"env": {
"es6": true,
"node": true
},
"extends": "eslint:recommended"
},
"author": "Josh Star",
"license": "MIT",
Expand Down
8 changes: 4 additions & 4 deletions src/api.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const { GraphQLClient } = require('graphql-request');
const { GraphQLClient } = require("graphql-request");

const client = new GraphQLClient('https://graphql.anilist.co', {
redirect: 'follow',
const client = new GraphQLClient("https://graphql.anilist.co", {
redirect: "follow"
});

const fetch = (query, variables) =>
client
.request(query, variables)
.then(data => data)
.catch(error => ({
error: error.response.errors[0] || 'Unknown Error'
error: error.response.errors[0] || "Unknown Error"
}));

module.exports = fetch;
12 changes: 6 additions & 6 deletions src/character/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const api = require('../api');
const query = require('./query');
const discordMessage = require('../discordMessage');
const api = require("../api");
const query = require("./query");
const discordMessage = require("../discordMessage");

const search = async (searchArg) => {
const search = async searchArg => {
const response = await api(query, {
search: searchArg,
search: searchArg
});

if (response.error) {
Expand All @@ -24,7 +24,7 @@ const search = async (searchArg) => {
imageUrl: data.image.large,
description: data.description
});
}
};

module.exports = {
search
Expand Down
23 changes: 15 additions & 8 deletions src/discordMessage.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
const toMarkdown = require('to-markdown');
const toMarkdown = require("to-markdown");
const anilistLogo = "https://anilist.co/img/logo_al.png";

const pipe = (op1, op2) => arg => op2(op1(arg))
const pipe = (op1, op2) => arg => op2(op1(arg));

const removeSpoilers = str => str.replace(/<span[^>]*>.*<\/span>/g, "");

const shorten = str => {
const markdown = toMarkdown(str);
if (markdown.length > 400) {
return markdown.substring(0, 400) + '...'
return markdown.substring(0, 400) + "...";
} else {
return markdown;
}
}
};

const discordMessage = ({ name, url, imageUrl, description, footer, title } = {}) => {
const discordMessage = ({
name,
url,
imageUrl,
description,
footer,
title
} = {}) => {
return {
title: title,
author: {
Expand All @@ -23,13 +30,13 @@ const discordMessage = ({ name, url, imageUrl, description, footer, title } = {}
icon_url: anilistLogo
},
thumbnail: {
url: imageUrl,
url: imageUrl
},
description: pipe(removeSpoilers, shorten)(description),
footer: {
text: footer
}
}
}
};
};

module.exports = discordMessage;
71 changes: 39 additions & 32 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,79 @@
const Discord = require('discord.js');
const config = require('./config.json');
const Discord = require("discord.js");
const config = require("./config.json");

const character = require('./character');
const media = require('./media');
const staff = require('./staff');
const user = require('./user');
const studio = require('./studio');
const character = require("./character");
const media = require("./media");
const staff = require("./staff");
const user = require("./user");
const studio = require("./studio");

const client = new Discord.Client();

client.on('ready', () => {
client.on("ready", () => {
// This event will run if the bot starts, and logs in, successfully.
console.log(`Bot has started, with ${client.users.size} users, in ${client.channels.size} channels of ${client.guilds.size} guilds.`);
console.log(
`Bot has started, with ${client.users.size} users, in ${
client.channels.size
} channels of ${client.guilds.size} guilds.`
);
});

client.on('message', async message => {
client.on("message", async message => {
// Ignore other bot messages
if (message.author.bot && message.author.username != 'irc') {
if (message.author.bot && message.author.username != "irc") {
return;
}

// Remove irc username suffix
const messageContent = message.content.replace(/<.*> /, '');
const messageContent = message.content.replace(/<.*> /, "");

// Ensure the message starts with our prefix
// Ensure the message starts with our prefix
if (messageContent.indexOf(config.prefix) !== 0) {
return;
}

let args = messageContent.slice(config.prefix.length).trim().split(/ +/g);
let args = messageContent
.slice(config.prefix.length)
.trim()
.split(/ +/g);
const command = args.shift().toLowerCase();
args = args.join(' ');
args = args.join(" ");

let response = null;

switch (command) {
case 'help':
case "help":
response = help;
break;

case 'a':
case 'anime':
response = await media.search(args, 'ANIME');
case "a":
case "anime":
response = await media.search(args, "ANIME");
break;

case 'm':
case 'manga':
response = await media.search(args, 'MANGA');
case "m":
case "manga":
response = await media.search(args, "MANGA");
break;

case 'c':
case 'character':
case "c":
case "character":
response = await character.search(args);
break;

case 'p':
case 'person':
case 'staff':
case "p":
case "person":
case "staff":
response = await staff.search(args);
break;

case 's':
case 'studio':
case "s":
case "studio":
response = await studio.search(args);
break;

case 'u':
case 'user':
case "u":
case "user":
response = await user.search(args);
break;
}
Expand All @@ -89,7 +96,7 @@ client.on('message', async message => {
});

const help = {
title: 'Commands',
title: "Commands",
description: `
Search anime: !a or !anime <anime title>
Search manga: !m or !manga <manga title>
Expand Down
23 changes: 12 additions & 11 deletions src/media/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const api = require('../api');
const query = require('./query');
const discordMessage = require('../discordMessage');
const api = require("../api");
const query = require("./query");
const discordMessage = require("../discordMessage");

const capitalize = str => str.charAt(0).toUpperCase() + str.substring(1).toLowerCase();
const capitalize = str =>
str.charAt(0).toUpperCase() + str.substring(1).toLowerCase();

const search = async (searchArg, type) => {
const response = await api(query, {
Expand All @@ -15,14 +16,14 @@ const search = async (searchArg, type) => {
}

const data = response.Media;
const {averageScore: score, status} = data;
const { averageScore: score, status } = data;

const scoreString = score != null ? `Score: ${score}%` : '';
const statusString = status != null ? `Status: ${capitalize(status)}` : '';
const scoreString = score != null ? `Score: ${score}%` : "";
const statusString = status != null ? `Status: ${capitalize(status)}` : "";

let footer = '';
let footer = "";
// Use the en quad space after score to not get stripped by Discord
if (score) footer += scoreString + '  ';
if (score) footer += scoreString + "  ";
if (status) footer += statusString;

return discordMessage({
Expand All @@ -31,8 +32,8 @@ const search = async (searchArg, type) => {
imageUrl: data.coverImage.large,
description: data.description,
footer: footer
})
}
});
};

module.exports = {
search
Expand Down
12 changes: 6 additions & 6 deletions src/staff/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const api = require('../api');
const query = require('./query');
const discordMessage = require('../discordMessage');
const api = require("../api");
const query = require("./query");
const discordMessage = require("../discordMessage");

const search = async (searchArg) => {
const search = async searchArg => {
const response = await api(query, {
search: searchArg,
search: searchArg
});

if (response.error) {
Expand All @@ -24,7 +24,7 @@ const search = async (searchArg) => {
imageUrl: data.image.large,
description: data.description
});
}
};

module.exports = {
search
Expand Down
21 changes: 10 additions & 11 deletions src/studio/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const api = require('../api');
const query = require('./query');
const discordMessage = require('../discordMessage');
const toMarkdown = require('to-markdown');
const api = require("../api");
const query = require("./query");
const discordMessage = require("../discordMessage");

const search = async (searchArg) => {
const search = async searchArg => {
const response = await api(query, {
search: searchArg
});
Expand All @@ -12,21 +11,21 @@ const search = async (searchArg) => {
return response;
}

const data = response.Studio
let anime = '';
const data = response.Studio;
let anime = "";
data.media.nodes.map(media => {
anime += `
<a href='${media.siteUrl}'>${media.title.romaji}</a> <br>
`;
});

return discordMessage({
title: 'Popular Anime',
title: "Popular Anime",
name: data.name,
url: data.siteUrl,
description: anime,
})
}
description: anime
});
};

module.exports = {
search
Expand Down
Loading

0 comments on commit d5f8cde

Please sign in to comment.