コード例 #1
0
def initiateTeachingCheck(comment):
    try:
        if comment.id not in c.t_checked_comments and h.botHasNotAnswered(
                comment):
            i = 0
            output = ""
            if "!teach " in comment.body:
                output = "The following units have been added: \n\n"
                regex = re.findall('!teach (\w+\W?:\d+)', comment.body)
                for string in regex:
                    if i >= 25:
                        output += "However, the maximum for units to be added in a single post has been exceeded, " \
                                  "so some of your input could not be added anymore. Please try again in a new comment."
                        break
                    string = string.split(":")
                    output += " * %s \n" % (db.addNameID(
                        name=string[0].lower(), id=string[1]))
                    i += 1

            if output != "":
                comment.reply(output + c.MESSAGE_FOOTER)
            c.t_checked_comments.append(comment.id)

    except Exception as e:
        print(e)
        log.unhandledException(exception=e, location="initiateTeachingCheck()")
コード例 #2
0
def updateFiles():
    try:
        updateUnitFiles()
        updateDetailsFiles()
        updateCooldownsFiles()
    except Exception as e:
        log.unhandledException(e, "unitResport.updateFiles()")
コード例 #3
0
def detailReport(id):
    with open(c.detailsPath) as text:
        data = json.load(text)
    try:
        return data[str(id)]
    except KeyError:
        log.unhandledException(exception=KeyError, location="unitReport.detailReport()")
コード例 #4
0
def testMain():
    i = 0
    #    enforceTitle()
    while 1:
        try:
            time.sleep(60)
            # checkFlairs is a fully functional Flair-Enforcer. It's currently disabled because no subreddit I moderate
            # requires me to host one of these.
            # checkFlairs(reddit=reddit, subreddit=subreddit)

            # Update all required files
            i = fileUpdate(i)

            for submission in subreddit.new():
                # Update Sidebar links to Megathreads
                alreadyDoneForAutomod = updateSidebar(moderator, submission,
                                                      alreadyDoneForAutomod)

            for comment in subreddit.comments(limit=5):
                if comment.author.name in c.giveaway_banned_users:
                    prob.probationControl(reddit=reddit,
                                          subreddit=subreddit,
                                          comment=comment)
                    # Unit Reporter: !teach
                    # initiateTeachingCheck(comment)

                    # !Unit Reporter: !unit !skills !stats
                    # initiateUnitReportCheck(comment)

                    # Probation Control
                    # GA scans
                    # gac.initiateGAScans
        except ConnectionResetError:
            log.connectionError("ConnectionResetError")
            time.sleep(30)
        except ConnectionRefusedError:
            log.connectionError("ConnectionRefusedError")
            time.sleep(30)
        except ConnectionAbortedError:
            log.connectionError("ConnectionAbortedError")
            time.sleep(30)
        except ConnectionError:
            log.connectionError("ConnectionError")
            time.sleep(30)
        except Exception as e:
            log.unhandledException(exception=e, location="botCore.main()")
            time.sleep(30)
        time.sleep(c.BOT_CYCLE_TIME)
コード例 #5
0
def probationControl(reddit, subreddit, comment):
    if " Weekly Updated Giveaway Megathread" in comment.submission.title and comment.permalink not in \
            c.giveaway_handled:
        try:
            comment.mod.remove()
            reddit.redditor(comment.author.name).message(subject=c.giveaway_ban_message_title,
                                                         message=(c.giveaway_ban_message_1 +
                                                                  comment.author.name + c.giveaway_ban_message_2))
            c.giveaway_handled.append(comment.permalink)
            log.probationViolation(name=comment.author.name, comment=comment.permalink)
            subreddit.message(subject="Probation Violation - " + comment.author.name, message="u/" +
                    comment.author.name + " has broken his probation. Please investigate as soon as possible.")
            #subreddit.banned.add(comment.author.name, ban_reason='OPTCBot: Account Hoarding - Automatic Ban for '
            #                                                     'Probation Violation')
        except Exception as e:
            log.unhandledException(exception=e, location="probation.probationControl()")
コード例 #6
0
def checkFlairs(reddit, subreddit):
    # FlairEnforcer
    try:
        flair.checkNewSubmissions(
            subreddit=subreddit,
            approved_submissions=c.approved_submissions,
            submissions_with_no_flair=c.submissions_with_no_flair,
            self="")
    except Exception as e:
        log.unhandledException(exception=e,
                               location="botCore.checkFlairs()_newSubmissions")

    try:
        flair.revisitSubmissions(
            reddit=reddit,
            approved_submissions=c.approved_submissions,
            submissions_with_no_flair=c.submissions_with_no_flair,
            removed_submissions=c.removed_submissions,
            id_for_replies=c.id_for_replies,
            self="")
    except Exception as e:
        log.unhandledException(exception=e,
                               location="botCore.checkFlairs()_oldSubmissions")
コード例 #7
0
def initiateUnitReportCheck(comment):
    try:
        if comment.id not in c.ur_checked_comments and h.botHasNotAnswered(
                comment):
            i = 0
            output = ""
            if "!unit " in comment.body:
                regex = re.findall('!unit (\d+\s+)',
                                   comment.body)  # TODO CLEAN THIS UP
                regex_temp = re.findall('!unit (\w*\+?)', comment.body)
                regex_work = []
                for string in regex_temp:
                    if not h.is_number(string):
                        try:
                            unitID = db.isValid(string)
                        except Exception as e:
                            log.unhandledException(
                                exception=e,
                                location=initiateUnitReportCheck())
                        if unitID != False:
                            regex_work.append(unitID)
                        else:
                            output += "* The name '%s' could not be recognized. \n\n" % (
                                string)
                            i += 1
                for number in regex:
                    number = number.strip(" ")
                    if h.is_number(number):
                        regex_work.append(number)
                for number in regex_work:
                    if i > 2:
                        break
                    number = str(number.lstrip('0'))
                    output += ur.buildReport(number)
                    i += 1

            if "!stats " in comment.body:
                regex = re.findall('!stats (\d+)', comment.body)
                for number in regex:
                    if i > 2:
                        break
                    number = str(number.lstrip('0'))
                    output += ur.buildStats(number)
                    i += 1

            if "!skills " in comment.body:
                regex = re.findall('!skills (\d+)', comment.body)
                for number in regex:
                    if i > 2:
                        break
                    number = str(number.lstrip('0'))
                    output += ur.preBuildAbilities(number)
                    i += 1

            if output != "":
                output += c.MESSAGE_FOOTER
                comment.reply(output)
                log.unitReported(comment.permalink(fast=True))
            c.ur_checked_comments.append(comment.id)
    except Exception as ex:
        log.unhandledException(exception=ex,
                               location="botCore.initiateUnitReportCheck()")