Sequelize rounding id - javascript

I'm using Sequelize with SQLite on NodeJS. I have a User table in which I store IDs (16 chars long. Example: 795051544012783646). Whenever I query the DB for a specific user, it does something weird with it's ID:
user {
dataValues: {
id: 218062175636291600,
name: 'Raki',
balance: 0,
ap: 0,
objCount: 0
},
_previousDataValues: {
id: 218062175636291600,
name: 'Raki',
balance: 0,
ap: 0,
objCount: 0
},
uniqno: 1,
_changed: Set(0) {},
_options: {
isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
raw: true,
attributes: [ 'id', 'name', 'balance', 'ap', 'objCount' ]
},
isNewRecord: false
}
The ID should be 218062175636291586, but it shows 218062175636291600. It's worth noting that the DB itself stores it as it is (it works perfectly).
What I tried
My User model declares IDs as INTEGERs, so I switched them to BIGINTs. Didn't work.

Related

How to read through object of server roles Discord.js

I have the following code, which basically assigns a RoleManager object to the variable roles
var roles = receivedMessage.guild.roles;
console.log(roles['cache']);
Now, the log returns some mess that (partially) looks like this:
Collection [Map] {
'529502688183058443' => Role {
guild: Guild {
members: [GuildMemberManager],
channels: [GuildChannelManager],
roles: [RoleManager],
presences: [PresenceManager],
voiceStates: [VoiceStateManager],
deleted: false,
available: true,
id: '529502688183058443',
shardID: 0,
name: 'GuyDyamond Studios',
icon: '36e1f32f9fc98818872ca4583d50cc52',
splash: null,
discoverySplash: null,
region: 'us-east',
memberCount: 6,
large: false,
features: [],
applicationID: null,
afkTimeout: 300,
afkChannelID: null,
systemChannelID: '529502688183058445',
embedEnabled: undefined,
premiumTier: 0,
premiumSubscriptionCount: 0,
verificationLevel: 'MEDIUM',
explicitContentFilter: 'DISABLED',
mfaLevel: 0,
joinedTimestamp: 1600020773558,
defaultMessageNotifications: 'ALL',
systemChannelFlags: [SystemChannelFlags],
maximumMembers: 250000,
vanityURLCode: null,
vanityURLUses: null,
description: null,
banner: null,
rulesChannelID: null,
publicUpdatesChannelID: null,
preferredLocale: 'en-US',
ownerID: '423162345108275213',
emojis: [GuildEmojiManager]
},
id: '529502688183058443',
name: '#everyone',
color: 0,
hoist: false,
rawPosition: 0,
permissions: Permissions { bitfield: 104324673 },
managed: false,
mentionable: false,
deleted: false
},
'529672467200081922' => Role {
guild: Guild {
members: [GuildMemberManager],
channels: [GuildChannelManager],
roles: [RoleManager],
presences: [PresenceManager],
voiceStates: [VoiceStateManager],
deleted: false,
available: true,
id: '529502688183058443',
shardID: 0,
name: 'GuyDyamond Studios',
icon: '36e1f32f9fc98818872ca4583d50cc52',
splash: null,
discoverySplash: null,
region: 'us-east',
memberCount: 6,
large: false,
features: [],
applicationID: null,
afkTimeout: 300,
afkChannelID: null,
systemChannelID: '529502688183058445',
embedEnabled: undefined,
premiumTier: 0,
premiumSubscriptionCount: 0,
verificationLevel: 'MEDIUM',
explicitContentFilter: 'DISABLED',
mfaLevel: 0,
joinedTimestamp: 1600020773558,
defaultMessageNotifications: 'ALL',
systemChannelFlags: [SystemChannelFlags],
maximumMembers: 250000,
vanityURLCode: null,
vanityURLUses: null,
description: null,
banner: null,
rulesChannelID: null,
publicUpdatesChannelID: null,
preferredLocale: 'en-US',
ownerID: '423162345108275213',
emojis: [GuildEmojiManager]
},
Now, I've literally tried everything, but I can't seem to iterate over the object roles. I've tried a forEach function, a for...in... loop, etc etc, nothing. Additionally, I'm trying to get the name of each role and put it in an array, but I can't seem to get the name parameter. Any help on how to do this?
If all you need is the names, you can use Array.prototype.map:
console.log(
recievedMessage.guild.roles.cache.map((role) => role.name)
);
Example result:
['Admin', 'Mod', 'VIP', 'Member', 'Muted', '#everyone']
To iterate a function through every role, use:
recievedMessage.guild.roles.cache.forEach((role) => {
console.log(role.id);
});

Mongoose allows non existed field for sorting. How can I restrict for existed fields only?

Below query returns data but hgf field does not exist in document(db). How can I restrict sorting only for existed fields?
files.find({ account_id: 1, deleted_at: { '$eq': null },
status: { '$ne': 3 }}, { skip: 0, limit: 100, sort: { hgf: -1 }, projection: {} });
This should work:
files.find({
account_id: 1,
deleted_at: { '$eq': null },
status: { '$ne': 3 },
hgf: { $exists: true, $ne: null } // Check it exists and not null
}, { skip: 0, limit: 100, sort: { hgf: -1 }, projection: {} });

Get random Discord user

Im creating a bot that taggs a random user, but im having some difficulties.
How can I get a random user? Im currently doing this:
let usersCount = message.guild.memberCount;
let users = Array.from(message.guild.members);
let randomNumber = Math.floor(Math.random() * usersCount);
let randomUser = users[randomNumber];
console.log(randomUser);
But its returning this, with the whole guild:
[ '208045530369097728', GuildMember {
guild:
Guild {
members: [Object],
channels: [Object],
roles: [Object],
presences: [Object],
deleted: false,
available: true,
id: '4481898438608814093132',
name: 'bot test',
icon: '21cddd6a700aaff9b9ccb0c2c1b8de5e',
splash: null,
region: 'brazil',
memberCount: 71,
large: false,
features: [],
applicationID: null,
afkTimeout: 300,
afkChannelID: '448206219711217674',
systemChannelID: null,
embedEnabled: undefined,
verificationLevel: 0,
explicitContentFilter: 0,
mfaLevel: 0,
joinedTimestamp: 1535857830448,
defaultMessageNotifications: 'ALL',
ownerID: '2013795851090283612',
_rawVoiceStates: Collection {},
emojis: [Object] },
user:
User {
id: '2180145503619097728',
username: 'xxxx!',
discriminator: '4198',
avatar: 'a1fb0d1c273a18acc69fa9f796a8c7d7',
bot: false,
lastMessageID: null,
lastMessage: null },
joinedTimestamp: 1526933713197,
_roles:
[ '44811902750147915532',
'45769217147885815476',
'47113897343090168840' ],
serverDeaf: false,
serverMute: false,
selfMute: undefined,
selfDeaf: undefined,
voiceSessionID: undefined,
voiceChannelID: undefined,
speaking: false,
nickname: 'xxxx',
lastMessageID: null,
lastMessage: null,
deleted: false } ]
How can I get the user and tag him?
I already tried randomUser.user, returns undefined. I have no idea
Solved
var user = message.guild.members.random();
console.log(`${user.user}`);
let randomPer = message.guild.members.cache.random().user;
message.channel.send(`${randomPer}`)
This will mention a random user from your guild.

Accessing name and id of object - Javascript

So i have this following object in Javascript, and I am interested in only id: '410467873518256138', name: 'element1'
How can i extract this information from the object?
I tried storing it in object and doing object.id or object.name but it prints nothing.
'410467873518256138' => Emoji {
guild:
Guild {
members: [Object],
channels: [Object],
roles: [Object],
presences: [Object],
available: true,
id: '410467289767346186',
name: 'emoji_set4',
icon: null,
splash: null,
region: 'singapore',
memberCount: 2,
large: false,
features: [],
applicationID: null,
afkTimeout: 300,
afkChannelID: null,
systemChannelID: '410467289767346188',
embedEnabled: undefined,
verificationLevel: 0,
explicitContentFilter: 0,
joinedTimestamp: 1517933748730,
ownerID: '352458321456005123',
_rawVoiceStates: Collection {},
emojis: [Object] },
id: '410467873518256138',
name: 'element1',
requiresColons: true,
managed: false,
animated: false,
_roles: [] },
Also kindly explain what this syntax is '410467873518256138' => Emoji {, cause generally we write variable = {} to define an object.

Cant get the title from the following json

I have this code into my app that returns some job feed in json format:
My code looks as below:
JobFeed.find().sort('-created').exec(function (err, feeds) {
if (err) {
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});
} else {
_.forEach(feeds, function (row, key) {
console.log(row.data.title); // showing undefined
});
res.jsonp(feeds);
}
});
and the json looks like below:
{ data:
{ isSaved: null,
client:
{ lastContractTitle: null,
feedbackText: '4.78 Stars, based on 13 feedbacks',
paymentVerificationStatus: 1,
lastContractPlatform: null,
totalFeedback: 4.7819242373,
location: [Object],
lastContractRid: 0,
edcUserId: 3728985,
totalReviews: 13,
companyRid: 0,
spentTier: '$7,500+',
companyName: null },
amount: { amount: 0, currencyCode: 'USD' },
createdOn: '2016-10-13T06:30:54+00:00',
skills: [ [Object], [Object], [Object], [Object] ],
enterpriseJob: false,
ciphertext: '~01026b31d972ed826b',
proposalsTier: null,
description: 'Hello! We\'re currently searching for a developer with',
category2: 'Web, Mobile & Software Dev',
type: 2,
tierText: 'Intermediate ($$)',
relevance:
{ hoursInactive: 0,
id: 208660674,
publishTime: '1476340265000',
recommendedEffectiveCandidates: 2,
effectiveCandidates: 3,
uniqueImpressions: 0 },
isApplied: null,
engagement: '30+ hrs/week',
recno: 208660674,
title: 'Server-side and Client-side Game Developer for Indie MMO',
freelancersToHire: 0,
maxAmount: { amount: 0, currencyCode: 'USD' },
duration: 'More than 6 months',
subcategory2: 'Game Development',
sticky: false,
stickyLabel: '',
feedback: null },
id: 57ffcdbf717ca50cf0b4cbc1 }
{ data:
{ isSaved: null,
client:
{ lastContractTitle: null,
feedbackText: 'No feedback yet',
paymentVerificationStatus: 1,
lastContractPlatform: null,
totalFeedback: 0,
location: [Object],
lastContractRid: 0,
edcUserId: 0,
totalReviews: 0,
companyRid: 0,
spentTier: '$100+',
companyName: null },
amount: { amount: 0, currencyCode: 'USD' },
createdOn: '2016-10-13T06:30:51+00:00',
skills: [ [Object], [Object], [Object] ],
enterpriseJob: false,
ciphertext: '~01c59efb9135ed91d0',
proposalsTier: null,
description: 'Hello! We\'re currently searching for a developer with',
category2: 'Web, Mobile & Software Dev',
type: 2,
tierText: 'Entry Level ($)',
relevance:
{ hoursInactive: 0,
id: 208660673,
publishTime: '1476340266000',
recommendedEffectiveCandidates: 18,
effectiveCandidates: 74,
uniqueImpressions: 0 },
isApplied: null,
engagement: 'Less than 10 hrs/week',
recno: 208660673,
title: 'Wordpress & Stripe developer',
freelancersToHire: 0,
maxAmount: { amount: 0, currencyCode: 'USD' },
duration: 'More than 6 months',
subcategory2: 'Web Development',
sticky: false,
stickyLabel: '',
feedback: null },
id: 57ffcdbf717ca50cf0b4cbc2 }
{ data:
{ isSaved: null,
client:
{ lastContractTitle: null,
feedbackText: 'No feedback yet',
paymentVerificationStatus: 5,
lastContractPlatform: null,
totalFeedback: 0,
location: [Object],
lastContractRid: 0,
edcUserId: 0,
totalReviews: 0,
companyRid: 0,
spentTier: 'Less than $100',
companyName: null },
amount: { amount: 2000, currencyCode: 'USD' },
createdOn: '2016-10-13T06:30:18+00:00',
skills: [ [Object], [Object] ],
enterpriseJob: false,
ciphertext: '~0101449f91585e8e16',
proposalsTier: null,
description: 'I need a Christmas card app before 15th Dec.n',
category2: 'Web, Mobile & Software Dev',
type: 1,
tierText: 'Intermediate ($$)',
relevance:
{ hoursInactive: 0,
id: 208660669,
publishTime: '1476340233000',
recommendedEffectiveCandidates: 7,
effectiveCandidates: 52,
uniqueImpressions: 0 },
isApplied: null,
engagement: null,
recno: 208660669,
title: 'Christmas Card iPhone App',
freelancersToHire: 0,
maxAmount: { amount: 0, currencyCode: 'USD' },
duration: null,
subcategory2: 'Mobile Development',
sticky: false,
stickyLabel: '',
feedback: null },
id: 57ffcdbf717ca50cf0b4cbc3 }
{ data:
{ isSaved: null,
client:
{ lastContractTitle: null,
feedbackText: '4.88 Stars, based on 102 feedbacks',
paymentVerificationStatus: 1,
lastContractPlatform: null,
totalFeedback: 4.8843944128,
location: [Object],
lastContractRid: 0,
edcUserId: 0,
totalReviews: 102,
companyRid: 0,
spentTier: '$25,000+',
companyName: null },
amount: { amount: 100, currencyCode: 'USD' },
createdOn: '2016-10-13T06:30:00+00:00',
skills:
[ [Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object] ],
enterpriseJob: false,
ciphertext: '~01a04eab3b05372652',
proposalsTier: null,
description: 'Hello! We\'re currently searching for a developer with',
category2: 'Writing',
type: 1,
tierText: 'Entry Level ($)',
relevance:
{ hoursInactive: 0,
id: 208660668,
publishTime: '1476340202000',
recommendedEffectiveCandidates: 2,
effectiveCandidates: 6,
uniqueImpressions: 0 },
isApplied: null,
engagement: null,
recno: 208660668,
title: 'Filipino Blog/Content Writers For a Filipino Site (Using WordPress)',
freelancersToHire: 3,
maxAmount: { amount: 0, currencyCode: 'USD' },
duration: null,
subcategory2: 'Article & Blog Writing',
sticky: false,
stickyLabel: '',
feedback: null },
id: 57ffcdbf717ca50cf0b4cbc4 }
The foreach that I have, seems to iterate through each of items, but there is no way I can get the title for each item. Any Help?
I'm not really sure what you're trying to do, but something like this should work if the data is indeed what you have on your comments:
feeds.forEach(function(feed){
console.log(feed.data.title);
});
If you want faster performance, use the regular for loop. I tested this out on my project. Let me know if this doesn't work.

Categories