用PRAW制作机器人。似乎无视某些人?

时间:2018-09-09 15:23:28

标签: python python-3.x reddit praw

我的第一篇文章在这里。如果您现在签出/ r / EDH,则会在首页上看到我的机器人。这个想法是当您键入?edhbot [卡名]时?它为您提供了edhrec.com上相关页面的链接。

但是出于某种原因,它似乎忽略了一些人,并且我的机器人未报告任何速率限制问题。他们没有弄错口号,所以我真的无法弄清楚他们在做什么错吗?这是我的代码供参考:

  #imported modules
  import praw
  import string

  #functions
  def main():
        #API login
        #I have no idea what I can't show so I redacted most lol
        reddit = praw.Reddit(client_id="REDACTED",
                             client_secret = "REDACTED",
                             user_agent = "a bot for my epq, by aggressivechairs",
                             username = "EPQ_MTG_BOT",
                             password = "REDACTED")
        subreddit = reddit.subreddit("all")
        wakeword = "?edhbot "

        for comment in subreddit.stream.comments():
              if wakewordCheck(comment, wakeword): reply = generateComment(comment)

  #Checks comment to see if it contains the wake word for the bot
  def wakewordCheck(comment, wakeword):
        if wakeword in comment.body: return(True)
        else: return(False)

  #Generates the link extension
  def linkGenerator(inString):
        startPoint = inString.index("?edhbot ")
        inString = inString.lower()
        outString = ""
        for i in range(startPoint+8, len(inString)):
              if inString[i] == "?":
                    break
              elif inString[i] in string.punctuation:
                    continue
              elif inString[i] in string.whitespace:
                    outString += "-"
                    continue
              outString += inString[i]
        return(outString)



  #Generates the text that will be used in the bot's reply
  def generateComment(comment):
        try:
              normalisedLink = linkGenerator(comment.body)
              commentReply = "[EDHRec page for the commander](https://edhrec.com/commanders/"+normalisedLink+") \n\n [EDHREC page for that as a card](https://edhrec.com/cards/"+normalisedLink+")"
              comment.reply(commentReply)
              print("I did it with " + comment.body)
        except Exception as e: print(e)            

  if __name__ == "__main__":
        main()

是的,当您使用?edhbot类型时,它会一直读到注释结尾或遇到一个新的问号。如果您查看此线程,尽管可以看到它只是选择忽略某些人。 https://www.reddit.com/r/EDH/comments/9ec677/im_a_new_bot_made_just_for_this_sub/?sort=new

您有什么建议?我无法解决问题所在:/哦,如果您发现任何不良的编码习惯,请随时告诉我!我想改善哈哈

0 个答案:

没有答案