示例#1
0
def publish(bot, message, args):

    logger.info("publish")

    result = {'fire': False}

    response = "<u><b>Publish proposal<b><u>\n\n"

    userInfo = util.crossMessengerSplit(message)
    userId = userInfo['user'] if 'user' in userInfo else None
    userName = userInfo['name'] if 'name' in userInfo else "Unknown"

    result['author'] = userName

    if len(args) != 1:
        response += messages.proposalIdRequired(bot.messenger, 'publish')
    elif not util.isInt(args[0].replace('#', '')):
        response += messages.invalidProposalId(bot.messenger, args[0])
    else:

        proposal = bot.proposals.getProposal(int(args[0].replace('#', '')))

        if not proposal:
            response += messages.proposalNotFound(bot.messenger, args[0])
        else:

            result['proposal'] = proposal

            twitter = bot.tweeter != None
            reddit = bot.reddit != None
            gab = bot.gab != None
            discord = False
            telegram = False

            if 'discord' in bot.messenger:
                discord = True

            if 'telegram' in bot.messenger:
                telegram = True

            if proposal.published(twitter=twitter,
                                  reddit=reddit,
                                  gab=gab,
                                  discord=discord,
                                  telegram=telegram):
                response += messages.proposalAlreadyPublished(
                    bot.messenger, args[0])
            else:
                result['fire'] = True

    result['message'] = messages.markdown(response, bot.messenger)

    return result
示例#2
0
def remove(bot, message, args):

    logger.info("remove")

    response = "<u><b>Remove from watchlist<b><u>\n\n"

    userInfo = util.crossMessengerSplit(message)
    userId = userInfo['user'] if 'user' in userInfo else None
    userName = userInfo['name'] if 'name' in userInfo else "Unknown"
    public = userInfo['public']

    dbUser = bot.database.getUser(userId)
    if not dbUser:
        logger.error("User not in db?!")
        response += messages.unexpectedError(bot.messenger)
    else:

        if len(args) != 1:
            response += messages.proposalIdRequired(bot.messenger, 'remove')
        elif not util.isInt(args[0].replace('#', '')):
            response += messages.invalidProposalId(bot.messenger, args[0])
        else:

            proposal = bot.proposals.getProposal(int(args[0].replace('#', '')))

            if not proposal:
                response += messages.proposalNotFound(bot.messenger, args[0])
            else:

                currentList = bot.database.getWatchlist(userId=userId)

                if currentList and len(currentList) and\
                   not proposal.proposalId in list(map(lambda x: x['proposal_id'],currentList)) or\
                   not currentList or not len(currentList):

                    response += messages.proposalIsNotOnWatchlist(
                        bot.messenger, proposal.title)

                else:

                    if bot.database.removeFromWatchlist(
                            userId, proposal.proposalId):
                        response += "Succesfully removed the proposal <b>{}<b> from your watchlist.".format(
                            proposal.title)
                    else:
                        logger.error("Could not remove watchlist entry?!")
                        response += messages.unexpectedError(bot.messenger)

    return messages.markdown(response, bot.messenger)