Lists
Use Lists to store large amounts of data. List is a quick way to get and search data. Also list is preferred way for organize statistics.
List - it is a collection of properties or users.
Examples:
  • history (orders history, transactions, payments history, locations history, etc)
  • large price lists
  • table of cities with population
  • results for Inline Bot​
  • referrals list
Do not use JSON property to collect a large array. This is a very bad practice.
"Execution timeout" error - it is typical error if you use JSON prop for large data.
Use a List.

List initialization

Before using the list (new or existing), you need to initialize it.
List can be global for Bot:
1
let list = new List({ name: "MyList" })
2
​
3
Bot.inspect(list.exist) // false for new List, true for already exist list
Copied!
or can be personal for user:
1
let list = new List({ name: "MyList", user: user })
2
​
3
// or for user id
4
let list = new List({ name: "MyList", user_id: user.id })
Copied!
After it you can perform another list methods

Create new list

1
list.create();
Copied!

Remove list

1
list.remove();
Copied!

Recount list

Recalculate all statistical data in list.
Can spent 5-30 seconds and more for big list. So you need perform this task on background once in week/day or hour.
1
list.recount({
2
// this command will be runned after recount
3
// onComplete: 'onCompleteListRecount'
4
});
Copied!

Calculate the amount of all props and users

Need recount before
1
list.total; // integer value
Copied!

Properties management

Add property to bot list

Bot property is always add to List for bot
1
Bot.setProperty({
2
name: 'stringProp',
3
value: 'Bad Apple',
4
type: 'string',
5
list: 'MyList' // bot list will be created if not exist
6
});
Copied!

Add property to user list

User property is always add to List for user
1
User.setProperty({
2
name: "stringProp",
3
value: "Bad Apple",
4
type: "string",
5
list: "MyList" // bot list will be created if not exist
6
});
Copied!

Reject property

Reject property from list without destroying by prop name
1
list.rejectProperty("stringProp");
Copied!

Remove property

Reject property from list and destroy it by prop name
1
list.removeProperty("stringProp");
Copied!

Reject all properties (and all users)

Reject all properties from list
this method reject all properties and all users from list
1
list.rejectAll();
Copied!

Remove all properties (and reject all users)

Remove all properties from list
this method remove all properties and reject all users from list
1
list.rejectAll();
Copied!

Users management

Add user

1
list.addUser(user);
2
​
3
// or if you have id only
4
// list.addUser({ id: user.id });
Copied!

Reject user

Reject user from list
1
list.rejectUser(user);
2
// or by id
3
list.rejectUser({ id: user.id });
Copied!

Reject all users

Reject all users from list
1
list.rejectAllUsers();
Copied!

Getting data

Getting props from list

1
let props = list.get();
2
Bot.inspect(props[0])
3
​
4
/* result will be like:
5
{
6
"name": "stringProp",
7
"value": "Bad Apple",
8
"user": {
9
"id": null
10
},
11
"created_at": "2020-11-09T01:46:52.270Z",
12
"updated_at": "2020-11-09T01:46:52.270Z"
13
}
14
*/
Copied!

Getting users from list

1
let users = list.getUsers();
2
Bot.inspect(users[0])
Copied!

Paginating

We have pages for data. Data is given page by page from the first page.
One page have 100 items by default.
1
// page 1
2
let props = list.get();
3
let users = list.getUsers();
4
​
5
// page 2
6
list.page = 2
7
props = list.get(); // getting props from page 2
8
users = list.getUsers(); // getting users from page 2
9
​
10
// it is possible to change default per page
11
list.per_page = 10 // 100 by default
12
​
13
// total pages
14
let total_pages = list.total_pages;
Copied!

Ordering

Default order is ascending by id (prop's id or user's id)
1
// default order is ascending by id
2
let props = list.get();
3
props[0] // oldest prop in list
4
​
5
// Change order to descending:
6
list.order_ascending = false;
7
props[0] // newest prop in list
Copied!

Searching

Searching for text props

Searching is available for list's properties. (String and text props)
1
// search prop with text value "Apple"
2
// case sensetive by default
3
let props = list.search("Apple");
4
​
5
// case insensentive
6
list.case_sensitive = false;
7
// search props with text value "Apple", "apple", "aPpLe" and etc
8
props = list.search("Apple");
9
​
10
// search props started with text "apple"
11
props = list.search("%Apple");
12
​
13
// search props ended with text "apple"
14
props = list.search("Apple%");
15
​
16
// search props contains text "apple"
17
props = list.search("%Apple%");
18
​
19
​
Copied!
  • Percent sign ( %) matches any sequence of zero or more characters.
  • Underscore sign ( _) matches any single character.
Ordering and paginating also works with searching
1
list.page = 2;
2
list.order_ascending = false;
3
let props = list.search("Apple");
Copied!

User searching

Getting user by id from list

1
// getting user from list if exist
2
list.getUser({ id: user.id })
Copied!

Checking the user's existence in the list

1
list.haveUser(user)
2
​
3
// or by id:
4
list.haveUser({ id: user.id })
Copied!

Statistics

Is available for integer and float props
Need recount before
1
list.count // total props + users count
2
list.total_value // sum of all props
3
list.average_value // average of all props
4
list.max_value
5
list.min_value
Copied!
​
Last modified 4d ago