SockoBot is trying to be the only tool you'll ever need on your Discord Server or Facebook Page when it comes to steem, while also being easily expandable to anyone that knows a bit of Python.
In this important update, the whole reason for porting SockoBot to a more personal environment - Facebook's messenger - is about to show. A database (which for the purpose of this bot is SQLite, but can easily be expanded to any other) was introduced, which allows a lot of future functionality. For now, thanks to it 4 new functionalities were provided:
register command was added, which allows the user to tie his messengerID (which has no connection to their facebook account - so their personal information doesn't get stored anywhere) to any steem account by just providing its username.unregister command was added, which allows the user to remove his messengerID from the database, as well as register under a new nickname.vote command now automatically pulls the username from the database if the user doesn't provide any other username as an argument.payout command now automatically pulls the username from the database if the user doesn't provide any other username as an argument.On top of that, some other small changes were made:
"Too few arguments provided" if a command requires an argument, but didn't receive one.calculate_estimated_upvote will now correctly calculate the upvote if the user delegates some of his SP.command function now takes user_id as an argument, which is supposed to be used with the messengerID.A total of 4 functions were added, and their returns were used in the command function. They are all a mix of Python 3 and SQL.
def data_entry(username, user_id):
c.execute('CREATE TABLE IF NOT EXISTS users(unix REAL, datestamp TEXT, username TEXT, user_id INTEGER)')
unix = time.time()
datestamp = str(datetime.datetime.fromtimestamp(unix).strftime('%Y-%m-%d %H:%M:%S'))
c.execute("INSERT INTO users (unix, datestamp, username, user_id) VALUES (?, ?, ?, ?)", (unix, datestamp, username, user_id))
conn.commit()
The data_entry function pairs the messengerID and the provided username in the database, giving it an UNIX and a datestamp as well.
def data_check(user_id):
c.execute("SELECT user_id FROM users WHERE user_id=?", (user_id,))
data = c.fetchall()
if not data:
return False
else:
return True
The data_check function checks if the user_id is already stored in the database and returns True or False
def data_removal(user_id):
c.execute("DELETE FROM users WHERE user_id = ?", (user_id,))
conn.commit()
The data_removal function removes the messengerID and the whole row tied to it from the database.
def data_name_check(user_id):
row = c.execute("SELECT username FROM users where user_id = ?", (user_id,)).fetchone()
username = row[0]
return username
The data_name_check function returns the username that the user is registered under.
On top of that, the command function has changed a lot to welcome these changes. All the changes can be found in these commits: 61d0ac5 , 8518453, ec2f039;
The code was properly commented in the last commit and prepared for future improvements.