Skip to content
Ethosa edited this page Mar 13, 2020 · 10 revisions

The main module in Shizuka.

Authorization

User

Via Login and password:

import shizuka

var vk = Vk("89123456789", "your password", debug=true) # debug param optional.

Via access_token:

import shizuka

var vk = Vk(access_token="your access token here", debug=true)

Group

import shizuka

var vk = Vk(access_token="your access token here", group_id=123456789, debug=true)

Calling methods

Sync

Without macro:

var response = vk.call_method("users.get", %*{"user_ids": "akihayase"})

With ~ macro:

var response = vk~users.get(user_ids="akihayase")

Async

Without macro:

var response = waitFor vk.call_method("users.get", %*{"user_ids": "akihayase"})

With ~ macro:

var response = waitFor vk~users.get(user_ids="akihayase")

Receiving real-time events

Without macro

for event in vk.longpoll.listen():
  if event["type"].getStr == "message_new":
    echo event

With eventhandler macro

var vk = Vk(...)

# This proc will called when got new event with type "message_new".
proc message_new(event: JsonNode) {. eventhandler: vk .} =
  echo event

vk.start_listen

With @ macro

var vk = Vk(...)

vk@message_new(event):
  echo event

vk.start_listen
Clone this wiki locally