Ejemplo n.º 1
0
async def cdoLog(**kwargs):
    """
    Posts the last lines of a given logfile
    :param kwargs:
    :return:
    """

    fileList = ["debug","info","errors"]
    data = kwargs['msg'].content.split(" ")
    if len(data) != 2:
        return CDOInteralResponseData("Data needs to contain logname and length")

    if data[1] not in fileList:
        return CDOInteralResponseData(f"Possible logfiles are {fileList}")

    with open(data[1]+".log") as f:
        fileContent = f.read()

    respStr = "LogContent: "

    addInfo = OrderedDict()
    try:
        addInfo[f"Lines 1 to 1000"] = fileContent[0:200]
    except IndexError:
        addInfo[f"Lines 1 to {len(fileContent)}"] = fileContent[0:len(fileContent) -1]

    class pageContent:
        index = 1
        @staticmethod
        def page(page):
            oldIndex = pageContent.index
            pageString = respStr + f" _(page {pageContent.index+1})_"
            if page == pageNav.forward:
                pageContent.index +=1
            else:
                pageContent.index -=1

            lowerIndex = (pageContent.index - 1) * 1000
            upperIndex = (pageContent.index) * 1000
            addInfo = OrderedDict()
            try:
                addInfo[f"Lines {lowerIndex} to {upperIndex}"] = fileContent[lowerIndex:upperIndex]
            except IndexError:
                addInfo[f"Lines {lowerIndex} to {len(fileContent)}"] = fileContent[lowerIndex:len(fileContent) - 1]
            try:
                return CDOInteralResponseData(pageString,addInfo)
            except IndexError:
                pageContent.index = oldIndex
                return CDOInteralResponseData(pageString, addInfo)

    response = CDOInteralResponseData(respStr,addInfo)
    if len(fileContent) != 0:
        response.paging = pageContent.page

    return response
Ejemplo n.º 2
0
async def cdoUpcomingGames(**kwargs):
    """
    Lists all upcoming games
    :param kwargs:
    :return:
    """

    matchList = Scheduler.upcomingMatches()
    addInfo = OrderedDict()
    count = 0
    addInfoList = []
    for match in matchList:
        addInfo[match.title] = f"{match.match.date} (UTC)"
        count +=1
        if count == 10:
            addInfoList.append(addInfo)
            addInfo = OrderedDict()
            count = 0

    if addInfo != OrderedDict():
        addInfoList.append(addInfo)

    if addInfoList == []:
        respStr = "No upcoming matches"
    else:
        respStr = "Upcoming matches:"

    resp = CDOInteralResponseData(respStr)
    if addInfoList != []:
        resp.additionalInfo = addInfoList[0]


    class pageContent:
        index = 0
        @staticmethod
        def page(page):
            oldIndex = pageContent.index
            pageString = respStr + f" _(page {pageContent.index+1})_"
            if page == pageNav.forward:
                pageContent.index +=1
            else:
                pageContent.index -=1
            try:
                return CDOInteralResponseData(pageString,addInfoList[pageContent.index])
            except IndexError:
                pageContent.index = oldIndex
                return CDOInteralResponseData(pageString, addInfoList[pageContent.index])

    if addInfoList != []:
        resp.paging = pageContent.page
    return resp
Ejemplo n.º 3
0
async def cdoGetHelp(**kwargs):
    """
    Returns all available Commandos and their documentation.
    :return:
    """
    retString = "Available Commandos:"
    addInfo = OrderedDict()
    try:
        prefix = Settings.objects.get(name="prefix")
        prefix = prefix.value
    except ObjectDoesNotExist:
        prefix = "!"

    try:
        userQuery = DiscordUsers.objects.get(id=kwargs['msg'].author.id)
        authorUserLevel = userQuery.userLevel
    except ObjectDoesNotExist:
        authorUserLevel = 0

    addInfoList = []
    count = 0
    for i in DiscordCommando.allCommandos():
        if i.userLevel <= authorUserLevel:
            doc = i.docstring
            doc = re.sub(':.+\n', "", doc)
            doc = re.sub('\n+', "", doc)
            if authorUserLevel >= 5:
                level = f" lvl:{i.userLevel}"
            else:
                level = ""
            addInfo[prefix + i.commando + level] = doc
            count +=1
            if count ==5:
                addInfoList.append(addInfo)
                addInfo = OrderedDict()
                count = 0

    if addInfo != OrderedDict():
        addInfoList.append(addInfo)

    responseData = CDOInteralResponseData(retString, addInfoList[0])

    class pageContent:
        index = 0
        @staticmethod
        def page(page):
            oldIndex = pageContent.index
            pageString = retString + f" _(page {pageContent.index+1})_"
            if page == pageNav.forward:
                pageContent.index +=1
            else:
                pageContent.index -=1
            try:
                return CDOInteralResponseData(pageString,addInfoList[pageContent.index])
            except IndexError:
                pageContent.index = oldIndex
                return CDOInteralResponseData(pageString, addInfoList[pageContent.index])


    responseData.paging = pageContent.page

    return responseData