Skip to content

Commit 76f43fc

Browse files
AdamSiekierskiMichał Miszczyszyn
andauthored
Add skierowanie command (#56)
* feat: add skierowanie command * Add tests for skierowanie command * Update src/commands/skierowanie.ts Co-authored-by: Michał Miszczyszyn <mmiszy@users.noreply.github.com> * Remove Link type, change links' address property to url * fix: filtering the links Co-authored-by: Michał Miszczyszyn <mmiszy@users.noreply.github.com>
1 parent bc346bc commit 76f43fc

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

src/commands/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import youtube from './youtube';
2222
import typeofweb from './towarticle';
2323
import wiki from './wiki';
2424
import m1 from './m1';
25+
import skierowanie from './skierowanie';
2526

2627
const COMMAND_PATTERN = new RegExp(getConfig('PREFIX') + '([a-z1-9]+)(?: (.*))?');
2728

@@ -46,6 +47,7 @@ const allCommands = [
4647
youtube,
4748
typeofweb,
4849
wiki,
50+
skierowanie,
4951
];
5052

5153
const cooldowns = new Discord.Collection<string, Discord.Collection<string, number>>();

src/commands/skierowanie.spec.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* eslint no-implicit-dependencies: "off" */
2+
/* eslint no-magic-numbers: "off" */
3+
/* tslint:disable:no-implicit-dependencies no-magic-numbers */
4+
5+
import skierowanie from './skierowanie';
6+
import { getMessageMock } from '../../test/mocks';
7+
import { expect } from 'chai';
8+
import * as Discord from 'discord.js';
9+
10+
describe('skierowanie', () => {
11+
const mockAuthor = { username: 'user', avatarURL: 'url' };
12+
13+
it('it should send a message', async () => {
14+
const msg = getMessageMock('msg', { author: mockAuthor });
15+
16+
await skierowanie.execute((msg as unknown) as Discord.Message, ['user']);
17+
18+
await expect(msg.channel.send).to.have.been.calledTwice;
19+
});
20+
21+
it('it should send the links for the passed category', async () => {
22+
const msg = getMessageMock('msg', { author: mockAuthor });
23+
24+
await skierowanie.execute((msg as unknown) as Discord.Message, ['user', 'react']);
25+
26+
const linksMessageMock = [
27+
'Z powyższym skierowaniem należy udać się na poniższe strony internetowe:',
28+
'https://reactjs.org/docs',
29+
'https://developer.mozilla.org/en-US/docs/Learn',
30+
'https://typeofweb.com',
31+
'https://frontlive.pl',
32+
];
33+
34+
await expect(msg.channel.send).to.have.been.calledWithExactly(linksMessageMock);
35+
});
36+
});

src/commands/skierowanie.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import Discord from 'discord.js';
2+
import { Command } from '../types';
3+
4+
const links = [
5+
{ url: 'https://kursjs.pl', category: 'js' },
6+
{ url: 'https://javascript.info', category: 'js' },
7+
{ url: 'https://reactjs.org/docs', category: 'react' },
8+
{ url: 'https://developer.mozilla.org/en-US/docs/Learn/JavaScript', category: 'js' },
9+
{ url: 'https://developer.mozilla.org/en-US/docs/Learn' },
10+
{ url: 'https://typeofweb.com' },
11+
{ url: 'https://frontlive.pl' },
12+
];
13+
14+
const skierowanie: Command = {
15+
name: 'skierowanie',
16+
description: 'Skierowanie na naukę podstaw (+ dobre materiały do nauki)',
17+
args: true,
18+
cooldown: 10,
19+
async execute(msg, args) {
20+
const skierowanieEmbed = new Discord.RichEmbed()
21+
.setColor('#5ab783')
22+
.setAuthor(
23+
`Type of Web oraz ${msg.author.username}`,
24+
msg.author.avatarURL,
25+
'https://typeofweb.com'
26+
)
27+
.setTitle('Skierowanie na naukę podstaw')
28+
.setThumbnail('https://typeofweb.com/wp-content/uploads/2020/04/logo_kwadrat11.png')
29+
.addField(
30+
'Działając na podstawie mojej intuicji oraz wiadomości wysłanych przez osobę skierowaną, kieruję użytkownika/użytkowniczkę',
31+
args[0]
32+
)
33+
.addField(
34+
`na naukę podstaw wybranej przez siebie technologii, w celu lepszego zrozumienia fundamentów jej działania oraz poznania informacji niezbędnych do rozszerzania swojej wiedzy o bardziej zaawansowane zagadnienia`,
35+
`Obecnie posiadana wiedza przez wyżej wymienioną osobę jest zbyt wąska, by mogła ona dalej kontynuować swoją naukę w trudniejszych zagadnieniach w sposób efektywny i zrozumiały`
36+
)
37+
.setTimestamp()
38+
.setFooter(
39+
'Type of Web, Discord, Polska',
40+
'https://cdn.discordapp.com/avatars/574682557988470825/6b0fab28093e6020f497fda41bdd3219.png?size=64'
41+
);
42+
43+
const categoryFilter = args[1]?.toLowerCase();
44+
const linksFiltered = categoryFilter
45+
? links.filter(({ category }) => !category || category === categoryFilter)
46+
: links;
47+
48+
const linksMessage = 'Z powyższym skierowaniem należy udać się na poniższe strony internetowe:';
49+
50+
await msg.channel.send(skierowanieEmbed);
51+
return msg.channel.send([linksMessage, ...linksFiltered.map((link) => link.url)]);
52+
},
53+
};
54+
55+
export default skierowanie;

0 commit comments

Comments
 (0)