ba0f3 / telebot.nim

Async Telegram Bot API Client implement in @Nim-Lang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

setMyCommands compiler error

Newrite opened this issue · comments

First of all English is not my mother language, so...

To reproduce:

import telebot

const API_TOKEN = "token"

let command = telebot.BotCommand(command: "command", description: "Return you command")

let bot = newTeleBot(API_TOKEN)
discard bot.setMyCommands(@[command])

first error (i found it mb a compiller bug)

PS G:\Programming\Languages\Nim\HelloTwo> nim r -d:ssl .\main.nim
Hint: used config file 'G:\Programming\nim\config\nim.cfg' [Conf]
Hint: used config file 'G:\Programming\nim\config\config.nims' [Conf]
.............................................................
G:\Programming\Languages\Nim\HelloTwo\main.nim(11, 12) template/generic instantiation of `setMyCommands` from here
C:\Users\nirn2\.nimble\pkgs\telebot-1.0.9\telebot\private\api.nim(1002, 7) Error: redefinition of 'json'; previous declaration here: C:\Users\nirn2\.nimble\pkgs\telebot-1.0.9\telebot\private\api.nim(998, 7)
PS G:\Programming\Languages\Nim\HelloTwo>

Well, small fix setMyCommands json's variables names:

proc setMyCommands*(b: TeleBot, commands: seq[BotCommand], scope = BotCommandScopeDefault, languageCode = ""): Future[bool] {.async.} =
  var data = newMultipartData()
  var json  = ""
  marshal(commands, json)
  data["commands"] = json

  var json = ""
  marshal(scope, json)
  data["scope"] = json

  if languageCode.len != 0:
    data["language_code"] = languageCode

  let res = await makeRequest(b, procName, data)
  result = res.toBool

To

proc setMyCommands*(b: TeleBot, commands: seq[BotCommand], scope = BotCommandScopeDefault, languageCode = ""): Future[bool] {.async.} =
var data = newMultipartData()
var jsonCommands  = ""
marshal(commands, jsonCommands)
data["commands"] = jsonCommands

var jsonScope = ""
marshal(scope, jsonScope)
data["scope"] = jsonScope

if languageCode.len != 0:
  data["language_code"] = languageCode

let res = await makeRequest(b, procName, data)
result = res.toBool

And now we have another compiller error

PS G:\Programming\Languages\Nim\HelloTwo> nim r -d:ssl .\main.nim
Hint: used config file 'G:\Programming\nim\config\nim.cfg' [Conf]
Hint: used config file 'G:\Programming\nim\config\config.nims' [Conf]
.............................................................
G:\Programming\Languages\Nim\HelloTwo\main.nim(8, 12) template/generic instantiation of `setMyCommands` from here
C:\Users\nirn2\.nimble\pkgs\telebot-1.0.9\telebot\private\api.nim(1003, 10) Error: type mismatch: got <type BotCommandScopeDefault, string>
but expected one of:
proc marshal[T](t: T; s: var string)
first type mismatch at position: 1
required type for t: T
but expression 'scope' is of type: type BotCommandScopeDefault

expression: marshal(scope, jsonScope)
PS G:\Programming\Languages\Nim\HelloTwo>

I'am new in Nim and i don't know what can i do with this.

nim version

PS G:\Programming\Languages\Nim\HelloTwo> nim --version
Nim Compiler Version 1.4.8 [Windows: amd64]
Compiled at 2021-05-25
Copyright (c) 2006-2021 by Andreas Rumpf

active boot switches: -d:release
PS G:\Programming\Languages\Nim\HelloTwo>

Hi! I check with last commit and now it's work, thanks!