Example #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))
Example #2
0
    async def addStream(client, member):
        p = DictionaryReader()
        channel = client.get_channel(int(p.streamingBroadcastChannel()))
        currentlyStreaming = utils.find(
            lambda r: r.name == p.currentlyStreamingRole(), member.guild.roles)

        await RoleHandler.removeStream(client, member)

        if channel is None:
            print('Streaming Channel not found!')
            return

        if not await TwitchHandler.validateStream(member.activity.url,
                                                  Key().twitchApiKey()):
            return

        title, description, avatar, views, followers = await TwitchHandler.fetchStreamInfo(
            member.activity.url,
            Key().twitchApiKey())

        emb = Embed()
        emb.title = title
        emb.type = 'rich'
        emb.description = description
        emb.url = member.activity.url
        emb.colour = Colour.purple()
        emb.set_footer(text='Created by PriestBot', icon_url=p.h2pIcon())
        emb.set_thumbnail(url=avatar)
        emb.set_author(name=member.name, icon_url=member.avatar_url)
        emb.add_field(name='Views', value=views)
        emb.add_field(name='Followers', value=followers)

        if currentlyStreaming not in member.roles:
            await member.add_roles(currentlyStreaming,
                                   reason='User started streaming')
            await channel.send(
                '{0.mention} is now Live on Twitch!'.format(member), embed=emb)

        else:
            # This could be slow, but shouldn't, assuming there should be few messages in the channel
            messages = await channel.history(limit=None).flatten()

            for message in messages:
                if member in message.mentions:
                    await message.edit(embed=emb)
Example #3
0
async def sendWebhook(topicId):
    print('New topic found ({0}), sending Webhook'.format(topicId))

    # Fetch Webhook URL
    webhookurl = Key().webhook()

    async with aiohttp.ClientSession() as session:
        webhook = Webhook.from_url('{0}'.format(webhookurl),
                                   adapter=AsyncWebhookAdapter(session))
        await webhook.send(
            'https://us.battle.net/forums/en/wow/topic/{0}'.format(topicId),
            username='******',
            avatar_url='https://i.imgur.com/sO0KcOb.png')
Example #4
0
async def sendWebhook(article):
    print('New article found, sending Webhook')

    # Fetch Webhook URL
    webhookurl = Key().webhook()

    async with aiohttp.ClientSession() as session:
        webhook = Webhook.from_url('{0}'.format(webhookurl),
                                   adapter=AsyncWebhookAdapter(session))
        await webhook.send(
            '<@118461244784115713> New BlizzCon Article published!\n<https://blizzcon.com/en-us/news/{0}>\n```{1}```'
            .format(article[1], article[0]),
            username='******',
            avatar_url=
            'https://www.telegraph.co.uk/content/dam/gaming/2017/10/13/BlizzCon-Logo_trans_NvBQzQNjv4BqutubNGxeqbD0m2XylzINLiOoem_3qpp9C-iKHR23jxY.jpg'
        )
Example #5
0
 def getcharstats(self,name,realm,zone):
     zone = zone.lower()
     locales = {"us":"en_US","eu":"en_GB","kr":"ko_KR","tw":"zh_TW"}
     locale = locales[zone]
     url = "https://"+zone+".api.battle.net/wow/character/"+realm+"/"+name+"?fields=stats&locale="+locale+"&apikey="+Key().bnetApiKey()
     r = requests.get(url)
     response = r.json()
     blelfworg = (0,1)[response["race"] == 10 or response["race"] == 22]
     taurdwarf = (0,1)[response["race"] == 6 or response["race"] == 3]
     charint = response["stats"]["int"]
     charcrit = response["stats"]["critRating"]
     charhaste = response["stats"]["hasteRating"]
     charmastery = response["stats"]["masteryRating"]
     charvers = response["stats"]["versatility"]
     url = "https://"+zone+".api.battle.net/wow/character/"+realm+"/"+name+"?fields=items&locale="+locale+"&apikey="+Key().bnetApiKey()
     r = requests.get(url)
     response = r.json()
     drape = (0,1)[response["items"]["back"]["name"] == "Drape of Shame"]
     
     return [charint,charcrit,charhaste,charmastery,charvers,blelfworg,taurdwarf,drape]
Example #6
0
    def getShadowCharStats(self, name, realm, zone):
        zone = zone.lower()
        locales = {"us": "en_US", "eu": "en_GB", "kr": "ko_KR", "tw": "zh_TW"}
        try:
            locale = locales[zone]
            url = "https://" + zone + ".api.battle.net/wow/character/" + realm + "/" + name + "?fields=stats&locale=" + locale + "&apikey=" + Key(
            ).bnetApiKey()
            r = requests.get(url)
            response = r.json()
            extracrit = (0, 1)[response["race"] == 10 or response["race"] == 22
                               or response["race"] == 4]
            extrafood = (0, 1)[response["race"] == 24 or response["race"] == 25
                               or response["race"] == 26]
            charint = response["stats"]["int"]
            charcrit = response["stats"]["critRating"]
            charhaste = response["stats"]["hasteRating"]
            charmastery = response["stats"]["masteryRating"]
            charvers = response["stats"]["versatility"]

            return [
                charint, charcrit, charhaste, charmastery, charvers, extracrit,
                extrafood
            ]
        except:
            return None
Example #7
0
from subprocess import call
import sys
from priestLogger import PriestLogger
from perspectiveHandler import PerspectiveHandler
import logging
import time
from discord import HTTPException
from discord import utils
from discord import DMChannel
from roleHandler import RoleHandler

logging.basicConfig(level=logging.INFO)

client = discord.Client()

prefix = Key().prefix()

logger = PriestLogger()

toxicity = PerspectiveHandler()

@client.event
async def on_ready():
    print('Logged in as')
    print(client.user.name)
    print(client.user.id)
    print('------')

@client.event
async def on_message(message):
    r = DictionaryReader()