DiscordJS Member Counter Weird Appearance - discord.js

So I have added member count to the bot but I discovered something a bit strange.
If I use guild.memberCount I get the same result as the counter on the server settings page.
But if I use guild.members.cache.size I get a different result number.
Example
guild.memberCount says 1335 (Same as Server Settings Page)
guild.members.cache.size says 1332
Is there a reason why it keeps removing 3?
W do not use bot user filters. Just a total count.

Not all members will be in the cache. Generally, they only become cached once they send a message, at which point they're stored temporarily in memory.
guild.memberCount, on the other hand, is the member count directly received from Discord's API.

Related

pagination for the list secrets for logic apps

I am using List secrets activity to get all the secrets from key vault. I am only able to get first few values as pagination is not Woking for this activity. Is there any other way I can get all the secrets values from the logic apps.Right now I am only able to do for first page values only and as per Microsoft there is limitation of maximum 25 items.
I've managed to recreate the problem in my own tenant and yes, it is indeed an issue. There should be a paging option in the settings but there's not.
To get around this, I suggest calling the REST API's directly. The only consideration is how you authenticate and if it were me, I'd be using a managed identity to do so.
I've mocked up a small example for you ...
The steps are ...
Create a variable that stores the nextLink property. Initialise it with the initial URL for the first call to the REST API, it looks something like this ... https://my-test-kv.vault.azure.net/secrets?maxresults=25&api-version=7.3 ... and is straight out of the doco ... https://learn.microsoft.com/en-us/rest/api/keyvault/secrets/get-secrets/get-secrets?tabs=HTTP
In the HTTP call as shown, use the Next Link variable given that will contain the URL. As for authentication, my suggestion is to use a managed identity. If you're unsure how to do that, sorry but it's a whole other question. In simple terms, go to the Identity tab on the LogicApp and switch on the system managed status to on. You'll then need to assign it access in the KeyVault itself (Key Vault Secrets User or Officer will do the job).
Next, create an Until action and set the left hand side to be the Next Link variable with the equal to value being expression string('') which will check for a blank string (that's how I like to do it).
Finally, set the value of the Next Link value to the property in the response from the last call, the expression is ... body('HTTP')?['nextLink']
From here, you can choose what you do with the output, I'd suggest creating an array and appending all of the entries to that array so you can process it later. I haven't taken the answer that far given I don't know the exactness of how you want to process the results.
That should get you across the line.

Access every variable individually in quick.db?

I code a discord bot in discord.js and I have an economy with hunger and fun as a variable. I want those variables to decrease over time, and I would need a for loop to do this, but I don't know how I would access every single account hunger variable. Normally what I would do to change something is have the user be the message author id but since it happens at all times i cant connect it to a authors message.

USPS API for Address Correction Response Question

I want to use the USPS API https://www.usps.com/business/web-tools-apis/address-information-api.htm for correcting addresses typed into our application.
Specifically, I will add a little button next to the address that will allow the user send the typed address to the service and then confirm that that the returned address is the one they would like to replace it with.
I have seen other websites do this and I like it because the user has control over inserting errant addresses returned by USPS. [I am not saying that the USPS data is bad; the likely scenario is that the entered address is so bad the USPS guessed wrong].
Anyway, I am looking at the response sample for the verify service:
I am observing that only one guess at the real address is returned. Other services I have seen return multiple so the user can pick the best one.
Is there an option on the USPS API that will return multiple guesses for a single address?
Note: the Address ID='0' is for sending multiple addresses and being able to sort it out in the returned data.
The address you input contained the suite number (STE K) so there is no ambiguity with the result. It is a "precise match". If you remove the "STE K" from the input address, the response will contain a ZIP + 4, but the DPV parameters will indicate that the match is a "default match". This type of match occurs with high rises and apartment complexes, where there is a main street address which has a "default" ZIP+4, but there is frequently a better "precise" response if an apartment or suite identifier is provided. The precise response will typically have a different +4 and carrier route than the default response.

Watching for messages being deleted (and created to some extent) via the Gmail API

Is it possible to do this without storing state? I see that it's possible to watch for all labels except DRAFT, but when you fetch the history, it's impossible to filter by more than a label (at least according to the documentation: https://developers.google.com/gmail/api/v1/reference/users/history/list).
Backstory: when you type something in a message, upon draft saving you get a spam of messageAdded and messageDeleted for the draft. The first one is okay, since you can almost safely assume that if it's not there when you try to fetch it, it's a draft, if you're fast enough. For the latter, it's impossible to figure out if the message was a draft or not without storing that in advance.
Gmail API now returns the (full set of) labelIds as part of the messageAdded and messageDeleted in the history.list() response:
https://developers.google.com/gmail/api/release-notes#2015-06-22
So at least you can use that to ignore DRAFTs from the reply.

IMAP - JavaMail - How to know which messages to process?

What I want to achieve:
I am coding a Java program that uses IMAP to connect to some gmail accounts every 5 minutes and extract information from some messages.
I want to check all the messages (incoming and outgoing) and take only the ones I have not processed. By "processed" I do not mean only "read" or "seen" messages. My application does not care whether or not another user has accessed that account and read a message. My application needs to keep track of which was the last message it processed and, the next time it goes through the messages, start with the first non-processed message.
I do not want to change anything in the messages. I do not want to mark them as seen or read.
What I have implemented:
Establish IMAP connection.
Open and access all messages in "[Gmail]/All Mail" folder.
What I have tried:
I have been reading about UID and message number, but I am not sure if any of them could help me achieve what I want. Maybe UID could, but: how do I retrieve it with JavaMail?
I found Folder.getMessages(int start, int end), but I think it refers to the index of the message in a folder, which I believe can easily change.
Can anyone provide some guidance at what is the best approach to take here?
Thanks!
IMAP UIDs are relative to the folder containing the message. I don't know how Gmail handles UIDs for messages in the "[Gmail]/All Mail" folder, but if it does the right thing you could use the UIDFolder interface to get the UIDs. And as described, once you've processed a certain UID, all the new messages will have larger UIDs, which can make processing more efficient.
The alternative is to use Message-IDs, which has a different set of problems...

Resources