Skip to content

Commit

Permalink
removes textgears-api
Browse files Browse the repository at this point in the history
the textgears-api npm package had several security issues and has thus been removed
  • Loading branch information
Chr1s70ph committed Apr 17, 2024
1 parent 67dac6b commit 8faff0a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 86 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Clone the repository, `cd` into it and run `npm install`.
- [x] Random Gifs
- [x] Role Assignment
- [x] Table of Contents generation
- [x] TextGears
- [x] Timetable
- [x] Timetable Reminders
- [x] User info
Expand All @@ -40,7 +39,6 @@ The only required value is `botToken`, which you can get from the [Discord Devel

```json
{
"textgears_api_key": "<your api key>",
"tenor": {
"Key": "<your api key>",
"Filter": "off",
Expand Down
72 changes: 0 additions & 72 deletions events/messageCreate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { EmbedBuilder, MessageCreateOptions, MessagePayload, TextChannel } from 'discord.js'
import textgears from 'textgears-api'
import tx2 from 'tx2'
import { DiscordClient, DiscordMessage } from '../types/customTypes'

Expand Down Expand Up @@ -91,14 +90,6 @@ exports.run = (client: DiscordClient, message: DiscordMessage) => {
}
}

/**
* Annoy people :)
*/
const channel = message.channel as TextChannel
if (channel.parentId === '773683524833902632' && message.author.id === client.config.ids.userID.david) {
check_spelling(client, message)
}

/**
* DM handling and forwarding.
*/
Expand Down Expand Up @@ -143,69 +134,6 @@ exports.run = (client: DiscordClient, message: DiscordMessage) => {
}
}

/**
* Just a small function to annoy a friend ;)
* @param {Discordlient} client Discord-Client
* @param {DiscordMessage} message Message to scan
*/
function check_spelling(client: DiscordClient, message: DiscordMessage) {
if (!client.config.sensitive.textgears_api_key) {
console.error('client.config.sensitive.textgears_api_key is undefined')
return
}
const test_query = message.toString()

const textgearsApi = textgears(client.config.sensitive.textgears_api_key, { language: 'de-DE', ai: false })
textgearsApi
.checkGrammar(test_query)
.then(async return_data => {
if (return_data.response.errors.length > 0) {
/**
* Message to do better next time
*/
await message.reply({
embeds: [
new EmbedBuilder()
.setTitle('⚠FEHLER ENTDECKT!!⚠')
.setThumbnail('https://www.duden.de/modules/custom/duden_og_image/images/Duden_FB_Profilbild.jpg')
.setDescription('Das nächste Mal bitte vorher auf Rechtschreibung überprüfen'),
],
})
/**
* Loop over all suggestions
*/
for (const error of return_data.response.errors) {
/**
* Nicely formatted list of links to duden.de entries
*/
let suggestion_links = `__Verbesserungen__:\n`
for (const suggestion of error.better) {
suggestion_links += `- **__[${suggestion}](https://duden.de/rechtschreibung/${suggestion})__**\n`
}
/**
* Send embed with all the suggestions for one error
*/
const embed = new EmbedBuilder()
.setTitle(`Fehler: ${error.bad}`)
.setAuthor({
name: '⚠Fehler Verbesserung⚠',
iconURL: 'https://www.duden.de/modules/custom/duden_og_image/images/Duden_FB_Profilbild.jpg',
})
.setThumbnail('https://www.duden.de/modules/custom/duden_og_image/images/Duden_FB_Profilbild.jpg')
.setDescription(suggestion_links)
.setFooter({
text: 'Du hast einen physischen Duden, also nutze ihn ;)',
})
.setTimestamp()
// eslint-disable-next-line no-await-in-loop
await message.reply({ embeds: [embed] })
}
}
})
.catch(err => {
throw new Error(err)
})
}

/**
* A function for splitting a string into fixed-length parts. Designed as a
Expand Down
21 changes: 10 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,33 @@
"homepage": "https://github.com/Chr1s70ph/ETIT-Master-JS#readme",
"author": "Christoph Bluem",
"dependencies": {
"@discordjs/rest": "^2.2.0",
"discord-api-types": "^0.37.70",
"discord.js": "^14.14.1",
"@discordjs/rest": "^2.0.0",
"discord-api-types": "^0.37.79",
"discord.js": "^14.12.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.3",
"fs": "^0.0.1-security",
"https": "^1.0.0",
"i18next": "^23.8.2",
"i18next": "^23.11.2",
"i18next-fs-backend": "^2.3.1",
"luxon": "^3.4.4",
"moment": "^2.30.1",
"moment-timezone": "^0.5.45",
"node-ical": "^0.17.2",
"node-ical": "^0.18.0",
"node-schedule": "^2.1.1",
"openai": "^4.28.0",
"openai": "^4.36.0",
"os": "^0.1.2",
"pm2": "^5.3.1",
"tenorjs": "^1.0.10",
"textgears-api": "^1.1.11",
"tx2": "^1.0.5",
"valid-url": "^1.0.9"
},
"devDependencies": {
"@types/node-schedule": "^2.1.6",
"@types/node-schedule": "^2.1.7",
"@types/tx2": "^1.0.3",
"@typescript-eslint/eslint-plugin": "^7.0.1",
"@typescript-eslint/parser": "^7.0.1",
"eslint": "^8.56.0"
"@typescript-eslint/eslint-plugin": "^7.7.0",
"@typescript-eslint/parser": "^7.7.0",
"eslint": "^9.0.0"
}
}
1 change: 0 additions & 1 deletion types/customTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,6 @@ interface config_settings_typing {
}

interface config_sensitive_typing {
textgears_api_key?: string
tenor?: {
Key: string
Filter: string
Expand Down

0 comments on commit 8faff0a

Please sign in to comment.