-
Notifications
You must be signed in to change notification settings - Fork 9
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
JohnnyJayJay
wants to merge
4
commits into
TheDeveloperDen:master
Choose a base branch
from
JohnnyJayJay:feature/web3isgoinggreat
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Web3facts #48
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
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' | ||
import fetch from 'node-fetch' | ||
|
||
|
||
const web3RssUrl = 'https://web3isgoinggreat.com/feed.xml' | ||
|
||
const rssParser = new Parser() | ||
|
||
const turndownService = new TurndownService({ bulletListMarker: '-' }) | ||
|
||
const imgTag = /<img.*?\/>/g | ||
|
||
const fetchPeriod = 5 * 60 * 1000 | ||
|
||
// this any type is part of what rssParser returns | ||
let rssUpdate: {feed: {[p: string]: any}, timestamp: number} = { | ||
feed: {}, | ||
timestamp: 0 | ||
} | ||
|
||
export const Web3Command: Command<ApplicationCommandType.ChatInput> = { | ||
name: 'web3fact', | ||
description: 'Learn more about Web3, the future of human society', | ||
type: ApplicationCommandType.ChatInput, | ||
options: [], | ||
|
||
async handle(interaction: CommandInteraction) { | ||
if (Date.now() - rssUpdate.timestamp > fetchPeriod) { | ||
const xml = await fetch(web3RssUrl, {compress: true}) | ||
.then(r => r.text()) | ||
.catch(e => console.log(e)) | ||
if (xml !== undefined) { | ||
rssUpdate = { feed: await rssParser.parseString(xml as string), timestamp: Date.now() } | ||
} | ||
} | ||
|
||
const feed = rssUpdate.feed | ||
const entry = feed.items.randomElement() | ||
const embed = new EmbedBuilder() | ||
.setTitle(entry.title ?? 'Missing title') | ||
.setAuthor({name: 'Molly White', url: 'https://mollywhite.net', iconURL: 'https://storage.googleapis.com/primary-web3/monkey_500.webp'}) | ||
.setColor(0x1F193A) | ||
.setURL(entry.link ?? feed.link ?? 'http://example.com') | ||
// why do I have to regex match img tags? because turndown filters don't detect them for some reason | ||
.setDescription(turndownService.turndown(entry.content?.replaceAll(imgTag, '') ?? 'Missing content')) | ||
.setTimestamp(new Date(entry.isoDate ?? Date().toString())) | ||
.setFooter({text: feed.title ?? 'Missing feed title'}) | ||
.toJSON() | ||
await interaction.reply({embeds: [embed]}) | ||
} | ||
} | ||
|
||
export default Web3Command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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