Skip to content

Commit

Permalink
#32 move channelID whitelist to env and improve logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter committed Jun 30, 2024
1 parent 46ab4f1 commit d290948
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Written in javascript with node, with mongoDB as the database.
DISCORD_OAUTH_CLIENT_ID=
DISCORD_OAUTH_CLIENT_SECRET=
DISCORD_BOT_TOKEN=
DISCORD_ENABLED_CHANNEL_ID=
# optional: enables bot admin features directly in discord channel
ADMIN_DISCORD_USER_ID=
Expand Down
2 changes: 1 addition & 1 deletion config/envVarConstants.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const requiredEnvVars = ['DISCORD_OAUTH_CLIENT_ID', 'DISCORD_OAUTH_CLIENT_SECRET', 'DISCORD_BOT_TOKEN']
export const requiredEnvVars = ['DISCORD_OAUTH_CLIENT_ID', 'DISCORD_OAUTH_CLIENT_SECRET', 'DISCORD_BOT_TOKEN', 'DISCORD_ENABLED_CHANNEL_ID']
export const optionalEnvVars = ['ADMIN_DISCORD_USER_ID']
4 changes: 3 additions & 1 deletion constants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const enabledChannelIDS = ['1210534521573744720']
import { config } from "dotenv"
config()
export const enabledChannelID = process.env.DISCORD_ENABLED_CHANNEL_ID

export const commands = [
{
Expand Down
10 changes: 5 additions & 5 deletions dailydle.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Entry from './db/models/entry.js'

import { links } from './constants.js'
import { enabledChannelIDS } from './constants.js'
import { enabledChannelID } from './constants.js'

let top_wordle = ''
let top_mini_crossword = ''
Expand Down Expand Up @@ -258,8 +258,8 @@ function getEmbedFields() {
function messagePassesContentFilter(message) {
const content = message.content

if (!enabledChannelIDS.includes(message.channel.id)) {
return [false, 'Channel ID is not in whitelist']
if (enabledChannelID !== message.channel.id) {
return [false, `Channel ID is not in whitelist. Expected ${enabledChannelID} but recieved ${message.channel.id}`]
}

if (message.author.bot) {
Expand Down Expand Up @@ -321,7 +321,7 @@ export const onChannelMessage = async (message) => {
}

if (!validMessage) {
console.log("Recived a non-game message, ignoring..") //TODO add a logging lib? e.g Pino
console.log(`Recived a non-game message, ignoring... (reason: ${errMsg})`) //TODO add a logging lib? e.g Pino
return
}

Expand Down Expand Up @@ -349,7 +349,7 @@ export const onChannelMessage = async (message) => {
}

export const onChannelMessageReact = async (reaction_orig, user) => {
if (!user.bot && enabledChannelIDS.includes(reaction_orig.message.channel.id)) {
if (!user.bot && enabledChannelID === reaction_orig.message.channel.id) {
await loadEntriesForEmbed()
await updateEmbedMessageForChannel(reaction_orig.message)
}
Expand Down

0 comments on commit d290948

Please sign in to comment.