-
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
8 changed files
with
98 additions
and
43 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,51 @@ | ||
/* eslint-disable linebreak-style */ | ||
import { Message } from 'discord.js'; | ||
import environment from '@/environment'; | ||
import { Message } from "discord.js"; | ||
import { logger } from '@/utils'; | ||
|
||
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 ); | ||
} | ||
async function sendMessage( msg: Message ): Promise< number > { | ||
// 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\n"${msg.cleanContent}"\n\n` | ||
+ `Folge dem Link, um direkt zur Nachricht zu gelangen:\n${msg.url}`; | ||
try { | ||
bot.sendMessage( | ||
environment.telegram_feed_id, | ||
completeMessage, | ||
{ | ||
disable_web_page_preview: true, | ||
}, | ||
); | ||
} catch ( error ) { | ||
logger.error( `Sending message to the Telegram API failed:\n"${error}"` ); | ||
|
||
export { | ||
sendMessage | ||
return -1; | ||
} | ||
return 0; | ||
} | ||
|
||
export default { | ||
sendMessage, | ||
}; |
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