Beispiel #1
0
def vote(user, info):
    try:
        [vote_id, vote] = info.split(" ")
        if vote.lower() not in ("upvote", "downvote"):
            raise ValueError()

        if db.Proposals.select().where(
                db.get_where_condition(db.Proposals, id=vote_id,
                                       active=True)).count() == 0:
            ZOMICBOT.send(user, strings.NOT_FOUND)
            return False

        if db.Votes.select().where(
                db.get_where_condition(
                    db.Votes, chat_id=user, proposal=vote_id)).count() > 0:
            ZOMICBOT.send(user, strings.CONFLICT)
            return False

        db.Votes.create(chat_id=user,
                        proposal=vote_id,
                        vote=vote_number(vote.lower()))

        return ZOMICBOT.send(user, strings.SUCCESS)
    except:
        ZOMICBOT.send(user, strings.BAD_REQUEST)
        return False
Beispiel #2
0
def invite(user, info):
    try:
        username = info.split(" ")[0]
        description = info.split(" ")[1:]

        if username == "":
            raise ValueError()

        if db.Proposals.select().where(
                db.get_where_condition(db.Proposals,
                                       genesis=genesis(),
                                       chat_id=user,
                                       active=True,
                                       username_exists=True)).count() > 0:
            return ZOMICBOT.send(user, strings.CONFLICT)
            return False

        db.Proposals.create(genesis=genesis(),
                            chat_id=user,
                            username=username,
                            description=" ".join(description))
        return ZOMICBOT.send(user, strings.SUCCESS)
    except:
        ZOMICBOT.send(user, strings.BAD_REQUEST)
        return False
Beispiel #3
0
    def get(self):
        """List community rules"""
        args = get_parser_list(rule=True).parse_args()
        condition = db.get_where_condition(db.Rules,
                                           id=args.id,
                                           genesis=args.genesis,
                                           active=args.active,
                                           chat_id=args.chat_id,
                                           description=args.description)

        rules = db.Rules.select().where(condition)
        return db.get_lines(rules, rule=True)
Beispiel #4
0
def update_info(user, info):
    wallet = None
    email = None
    try:
        wallet = types.wallet(info)
    except Exception as exception:
        try:
            email = types.email(info)
        except Exception as exception:
            ZOMICBOT.send(user, strings.BAD_REQUEST)
            return False

    if wallet:
        db.Members.update(wallet=wallet).where(
            db.get_where_condition(db.Members, chat_id=user)).execute()

    if email:
        db.Members.update(email=email).where(
            db.get_where_condition(db.Members, chat_id=user)).execute()

    return ZOMICBOT.send(user, strings.SUCCESS)
Beispiel #5
0
    def get(self):
        """List community proposals"""
        args = get_parser_list(proposal=True).parse_args()
        condition = db.get_where_condition(db.Proposals,
                                           id=args.id,
                                           genesis=args.genesis,
                                           active=args.active,
                                           chat_id=args.chat_id,
                                           description=args.description,
                                           username=args.username)

        proposals = db.Proposals.select().where(condition)
        return db.get_lines(proposals, proposal=True)
Beispiel #6
0
    def get(self):
        """List community members"""
        args = get_parser_list(member=True).parse_args()
        condition = db.get_where_condition(db.Members,
                                           id=args.id,
                                           genesis=args.genesis,
                                           active=args.active,
                                           name=args.name,
                                           email=args.email,
                                           wallet=args.wallet)

        members = db.Members.select().where(condition)
        return db.get_lines(members, member=True)
Beispiel #7
0
def propose(user, description):
    if description == "":
        ZOMICBOT.send(user, strings.NOT_FOUND)
        return False

    if db.Proposals.select().where(
            db.get_where_condition(db.Proposals,
                                   genesis=genesis(),
                                   chat_id=user,
                                   active=True,
                                   username=None)).count() > 0:
        ZOMICBOT.send(user, strings.CONFLICT)
        return False

    db.Proposals.create(genesis=genesis(),
                        chat_id=user,
                        description=description)
    return ZOMICBOT.send(user, strings.SUCCESS)
Beispiel #8
0
def quit(user, wallet=None):
    if wallet is not None:
        try:
            wallet = types.wallet(wallet)
        except Exception as exception:
            ZOMICBOT.send(user, exception)
            ZOMICBOT.send(user, strings.RAGE_QUIT)
            return False

    db.Members.update(active=False).where(
        db.get_where_condition(db.Members, chat_id=user)).execute()
    # /quit
    if wallet:
        ZOMICBOT.send(user, strings.QUIT % wallet)
    # /rage_quit
    else:
        ZOMICBOT.send(user, strings.QUIT.split("\n")[0])

    return ZOMICBOT.send(user, strings.SUCCESS)
Beispiel #9
0
                    user = msg["edited_message"]["from"]["id"]
                    username = msg["edited_message"]["from"]["username"]
                    text = msg["edited_message"]["text"]
                except:
                    logger.error('COULDNT READ %s' % msg)

            #Msg Already Processed
            if update_id <= last_msg:
                continue

            db.Telegram.create(chat_id=user, update_id=update_id, text=text)

            #New Member
            if db.Members.select().where(
                    db.get_where_condition(db.Members,
                                           name=username,
                                           chat_id=0,
                                           active=True)):
                first_name = msg["message"]["from"]["first_name"]
                last_name = msg["message"]["from"]["last_name"]
                name = first_name + " " + last_name
                db.Members.update(name=name, chat_id=user).where(
                    db.get_where_condition(db.Members,
                                           name=username,
                                           chat_id=0,
                                           active=True)).execute()

            #Not An Active Member
            if not db.Members.select().where(
                    db.get_where_condition(
                        db.Members, chat_id=user, active=True)):
                ZOMICBOT.send(user, strings.NOT_MEMBER)