From 0719b094f8e9cca9d859bf8dfaf3e04d4501ea6c Mon Sep 17 00:00:00 2001 From: b3yond Date: Sun, 24 Jun 2018 00:00:48 +0200 Subject: [PATCH] added telegram to frontend --- db.py | 9 +++++++++ frontend.py | 8 ++++++++ template/settings.tpl | 15 +++++++++++++++ user.py | 4 ++++ 4 files changed, 36 insertions(+) diff --git a/db.py b/db.py index 942cbf5..f96927e 100644 --- a/db.py +++ b/db.py @@ -90,6 +90,13 @@ class DB(object): active INTEGER, FOREIGN KEY(user_id) REFERENCES user(id) ); + CREATE TABLE IF NOT EXISTS telegram_accounts ( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, + user_id INTEGER, + apikey TEXT, + active INTEGER, + FOREIGN KEY(user_id) REFERENCES user(id) + ); CREATE TABLE IF NOT EXISTS seen_tweets ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, user_id INTEGER, @@ -173,6 +180,8 @@ u\d\d? uid = json['uid'] self.execute("INSERT INTO email (user_id, email) VALUES(?, ?);", (uid, json['email'])) + self.execute("""INSERT INTO telegram_accounts (user_id, apikey, + active) VALUES(?, ?, ?);""", (uid, "", 1)) self.commit() user = User(uid) user.set_city(city) diff --git a/frontend.py b/frontend.py index a3ae423..969bea6 100755 --- a/frontend.py +++ b/frontend.py @@ -114,6 +114,14 @@ def update_badwords(user): return user.state() +@post('/settings/telegram') +@view('template/settings.tpl') +def register_telegram(user): + apikey = request.forms['apikey'] + user.set_telegram_key(apikey) + return user.state() + + @get('/api/state') def api_enable(user): return user.state() diff --git a/template/settings.tpl b/template/settings.tpl index cd7e524..5ce48cb 100644 --- a/template/settings.tpl +++ b/template/settings.tpl @@ -67,6 +67,21 @@

+
+

Connect with Telegram

+

+ If you have a Telegram account, you can register a bot there. Just write to @botfather. You can find detailed + instructions on Bots for + Telegram. +

+

+ The botfather will give you an API key - with the API key, Ticketfrei can use the Telegram bot. Enter it here: +

+
+ + +

Edit your city page

diff --git a/user.py b/user.py index edadd48..368184a 100644 --- a/user.py +++ b/user.py @@ -205,6 +205,10 @@ schlitz (self.uid, )) return db.cur.fetchall() + def set_telegram_key(self, apikey): + db.execute("UPDATE telegram_accounts SET apikey = ? WHERE user_id = ?;", (apikey, self.uid)) + db.commit() + def get_mastodon_app_keys(self, instance): db.execute("SELECT client_id, client_secret FROM mastodon_instances WHERE instance = ?;", (instance, )) try: