Adding, Removing, Enabling and Deleting Bots
This commit is contained in:
1 parent
9a4aadc14d
commit
99eead9640
8 files changed
+161
-91
No files matched your search
@@ -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')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
+55
-6
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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.
|
||||
@@ -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"
|
||||
}
|
||||
]
|
||||
+74
-4
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user