Skip to content

Commit cde4dbc

Browse files
committed
Twitter feed improvements
ADDED - Support for outputting Twitter tweet text via Twitter Feeds
1 parent 77ea7de commit cde4dbc

5 files changed

Lines changed: 22 additions & 16 deletions

File tree

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,17 +1586,17 @@ Receive tweets from other users on Twitter and send them directly to your channe
15861586

15871587
__NOTE:__ To ensure feed availability even when the user protects their tweets, it is recommended that you follow the Twitter handle.
15881588

1589-
| __Key__ | __Type__ | __Description__ | __Required__ | __Accepted Values__ |
1590-
|----------------------------------------|------------|---------------------------------------------------------|--------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|
1591-
| `twitter-feeds` | `object[]` | | no | |
1592-
| `twitter-feeds[x].name` | `string` | Name of the event | no | |
1593-
| `twitter-feeds[x].twitter-id` | `string` | User ID | yes | Visit [Find Twitter ID](https://tools.codeofaninja.com/find-twitter-id) |
1594-
| `twitter-feeds[x].exclude-retweets` | `boolean` | Exclude retweets | no | `true` or `false` |
1595-
| `twitter-feeds[x].exclude-replies` | `boolean` | Exclude replies | no | `true` or `false` |
1596-
| `twitter-feeds[x].payload` | `object` | Message content to send for each Twitter feed update | no | `BaseMessageOptions` in [discord.js Documentation](https://discord.js.org/#/docs/main/stable/typedef/BaseMessageOptions). Variables include `%TWEET_LINK%` |
1597-
| `twitter-feeds[x].channel` | `object` | | yes | |
1598-
| `twitter-feeds[x].channel.description` | `string` | Description of the channel used to send message content | no | |
1599-
| `twitter-feeds[x].channel.channel-id` | `string` | Channel used to send message content | yes | Discord channel ID |
1589+
| __Key__ | __Type__ | __Description__ | __Required__ | __Accepted Values__ |
1590+
|----------------------------------------|------------|---------------------------------------------------------|--------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
1591+
| `twitter-feeds` | `object[]` | | no | |
1592+
| `twitter-feeds[x].name` | `string` | Name of the event | no | |
1593+
| `twitter-feeds[x].twitter-id` | `string` | User ID | yes | Visit [Find Twitter ID](https://tools.codeofaninja.com/find-twitter-id) |
1594+
| `twitter-feeds[x].exclude-retweets` | `boolean` | Exclude retweets | no | `true` or `false` |
1595+
| `twitter-feeds[x].exclude-replies` | `boolean` | Exclude replies | no | `true` or `false` |
1596+
| `twitter-feeds[x].payload` | `object` | Message content to send for each Twitter feed update | no | `BaseMessageOptions` in [discord.js Documentation](https://discord.js.org/#/docs/main/stable/typedef/BaseMessageOptions). Variables include `%TWEET_TEXT%` and `%TWEET_LINK%` |
1597+
| `twitter-feeds[x].channel` | `object` | | yes | |
1598+
| `twitter-feeds[x].channel.description` | `string` | Description of the channel used to send message content | no | |
1599+
| `twitter-feeds[x].channel.channel-id` | `string` | Channel used to send message content | yes | Discord channel ID |
16001600

16011601
```json
16021602
{
@@ -1607,7 +1607,7 @@ __NOTE:__ To ensure feed availability even when the user protects their tweets,
16071607
"exclude-retweets": false,
16081608
"exclude-replies": false,
16091609
"payload": {
1610-
"content": "Sample: %TWEET_LINK%"
1610+
"content": "Sample: %TWEET_TEXT% - %TWEET_LINK%"
16111611
},
16121612
"channel": {
16131613
"description": "Sample channel",

config-sample.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@
841841
"exclude-retweets": false,
842842
"exclude-replies": false,
843843
"payload": {
844-
"content": "Sample: %TWEET_LINK%"
844+
"content": "Sample: %TWEET_TEXT% - %TWEET_LINK%"
845845
},
846846
"channel": {
847847
"description": "Sample channel",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "discord-stocker-bot",
33
"displayName": "Discord Stonker Bot",
4-
"version": "3.1.3",
4+
"version": "3.1.4",
55
"description": "An advanced bot built for finance-related Discord servers",
66
"main": "build/src/index.js",
77
"private": true,

src/modules/twitter.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
TwitterFeedsReplaceVariablesConfigPayload,
1616
TwitterFeedsReplaceVariablesReturns,
1717
TwitterFeedsReplaceVariablesTweetLink,
18+
TwitterFeedsReplaceVariablesTweetText,
1819
TwitterFeedsReturns,
1920
TwitterFeedsStreamChannel,
2021
TwitterFeedsStreamEventExcludeReplies,
@@ -53,14 +54,16 @@ export function twitterFeeds(twitterClient: TwitterFeedsTwitterClient, guild: Tw
5354
* Twitter feeds - Replace variables.
5455
*
5556
* @param {TwitterFeedsReplaceVariablesConfigPayload} configPayload - Config payload.
57+
* @param {TwitterFeedsReplaceVariablesTweetText} tweetText - Tweet text.
5658
* @param {TwitterFeedsReplaceVariablesTweetLink} tweetLink - Tweet link.
5759
*
5860
* @returns {TwitterFeedsReplaceVariablesReturns}
5961
*
6062
* @since 1.0.0
6163
*/
62-
const replaceVariables = (configPayload: TwitterFeedsReplaceVariablesConfigPayload, tweetLink: TwitterFeedsReplaceVariablesTweetLink): TwitterFeedsReplaceVariablesReturns => {
64+
const replaceVariables = (configPayload: TwitterFeedsReplaceVariablesConfigPayload, tweetText: TwitterFeedsReplaceVariablesTweetText, tweetLink: TwitterFeedsReplaceVariablesTweetLink): TwitterFeedsReplaceVariablesReturns => {
6365
const editedPayload = JSON.stringify(configPayload)
66+
.replace(/%TWEET_TEXT%/g, tweetText)
6467
.replace(/%TWEET_LINK%/g, tweetLink);
6568

6669
return JSON.parse(editedPayload);
@@ -138,6 +141,7 @@ export function twitterFeeds(twitterClient: TwitterFeedsTwitterClient, guild: Tw
138141
userTimelineResponse.tweets.forEach((userTimelineResponseTweet) => {
139142
const userTimelineResponseTweetAuthorId = userTimelineResponseTweet.author_id;
140143
const userTimelineResponseTweetId = userTimelineResponseTweet.id;
144+
const userTimelineResponseTweetText = userTimelineResponseTweet.text;
141145

142146
const author = userTimelineResponse.includes.author(userTimelineResponseTweet);
143147
const authorUsername = (author !== undefined) ? author.username : undefined;
@@ -148,7 +152,7 @@ export function twitterFeeds(twitterClient: TwitterFeedsTwitterClient, guild: Tw
148152
&& _.isPlainObject(eventPayload)
149153
&& !_.isEmpty(eventPayload)
150154
) {
151-
payload = replaceVariables(eventPayload, tweetUrl);
155+
payload = replaceVariables(eventPayload, userTimelineResponseTweetText, tweetUrl);
152156
} else {
153157
payload = {
154158
content: tweetUrl,

src/types/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2636,6 +2636,8 @@ export type TwitterFeedsReturns = void;
26362636
*/
26372637
export type TwitterFeedsReplaceVariablesConfigPayload = MessageOptions;
26382638

2639+
export type TwitterFeedsReplaceVariablesTweetText = string;
2640+
26392641
export type TwitterFeedsReplaceVariablesTweetLink = string;
26402642

26412643
export type TwitterFeedsReplaceVariablesReturns = MessageOptions;

0 commit comments

Comments
 (0)