Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LogNow get live logs in Action #23

Open
HCWcoder opened this issue Dec 19, 2018 · 2 comments
Open

LogNow get live logs in Action #23

HCWcoder opened this issue Dec 19, 2018 · 2 comments

Comments

@HCWcoder
Copy link

HCWcoder commented Dec 19, 2018

Thanks to @Tkd-Alex for helping and making this happen.

I would like to share this Function that you can have Live logs sent to your Telegram chat.

Add this Function :

def lognow(bot, update, args):
    if str(update.message.chat_id) in allowed_id:
            message1 = ""
            messagecounter = int( args[1] )
            time.sleep(2)
            for x in range(messagecounter):
                usernames = [ a['username'].lower() for a in users ]
                if not args[0].lower() in usernames:
                    update.message.reply_text("Sorry, username <b>{}</b> is not saved.".format(args[0]), parse_mode='HTML')
                    return
                logsline = 1
                with open('{}/logs/{}/general.log'.format(settings['instapy_folder'], args[0].lower()), "r") as f:
                    lines = f.readlines()
                lines = lines[-(logsline+20):] # Prevent empty lines
                message = '\n'.join(x for x in lines)
                message = clear_lines( '\n'.join(x for x in lines), username=args[0].lower() )
                lines = message.split('\n')[-logsline:]
                message = '\n'.join(x for x in lines)
                if message1 != message:
                    update.message.reply_text(message, parse_mode='HTML')
                    message1 = message
                    time.sleep(2)
                else:
                    time.sleep(4)

ADD
dp.add_handler(CommandHandler("lognow", lognow, pass_args=True))
AFTER
if __name__ == '__main__':

Usage /lognow username number

Number is the number of logs you wish to get

@Tkd-Alex
Copy link
Owner

I'm not sure this feature is a good idea.
The bot will be a spammer :/

@HCWcoder
Copy link
Author

Yes i was testing and its not a good idea 💡

Your totally right

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants