ba0f3 / telebot.nim

Async Telegram Bot API Client implement in @Nim-Lang
MIT License
165 stars 24 forks source link

RangeError when I start program #24

Closed altfoxie closed 5 years ago

altfoxie commented 5 years ago

Hello! When i start my program with any token - RangeError Program:


import telebot, asyncdispatch, logging, options, os
const API_KEY = ""

proc updateHandler(b: Telebot, u: Update) {.async.} =
  var response = u.message.get
  if response.text.isSome:
    let
      text = response.text.get
    var message = newMessage(response.chat.id, text)
    message.disableNotification = true
    message.replyToMessageId = response.messageId
    message.parseMode = "markdown"
    discard await b.send(message)

let bot = newTeleBot(API_KEY)
bot.onUpdate(updateHandler)
bot.poll(timeout=300)

Error:
main.nim(18)             main
api.nim(652)             poll
utils.nim(94)            unmarshal
utils.nim(155)           toOption
utils.nim(96)            unmarshal
system.nim(1280)         unmarshal
system.nim(2924)         sysFatal
Error: unhandled exception: value out of range: -1001457161642 [RangeError]
ba0f3 commented 5 years ago

what is your Nim version? and your cpu? do you using 32bit?

altfoxie commented 5 years ago

on versions 0.19.4 and 0.19.9 it's crashs. i am using x64 cpu and os.

what is your Nim version? and your cpu? do you using 32bit?

ba0f3 commented 5 years ago

hmm strange, it still works fine for me. make sure you have latest telebot version.

altfoxie commented 5 years ago

I have updated telebot. It still crash

hmm strange, it still works fine for me. make sure you have latest telebot version.

altfoxie commented 5 years ago

I created new bot, which not in group - no crashs

ba0f3 commented 5 years ago

please insert these lines bellow import section. and show me what it got before crashes:

var L = newConsoleLogger(fmtStr="$levelname, [$time] ")
addHandler(L)
altfoxie commented 5 years ago

Error in chat id. Maybe chat id is bigger than max permissible value of int

DEBUG, [22:03:07] Making request to https://api.telegram.org/botBOTTOKEN/getUpdates
DEBUG, [22:03:08] Result: [
  {
    "update_id": 813247778,
    "message": {
      "message_id": 28135,
      "from": {
        "id": 372525970,
        "is_bot": false,
        "first_name": "макс �️‍�⃠",
        "username": "MaKcyHOf"
      },
      "chat": {
        "id": -1001457161642,
        "title": "LC | FX 6300",
        "username": "l_chat",
        "type": "supergroup"
      },
      "date": 1551206490,
      "new_chat_participant": {
        "id": 707209775,
        "is_bot": true,
        "first_name": "jddjdj",
        "username": "ndxjjskskbot"
      },
      "new_chat_member": {
        "id": 707209775,
        "is_bot": true,
        "first_name": "jddjdj",
        "username": "ndxjjskskbot"
      },
      "new_chat_members": [
        {
          "id": 707209775,
          "is_bot": true,
          "first_name": "jddjdj",
          "username": "ndxjjskskbot"
        }
      ]
    }
  }
]
main.nim(20)             main
api.nim(652)             poll
utils.nim(94)            unmarshal
utils.nim(155)           toOption
utils.nim(96)            unmarshal
json.nim(1004)           unmarshal
system.nim(3059)         sysFatal
Error: unhandled exception: value out of range: -1001457161642 [RangeError]

please insert these lines bellow import section. and show me what it got before crashes:

var L = newConsoleLogger(fmtStr="$levelname, [$time] ")
addHandler(L)
ba0f3 commented 5 years ago

I think you compiled the program for 32bit CPU. But this is a bug anyway, I will fix it soon.

SolitudeSF commented 5 years ago

after this update i needed to update some ints in my bot to int64 which is to be expected, but then compiler complained that newPhoto proc accepts int, but not int64, so now i need to convert it back to int and it seems like its asking to break. have you missed something or am i misunderstanding?

ba0f3 commented 5 years ago

Can you give me the code?

SolitudeSF commented 5 years ago

https://github.com/ba0f3/telebot.nim/blob/master/telebot/types.nim#L30 chat id is int64 https://github.com/ba0f3/telebot.nim/blob/master/telebot/api.nim#L13 here you changed chat_id property to int64 only on message type

ba0f3 commented 5 years ago

oh my bad, im gonna fix it rn