changed toot logic
This commit is contained in:
parent
b94ead7041
commit
732ac1c5d3
|
@ -29,12 +29,10 @@ class MastodonBot(Bot):
|
|||
logger.error("Unknown Mastodon API Error.", exc_info=True)
|
||||
return mentions
|
||||
for status in notifications:
|
||||
if user.get_seen_toot() is None:
|
||||
user.init_seen_toot(m.instance()['uri'])
|
||||
if (status['type'] == 'mention' and
|
||||
status['status']['id'] > user.get_seen_toot()):
|
||||
not user.toot_is_seen(status['status']['uri'])):
|
||||
# save state
|
||||
user.save_seen_toot(status['status']['id'])
|
||||
user.toot_witness(status['status']['uri'])
|
||||
# add mention to mentions
|
||||
text = re.sub(r'<[^>]*>', '', status['status']['content'])
|
||||
text = re.sub(
|
||||
|
|
5
db.py
5
db.py
|
@ -69,11 +69,8 @@ class DB(object):
|
|||
CREATE TABLE IF NOT EXISTS seen_toots (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||
user_id INTEGER,
|
||||
mastodon_accounts_id INTEGER,
|
||||
toot_id INTEGER,
|
||||
toot_uri TEXT,
|
||||
FOREIGN KEY(user_id) REFERENCES user(id),
|
||||
FOREIGN KEY(mastodon_accounts_id)
|
||||
REFERENCES mastodon_accounts(id)
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS seen_telegrams (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||
|
|
26
user.py
26
user.py
|
@ -154,26 +154,14 @@ schlitz
|
|||
(date, self.uid))
|
||||
db.commit()
|
||||
|
||||
def init_seen_toot(self, instance_url):
|
||||
db.execute("SELECT id FROM mastodon_instances WHERE instance = ?;",
|
||||
(instance_url,))
|
||||
masto_instance = db.cur.fetchone()[0]
|
||||
db.execute("INSERT INTO seen_toots (user_id, mastodon_accounts_id, toot_id) VALUES (?,?,?);",
|
||||
(self.uid, masto_instance, 0))
|
||||
db.conn.commit()
|
||||
return
|
||||
def toot_is_seen(self, toot_uri):
|
||||
db.execute("SELECT COUNT(*) FROM seen_toots WHERE user_id = ? AND toot_uri = ?;",
|
||||
(self.uid, toot_uri))
|
||||
return db.cur.fetchone()[0] > 0
|
||||
|
||||
def get_seen_toot(self):
|
||||
db.execute("SELECT toot_id FROM seen_toots WHERE user_id = ?;",
|
||||
(self.uid,))
|
||||
try:
|
||||
return db.cur.fetchone()[0]
|
||||
except TypeError:
|
||||
return None
|
||||
|
||||
def save_seen_toot(self, toot_id):
|
||||
db.execute("UPDATE seen_toots SET toot_id = ? WHERE user_id = ?;",
|
||||
(toot_id, self.uid))
|
||||
def toot_witness(self, toot_uri):
|
||||
db.execute("INSERT INTO seen_toots SET (toot_uri, user_id) VALUES (?,?);",
|
||||
(toot_uri, self.uid))
|
||||
db.commit()
|
||||
|
||||
def get_seen_tweet(self):
|
||||
|
|
Loading…
Reference in a new issue