1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-11-17 16:30:58 -05:00

Compare commits

...

3 Commits

Author SHA1 Message Date
AnxietyisReal
b1b0c3692e Forgot to add disclaimer 2024-01-02 01:17:01 +11:00
AnxietyisReal
8fa72b2aa1 Update articles 2024-01-02 01:11:05 +11:00
AnxietyisReal
c53c1493d7 Add academy command 2024-01-02 00:50:50 +11:00
6 changed files with 116 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",

10
src/articles.yaml Normal file
View File

@ -0,0 +1,10 @@
articles:
- embed:
id: 338
title: "[Animals] Chickens"
description: |
Chickens are a type of livestock in Farming Simulator 22, they are commonly raised for their eggs. To keep chickens healthy and productive, it is important to provide them with proper care and nutrition.
Chickens primarily eat grains such as wheat, barley and sorghum.
Taking care of chickens can be a rewarding experience in Farming Simulator 22, as they can provide a steady supply of eggs for your farm profits. Properly managing their nutrition and environment will help ensure their well-being and productivity.

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

@ -0,0 +1,82 @@
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({content: 'This command is a trial run, it may stay or be removed in near future.', 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: 'This information is provided by the contributors with their best FS knowledge. If you find any mistakes, please contact Toast.'})
]});
},
how_to_contribute: ()=>interaction.reply({embeds: [new client.embed()
.setColor(client.config.embedColor)
.setTitle('How to contribute to the Academy')
.setDescription(MessageTool.concatMessage(
'If you want to show your support and contribute your knowledge to the academy command, you can do so by following the steps below:',
'1. Create a [GitHub account](https://github.com/signup) if you haven\'t already',
'2. Fork the [GitHub repository](https://github.com/AnxietyisReal/Daggerbot-TS/tree/master)',
'3. Navigate to the `articles.yaml` file inside the `src` directory.',
'4. Click the pencil icon to edit the file and add your article (**has to be closely related to official FSA article**) using the following format:',
'```yaml',
'- embed:',
' id: <article_id> # Article ID (/newsArticle.php?news_id=<article_id>)',
' title: <article_title> # Embed title and search term, don\'t make it too long',
' description: <article_description> # Embed description, limit is 4096 and multi-line is supported',
'```',
)).setFooter({text: 'Or if you\'re not familiar with GitHub, you can contact Toast directly with your article'})
]}),
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('how_to_contribute')
.setDescription('Provides information on how to contribute to the academy command'))
.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