diff --git a/.pnp.cjs b/.pnp.cjs index d61744d..74c1678 100644 --- a/.pnp.cjs +++ b/.pnp.cjs @@ -48,7 +48,8 @@ const RAW_RUNTIME_STATE = ["simple-git", "npm:3.22.0"],\ ["systeminformation", "npm:5.21.22"],\ ["typescript", "patch:typescript@npm%3A5.3.3#optional!builtin::version=5.3.3&hash=e012d7"],\ - ["undici", "npm:6.2.1"]\ + ["undici", "npm:6.2.1"],\ + ["yaml", "npm:2.3.4"]\ ],\ "linkType": "SOFT"\ }]\ @@ -1013,7 +1014,8 @@ const RAW_RUNTIME_STATE = ["simple-git", "npm:3.22.0"],\ ["systeminformation", "npm:5.21.22"],\ ["typescript", "patch:typescript@npm%3A5.3.3#optional!builtin::version=5.3.3&hash=e012d7"],\ - ["undici", "npm:6.2.1"]\ + ["undici", "npm:6.2.1"],\ + ["yaml", "npm:2.3.4"]\ ],\ "linkType": "SOFT"\ }]\ @@ -2804,6 +2806,15 @@ const RAW_RUNTIME_STATE = ],\ "linkType": "HARD"\ }]\ + ]],\ + ["yaml", [\ + ["npm:2.3.4", {\ + "packageLocation": "./.yarn/cache/yaml-npm-2.3.4-8bb6dc2c0d-f8207ce430.zip/node_modules/yaml/",\ + "packageDependencies": [\ + ["yaml", "npm:2.3.4"]\ + ],\ + "linkType": "HARD"\ + }]\ ]]\ ]\ }'; diff --git a/package.json b/package.json index ff4056e..10735d1 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,8 @@ "sequelize": "6.35.2", "simple-git": "3.22.0", "systeminformation": "5.21.22", - "undici": "6.2.1" + "undici": "6.2.1", + "yaml": "2.3.4" }, "devDependencies": { "@types/ms": "0.7.34", diff --git a/src/articles.yaml b/src/articles.yaml new file mode 100644 index 0000000..77cead2 --- /dev/null +++ b/src/articles.yaml @@ -0,0 +1,5 @@ +articles: + - embed: + id: 0 + title: "" + description: "" diff --git a/src/commands/academy.ts b/src/commands/academy.ts new file mode 100644 index 0000000..4e2398f --- /dev/null +++ b/src/commands/academy.ts @@ -0,0 +1,62 @@ +interface IArticles { + articles: IArticleEmbed[]; +} +interface IArticleEmbed { + embed: { + id:number; // Article ID (news_id) + title:string; + description:string; + } +} +import yaml from 'yaml'; +import Undici from 'undici'; +import Discord from 'discord.js'; +import TClient from '../client.js'; +import MessageTool from '../helpers/MessageTool.js'; +import {readFileSync, writeFileSync} from 'node:fs'; +export default class Academy { + private static yaml_file:IArticles = yaml.parse(readFileSync('src/articles.yaml', 'utf-8')); + static async autocomplete(_client:TClient, interaction:Discord.AutocompleteInteraction<'raw'>) { + const filterArray = this.yaml_file.articles.map(x=>x.embed.title).filter(x=>x.startsWith(interaction?.options.getFocused())); + await interaction?.respond(filterArray.map(x=>({name: x, value: x}))); + } + static async run(client:TClient, interaction:Discord.ChatInputCommandInteraction<'cached'>) { + ({ + query: async()=>{ + const answer = interaction.options.getString('answer'); + const queryFound = this.yaml_file.articles.find(x=>x.embed.title === answer); + interaction.reply({embeds: [new client.embed() + .setColor(client.config.embedColor) + .setTitle(queryFound.embed.title) + .setURL(`https://www.farming-simulator.com/newsArticle.php?news_id=${queryFound.embed.id}`) + .setDescription(queryFound.embed.description) + .setFooter({text: 'Farming Simulator Academy'}) + ]}); + }, + update: async()=>{ + if (!client.config.whitelist.includes(interaction.user.id)) return MessageTool.youNeedRole(interaction, 'bottech'); + const articles = await Undici.fetch('https://raw.githubusercontent.com/AnxietyisReal/Daggerbot-TS/master/src/articles.yml').then(x=>x.text()); + writeFileSync('src/articles.yml', articles, 'utf8'); + await interaction.reply({embeds: [new client.embed() + .setColor(client.config.embedColorGreen) + .setTitle('Academy file updated') + .setDescription('The local file (`src/articles.yaml`) has been updated with the new information from the GitHub repository.') + ]}); + } + } as any)[interaction.options.getSubcommand()](); + } + static data = new Discord.SlashCommandBuilder() + .setName('academy') + .setDescription('Provides useful information from Farming Simulator Academy') + .addSubcommand(x=>x + .setName('query') + .setDescription('Queries the articles for given search term') + .addStringOption(x=>x + .setName('answer') + .setDescription('The search term') + .setRequired(true) + .setAutocomplete(true))) + .addSubcommand(x=>x + .setName('update') + .setDescription('Updates the local file with new information from GitHub repository')) +} diff --git a/src/events/messageCreate.ts b/src/events/messageCreate.ts index 29dc4b5..0c6b9c4 100644 --- a/src/events/messageCreate.ts +++ b/src/events/messageCreate.ts @@ -54,7 +54,7 @@ export default class MessageCreate { Response.create(client, message, GeneralChatID, 'evening'); Response.create(client, message, GeneralChatID, 'night'); - CmdTrigger.registerCmds(client, message, 'wepanikfrfr'); + CmdTrigger.registerCmds(client, message, 'register'); CmdTrigger.MFPwTrigger(message, 'farmpw'); let picStorage = { diff --git a/yarn.lock b/yarn.lock index d9c037a..cec5249 100644 --- a/yarn.lock +++ b/yarn.lock @@ -767,6 +767,7 @@ __metadata: systeminformation: "npm:5.21.22" typescript: "npm:5.3.3" undici: "npm:6.2.1" + yaml: "npm:2.3.4" languageName: unknown linkType: soft @@ -2320,3 +2321,10 @@ __metadata: checksum: 4cb02b42b8a93b5cf50caf5d8e9beb409400a8a4d85e83bb0685c1457e9ac0b7a00819e9f5991ac25ffabb56a78e2f017c1acc010b3a1babfe6de690ba531abd languageName: node linkType: hard + +"yaml@npm:2.3.4": + version: 2.3.4 + resolution: "yaml@npm:2.3.4" + checksum: f8207ce43065a22268a2806ea6a0fa3974c6fde92b4b2fa0082357e487bc333e85dc518910007e7ac001b532c7c84bd3eccb6c7757e94182b564028b0008f44b + languageName: node + linkType: hard