Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web3facts #48

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
"node-fetch": "^3.2.10",
"opentype.js": "^1.3.4",
"reflect-metadata": "^0.1.13",
"rss-parser": "^3.12.0",
"sequelize": "^6.21.3",
"sequelize-typescript": "^2.1.1",
"string-similarity": "^4.0.4",
"turndown": "^7.1.1",
"winston": "^3.8.1",
"yaml": "^2.1.1"
},
Expand All @@ -40,6 +42,7 @@
"@types/sequelize": "^4.28.14",
"@types/sqlite3": "^3.1.8",
"@types/string-similarity": "^4.0.0",
"@types/turndown": "^5.0.1",
"@typescript-eslint/eslint-plugin": "^5.33.0",
"@typescript-eslint/parser": "^5.33.0",
"eslint": "^8.21.0",
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import JoinLeaveMessageModule from './modules/joinLeaveMessage.module.js'
import {CoreModule} from './modules/core/core.module.js'
import {LearningModule} from './modules/learning/learning.module.js'
import {InformationModule} from './modules/information/information.module.js'
import {Web3Module} from './modules/web3/web3.module.js'

const client = new Client({
intents: [
Expand All @@ -36,6 +37,7 @@ export const moduleManager = new ModuleManager(client,
CoreModule,
FaqModule,
HotTakesModule,
Web3Module,
ImageForwarderModule,
InformationModule,
JoinLeaveMessageModule,
Expand Down
36 changes: 36 additions & 0 deletions src/modules/web3/web3.command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {Command} from 'djs-slash-helper'
import {ApplicationCommandType} from 'discord-api-types/v10'
import {CommandInteraction, EmbedBuilder} from 'discord.js'
import Parser from 'rss-parser'
import TurndownService from 'turndown'


const web3RssUrl = 'https://web3isgoinggreat.com/feed.xml'

const rssParser = new Parser()

const turndownService = new TurndownService({ bulletListMarker: '-' })

export const Web3Command: Command<ApplicationCommandType.ChatInput> = {
name: 'web3fact',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is calling it "web3fact" a good idea? the source is truthful but very biased, i can see how that may cause contention

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It gives you a fact about Web3 👍 hope this helps

description: 'Learn more about Web3, the future of human society',
type: ApplicationCommandType.ChatInput,
options: [],

async handle(interaction: CommandInteraction) {
const feed = await rssParser.parseURL(web3RssUrl)
const recentEntries = feed.items.slice(0, 10)
const entry = recentEntries.randomElement()
const embed = new EmbedBuilder()
.setTitle(entry.title ?? 'Missing title')
.setAuthor({name: 'Molly White', url: 'https://mollywhite.net'})
.setURL(entry.link ?? feed.link ?? 'http://example.com')
.setDescription(turndownService.turndown(entry.content ?? 'Missing content'))
.setTimestamp(new Date(entry.pubDate ?? Date().toString()))
.setFooter({text: feed.title ?? 'Missing feed title'})
.toJSON()
await interaction.reply({embeds: [embed]})
}
}

export default Web3Command
7 changes: 7 additions & 0 deletions src/modules/web3/web3.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Module from '../module.js';
import Web3Command from './web3.command.js';

export const Web3Module: Module = {
name: 'web3',
commands: [Web3Command]
}
Loading