Example #1
0
def gh(bot: Bot, update: Update, args: List[str]):
    try:
        message = update.effective_message
        command = args[0].lower()

        if command == "unregister":
            update.effective_message.reply_text(sql.unregister_repo(
                message.chat.id),
                                                parse_mode=ParseMode.MARKDOWN)
            return

        repo = sql.get_repo(message.chat.id)
        entries = 5
        if len(args) > 1:
            try:
                entries = int(args[1])
            except:
                repo = args[1]
        if len(args) > 2:
            repo = args[2]
        if not repo:
            update.effective_message.reply_text(
                "Target repository not specified!")
            return

        try:
            target = Github().get_repo(repo)
        except:
            update.effective_message.reply_text(
                "Invalid/inaccessible repository!")
            return

        if command == "commits" or command == "log":
            commits(target, entries, bot, update)
        elif command == "register":
            update.effective_message.reply_text(sql.register_repo(
                message.chat.id, repo),
                                                parse_mode=ParseMode.MARKDOWN)
        elif command == "events":
            events(target, bot, update)
        else:
            update.effective_message.reply_text(
                "'%s' is not a valid gh command." % args[0])
    except:
        update.effective_message.reply_text(
            "Something went wrong! Check command arguments and retry in a while."
        )
Example #2
0
def getRepo(bot, update, reponame):
    chat_id = update.effective_chat.id
    repo = sql.get_repo(str(chat_id), reponame)
    if repo:
        return repo.value, repo.backoffset
    return None, None