コード例 #1
0
def cmd_gtao(chat):
    data = utils.getURL(
        'https://support.rockstargames.com/hc/en-us/articles/200426246-GTA-Online-Server-Status-Latest-Updates'
    )
    if data is None:
        skype.sendMessageToChat(chat, "Strona R* leży.")
        return

    pcWarn_start = data.find('<div id="pcWarn">') + 17
    pcWarn_end = data.find('</div>', pcWarn_start)
    pcWarn = data[pcWarn_start:pcWarn_end]

    rsgsUpOrDown_start = data.find(
        '<div id="rsgsUpOrDown" data-rsgsupordown="', pcWarn_end) + 42
    rsgsUpOrDown_end = data.find('"></div>', rsgsUpOrDown_start)
    rsgsUpOrDown = data[rsgsUpOrDown_start:rsgsUpOrDown_end]

    pcUpOrDown_start = data.find('<div id="pcUpOrDown" data-upordown="',
                                 rsgsUpOrDown_end) + 36
    pcUpOrDown_end = data.find('"></div>', pcUpOrDown_start)
    pcUpOrDown = data[pcUpOrDown_start:pcUpOrDown_end]

    txt = "Social Club: " + rsgsUpOrDown + "\nPC: " + pcUpOrDown
    if pcWarn != "" and pcWarn != "no content":
        txt = txt + "\nKomunikat: " + pcWarn
    skype.sendMessageToChat(chat, txt)
コード例 #2
0
def cmd_help(chat):
    txt = "!twitch [nick]\n!twitchtop [opcjonalnie kategoria] - top streamy z danej kategorii\n!hitbox [nick]\n!topic\n\
!lines - ilosć linii w kodzie\n!id [pojazd/kategoria]\n!steam\n!ets - status serwerów TruckersMP\n!bandit\n\
!btc - przelicznik btc/pln i ltc/pln\n!gtao - status serwerów gtao\n!rct - status serwerów OpenRCT2"

    if chat.Name == skype.g_chats["mta"]:
        txt = txt + "\n!w(iki) [tytuł]"
    skype.sendMessageToChat(chat, txt)
コード例 #3
0
def checkMantis():
    name, severity, status = checkMantisBug(utils.g_settings["lastBugID"] + 1)
    if name is not None:
        skype.sendMessageToChat(
            skype.g_chats["mta"], "[" + severity + "/" + status + "] " + name +
            "\nhttps://bugs.mtasa.com/view.php?id=" +
            str(utils.g_settings["lastBugID"] + 1))
        utils.g_settings["lastBugID"] = utils.g_settings["lastBugID"] + 1
        utils.saveSettings()
    Timer(60 * 10, checkMantis).start()
コード例 #4
0
def cmd_bitcoin(chat):
    data = utils.getJSON('https://www.bitmarket.pl/json/BTCPLN/ticker.json')
    if data is None:
        return
    txt = "1 BTC = " + str(data["last"]) + " PLN"
    data = utils.getJSON('https://www.bitmarket.pl/json/LTCPLN/ticker.json')
    if data is None:
        return
    skype.sendMessageToChat(chat,
                            txt + "\n1 LTC = " + str(data["last"]) + " PLN")
コード例 #5
0
def cmd_twitch(chat, nick):
    data = utils.getJSON("https://api.twitch.tv/kraken/streams/" + nick)
    if data is None:
        return

    if "error" in data:
        skype.sendMessageToChat(chat, "Nie ma takiego kanału.")
        return

    if data["stream"] is not None:
        nick = data["stream"]["channel"]["display_name"]
        game = data["stream"]["game"]
        status = data["stream"]["channel"]["status"]
        viewers = str(data["stream"]["viewers"])
        fps = str(int(round(data["stream"]["average_fps"])))

        if game:
            skype.sendMessageToChat(
                chat,
                nick + " streamuje " + game + " (" + status + ", " + viewers +
                " widzów, " + fps + " FPS)\nhttps://twitch.tv/" + nick)
        else:
            skype.sendMessageToChat(
                chat, nick + " prowadzi stream (" + status + ", " + viewers +
                " widzów, " + fps + " FPS)\nhttps://twitch.tv/" + nick)
    else:
        skype.sendMessageToChat(chat, nick + " obecnie nic nie streamuje!")
    return
コード例 #6
0
def checkFreeGamesSubreddit():
    Timer(60 * 1, checkFreeGamesSubreddit).start()

    data = utils.getJSON(
        "https://www.reddit.com/r/freegamesonsteam/new.json?limit=1")
    if data is None or "data" not in data:
        return

    for link in data["data"]["children"]:
        if link["data"]["created_utc"] > utils.g_settings["lastFGTime"]:
            skype.sendMessageToChat(
                skype.g_chats["tr"], link["data"]["title"] +
                "\nhttps://reddit.com" + link["data"]["permalink"])
            utils.g_settings["lastFGTime"] = link["data"]["created_utc"]
            utils.saveSettings()
コード例 #7
0
def cmd_steam(chat):
    data = utils.getJSON('http://store.steampowered.com/api/featured/')
    if data is None:
        return

    txt = "Polecane:\n"
    for game in data["large_capsules"]:
        price1 = str(game["final_price"])[:-2]
        if price1 == "":
            price1 = "0"
        price2 = str(game["final_price"])[-2:]
        txt = txt + game["name"] + " " + price1 + "." + price2 + "€"
        if game["discounted"] and game["discount_percent"] > 0:
            txt = txt + " [-" + str(game["discount_percent"]) + "%]"
        txt = txt + "\n"
    skype.sendMessageToChat(chat, txt)
コード例 #8
0
def cmd_mtawiki ( chat, title ):
    data = utils.getJSON( "https://wiki.multitheftauto.com/api.php?action=query&list=search&format=json&prop=revisions&rvprop=content&srsearch=" + title )
    if data is None:
        return

    if len(data["query"]["search"]) == 0:
        skype.sendMessageToChat( chat, "Nie ma takiej strony." )
        return

    page = data["query"]["search"][0]
    txt = "https://wiki.mtasa.com/wiki/" + page["title"].replace(" ", "_")
    
    # Syntax
    data = utils.getJSON( "https://wiki.multitheftauto.com/api.php?format=json&action=query&prop=revisions&rvprop=content&titles=" + page["title"] )
    if data is None:
        return

    for k, page in data["query"]["pages"].items():
        content = page["revisions"][0]["*"]
        # check if this page is function or event and if is, grab syntax
        if content.find("function}}") != -1 or content.find("event}}") != -1:

            header_syntax_start = content.find("Syntax")
            if header_syntax_start == -1:
                header_syntax_start = content.find("Parameters")

            if header_syntax_start != -1:
                header_syntax_end = content.find("Returns", header_syntax_start)
                if header_syntax_end == -1:
                    header_syntax_end = content.find("Example", header_syntax_start)
                if header_syntax_end == -1:
                    header_syntax_end = len(content)

                syntax_startPos = content.find("<code>[lua", header_syntax_start, header_syntax_end)
                if syntax_startPos != -1:
                    syntax_startPos = syntax_startPos + 10
                    syntax_startPos = content.find("]", syntax_startPos) + 1

                    syntax_endPos = content.find("</code>", syntax_startPos)
                    syntax = content [ syntax_startPos : syntax_endPos ]
                    syntax = syntax.replace("\n", "")
                    syntax = syntax.replace("  ", "")
                    txt = txt + "\n" + syntax
                else:
                    # function without parameters
                    txt = txt + "\nbrak parametrów"
        skype.sendMessageToChat( chat, txt )
コード例 #9
0
def cmd_ets(chat):
    # servers status
    data = utils.getJSON('https://api.ets2mp.com/servers/')
    if data is None:
        return

    if data["error"] != "false":
        return

    txt = "Serwery TruckersMP:"
    total_players = 0
    total_slots = 0
    for server in data["response"]:
        txt = txt + "\n" + server["game"] + " " + server["name"]
        if server["online"]:
            txt = txt + " (" + str(server["players"]) + "/" + str(
                server["maxplayers"]) + ")"
            total_players = total_players + server["players"]
            total_slots = total_slots + server["maxplayers"]
        else:
            txt = txt + " (offline)"
    txt = txt + "\nŁącznie " + str(total_players) + "/" + str(
        total_slots) + " graczy."

    # game time
    data = utils.getJSON('https://api.ets2mp.com/game_time/')
    if data is not None:
        if data["error"]:
            return

        gameTime = datetime.datetime(
            2015, 10, 25) + datetime.timedelta(minutes=data["game_time"])
        txt = txt + "\nCzas w grze: " + gameTime.strftime('%H:%M')

    # song at TruckersFM
    data = utils.getURL('http://truckers.fm/')
    if data is not None:
        song_start = data.find(
            '<span id="currently_playing"> <span id="song"><span class="song-details">'
        ) + 73
        if song_start != 72:
            song_end = data.find('</span>', song_start)
            txt = txt + "\nTruckersFM: " + data[song_start:song_end]

    skype.sendMessageToChat(chat, txt)
コード例 #10
0
def cmd_bandit(chat, size_x, size_y):
    size_x = int(size_x)
    if size_x is None:
        size_x = 3
    size_x = int(size_y)
    if size_y is None:
        size_y = 3

    if size_x < 1:
        size_x = 1
    elif size_x > 8:
        size_x = 8
    if size_y < 1:
        size_y = 1
    elif size_y > 5:
        size_y = 5

    #icons = [ ':)', ':(', ':D', '(cool)', ';)', ':o', '(sweat)', ':|', ':*',
    #':P', '(yn)', '(blush)', ':^)', '(snooze)', '|(', '(inlove)', '(yawn)',
    #'(puke)', '(doh)', '(wasntme)', '(facepalm)', ':S', '(mm)', '8-|',
    #':x', '(wave)', '(devil)', '(envy)', '(makeup)', '(moustache)',
    #'(giggle)', '(clap)', '(think)', '(happy)', '(smirk)',
    #'(nod)', '(shake)', '(emo)', '(tmi)', '(rock)', '(swear)',
    #'(punch)', '(talk)', '(call)',
    #'(wtf)', '(donttalk)' ]

    icons = [
        '(heidy)', '(hug)', '(dog)', '(sun)', '(coffee)', '(^)', '(cash)',
        '(gift)', '(tandoori)', '(cheese)', '(d)', '(bell)', '(cat)', '(~)',
        '(heart)', '(mooning)'
    ]

    txt = ""
    lines = []
    for i in range(0, size_y):
        line = []
        for j in range(0, size_x):
            line.insert(j, random.choice(icons))
            txt = txt + line[j] + " "
        lines.insert(i, line)
        txt = txt + "\n"

    message = skype.sendMessageToChat(chat, txt)

    for o in range(1, 21):
        time.sleep(0.2)
        txt = ""
        for i in reversed(range(0, size_y)):
            for j in reversed(range(0, size_x)):
                if i > 0:
                    lines[i][j] = lines[i - 1][j]
                else:  # 2
                    lines[i][j] = random.choice(icons)
                txt = txt + lines[i][j] + " "
            txt = txt + "\n"
        message.Body = txt
コード例 #11
0
def printEntitiesInGroup ( groups, groupName, chatName ):
    for group in groups:
        #print(group["name"])
        if group["name"] == groupName:
            #print(group["name"] + " goood!")
            if "group" in group:
                txt = "Podgrupy w grupie " + groupName + ":\n"
                for group in group["group"]:
                    txt = txt + " > " + group["name"]
                skype.sendMessageToChat( chatName, txt )
            elif "vehicle" in group:
                txt = "Pojazdy w grupie " + groupName + ":\n"
                for element in group["vehicle"]:
                    txt = txt + " > " + element["name"] + " - " + element["id"] + "\n"
                skype.sendMessageToChat( chatName, txt )
            return
        elif "group" in group:
            printEntitiesInGroup ( group["group"], groupName, chatName )
    return
コード例 #12
0
def findEntityID ( name, chatName ):
    with open("vehicles-sa.json") as f:
        try:
            data = json.loads( f.read() )
        except Exception:
            return

        last = { "ratio": 0.0, "type": None, "name": None, "id": None }
        processEntityGroup( data["catalog"]["groups"], name, last )

        print("found " + str(last["name"]) + " (" + str(last["ratio"]) + ")")

        if last["ratio"] < 0.4:
            skype.sendMessageToChat( chatName, "Nic nie znalazłem." )
            return

        if last["type"] == "element":
            txt = last["name"] + " - " + last["id"]
            data = utils.getURL( "https://gta.wikia.com/api.php?action=query&list=search&format=json&prop=revisions&rvprop=content&srlimit=1&srwhat=nearmatch&srsearch=" + last["name"] )
            if data:
                data = json.loads(data)
                if len(data["query"]["search"]) > 0:
                    title = data["query"]["search"][0]["title"].replace(" ", "_")
                    txt = txt + " | https://gta.wikia.com/" + title
            skype.sendMessageToChat( chatName, txt )

        elif last["type"] == "group":
            printEntitiesInGroup( data["catalog"]["groups"], last["name"], chatName )
        else:
            skype.sendMessageToChat( chatName, "Nic nie znalazłem." )
コード例 #13
0
    def process(self, message, chat):
        print("getArgumentsCount(): " + str(self.getArgumentsCount()))

        print("Required arguments:")
        for arg in self.getArguments():
            print(arg)

        msgArgs = message.split()
        print("Arguments:")

        #msgArgs.remove ( self.name )
        # put chat as first argument instead of cmd name
        msgArgs[0] = chat
        print(msgArgs)
        for arg in msgArgs:
            print(arg)

        if self.getArgumentsCount() == 2 and len(msgArgs) > 1:
            # cmd require only 1 argument, pass all args as only 1
            msgArgs.remove(chat)
            arg = " ".join(msgArgs)
            self.callFunction([chat, arg])
        elif len(msgArgs) == self.getArgumentsCount():
            # exact amount of arguments
            self.callFunction(msgArgs)

        elif len(msgArgs) > self.getArgumentsCount():
            # too much arguments passed, cut it
            for i in range(self.getArgumentsCount(), len(msgArgs)):
                msgArgs.pop()
            self.callFunction(msgArgs)
        else:
            # too less arguments, output command schema (without first chat argument)
            txt = "Użycie: " + self.name
            args = self.getArguments()
            for i in range(1, len(args)):
                txt = txt + " [" + args[i] + "]"
            if self.description != "":
                txt = txt + " (" + self.description + ")"
            skype.sendMessageToChat(chat, txt)
コード例 #14
0
def cmd_orct(chat):
    data = utils.getJSON("https://servers.openrct2.website/")
    if data is None or data["status"] != 200:
        skype.sendMessageToChat(chat, "Master server leży.")
        return

    total_players = 0
    total_slots = 0
    txt = "Serwery OpenRCT2:\n"
    for server in data["servers"]:
        if server["requiresPassword"]:
            txt = txt + " 🔒 "
        else:
            txt = txt + "     "
        txt = txt + server["name"] + " " + str(server["players"]) + "/" + str(
            server["maxPlayers"]) + " (" + server["ip"]["v4"][0] + ":" + str(
                server["port"]) + ")\n"
        total_players = total_players + server["players"]
        total_slots = total_slots + server["maxPlayers"]
    skype.sendMessageToChat(
        chat, txt + "Łącznie " + str(total_players) + "/" + str(total_slots) +
        " graczy.")
コード例 #15
0
def checkGitHub():
    print('checkGitHub')

    Timer(checkGithub_interval, checkGitHub).start()
    data = utils.getJSON(
        "https://api.github.com/repos/multitheftauto/mtasa-blue/commits?client_id=29c28b58cce0387e19a5&client_secret=62c2157f307108b637a8258a9f5e6ec549b69fbd&per_page=5"
    )
    if data is None:
        return

    for commit in reversed(data):
        date = commit["commit"]["committer"]["date"]
        commitTime = time.mktime(
            datetime.datetime.strptime(
                date, "%Y-%m-%dT%H:%M:%SZ").timetuple())  # timestamp
        print(
            str(commitTime) + " > " + str(utils.g_settings["lastCommitTime"]))
        if commitTime > utils.g_settings["lastCommitTime"]:
            skype.sendMessageToChat(
                skype.g_chats["mta"],
                "[commit] " + commit["commit"]["message"] + " @ " +
                commit["author"]["login"] + "\n" + commit["html_url"])
            utils.g_settings["lastCommitTime"] = commitTime
            utils.saveSettings()
コード例 #16
0
def cmd_twitchTop(chat, category=""):
    if category != "":
        data = utils.getJSON(
            "https://api.twitch.tv/kraken/search/games?type=suggest&live=1&limit=1&q="
            + category)
        if data is None:
            return
        if len(data["games"]) == 0:
            skype.sendMessageToChat(chat, "Nie ma takiej kategorii.")
            return
        category = data["games"][0]["name"]

    data = utils.getJSON("https://api.twitch.tv/kraken/streams?limit=3&game=" +
                         category)
    if data is None:
        return

    if len(data["streams"]) == 0:
        skype.sendMessageToChat(chat, "Brak streamów w kategorii " + category)
        return

    txt = ""
    for k, stream in enumerate(data["streams"]):
        nick = stream["channel"]["display_name"]
        status = stream["channel"]["status"]
        viewers = str(stream["viewers"])
        fps = str(int(round(stream["average_fps"])))
        if len(arg) > 0:
            txt = txt + "\n" + str(
                k + 1
            ) + ". " + nick + " (" + status + ", " + viewers + " widzów, " + fps + " FPS) https://twitch.tv/" + nick
        else:
            game = stream["game"]
            txt = txt + "\n" + str(
                k + 1
            ) + ". " + nick + " (" + game + ", " + status + ", " + viewers + " widzów, " + fps + " FPS) https://twitch.tv/" + nick

    if len(category) > 0:
        skype.sendMessageToChat(
            chat, "Top 3 streamów z kategorii " + category + ":" + txt)
    else:
        skype.sendMessageToChat(chat, "Top 3 streamów:" + txt)
    return
コード例 #17
0
def cmd_hitbox(chat, nick):
    print("cmd_hitbox " + nick)
    data = utils.getJSON("https://api.hitbox.tv/media/live/" + nick)
    if data is None:
        # todo: inspect this further
        skype.sendMessageToChat(chat, "api hitboxa jest zjebane")
        return

    if "error" in data:
        skype.sendMessageToChat(chat, "Nie ma takiego kanału.")
        return

    nick = data["livestream"][0]["media_display_name"]
    if data["livestream"][0]["media_is_live"] == "0":
        skype.sendMessageToChat(chat, nick + " obecnie nic nie streamuje!")
        return

    game = data["livestream"][0]["category_name"]
    status = data["livestream"][0]["media_status"]
    viewers = data["livestream"][0]["category_viewers"]
    skype.sendMessageToChat(
        chat, nick + " streamuje " + game + " (" + status + ", " + viewers +
        " widzów)" + "\nhttps://hitbox.tv/" + nick)
コード例 #18
0
def cmd_cmdsystem(chat):
    skype.sendMessageToChat(chat,
                            "Zdefiniownych komend: " + str(len(g_commands)))
コード例 #19
0
def OnMessageStatus(message, status):
    if status == 'RECEIVED' or status == 'SENT':
        if (message.Chat.Name == skype.g_chats["mta"] or message.Chat.Name
                == skype.g_chats["test"]) and message.Body.find('#') != -1:
            bugID_start = message.Body.find('#') + 1
            bugID_end = message.Body.find(' ', bugID_start)
            if bugID_end == -1:
                bugID_end = len(message.Body)
            bugID = message.Body[bugID_start:bugID_end]

            name, severity, status = notifications.checkMantisBug(bugID)
            if name is None:
                return

            skype.sendMessageToChat(
                message.Chat, "[" + severity + "/" + status + "] " + name +
                "\nhttps://bugs.mtasa.com/view.php?id=" + bugID)
            return

    if status == 'RECEIVED':
        for command in g_commands:
            #if message.Body.find(command.name) == 0:
            if message.Body.split()[0] == command.name:
                command.process(message.Body, message.Chat)
                return

        # other stuff
        if message.Body.find('v=') >= 0 or message.Body.find('youtu.be/') >= 0:
            link_start = message.Body.find('youtu.be/') + 9
            if link_start - 9 == -1:
                link_start = message.Body.find('v=') + 2

            link_end = message.Body.find('&', link_start)
            if link_end == -1:
                link_end = message.Body.find(' ', link_start)
                if link_end == -1:
                    link_end = len(message.Body)

            vidID = message.Body[link_start:link_end]
            data = utils.getJSON(
                "https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails&key=AIzaSyDViQNqCB7CxTiqS5YiBogXVBykLUtrUmY&id="
                + vidID)
            if data is None:
                return
            if len(data["items"]) > 0:
                title = data["items"][0]["snippet"]["title"]
                skype.sendMessageToChat(message.Chat, 'YT: ' + title)
            return

        if message.Body.find('lenny') != -1:
            skype.sendMessageToChat(message.Chat, "( ͡° ͜ʖ ͡°)")
        return

        if message.Body.find(
                'community.mtasa.com/index.php?p=resources&s=details&id='
        ) >= 0:
            link_start = message.Body.find(
                'community.mtasa.com/index.php?set_lang=eng&p=resources&s=details&id='
            ) + 55
            link_end = message.Body.find(' ', link_start)
            if link_end == -1:
                link_end = len(message.Body)

            if link_start >= 0:
                source = utils.getURL(
                    "http://community.mtasa.com/index.php?p=resources&s=details&id="
                    + message.Body[link_start:link_end])
                if source is None:
                    return

                title_start = source.find('">rss</a></span>') + 16
                title_end = source.find('</h2>', title_start) - 3
                title = source[title_start:title_end]

                if title_start - 16 == -1:
                    return

                author_start = source.find(
                    '<tr><th>Author:</th><td><a href="?p=profile&amp;id=') + 51
                author_start = source.find('">', author_start) + 2
                author_end = source.find('</a>', author_start)
                author = source[author_start:author_end]

                downloads_start = source.find(
                    '<tr><th>Downloads:</th><td>') + 27
                downloads_end = source.find('</td>', downloads_start)
                downloads = source[downloads_start:downloads_end]

                skype.sendMessageToChat(
                    message.Chat, 'Community: ' + title + " @ " + author +
                    " (" + downloads + " pobrań)")
            return

        if message.Body.find('store.steampowered.com/app/') >= 0:
            link_start = message.Body.find('store.steampowered.com/app/') + 27
            link_end1 = message.Body.find('/', link_start)
            link_end2 = message.Body.find(' ', link_start)

            link_end = link_end1
            if (link_end2 < link_end and link_end2 != -1) or link_end == -1:
                link_end = link_end2

            if link_end == -1:
                link_end = len(message.Body)

            appID = message.Body[link_start:link_end]
            data = utils.getJSON(
                'http://store.steampowered.com/api/appdetails?appids=' + appID)

            if data is None:
                return

            if not data[appID]["success"]:
                return

            data = data[appID]["data"]
            txt = "Steam: " + data["name"]
            if data["is_free"]:
                txt = txt + " (darmowe)"
            else:
                price1 = str(data["price_overview"]["final"])[:-2]
                if price1 == "":
                    price1 = "0"
                price2 = str(data["price_overview"]["final"])[-2:]

                if data["price_overview"]["currency"] == "EUR":
                    currency = "€"
                else:
                    currency = "$"

                txt = txt + " " + price1 + "." + price2 + currency
                if data["price_overview"]["discount_percent"] > 0:
                    txt = txt + " [-" + str(
                        data["price_overview"]["discount_percent"]) + "%]"
            message.Chat.SendMessage(txt)
            return
コード例 #20
0
def cmd_topic(chat):
    skype.sendMessageToChat("Aktualny temat: " + chat.Topic)