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

Commit

Permalink
Merge pull request #32 from project-yuigahama/next
Browse files Browse the repository at this point in the history
v1.0.6-pre
  • Loading branch information
InkoHX authored Jun 20, 2019
2 parents 188e077 + f149ae5 commit 64164b2
Show file tree
Hide file tree
Showing 13 changed files with 156 additions and 72 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ typings/

# Provider
src/bwd/provider/

# Visual Studio IDE
.vs/

# JetBrains IDE
.idea/

# Firebase
resources/serviceAccount.json
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ npm run start
* [cross-env](https://github.com/kentcdodds/cross-env)
* [firebase-admin](https://github.com/firebase/firebase-admin-node)
* [fs-nextra](https://github.com/bdistin/fs-nextra)
* [nsfwjs](https://github.com/infinitered/nsfwjs)
* [cross-env](https://github.com/kentcdodds/cross-env)
* [canvas](https://github.com/Automattic/node-canvas)
* [@tensorflow/tfjs-node](https://github.com/tensorflow/tfjs-node)
62 changes: 31 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yuigahama",
"version": "1.0.5",
"version": "1.0.6",
"description": "Powerful multifunction discord bot",
"main": "src/Yui.js",
"scripts": {
Expand All @@ -26,7 +26,7 @@
},
"homepage": "https://github.com/InkoHX/Yui#readme",
"dependencies": {
"@tensorflow/tfjs-node": "^1.1.2",
"@tensorflow/tfjs-node": "^1.2.1",
"canvas": "^2.5.0",
"cross-env": "^5.2.0",
"dblapi.js": "^2.3.0",
Expand Down
1 change: 0 additions & 1 deletion src/Yui.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const client = new Client({
if ('DBL_TOKEN' in process.env) {
const DBL = new DBLAPI(process.env.DBL_TOKEN, client)
DBL.on('error', error => client.emit('DblError', error))
DBL.on('posted', () => client.emit('DblPosted'))
}

client.login()
Expand Down
35 changes: 35 additions & 0 deletions src/commands/Game/ETS2/truckers-mp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const { Command, KlasaMessage, RichDisplay } = require('klasa')
const { MessageEmbed } = require('discord.js')
const fetch = require('node-fetch')

class TruckersMP extends Command {
constructor (...args) {
super(...args, {
enabled: true,
requiredPermissions: ['MANAGE_MESSAGES'],
description: language => language.get('COMMAND_TRUCKERS_MP_DESCRIPTION')
})
}

/**
* @param {KlasaMessage} message
*/
async run (message) {
const data = await fetch('https://stats.truckersmp.com/api/v4/overall.json').then(res => res.json()).catch(() => null)
if (data === null) throw new Error('Request failed.')
if (data.error === true) return message.sendMessage('Error.')
const Display = new RichDisplay()

for (let index = 0; index < data.color.length; index++) {
const color = data.color[index]
const embed = new MessageEmbed().setColor(color)
const server = data.data[index]
embed.setTitle(server.name).addField('Players', server.players, true).addField('Max Players', server.max_players, true)
Display.addPage(embed)
}

return Display.run(message)
}
}

module.exports = TruckersMP
33 changes: 33 additions & 0 deletions src/commands/Guild/Information/emoji-info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const { Command, KlasaMessage } = require('klasa')
const { MessageEmbed, GuildEmoji } = require('discord.js')

module.exports = class extends Command {
constructor (...args) {
super(...args, {
runIn: ['text'],
description: language => language.get('COMMAND_EMOJI_INFO_DESCRIPTION'),
usage: '<emoji:emoji>'
})
}

/**
* @param {KlasaMessage} message
* @param {[GuildEmoji]} usage
*/
async run (message, [emoji]) {
const Embed = new MessageEmbed()
.setColor('RANDOM')
.setThumbnail(emoji.url)
.addField('Emoji name', emoji.name, true)
.addField('ID', emoji.id, true)
.addField('Animated', emoji.animated ? 'Yes' : 'No', true)
.addField('Deleted', emoji.deleted ? 'Yes' : 'No', true)
.setFooter('Created At')
.setTimestamp(emoji.createdTimestamp)

const author = await emoji.fetchAuthor().catch(() => null)

if (author === null) return message.sendEmbed(Embed)
else return message.sendEmbed(Embed.setAuthor(`${author.tag} has added.`, author.avatarURL({ format: 'png' })))
}
}
2 changes: 2 additions & 0 deletions src/commands/Guild/Information/guildinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class GuideInfo extends Command {
.setFooter('Created At')
.addField('Guild ID', message.guild.id, true)
.addField('Owner', message.guild.owner !== null ? message.guild.owner.user.tag : 'None', true)
.addField('Server Boost Level', `Lv.${message.guild.premiumTier}`, true)
.addField('Boosters', message.guild.premiumSubscriptionCount || 0, true)
.addField('Members', memberCount, true)
.addField('Channels', Channels, true)
.addField('Emojis', Emojis, true)
Expand Down
28 changes: 10 additions & 18 deletions src/commands/Guild/Information/topinvite.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { Command, KlasaMessage, RichDisplay } = require('klasa')
const { Command, KlasaMessage, RichDisplay, Timestamp } = require('klasa')
const { MessageEmbed } = require('discord.js')

class TopInvite extends Command {
Expand All @@ -15,33 +15,25 @@ class TopInvite extends Command {
*/
async run (message) {
const invites = await message.guild.fetchInvites()
const inviters = []

if (invites.size === 0) return message.sendMessage(message.language.get('COMMAND_TOP_INVITE_NOT_FOUND'))
invites.map((invite) => {
inviters.push({ inviter: invite.inviter ? invite.inviter : null, url: invite.url, uses: invite.uses, createdAt: invite.createdAt })
})

inviters.sort((a, b) => {
return a.uses < b.uses
})
const top = invites.filter(invite => invite.uses > 0).sort((a, b) => b.uses - a.uses).first(10)
if (top.length === 0) throw message.language.get('COMMAND_TOP_INVITE_FAIL')

const Display = new RichDisplay()
let count = 0

inviters.forEach((value) => {
top.map((invite) => {
count++
Display.addPage(new MessageEmbed()
.setColor('RANDOM')
.setThumbnail(value.inviter.avatarURL({ format: 'png' }) || 'https://discordapp.com/assets/dd4dbc0016779df1378e7812eabaa04d.png')
.setTitle(`${value.inviter !== null ? value.inviter.tag : 'Unknown'} - Top ${count}`)
.addField('URL', value.url, true)
.addField('Uses', value.uses, true)
.setTimestamp(value.createdAt)
.setTitle(`Top ${count}`)
.addField('Uses', invite.uses, true)
.addField('Code', invite.code, true)
.addField('Author', invite.inviter !== null ? invite.inviter.tag : 'Deleted', true)
.addField('Created At', new Timestamp('YYYY-MM-DD HH:mm:ss').display(invite.createdTimestamp), true)
)
})

return Display.run(await message.send('Loading...'))
return Display.run(message)
}
}

Expand Down
12 changes: 0 additions & 12 deletions src/events/DblPosted.js

This file was deleted.

6 changes: 4 additions & 2 deletions src/languages/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module.exports = class extends Language {
COMMAND_MOJANG_STATUS: 'Display the status of various Mojang services.',
COMMAND_MDN_DESCRIPTION: 'You can search MDN Web docs.',
COMMAND_TOP_INVITE_DESCRIPTION: 'Display the invitation ranking.',
COMMAND_TOP_INVITE_NOT_FOUND: 'There is no invitation link.',
COMMAND_TOP_INVITE_FAIL: 'There are no invites, or none of them have been used!',
IMAGE_FILTER_DELETE_MESSAGE: 'Please do not send NSFW images to SFW channels.',
COMMAND_IMAGE_FILTER_DESCRIPTION: 'Powerful image filter.',
COMMAND_IMAGE_FILTER_EXTENDED_HELP: [
Expand All @@ -82,7 +82,9 @@ module.exports = class extends Language {
COMMAND_APPROVAL_DISABLED: 'The approval has been discarded.',
COMMAND_APPROVAL_FAIL: 'It is not a server or YuigahamaBot has not been introduced.',
COMMAND_APPROVAL_ENABLED_RLREADY: 'This server has already been approved.',
COMMAND_APPROVAL_DISABLED_RLREADY: 'This server has not been approved.'
COMMAND_APPROVAL_DISABLED_RLREADY: 'This server has not been approved.',
COMMAND_TRUCKERS_MP_DESCRIPTION: 'Display the TruckersMP status.',
COMMAND_EMOJI_INFO_DESCRIPTION: 'Display detailed information of emoji.'
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/languages/ja-JP.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ module.exports = class extends Language {
COMMAND_MOJANG_STATUS: 'さまざまなMojangサービスの状態を表示します。',
COMMAND_MDN_DESCRIPTION: 'MDN Web docs を検索することができます。',
COMMAND_TOP_INVITE_DESCRIPTION: '招待回数ランキングを表示します。',
COMMAND_TOP_INVITE_NOT_FOUND: '招待リンクが一つもありません。',
COMMAND_TOP_INVITE_FAIL: '招待リンクが一つもないか、存在するが一度も使われていません。',
IMAGE_FILTER_DELETE_MESSAGE: 'NSFWチャンネルでないSFWチャンネルにNSFW画像を送信しないでください。',
COMMAND_IMAGE_FILTER_DESCRIPTION: '強力な画像フィルター、ポルノ画像や卑猥な画像を削除します。',
COMMAND_IMAGE_FILTER_EXTENDED_HELP: [
Expand All @@ -252,7 +252,9 @@ module.exports = class extends Language {
COMMAND_APPROVAL_DISABLED: '承認を破棄しました。',
COMMAND_APPROVAL_FAIL: (id) => `${id}はサーバーでないもしくは${this.client.user.tag}を導入していません。`,
COMMAND_APPROVAL_ENABLED_RLREADY: '既に認証しています。',
COMMAND_APPROVAL_DISABLED_RLREADY: 'このサーバーは認証されていません。'
COMMAND_APPROVAL_DISABLED_RLREADY: 'このサーバーは認証されていません。',
COMMAND_TRUCKERS_MP_DESCRIPTION: 'TruckersMPのサーバー情報を表示します。',
COMMAND_EMOJI_INFO_DESCRIPTION: '絵文字の詳細情報を表示します。'
}
}

Expand Down
30 changes: 29 additions & 1 deletion test/Utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Utils', () => {
})

describe('resolveModTypeColor', () => {
it('Return integer', () => {
it('Return number', () => {
assert.strictEqual(typeof utils.resolveModTypeColor('KICK'), 'number')
assert.strictEqual(typeof utils.resolveModTypeColor('BAN'), 'number')
assert.strictEqual(typeof utils.resolveModTypeColor('UNKNOWN'), 'number')
Expand All @@ -25,4 +25,32 @@ describe('Utils', () => {
assert.strictEqual(utils.resolveModTypeColor('???'), 0x000000)
})
})

describe('getFilterLevel', () => {
it('Return number', () => {
assert.strictEqual(typeof utils.getFilterLevel(1), 'number')
assert.strictEqual(typeof utils.getFilterLevel(2), 'number')
assert.strictEqual(typeof utils.getFilterLevel(3), 'number')
assert.strictEqual(typeof utils.getFilterLevel(4), 'number')
assert.strictEqual(typeof utils.getFilterLevel(5), 'number')
assert.strictEqual(typeof utils.getFilterLevel(6), 'number')
assert.strictEqual(typeof utils.getFilterLevel(7), 'number')
assert.strictEqual(typeof utils.getFilterLevel(8), 'number')
assert.strictEqual(typeof utils.getFilterLevel(9), 'number')
assert.strictEqual(typeof utils.getFilterLevel(0), 'number')
})

it('Return correct value', () => {
assert.strictEqual(utils.getFilterLevel(1), 0.9)
assert.strictEqual(utils.getFilterLevel(2), 0.8)
assert.strictEqual(utils.getFilterLevel(3), 0.7)
assert.strictEqual(utils.getFilterLevel(4), 0.6)
assert.strictEqual(utils.getFilterLevel(5), 0.5)
assert.strictEqual(utils.getFilterLevel(6), 0.4)
assert.strictEqual(utils.getFilterLevel(7), 0.3)
assert.strictEqual(utils.getFilterLevel(8), 0.2)
assert.strictEqual(utils.getFilterLevel(9), 0.1)
assert.strictEqual(utils.getFilterLevel(0), 0.6)
})
})
})

0 comments on commit 64164b2

Please sign in to comment.