ValorNaram / fosmbot

Other
10 stars 1 forks source link

Error while resolving username #3

Closed ValorNaram closed 4 years ago

ValorNaram commented 4 years ago
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/pyrogram/client/ext/dispatcher.py", line 204, in u
     await handler.callback(self.client, *args)
File "/home/spambot/fosmbot/bot.py", line 771, in precommandprocessing
     await commander.execCommand(command, client, message, userlevel, rightlevel, user)
File "/home/spambot/fosmbot/bot.py", line 652, in execCommand
     await self.__getattribute__(func)(client, message, userlevel, userlevel_int, userdata)
File "/home/spambot/fosmbot/bot.py", line 338, in changelevel
     targetuserdata = dbhelper.sendToPostgres(config["getuser"], (command[0],))
File "/home/spambot/fosmbot/lib/database.py", line 143, in sendToPostgres
     cursor.execute(query, params)
psycopg2.errors.InvalidTextRepresentation: invalid input syntax for integer: "valornaram"
LINE 1: select * from users where id='valornaram';

Code piece where the error occurs: (function changelevel)

command[0] = str(command[0])
userToPromote = command[0]
if command[0].startswith("@"): # if true, then resolve username to telegram id
    command[0], targetuserdata = dbhelper.resolveUsername(command[0])
    if command[0].startswith("error"): # if a username cannot be resolved, then command[0] contains an error message "error - user not existing"
        await self.__userNotFound(message, userToPromote)
        return False
if len(targetuserdata) == 0:
    targetuserdata = dbhelper.sendToPostgres(config["getuser"], (command[0],)) # line 338

(User data anonymized to valornaram)

ValorNaram commented 4 years ago

It is not a bug but a user fault as I discovered. The user did not add a @ before specifying the username which is required by Telegram and all bots are following this behaviour --> so this bot too.