-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: stickies for forum posts which get posted on forum post create (#…
…384) Co-authored-by: BenW <[email protected]>
- Loading branch information
Showing
8 changed files
with
715 additions
and
128 deletions.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,35 @@ | ||
import { getConn } from '../lib/db'; | ||
import Logger from '../lib/logger'; | ||
import StickyMessage from '../lib/schemas/stickyMessageSchema'; | ||
import { stickyMessageEmbed } from '../lib/stickyMessageEmbed'; | ||
|
||
module.exports = { | ||
event: 'threadCreate', | ||
executor: async (thread) => { | ||
const { parentId, parent, name } = thread; | ||
Logger.debug(`Thread Create - Handling thread create for ${name}`); | ||
const { name: parentName, type } = parent; | ||
Logger.debug(`Thread Create - Parent ID: ${parentId} - Parent Type: ${type} - Parent Name: ${parentName}`); | ||
if (type !== 15) { | ||
Logger.debug('Thread Create - Thread not created in a Forum Channel, skipping.'); | ||
return; | ||
} | ||
|
||
const conn = getConn(); | ||
if (!conn) { | ||
Logger.debug('Thread Create - Unable to connect to database, skipping.'); | ||
return; | ||
} | ||
|
||
const stickyMessageSearchResult = await StickyMessage.find({ channelId: parentId }); | ||
const [stickyMessage] = stickyMessageSearchResult.length === 1 ? stickyMessageSearchResult : []; | ||
if (!stickyMessage) { | ||
Logger.debug('Forum Post Create - No sticky for the forum, skipping.'); | ||
return; | ||
} | ||
|
||
const { message, imageUrl } = stickyMessage; | ||
Logger.debug('Forum Post Create - Posting new sticky.'); | ||
await thread.send({ embeds: [stickyMessageEmbed(message, imageUrl)] }); | ||
}, | ||
}; |
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,19 @@ | ||
import mongoose, { Schema } from 'mongoose'; | ||
|
||
const stickyMessageSchema = new Schema({ | ||
channelId: { | ||
type: String, | ||
unique: true, | ||
}, | ||
message: String, | ||
imageUrl: String, | ||
timeInterval: Number, | ||
messageCount: Number, | ||
moderator: String, | ||
updatedTimestamp: Date, | ||
lastPostedId: String, | ||
}); | ||
|
||
const stickyMessage = mongoose.model('StickyMessage', stickyMessageSchema); | ||
|
||
export default stickyMessage; |
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,12 @@ | ||
import { Colors } from '../constants'; | ||
import { makeEmbed } from './embed'; | ||
|
||
export const STICKY_MESSAGE_TITLE = 'Stickied Message'; | ||
export const STICKY_MOD_TITLE = 'Sticky Message - Log'; | ||
|
||
export const stickyMessageEmbed = (description: string, imageUrl: string) => makeEmbed({ | ||
title: STICKY_MESSAGE_TITLE, | ||
description, | ||
color: Colors.FBW_CYAN, | ||
image: imageUrl ? { url: imageUrl } : null, | ||
}); |