Superalgos Network: Bot Profile Stats Implemented
This commit is contained in:
1 parent
d866b898cd
commit
4a202b909a
6 files changed
+84
-17
No files matched your search
@@ -20,7 +20,8 @@ global.NT = {
|
||||
EVENT: require('./Event.js'),
|
||||
POST: require('./Post.js'),
|
||||
QUERY: require('./Query.js'),
|
||||
QUERY_PROFILE_STATS: require('./Queries/ProfileStats.js'),
|
||||
QUERY_USER_PROFILE_STATS: require('./Queries/UserProfileStats.js'),
|
||||
QUERY_BOT_PROFILE_STATS: require('./Queries/BotProfileStats.js'),
|
||||
QUERY_PROFILE_POSTS: require('./Queries/ProfilePosts.js'),
|
||||
QUERY_POST_REPLIES: require('./Queries/ProfileReplies.js'),
|
||||
QUERY_EVENTS: require('./Queries/Events.js')
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
exports.newBotProfileStats = function newBotProfileStats() {
|
||||
|
||||
let thisObject = {
|
||||
profile: undefined,
|
||||
execute: execute,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
thisObject.profile = undefined
|
||||
}
|
||||
|
||||
function initialize(queryReceived) {
|
||||
/*
|
||||
Validate Bot Profile
|
||||
*/
|
||||
let userProfile
|
||||
if (queryReceived.targetBotProfileId !== undefined) {
|
||||
userProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId)
|
||||
} else {
|
||||
userProfile = NT.memory.maps.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileId)
|
||||
}
|
||||
|
||||
if (userProfile === undefined) {
|
||||
throw ('Target User Profile Not Found.')
|
||||
}
|
||||
/*
|
||||
Validate Bot Profile
|
||||
*/
|
||||
thisObject.profile = userProfile.bots.get(queryReceived.targetBotProfileId)
|
||||
if (thisObject.profile === undefined) {
|
||||
throw ('Target Bot Profile Not Found.')
|
||||
}
|
||||
}
|
||||
|
||||
function execute() {
|
||||
|
||||
return {
|
||||
"botProfileId": thisObject.profile.botProfileId,
|
||||
"botProfileHandle": thisObject.profile.botProfileHandle,
|
||||
"ranking": thisObject.profile.ranking,
|
||||
"followingCount": thisObject.profile.followingCount,
|
||||
"followersCount": thisObject.profile.followersCount,
|
||||
"emitterEventsCount": thisObject.profile.emitterEventsCount,
|
||||
"targetEventsCount": thisObject.profile.targetEventsCount,
|
||||
"postsCount": thisObject.profile.postsCount
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -130,13 +130,13 @@ exports.newEvents = function newEvents() {
|
||||
Test #1 : The Emitter or Target profile must be the same as the Query Profile.
|
||||
*/
|
||||
if (emitterUserProfile !== undefined) {
|
||||
if (emitterUserProfile.userProfieId === thisObject.profile.userProfieId) {
|
||||
if (emitterUserProfile.userProfileId === thisObject.profile.userProfileId) {
|
||||
addToResponse(event)
|
||||
return
|
||||
}
|
||||
}
|
||||
if (targetUserProfile !== undefined) {
|
||||
if (targetUserProfile.userProfieId === thisObject.profile.userProfieId) {
|
||||
if (targetUserProfile.userProfileId === thisObject.profile.userProfileId) {
|
||||
addToResponse(event)
|
||||
return
|
||||
}
|
||||
@@ -145,13 +145,13 @@ exports.newEvents = function newEvents() {
|
||||
Test #2 : The Emitter or Traget profile must be at the Following map of the Query Profile.
|
||||
*/
|
||||
if (emitterUserProfile !== undefined) {
|
||||
if (thisObject.profile.following.get(emitterUserProfile.userProfieId) !== undefined) {
|
||||
if (thisObject.profile.following.get(emitterUserProfile.userProfileId) !== undefined) {
|
||||
addToResponse(event)
|
||||
return
|
||||
}
|
||||
}
|
||||
if (targetUserProfile !== undefined) {
|
||||
if (thisObject.profile.following.get(targetUserProfile.userProfieId) !== undefined) {
|
||||
if (thisObject.profile.following.get(targetUserProfile.userProfileId) !== undefined) {
|
||||
addToResponse(event)
|
||||
return
|
||||
}
|
||||
@@ -200,15 +200,17 @@ exports.newEvents = function newEvents() {
|
||||
}
|
||||
|
||||
if (emitterUserProfile !== undefined) {
|
||||
let query = NT.modules.QUERY_PROFILE_STATS.newProfileStats()
|
||||
let query = NT.modules.QUERY_PROFILE_STATS.newUserProfileStats()
|
||||
query.initialize({ targetUserProfileId: event.emitterUserProfileId })
|
||||
eventResponse.emitterUserProfile = query.execute()
|
||||
query.finalize()
|
||||
}
|
||||
|
||||
if (targetUserProfile !== undefined) {
|
||||
let query = NT.modules.QUERY_PROFILE_STATS.newProfileStats()
|
||||
let query = NT.modules.QUERY_PROFILE_STATS.newUserProfileStats()
|
||||
query.initialize({ targetUserProfileId: event.targetUserProfileId })
|
||||
eventResponse.targetUserProfile = query.execute()
|
||||
query.finalize()
|
||||
}
|
||||
|
||||
if (emitterPost !== undefined) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
exports.newProfileStats = function newProfileStats() {
|
||||
exports.newUserProfileStats = function newUserProfileStats() {
|
||||
|
||||
let thisObject = {
|
||||
profile: undefined,
|
||||
@@ -10,7 +10,7 @@ exports.newProfileStats = function newProfileStats() {
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
|
||||
thisObject.profile = undefined
|
||||
}
|
||||
|
||||
function initialize(queryReceived) {
|
||||
@@ -32,7 +32,7 @@ exports.newProfileStats = function newProfileStats() {
|
||||
function execute() {
|
||||
|
||||
return {
|
||||
"userProfieId": thisObject.profile.userProfieId,
|
||||
"userProfileId": thisObject.profile.userProfileId,
|
||||
"userProfileHandle": thisObject.profile.userProfileHandle,
|
||||
"blockchainAccount": thisObject.profile.blockchainAccount,
|
||||
"ranking": thisObject.profile.ranking,
|
||||
+18
-6
@@ -10,10 +10,11 @@ exports.newQuery = function newQuery() {
|
||||
|
||||
const QUERY_TYPES = {
|
||||
|
||||
PROFILE_STATS: 0,
|
||||
PROFILE_POSTS: 1,
|
||||
POST_REPLIES: 2,
|
||||
EVENTS: 3
|
||||
USER_PROFILE_STATS: 0,
|
||||
BOT_PROFILE_STATS: 1,
|
||||
PROFILE_POSTS: 2,
|
||||
POST_REPLIES: 3,
|
||||
EVENTS: 4
|
||||
|
||||
}
|
||||
|
||||
@@ -30,27 +31,38 @@ exports.newQuery = function newQuery() {
|
||||
|
||||
switch (thisObject.queryType) {
|
||||
|
||||
case QUERY_TYPES.PROFILE_STATS: {
|
||||
thisObject.query = NT.modules.QUERY_PROFILE_STATS.newProfileStats()
|
||||
case QUERY_TYPES.USER_PROFILE_STATS: {
|
||||
thisObject.query = NT.modules.QUERY_USER_PROFILE_STATS.newUserProfileStats()
|
||||
query.initialize(queryReceived)
|
||||
query.finalize()
|
||||
break
|
||||
}
|
||||
|
||||
case QUERY_TYPES.BOT_PROFILE_STATS: {
|
||||
thisObject.query = NT.modules.QUERY_BOT_PROFILE_STATS.newBotProfileStats()
|
||||
query.initialize(queryReceived)
|
||||
query.finalize()
|
||||
break
|
||||
}
|
||||
|
||||
case QUERY_TYPES.PROFILE_POSTS: {
|
||||
thisObject.query = NT.modules.QUERY_PROFILE_POSTS.newProfilePosts()
|
||||
query.initialize(queryReceived)
|
||||
query.finalize()
|
||||
break
|
||||
}
|
||||
|
||||
case QUERY_TYPES.POST_REPLIES: {
|
||||
thisObject.query = NT.modules.QUERY_POST_REPLIES.newPostReplies()
|
||||
query.initialize(queryReceived)
|
||||
query.finalize()
|
||||
break
|
||||
}
|
||||
|
||||
case QUERY_TYPES.maps.EVENTS: {
|
||||
thisObject.query = NT.modules.QUERY_EVENTS.newEvents()
|
||||
query.initialize(queryReceived)
|
||||
query.finalize()
|
||||
break
|
||||
}
|
||||
default: throw('Query Type Not Supported.')
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
exports.newUserProfile = function newUserProfile() {
|
||||
|
||||
let thisObject = {
|
||||
userProfieId: undefined,
|
||||
userProfileId: undefined,
|
||||
userProfileHandle: undefined,
|
||||
blockchainAccount: undefined,
|
||||
ranking: undefined,
|
||||
|
||||
Reference in new issue
Block a user