Beispiel #1
0
    async def measure(self, client, message):
        p = DictionaryReader()
        service = discovery.build('commentanalyzer',
                                  'v1alpha1',
                                  developerKey=Key().perspectiveApiKey())

        body = self.buildRequest(message.content,
                                 self.buildAttributes(self.defaultAttributes))

        #print(json.dumps(body, indent=2))

        response = service.comments().analyze(body=body).execute()

        #print(json.dumps(response, indent=2))

        if response is not None:
            score = response['attributeScores']['TOXICITY']['summaryScore'][
                'value']

            source = message.channel.name if isinstance(
                message.channel, TextChannel) else 'PM'

            if float(score) > 0.90:
                await client.get_channel(
                    int(p.perspectiveLogChannelH2P())
                ).send(
                    'Toxic Message Warning - {0:.2g}% Toxicity - on {2} from {1.author}({1.author.id})```{1.content}```'
                    .format(score * 100.0, message, source))
Beispiel #2
0
async def on_message(message):
    r = DictionaryReader()

    if message.channel.id == int(r.perspectiveLogChannelH2P()):
        await toxicity.addReactions(r, message)

    # we do not want the bot to reply to itself
    if message.author == client.user:
        return
        
    if message.content.startswith(prefix):
        await messageHandler(message)
        
    if isinstance(message.channel, DMChannel) or message.channel.name in r.logChannels():
        logger.log(message)
        await toxicity.measure(client, message)