mirror of
https://github.com/toast-ts/Daggerbot-TS.git
synced 2024-11-17 20:30:58 -05:00
Add academy command
This commit is contained in:
parent
a6299b3cea
commit
c53c1493d7
15
.pnp.cjs
generated
15
.pnp.cjs
generated
@ -48,7 +48,8 @@ const RAW_RUNTIME_STATE =
|
|||||||
["simple-git", "npm:3.22.0"],\
|
["simple-git", "npm:3.22.0"],\
|
||||||
["systeminformation", "npm:5.21.22"],\
|
["systeminformation", "npm:5.21.22"],\
|
||||||
["typescript", "patch:typescript@npm%3A5.3.3#optional!builtin<compat/typescript>::version=5.3.3&hash=e012d7"],\
|
["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"\
|
"linkType": "SOFT"\
|
||||||
}]\
|
}]\
|
||||||
@ -1013,7 +1014,8 @@ const RAW_RUNTIME_STATE =
|
|||||||
["simple-git", "npm:3.22.0"],\
|
["simple-git", "npm:3.22.0"],\
|
||||||
["systeminformation", "npm:5.21.22"],\
|
["systeminformation", "npm:5.21.22"],\
|
||||||
["typescript", "patch:typescript@npm%3A5.3.3#optional!builtin<compat/typescript>::version=5.3.3&hash=e012d7"],\
|
["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"\
|
"linkType": "SOFT"\
|
||||||
}]\
|
}]\
|
||||||
@ -2804,6 +2806,15 @@ const RAW_RUNTIME_STATE =
|
|||||||
],\
|
],\
|
||||||
"linkType": "HARD"\
|
"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"\
|
||||||
|
}]\
|
||||||
]]\
|
]]\
|
||||||
]\
|
]\
|
||||||
}';
|
}';
|
||||||
|
@ -48,7 +48,8 @@
|
|||||||
"sequelize": "6.35.2",
|
"sequelize": "6.35.2",
|
||||||
"simple-git": "3.22.0",
|
"simple-git": "3.22.0",
|
||||||
"systeminformation": "5.21.22",
|
"systeminformation": "5.21.22",
|
||||||
"undici": "6.2.1"
|
"undici": "6.2.1",
|
||||||
|
"yaml": "2.3.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/ms": "0.7.34",
|
"@types/ms": "0.7.34",
|
||||||
|
5
src/articles.yaml
Normal file
5
src/articles.yaml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
articles:
|
||||||
|
- embed:
|
||||||
|
id: 0
|
||||||
|
title: ""
|
||||||
|
description: ""
|
62
src/commands/academy.ts
Normal file
62
src/commands/academy.ts
Normal 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'))
|
||||||
|
}
|
@ -54,7 +54,7 @@ export default class MessageCreate {
|
|||||||
Response.create(client, message, GeneralChatID, 'evening');
|
Response.create(client, message, GeneralChatID, 'evening');
|
||||||
Response.create(client, message, GeneralChatID, 'night');
|
Response.create(client, message, GeneralChatID, 'night');
|
||||||
|
|
||||||
CmdTrigger.registerCmds(client, message, 'wepanikfrfr');
|
CmdTrigger.registerCmds(client, message, 'register');
|
||||||
CmdTrigger.MFPwTrigger(message, 'farmpw');
|
CmdTrigger.MFPwTrigger(message, 'farmpw');
|
||||||
|
|
||||||
let picStorage = {
|
let picStorage = {
|
||||||
|
@ -767,6 +767,7 @@ __metadata:
|
|||||||
systeminformation: "npm:5.21.22"
|
systeminformation: "npm:5.21.22"
|
||||||
typescript: "npm:5.3.3"
|
typescript: "npm:5.3.3"
|
||||||
undici: "npm:6.2.1"
|
undici: "npm:6.2.1"
|
||||||
|
yaml: "npm:2.3.4"
|
||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
|
|
||||||
@ -2320,3 +2321,10 @@ __metadata:
|
|||||||
checksum: 4cb02b42b8a93b5cf50caf5d8e9beb409400a8a4d85e83bb0685c1457e9ac0b7a00819e9f5991ac25ffabb56a78e2f017c1acc010b3a1babfe6de690ba531abd
|
checksum: 4cb02b42b8a93b5cf50caf5d8e9beb409400a8a4d85e83bb0685c1457e9ac0b7a00819e9f5991ac25ffabb56a78e2f017c1acc010b3a1babfe6de690ba531abd
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"yaml@npm:2.3.4":
|
||||||
|
version: 2.3.4
|
||||||
|
resolution: "yaml@npm:2.3.4"
|
||||||
|
checksum: f8207ce43065a22268a2806ea6a0fa3974c6fde92b4b2fa0082357e487bc333e85dc518910007e7ac001b532c7c84bd3eccb6c7757e94182b564028b0008f44b
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
Loading…
Reference in New Issue
Block a user