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

Chat.deleteMessage() doesn't seem to work #14

Closed
saki64 opened this issue Mar 11, 2023 · 19 comments
Closed

Chat.deleteMessage() doesn't seem to work #14

saki64 opened this issue Mar 11, 2023 · 19 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@saki64
Copy link

saki64 commented Mar 11, 2023

I tried deleting a message with const response = await chat.sendAndAwaitResponse(message, true); ... await chat.deleteMessage(response.lastUserMessageId.toString());

Received no error, but the message was not deleted on the site.

@saki64 saki64 changed the title chat.deleteMessage() doesn't seem to work Chat.deleteMessage() doesn't seem to work Mar 12, 2023
@saki64
Copy link
Author

saki64 commented Mar 12, 2023

I deleted the string check in Chat.deleteMessage() (chat.js line 149) and used number id instead.

It worked but I could only delete user's messages, not the character's ones.

I did try deleting both messages with const msg = await response.getMessage(); await msg.delete(true); but then found out that Message.delete() didn't await for .getPreviousMessage() (message.js line 83).

Edited it but still couldn't delete character's messages.

@saki64
Copy link
Author

saki64 commented Mar 12, 2023

Ran a couple of times, sometimes I managed to delete the character's messages. Inconsistency in the POST request I guess?

@realcoloride
Copy link
Owner

Hello,

I'm investigating this issue, I will let you know.

@realcoloride
Copy link
Owner

Hello, i've found an issue that is worth noting that i will fix:
I require a string passing in messageId but it must be a number.
Sorry for the inconvenience, i will fix other bugs if i see some and push an update.

@realcoloride
Copy link
Owner

sqJL8Vr9ju
Another issue ive spotted is that i forgot to add await, which returned a promise...

@realcoloride
Copy link
Owner

Hello,

Its been around an hour i've been trying to mess around and fix the delete message stuff. For some reason, no matter what I try, I cannot find a way to fix the deletion. I've tried a lot of things so far, but I really cant fix it....
Everything seems fine when from the website...

I will keep investigating but for now its broken. Sorry!

@realcoloride
Copy link
Owner

realcoloride commented Mar 12, 2023

Hello! ive seem to notice that the message ids that the website delete and the ones that are fetched then deleted are diferent..

Website json output:

{
  "messages": [
    {
      "id": 123372037927012370,
      "text": "Shogun: No salutations needed. My exalted status shall not be disclosed as we travel among the common folk. I acknowledge that you are a person of superior ability. Henceforth, you will be my guard. Worry not. Should any danger arise, I shall dispose of it.",
      "src": "12fb7ac8-1414-424a-96a4-20a9f28f973a",
      "tgt": "15b2701a-7cc2-4347-99a6-1237f1351a26",
      "is_alternative": false,
      "image_rel_path": "",
      "image_prompt_text": "",
      "deleted": null,
      "src__name": "Raiden Shogun and Ei",
      "src__user__username": "internal_id:64965:9bede7ad-da75-4ad8-a2e3-9f2972ae7dad",
      "src__is_human": false,
      "src__character__avatar_file_name": "uploaded/2022/10/20/FcaryjLtFi7uJMs4OYvG_1A5vSyUA8u2pu05F3iyYoM.webp",
      "src_char": {
        "participant": {
          "name": "Raiden Shogun and Ei"
        },
        "avatar_file_name": "uploaded/2022/10/20/FcaryjLtFi7uJMs4OYvG_1A5vSyUA8u2pu05F3iyYoM.webp"
      },
      "responsible_user__username": "Zap"
    },
    {
      "id": 123372037927307650,
      "text": "hello",
      "src": "15b2701a-7cc2-4347-99a6-1237f1351a26",
      "tgt": "12fb7ac8-1414-424a-96a4-20a9f28f973a",
      "is_alternative": false,
      "image_rel_path": "",
      "image_prompt_text": "",
      "deleted": null,
      "src__name": "coloride",
      "src__user__username": "oppsWalker",
      "src__is_human": true,
      "src__character__avatar_file_name": null,
      "src_char": {
        "participant": {
          "name": "coloride"
        },
        "avatar_file_name": null
      },
      "responsible_user__username": null
    },
    {
      "id": 123372037927307660,
      "text": "Shogun: How dare you take liberty without addressing this superior entity as the Raiden Shogun. You are but an insignificant speck of dust on this earth. I suggest you refrain from disturbing further. Your ignorance makes me sick, but if you keep your nose to the ground and continue to work hard, one day, there may be a place for you in my rule. Until then, I'll keep my eye on you too, lest you prove to be a worthless underling.",
      "src": "12fb7ac8-1414-424a-96a4-20a9f28f973a",
      "tgt": "15b2701a-7cc2-4347-99a6-1237f1351a26",
      "is_alternative": false,
      "image_rel_path": "",
      "image_prompt_text": "",
      "deleted": null,
      "src__name": "Raiden Shogun and Ei",
      "src__user__username": "internal_id:64965:9bede7ad-da75-4ad8-a2e3-9f2972ae7dad",
      "src__is_human": false,
      "src__character__avatar_file_name": "uploaded/2022/10/20/FcaryjLtFi7uJMs4OYvG_1A5vSyUA8u2pu05F3iyYoM.webp",
      "src_char": {
        "participant": {
          "name": "Raiden Shogun and Ei"
        },
        "avatar_file_name": "uploaded/2022/10/20/FcaryjLtFi7uJMs4OYvG_1A5vSyUA8u2pu05F3iyYoM.webp"
      },
      "responsible_user__username": null
    },
    {
      "id": 123372037927327650,
      "text": "okey",
      "src": "15b2701a-7cc2-4347-99a6-1237f1351a26",
      "tgt": "12fb7ac8-1414-424a-96a4-20a9f28f973a",
      "is_alternative": false,
      "image_rel_path": "",
      "image_prompt_text": "",
      "deleted": null,
      "src__name": "coloride",
      "src__user__username": "oppsWalker",
      "src__is_human": true,
      "src__character__avatar_file_name": null,
      "src_char": {
        "participant": {
          "name": "coloride"
        },
        "avatar_file_name": null
      },
      "responsible_user__username": null
    },
    {
      "id": 123372037927327660,
      "text": "Shogun: Inappropriate! I do not recall allowing you to address me in such a casual manner! The lack of politeness you have shown me is the height of discourtesy. In return, I too shall show you my lack of courtesy by casting you down into oblivion!",
      "src": "12fb7ac8-1414-424a-96a4-20a9f28f973a",
      "tgt": "15b2701a-7cc2-4347-99a6-1237f1351a26",
      "is_alternative": false,
      "image_rel_path": "",
      "image_prompt_text": "",
      "deleted": null,
      "src__name": "Raiden Shogun and Ei",
      "src__user__username": "internal_id:64965:9bede7ad-da75-4ad8-a2e3-9f2972ae7dad",
      "src__is_human": false,
      "src__character__avatar_file_name": "uploaded/2022/10/20/FcaryjLtFi7uJMs4OYvG_1A5vSyUA8u2pu05F3iyYoM.webp",
      "src_char": {
        "participant": {
          "name": "Raiden Shogun and Ei"
        },
        "avatar_file_name": "uploaded/2022/10/20/FcaryjLtFi7uJMs4OYvG_1A5vSyUA8u2pu05F3iyYoM.webp"
      },
      "responsible_user__username": null
    }
  ],
  "has_more": false,
  "next_page": 0
}

My program:

You: .deletebulk 10
--> Deleting 10 bulk messages...
{"history_id":"Mh8IVB-sIJFn3WBnNolSDVb3MgSWJ_SzpEM53If0t5Y","ids_to_delete":[123372037927012370,123372037927307650,123372037927307660,123372037927327650,123372037927327660],"regenerating":false}
{ status: 'OK' }

---

You: .fetch
--> Fetching messages...
[123372037927012370] Raiden Shogun and Ei: Shogun: No salutations needed. My exalted status shall not be disclosed as we travel among the common folk. I acknowledge that you are a person of superior ability. Henceforth, you will be my guard. Worry not. Should any danger arise, I shall dispose of it.
[123372037927307650] coloride: hello
[123372037927307660] Raiden Shogun and Ei: Shogun: How dare you take liberty without addressing this superior entity as the Raiden Shogun. You are but an insignificant speck of dust on this earth. I suggest you refrain from disturbing further. Your ignorance makes me sick, but if you keep your nose to the ground and continue to work hard, one day, there may be a place for you in my rule. Until then, I'll keep my eye on you too, lest you prove to be a worthless underling.
[123372037927327650] coloride: okey
[123372037927327660] Raiden Shogun and Ei: Shogun: Inappropriate! I do not recall allowing you to address me in such a casual manner! The lack of politeness you have shown me is the height of discourtesy. In return, I too shall show you my lack of courtesy by casting you down into oblivion!

Website:

{"history_id":"Mh8IVB-sIJFn3WBnNolSDVb3MgSWJ_SzpEM53If0t5Y","ids_to_delete":[123372037927307647,123372037927307661,123372037927327653,123372037927327664],"regenerating":false}

@realcoloride
Copy link
Owner

For now, I will hold this ticket as a priority for the next update.
If anybody knows in the meantime how to fix this, please let me know.

@realcoloride realcoloride added bug Something isn't working help wanted Extra attention is needed labels Mar 12, 2023
@saki64
Copy link
Author

saki64 commented Mar 12, 2023

Turns out you will lose some digits if you use large numbers: https://stackoverflow.com/questions/15529337/prevent-javascript-number-function-from-rounding-big-numbers

Which is why our ids always end with 0, which are not actual ids.

@realcoloride
Copy link
Owner

That makes sense, how do you think I should go around this?

@saki64
Copy link
Author

saki64 commented Mar 12, 2023

Weird that they want number ids instead of string. My solution is to use something like json-bigint to parse the response. That way we can get their ids as BigInt, then stringify those numbers back when we post the delete request.

@realcoloride
Copy link
Owner

realcoloride commented Mar 12, 2023 via email

@saki64
Copy link
Author

saki64 commented Mar 13, 2023

Tested it out, it kinda worked. Just needed to replace all request.json() and JSON.stringify(). Since our ids aren't numbers anymore, you might want to remove the type checks, or do some conversions. Also there's an id comparison in Chat.getMessageById(), so make sure to convert them beforehand.

@realcoloride
Copy link
Owner

Hello! I've ported to the JSONBig dependency and added it in the package.json for the next update.
I will try the things out and so far it made the parsing even faster!

I will keep you updated.

@realcoloride
Copy link
Owner

realcoloride commented Mar 13, 2023

image
image
image
So far so good!

@realcoloride
Copy link
Owner

realcoloride commented Mar 13, 2023

[Roadmap] Sum up of update goals:

  • Switch to big int and convert to bigger ints (Added Parser class for this dedicated use) Chat.deleteMessage() doesn't seem to work #14
  • Update some stuff in README.md
  • Fix some function arguments that required strings instead of ints Chat.deleteMessage() doesn't seem to work #14
  • Fix node issues in Tokens don't work #13
  • Fix cloudflare limiting guest authentification in Error, fetch is not defined. #15
  • Add ascending/descending mode to deleting in bulk (from up/down)
  • Added delete messages in array function [ids]
  • Converted message ids to strings instead of integers for big integers conversion in both classes and in functions
  • Make errors throw when an error occurs (message could not be sent for a reason such as nsfw, guest message limit)

This will be updated overtime.

@saki64
Copy link
Author

saki64 commented Mar 14, 2023

My code seems to be broken after the recent CAI maintenance. chat returns undefined.

@realcoloride
Copy link
Owner

realcoloride commented Mar 14, 2023 via email

@realcoloride
Copy link
Owner

Merging all updates for 1.1.1 in a new issue: #17.
Thank you for your understanding and patience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants