1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-09-29 08:20:59 -04:00

Add academy command

This commit is contained in:
toast-ts 2024-01-02 00:50:50 +11:00
parent 86ec8d4d8b
commit f111268164
6 changed files with 91 additions and 4 deletions

15
.pnp.cjs generated
View File

@ -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<compat/typescript>::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<compat/typescript>::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"\
}]\
]]\
]\
}';

View File

@ -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",

5
src/articles.yaml Normal file
View File

@ -0,0 +1,5 @@
articles:
- embed:
id: 0
title: ""
description: ""

62
src/commands/academy.ts Normal file
View File

@ -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'))
}

View File

@ -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 = {

View File

@ -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