topkecleon / telegram-bot-bash

Telegram bot written in bash
Other
426 stars 123 forks source link

Added send_html_topic_message and send_normal_topic_message... #198

Open harryeffinpotter opened 1 year ago

harryeffinpotter commented 1 year ago

Along with some example commands in mycommands.sh, feel free to adjust and change it, repo owners! I just had a billion commands setup on my server and couldn't just easily write it all in some other bot framework so I had to figure it out. Hope this helps someone!

I was bummed when I didn't see this in the PRs so I decided to take matters into my own hands, at least I hope I did, they work for me but I'm sure there's something I missed as I didn't take the time to fully parse all the code in normal_message. Hope this helps someone!

P.S. - IDK why it is saying I removed those 262 lines unless the new stuff just caused alignment issues. But in case I did accidentally wipe something, that was not my intention, intention is just to ADD the new code for topics and remove 0 lines. Thanks.

gnadelwartz commented 1 year ago

looks good on first impression, but I'll add your Changes manually to not cripple mycommands unnecessarily

thanks alot

harryeffinpotter commented 1 year ago

Hey no problem thanks for getting to it so fast I'm happy about that !

On Mon, Mar 20, 2023, 5:24 AM Kay Marquardt @.***> wrote:

looks good on first impression, but I'll add your Changes manually to not cripple mycommands unnecessarily

thanks alot

— Reply to this email directly, view it on GitHub https://github.com/topkecleon/telegram-bot-bash/pull/198#issuecomment-1475884301, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARQCVODYCGW74DQIRSIKR2DW5AO5PANCNFSM6AAAAAAWAX3XDA . You are receiving this because you authored the thread.Message ID: @.***>

harryeffinpotter commented 1 year ago

Also I totally agree keep it uniform with the rest of the code and do your thing with the docs and whatnot I just wanted it to stick out as if the git diff wouldn't have been obvious lol , hard to ditch those shell scripting habits !

Where I always write stuff like: echo -e "#####\nWelcome to my sick bash script!\n#####" Lmao.

I just now noticed that the description for this bot says it uses the magic of sed, can confirm: sed is Magic. Used to look like it was made up on the spot as some elaborate inside joke/prank against me and well now I love it, makes managing the thousands of folders and files on my server so much more convenient and less messy. I had learned tg python bot this past week but I still prefer bash bot, it's just more straight forward and easily digestible. So I'm super glad to help and awesome job on the repo! It's essential !

harryeffinpotter commented 1 year ago

Hey @gnadelwartz i had a quick question for you, when you implement it, when the bot is in a thread when summoned itr should be able to obtain the thread ID right? I was going to work on that right now but its probably a lot easier than I am imagining it to be. So that we can send messages in threadsa where it is called etc.

harryeffinpotter commented 1 year ago

I was super wrong about that btw, its a lot more difficult to understand than i thought it would be, im pretty sure its going down in bashbot.sh where it uses chat_id, since threads are a neighboring parameter of chat_id but man im totally lost with the way you mad lads built this, i can tell its systematically brilliant but thteres so many caveats, when you have to disable that many shell check warnings hoo boy youre in for a time.

gnadelwartz commented 1 year ago

Im not shure what you are refering to by thread? do you mean

harryeffinpotter commented 1 year ago

I mean the topics system its calling them "threads", in the json received in reply context in the API its message_thread_id:, I want to be able to retrieve this so it can reply to users.

harryeffinpotter commented 1 year ago

Its where you also get the user that is sending the chat, and the message ID, so we just need to pull that from the same spot so it can be used,I'm just having a hard time finding the code where you do so

gnadelwartz commented 1 year ago

OK, understood.

As I've not seen real data sent by telegram for subthreads I can provide a general explanation only, it should work like with USER[ID] insert something like this in process _message()

process_message() {
[....]
        THREAD[ID]="${UPD["result,${num},message,thread,id"]}"
            # UPD=JSON Array, num=message count (mostly  0), remaining string is the json field to get information from
            # e.g. ${UPD["result,0,message,thread,id"]} -> "thread,id" is a guess only, real string depends on JSON sent by telegram 

Note: add THREAD and any other new global array to declaration in line 360 in bashbot.sh:

bashbot.sh
....
     declare -Ax UPD ... THREAD
....
harryeffinpotter commented 1 year ago

OK, understood.

As I've not seen real data sent by telegram for subthreads I can provide a general explanation only, it should work like with USER[ID] insert something like this in process _message()

process_message() {
[....]
        THREAD[ID]="${UPD["result,${num},message,thread,id"]}"
            # UPD=JSON Array, num=message count (mostly  0), remaining string is the json field to get information from
            # e.g. ${UPD["result,0,message,thread,id"]} -> "thread,id" is a guess only, real string depends on JSON sent by telegram 

Note: add THREAD and any other new global array to declaration in line 360 in bashbot.sh:

bashbot.sh
....
     declare -Ax UPD ... THREAD
....

Literally just found this comment after already figuring this all out and doing it myself -_- but I did have it under pre-process message rather than process message, so I added it there too, and it looks like this, btw, when looking at the proper json data:

THREAD[ID]="${UPD["result,${num},message,message_thread_id"]}"

harryeffinpotter commented 9 months ago

any reason this is still unmerged? AFAIK it works well? This is pretty much all that the bash bot needs to stay current, IMO, the only feature I was sorely missing, at least.

harryeffinpotter commented 5 months ago

Actually one thing it should really have - but it's hard for me to understand the code in this repo because bash is fuckin complicated, but it should have the ability to store the message thread from a reply or some such and then use it.