-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add condition to handle unwanted log messages
- Loading branch information
Showing
4 changed files
with
47 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,34 @@ | ||
/* eslint-disable linebreak-style */ | ||
import { Message } from 'discord.js'; | ||
import { WarningMessageEmbed } from '@/embeds'; | ||
import { getMessage, logger, keyv } from '@/utils'; | ||
import { Message } from 'discord.js'; | ||
|
||
export default { | ||
name: 'init-exam-channel', | ||
guildOnly: true, | ||
cooldown: 0, | ||
permissions: ['ADMINISTRATOR'], | ||
execute(message: Message) { | ||
permissions: [ 'ADMINISTRATOR' ], | ||
execute( message: Message ) { | ||
const channelId = message.content.split( ' ' )[1]; | ||
const examChannel = message.guild?.channels.cache.get( channelId ); | ||
|
||
function isInvalid() { | ||
return !(channelId && message.guild?.channels.cache.get(channelId)); | ||
return !( channelId && examChannel ); | ||
} | ||
|
||
if (isInvalid()) { | ||
if ( isInvalid() ) { | ||
message.reply( | ||
new WarningMessageEmbed( | ||
{ | ||
description: getMessage('command.exams.invalid') + message.content, | ||
description: getMessage( 'command.exams.invalid' ) + message.content, | ||
}, | ||
), | ||
); | ||
logger.warn(`Invalid Channel ID: "${message.content}" provided`); | ||
logger.warn( `Invalid Channel ID: "${message.content}" provided` ); | ||
return; | ||
} | ||
const key = keyv('exams'); | ||
key.set('channel_id', channelId); | ||
logger.info(`New Exam Channel ID: "${channelId}" have been persisted`); | ||
const key = keyv( 'exams' ); | ||
key.set( 'channel_id', channelId ); | ||
logger.info( `New Exam Channel ID: "${channelId}" have been persisted` ); | ||
}, | ||
}; |
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 |
---|---|---|
@@ -1,19 +1,37 @@ | ||
/* eslint-disable linebreak-style */ | ||
import { Message } from 'discord.js'; | ||
import environment from '@/environment'; | ||
import { Message } from "discord.js"; | ||
|
||
const TelegramBot = require( 'node-telegram-bot-api' ); | ||
|
||
const botConfig = { | ||
polling: true | ||
} | ||
polling: true, | ||
}; | ||
|
||
const bot = new TelegramBot( environment.telegram_bot_token, botConfig ); | ||
|
||
async function sendMessage( msg: Message ) { | ||
const completeMessage = 'Eine neue Anfrage wurde auf dem Discord Server registriert:\n\n' + msg.cleanContent; | ||
bot.sendMessage( environment.telegram_feed_id, completeMessage ); | ||
// there is no i18n usage here because of only german recipients | ||
const formattedDate = msg.createdAt | ||
.toLocaleString( | ||
'de-DE', | ||
// creating a seperate object and assign it as param somehow doesn't work | ||
{ | ||
year: 'numeric', | ||
month: '2-digit', | ||
day: '2-digit', | ||
hour: '2-digit', | ||
minute: '2-digit', | ||
}, | ||
); | ||
const channelName = msg.guild?.channels.cache.get( msg.channel.id )?.name; | ||
const completeMessage = `Eine neue Anfrage wurde auf dem Discord Server im ${channelName}-Channel registriert:\n\n` | ||
+ `Nickname: ${msg.author.username}\nUser: ${msg.author.tag}\nID: ${msg.author.id}\nZeitstempel: ${formattedDate} Uhr\n\n` | ||
+ `Nachricht (${msg.id}):\n${msg.cleanContent}\n\n` | ||
+ `Spring direkt zur Nachricht: ${msg.url}`; | ||
bot.sendMessage( environment.telegram_feed_id, completeMessage ); | ||
} | ||
|
||
export { | ||
sendMessage | ||
} | ||
export default { | ||
sendMessage, | ||
}; |