+ if block_level == "reject":
+ blockdict.append(
+ {
+ "blocked": blocked,
+ "reason": reason
+ })
+ else:
+ c.execute(
+ "update blocks set last_seen = ? where blocker = ? and blocked = ? and block_level = ?",
+ (timestamp, blocker, blocked, block_level),
+ )
+ if reason != '':
+ c.execute(
+ "update blocks set reason = ? where blocker = ? and blocked = ? and block_level = ? and reason = ''",
+ (reason, blocker, blocked, block_level),
+ )
+ conn.commit()
+ except Exception as e:
+ print("error:", e, blocker)
+ elif software == "gotosocial":
+ print(blocker)
+ try:
+ # Blocks
+ federation = get(
+ f"https://{blocker}/api/v1/instance/peers?filter=suspended", headers=headers, timeout=5
+ ).json()
+ for peer in federation:
+ blocked = peer["domain"].lower()
+
+ if blocked.count("*") > 0:
+ # GTS does not have hashes for obscured domains, so we have to guess it
+ c.execute(
+ "select domain from instances where domain like ? order by rowid limit 1", (blocked.replace("*", "_"),)
+ )
+ searchres = c.fetchone()
+ if searchres != None:
+ blocked = searchres[0]
+
+ c.execute(
+ "select domain from instances where domain = ?", (blocked,)
+ )
+ if c.fetchone() == None:
+ c.execute(
+ "insert into instances select ?, ?, ?",
+ (blocked, get_hash(blocked), get_type(blocked)),
+ )
+ c.execute(
+ "select * from blocks where blocker = ? and blocked = ? and block_level = ?",
+ (blocker, blocked, "reject"),
+ )
+ timestamp = int(time())
+ if c.fetchone() == None:
+ c.execute(
+ "insert into blocks select ?, ?, ?, ?, ?, ?",
+ (blocker, blocked, "", "reject", timestamp, timestamp),
+ )
+ blockdict.append(
+ {
+ "blocked": blocked,
+ "reason": None
+ })
+ else:
+ c.execute(
+ "update blocks set last_seen = ? where blocker = ? and blocked = ? and block_level = ?",
+ (timestamp, blocker, blocked, "reject"),
+ )
+ if "public_comment" in peer:
+ reason = peer["public_comment"]
+ c.execute(
+ "update blocks set reason = ? where blocker = ? and blocked = ? and block_level = ? and reason = ''",
+ (reason, blocker, blocked, "reject"),
+ )
+ for entry in blockdict:
+ if entry["blocked"] == blocked:
+ entry["reason"] = reason