From 99eead96408de297b8e4c00ae607a72dc5f5ce52 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 26 Aug 2021 13:04:44 +0200 Subject: [PATCH] Adding, Removing, Enabling and Deleting Bots --- Network/{node.js => NetwokNode.js} | 6 ++- Network/bot.js | 28 +++++++++++ Network/event.js | 61 ++++++++++++++++++++--- Network/events.json | 10 ---- Network/graph.json | 20 -------- Network/profiles.json | 22 --------- Network/timeline.json | 27 ----------- Network/userProfile.js | 78 ++++++++++++++++++++++++++++-- 8 files changed, 161 insertions(+), 91 deletions(-) rename Network/{node.js => NetwokNode.js} (78%) create mode 100644 Network/bot.js delete mode 100644 Network/events.json delete mode 100644 Network/graph.json delete mode 100644 Network/profiles.json delete mode 100644 Network/timeline.json diff --git a/Network/node.js b/Network/NetwokNode.js similarity index 78% rename from Network/node.js rename to Network/NetwokNode.js index e218c488c..ff93a2489 100644 --- a/Network/node.js +++ b/Network/NetwokNode.js @@ -8,8 +8,10 @@ global.NT = { TIMELINE: [] // A time ordered list of Posts and Trades. }, modules: { - EVENT: require('./event.js'), - POST: require('./post.js') + EVENT: require('./UserProfile.js'), + EVENT: require('./Event.js'), + POST: require('./Post.js'), + BOT: require('./Bot.js') } } diff --git a/Network/bot.js b/Network/bot.js new file mode 100644 index 000000000..b6ad63f2b --- /dev/null +++ b/Network/bot.js @@ -0,0 +1,28 @@ +exports.newBot = function newBot() { + + let thisObject = { + botId: undefined, + botAsset: undefined, + botExchange: undefined, + enabled: undefined, + initialize: initialize, + finalize: finalize + } + + return thisObject + + function finalize() { + + } + + function initialize( + botId, + botAsset, + botExchange + ) { + thisObject.botId = botId + thisObject.botAsset = botAsset + thisObject.botExchange = botExchange + thisObject.enabled = true + } +} \ No newline at end of file diff --git a/Network/event.js b/Network/event.js index 864b1b6b9..fe2311e53 100644 --- a/Network/event.js +++ b/Network/event.js @@ -12,18 +12,26 @@ exports.newEvent = function newEvent() { } const EVENT_TYPES = { + NEW_MULTI_MEDIA_POST: 10, REPLY_TO_MULTI_MEDIA_POST: 11, REPOST_MULTI_MEDIA: 12, QUOTE_REPOST_MULTI_MEDIA: 13, FOLLOW_USER_PROFILE_MULTI_MEDIA_POSTS: 14, UNFOLLOW_USER_PROFILE_MULTI_MEDIA_POSTS: 15, + NEW_TRADE_POST: 20, REPLY_TO_TRADE_POST: 21, RE_POST_TRADE: 22, QUOTE_REPOST_TRADE: 23, FOLLOW_USER_PROFILE_TRADE_POSTS: 24, UNFOLLOW_USER_PROFILE_TRADE_POSTS: 25, + + ADD_BOT: 50, + REMOVE_BOT: 51, + ENABLE_BOT: 52, + DISABLE_BOT: 53, + ADD_REACTION_LIKE: 100, ADD_REACTION_LOVE: 101, ADD_REACTION_HAHA: 102, @@ -31,6 +39,7 @@ exports.newEvent = function newEvent() { ADD_REACTION_SAD: 104, ADD_REACTION_ANGRY: 105, ADD_REACTION_HUG: 106, + REMOVE_REACTION_LIKE: 200, REMOVE_REACTION_LOVE: 201, REMOVE_REACTION_HAHA: 202, @@ -58,8 +67,10 @@ exports.newEvent = function newEvent() { "targetUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", "emitterPostHash": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", "targetPostHash": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", - "asset": "BTC", - "timestamp": 124234234234 + "timestamp": 124234234234, + "botId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", + "botAsset": "BTC", + "botExchange": "Binance" } */ @@ -77,9 +88,9 @@ exports.newEvent = function newEvent() { if ( event.eventType !== EVENT_TYPES.NEW_MULTI_MEDIA_POST && event.eventType !== EVENT_TYPES.NEW_TRADE_POST - ) { - throw ('Target User Profile Not Found.') - } + ) { + throw ('Target User Profile Not Found.') + } } else { thisObject.targetUserProfile.targetEventsCount++ } @@ -88,7 +99,6 @@ exports.newEvent = function newEvent() { thisObject.eventType = event.eventType thisObject.asset = event.asset thisObject.timestamp = event.timestamp - /* Is is a new post? */ @@ -201,5 +211,44 @@ exports.newEvent = function newEvent() { targetPost.removeReaction(event.eventType - 200) return } + /* + Is is a Bot? + */ + if ( + event.eventType === EVENT_TYPES.ADD_BOT || + event.eventType === EVENT_TYPES.REMOVE_BOT || + event.eventType === EVENT_TYPES.ENABLE_BOT || + event.eventType === EVENT_TYPES.DISABLE_BOT + ) { + switch (event.eventType) { + case EVENT_TYPES.ADD_BOT: { + thisObject.emitterUserProfile.addBot( + thisObject.botId, + thisObject.botAsset, + thisObject.botExchange + ) + break + } + case EVENT_TYPES.REMOVE_BOT: { + thisObject.emitterUserProfile.removeBot( + thisObject.botId + ) + break + } + case EVENT_TYPES.ENABLE_BOT: { + thisObject.emitterUserProfile.enableBot( + thisObject.botId + ) + break + } + case EVENT_TYPES.DISABLE_BOT: { + thisObject.emitterUserProfile.disableBot( + thisObject.botId + ) + break + } + } + return + } } } \ No newline at end of file diff --git a/Network/events.json b/Network/events.json deleted file mode 100644 index 6eb03cb88..000000000 --- a/Network/events.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "eventId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", - "eventType": 10, - "emitterUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", - "targetUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", - "asset": "BTC", - "timestamp": 124234234234, - "postHash": "dasdhqJKGdadjlasgjaGSHAJGSDjhagsg", - "postId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db" -} diff --git a/Network/graph.json b/Network/graph.json deleted file mode 100644 index a3bb947fa..000000000 --- a/Network/graph.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "userProfiles": [ - { - "username": "Luis-Fernando-Molina", - "id": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", - "posts": [ - { - "id": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", - "replyTo": "a8de78f0-c3e4-4a2a-b7e8-f659073969db" - } - ], - "replies": [ - { - "id": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", - "replyTo": "a8de78f0-c3e4-4a2a-b7e8-f659073969db" - } - ] - } - ] -} \ No newline at end of file diff --git a/Network/profiles.json b/Network/profiles.json deleted file mode 100644 index fd6386178..000000000 --- a/Network/profiles.json +++ /dev/null @@ -1,22 +0,0 @@ -[ - { - "userProfile": "Luis-Fernando-Molina", - "id": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", - "followers": 0, - "following": 0, - "ranking": 0, - "joined": 123423423423, - "account": "asd23123aff23q2bcaa21447567" - }, - { - "userProfile": "Luis-Fernando-Molina", - "id": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", - "followers": 0, - "following": 0, - "ranking": 0, - "joined": 123423423423, - "account": "asd23123aff23q2bcaa21447567" - } -] - -// a map by userProfile would be needed. \ No newline at end of file diff --git a/Network/timeline.json b/Network/timeline.json deleted file mode 100644 index f7e9ab17c..000000000 --- a/Network/timeline.json +++ /dev/null @@ -1,27 +0,0 @@ -[ - { - "type": "post", - "timestamp": 12343242342, - "userProfile": "Luis-Fernando-Molina", - "hash": "dhaHSkjasdmwhdajSHSJhewshed" - }, - { - "type": "post", - "timestamp": 12343242342, - "userProfile": "Luis-Fernando-Molina", - "hash": "dhaHSkjasdmwhdajSHSJhewshed", - "relatedEvent": "daawerewdhkasdSdGHGjdsasd" - }, - { - "type": "trade", - "timestamp": 12343242342, - "userProfile": "Luis-Fernando-Molina", - "hash": "dhaHSkjasdmwhdajSHSJhewshed" - }, - { - "type": "post", - "timestamp": 12343242342, - "userProfile": "Luis-Fernando-Molina", - "hash": "dhaHSkjasdmwhdajSHSJhewshed" - } -] \ No newline at end of file diff --git a/Network/userProfile.js b/Network/userProfile.js index 476397d58..40208b147 100644 --- a/Network/userProfile.js +++ b/Network/userProfile.js @@ -16,14 +16,19 @@ exports.newUserProfile = function newUserProfile() { emitterEventsCount: undefined, targetEventsCount: undefined, postsCount: undefined, - addMultiMediaPostsFollowing: addMultiMediaPostsFollowing, - removeMultiMediaPostsFollowing: removeMultiMediaPostsFollowing, - addTradePostsFollowing: addTradePostsFollowing, + bots: undefined, + addMultiMediaPostsFollowing: addMultiMediaPostsFollowing, + removeMultiMediaPostsFollowing: removeMultiMediaPostsFollowing, + addTradePostsFollowing: addTradePostsFollowing, removeTradePostsFollowing: removeTradePostsFollowing, addMultiMediaPostsFollower: addMultiMediaPostsFollower, removeMultiMediaPostsFollower: removeMultiMediaPostsFollower, addTradePostsFollower: addTradePostsFollower, removeTradePostsFollower: removeTradePostsFollower, + addBot: addBot, + removeBot: removeBot, + enableBot: enableBot, + disableBot: disableBot, initialize: initialize, finalize: finalize } @@ -31,7 +36,13 @@ exports.newUserProfile = function newUserProfile() { return thisObject function finalize() { + thisObject.multiMediaPostsFollowing = undefined + thisObject.multiMediaPostsFollowers = undefined + thisObject.tradePostsFollowing = undefined + thisObject.tradePostsFollowers = undefined + + thisObject.bots = undefined } function initialize() { @@ -50,8 +61,9 @@ exports.newUserProfile = function newUserProfile() { thisObject.targetEventsCount = 0 thisObject.postsCount = 0 + thisObject.bots = new Map() } - + function addMultiMediaPostsFollowing( userProfile ) { @@ -123,4 +135,62 @@ exports.newUserProfile = function newUserProfile() { thisObject.tradePostsFollowersCount-- } } + + function addBot( + botId, + botAsset, + botExchange + ) { + if (thisObject.bots.get(botId) !== undefined) { + throw ('Bot Already Exists.') + } + + let bot = NT.modules.BOTS.newBot() + bot.initialize( + botId, + botAsset, + botExchange + ) + thisObject.bots.set(botId, bot) + } + + function removeBot( + botId + ) { + if (thisObject.bots.get(botId) === undefined) { + throw ('Bot Does Not Exist.') + } + + thisObject.bots.delete(botId) + } + + function enableBot( + botId + ) { + let bot = thisObject.bots.get(botId) + if (bot === undefined) { + throw ('Bot Does Not Exist.') + } + + if (bot.enabled === true) { + throw ('Bot Already Enabled.') + } + + bot.enabled = true + } + + function disableBot( + botId + ) { + let bot = thisObject.bots.get(botId) + if (bot === undefined) { + throw ('Bot Does Not Exist.') + } + + if (bot.enabled === false) { + throw ('Bot Already Disabled.') + } + + bot.enabled = false + } } \ No newline at end of file