-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Banphrase): DRY and move to a separate file.
- Loading branch information
Showing
8 changed files
with
75 additions
and
76 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Logger } from '@adonisjs/logger' | ||
import env from './env' | ||
|
||
const logger = new Logger({ | ||
name: 'befriendlier-bot', | ||
enabled: true, | ||
level: typeof env.get('LOG_LEVEL') === 'string' ? String(env.get('LOG_LEVEL')) : 'info', | ||
prettyPrint: env.get('NODE_ENV') === 'development' | ||
}) | ||
|
||
export default logger |
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
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
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { PajbotAPI } from 'befriendlier-shared' | ||
import logger from '../logger' | ||
|
||
import PajbotConfig from '../config/Pajbot' | ||
|
||
const pajAPIConfig = new PajbotConfig() | ||
const pajbotAPI = new PajbotAPI(pajAPIConfig, logger.level) | ||
|
||
async function pajbotBanphraseCheck (channelName: string, message: string): Promise<string[]> { | ||
const checkMessages: string[] = [] | ||
|
||
const pajbotCheck = await pajbotAPI.check(channelName, message) | ||
if (pajbotCheck === null) { | ||
checkMessages.push('Banphrase v1 API is offline.') | ||
} else if (pajbotCheck.banned) { | ||
// banphrase_data appears on banned === true | ||
// const banphraseData = pajbotCheck.banphrase_data as { phrase: string } | ||
logger.warn('"%s" contains bad words (%s)', message, JSON.stringify(pajbotCheck.banphrase_data)) | ||
checkMessages.push('(v1) message contains banned phrases.') | ||
} | ||
|
||
const pajbot2Check = await pajbotAPI.checkVersion2(channelName, message) | ||
if (pajbot2Check === null) { | ||
checkMessages.push('Banphrase v2 API is offline.') | ||
} else if (pajbot2Check.banned) { | ||
// banphrase_data appears on banned === true | ||
// const banphraseData = pajbotCheck.banphrase_data as { phrase: string } | ||
logger.warn('"%s" contains bad words (%s)', message, JSON.stringify(pajbot2Check.filter_data)) | ||
checkMessages.push('(v2) message contains banned phrases.') | ||
} | ||
|
||
return checkMessages | ||
} | ||
|
||
export default pajbotBanphraseCheck |