当前位置: 首页>>代码示例>>Python>>正文


Python DatabaseHandler.addMessage方法代码示例

本文整理汇总了Python中DatabaseHandler.addMessage方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseHandler.addMessage方法的具体用法?Python DatabaseHandler.addMessage怎么用?Python DatabaseHandler.addMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DatabaseHandler的用法示例。


在下文中一共展示了DatabaseHandler.addMessage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: on_message

# 需要导入模块: import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler import addMessage [as 别名]
async def on_message(message):
    print('Message recieved')
    #Is the message valid (i.e. it's not made by Discordoragi and I haven't seen it already). If no, try to add it to the "already seen pile" and skip to the next message. If yes, keep going.
    if not (DiscordoragiSearch.isValidMessage(message)):
        try:
            if not (DatabaseHandler.messageExists(message.id)):
                DatabaseHandler.addMessage(message.id, message.author.id, message.server.id, False)
        except Exception:
            traceback.print_exc()
            pass
    else:
        await process_message(message)
开发者ID:jwolff52,项目名称:Discordoragi,代码行数:14,代码来源:AnimeBot.py

示例2: isValidMessage

# 需要导入模块: import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler import addMessage [as 别名]
def isValidMessage(message):
    try:
        if (DatabaseHandler.messageExists(message.id)):
            return False

        try:
            if (message.author.name == USERNAME):
                DatabaseHandler.addMessage(message.id, message.author.id, message.server.id, False)
                return False
        except:
            pass

        return True
        
    except:
        traceback.print_exc()
        return False
开发者ID:jwolff52,项目名称:Discordoragi,代码行数:19,代码来源:DiscordoragiSearch.py

示例3: process_message

# 需要导入模块: import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler import addMessage [as 别名]

#.........这里部分代码省略.........
        for match in re.finditer("(?<=(?<!\<)\<)([^\<\>]*)\>:\(([^)]+)\)", cleanMessage, re.S):
            reply = DiscordoragiSearch.buildMangaReplyWithAuthor(match.group(1), match.group(2), message, False)

            if (reply is not None):
                mangaArray.append(reply)

        #Expanded LN
        for match in re.finditer("\]{2}([^]]*)\[{2}", cleanMessage, re.S):
            reply = ''

            if (forceNormal) or (str(message.server).lower() in disableexpanded):
                reply = DiscordoragiSearch.buildLightNovelReply(match.group(1), False, message)
            else:
                reply = DiscordoragiSearch.buildLightNovelReply(match.group(1), True, message)                    

            if (reply is not None):
                lnArray.append(reply)

        #Normal LN  
        for match in re.finditer("(?<=(?<!\])\])([^\]\[]*)(?=\[(?!\[))", cleanMessage, re.S):
            reply = DiscordoragiSearch.buildLightNovelReply(match.group(1), False, message)
            
            if (reply is not None):
                lnArray.append(reply)

        #Here is where we create the final reply to be posted

        #The final message reply. We add stuff to this progressively.
        messageReply = ''

        #Basically just to keep track of people posting the same title multiple times (e.g. {Nisekoi}{Nisekoi}{Nisekoi})
        postedAnimeTitles = []
        postedMangaTitles = []
        postedLNTitles = []

        #Adding all the anime to the final message. If there's manga too we split up all the paragraphs and indent them in Reddit markup by adding a '>', then recombine them
        for i, animeReply in enumerate(animeArray):
            if not (i is 0):
                messageReply += '\n\n'

            if not (animeReply['title'] in postedAnimeTitles):
                postedAnimeTitles.append(animeReply['title'])
                messageReply += animeReply['comment']


        if mangaArray:
            messageReply += '\n\n'

        #Adding all the manga to the final message
        for i, mangaReply in enumerate(mangaArray):
            if not (i is 0):
                messageReply += '\n\n'

            if not (mangaReply['title'] in postedMangaTitles):
                postedMangaTitles.append(mangaReply['title'])
                messageReply += mangaReply['comment']

        if lnArray:
            messageReply += '\n\n'

        #Adding all the manga to the final comment
        for i, lnReply in enumerate(lnArray):
            if not (i is 0):
                commentReply += '\n\n'
            
            if not (lnReply['title'] in postedLNTitles):
                postedLNTitles.append(lnReply['title'])
                messageReply += lnReply['comment']

        #If there are more than 10 requests, shorten them all
        if not (messageReply is '') and (len(animeArray) + len(mangaArray) >= 10):
            messageReply = re.sub(r"\^\((.*?)\)", "", messageReply, flags=re.M)

    #If there was actually something found, add the signature and post the message to Reddit. Then, add the message to the "already seen" database.
    if not (messageReply is ''):
        messageReply += Config.getSignature()

        if is_edit:
            await Discord.client.send_message(message.channel, messageReply)
        else:
            try:
                print("Message created.\n")
                await Discord.client.send_message(message.channel, messageReply)
            except discord.errors.Forbidden:
                print('Request from banned channel: ' + str(message.channel) + '\n')
            except Exception:
                traceback.print_exc()
            
            try:
                DatabaseHandler.addMessage(message.id, message.author.id, message.server.id, True)
            except:
                traceback.print_exc()
    else:
        try:
            if is_edit:
                return None
            else:
                DatabaseHandler.addMessage(message.id, message.author.id, message.server.id, False)
        except:
            traceback.print_exc()
开发者ID:jwolff52,项目名称:Discordoragi,代码行数:104,代码来源:AnimeBot.py


注:本文中的DatabaseHandler.addMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。