|
@@ -4,35 +4,41 @@ import sqlite3
|
|
|
import sys
|
|
import sys
|
|
|
import time
|
|
import time
|
|
|
import settings
|
|
import settings
|
|
|
-from pprint import pprint
|
|
|
|
|
|
|
+from pprint import pprint, pformat
|
|
|
|
|
|
|
|
|
|
|
|
|
def send_notification(maintainer, player, property, old_value, new_value):
|
|
def send_notification(maintainer, player, property, old_value, new_value):
|
|
|
- query = """SELECT discord FROM discord WHERE maintainer = ?;"""
|
|
|
|
|
- conn = sqlite3.connect(settings.db_path + '/slork.sqlite')
|
|
|
|
|
- conn.row_factory = sqlite3.Row
|
|
|
|
|
- cur = conn.cursor()
|
|
|
|
|
- cur.execute(query, (maintainer,))
|
|
|
|
|
- discord = cur.fetchone()['discord']
|
|
|
|
|
query = """SELECT value FROM player
|
|
query = """SELECT value FROM player
|
|
|
WHERE maintainer = ?
|
|
WHERE maintainer = ?
|
|
|
AND player = ?
|
|
AND player = ?
|
|
|
AND property = 'name';"""
|
|
AND property = 'name';"""
|
|
|
|
|
+ conn = sqlite3.connect(settings.db_path + '/slork.sqlite')
|
|
|
|
|
+ conn.row_factory = sqlite3.Row
|
|
|
|
|
+ cur = conn.cursor()
|
|
|
cur.execute(query, (maintainer, player))
|
|
cur.execute(query, (maintainer, player))
|
|
|
name = '?'
|
|
name = '?'
|
|
|
val = cur.fetchone()
|
|
val = cur.fetchone()
|
|
|
if val:
|
|
if val:
|
|
|
name = val['value']
|
|
name = val['value']
|
|
|
message = f"{name} [{player}] property '{property}' changed from {old_value} to {new_value}"
|
|
message = f"{name} [{player}] property '{property}' changed from {old_value} to {new_value}"
|
|
|
|
|
+ _send(maintainer, message)
|
|
|
|
|
+ conn.close()
|
|
|
|
|
+
|
|
|
|
|
+def _send(maintainer, message):
|
|
|
|
|
+ query = """SELECT discord FROM discord WHERE maintainer = ?;"""
|
|
|
|
|
+ conn = sqlite3.connect(settings.db_path + '/slork.sqlite')
|
|
|
|
|
+ conn.row_factory = sqlite3.Row
|
|
|
|
|
+ cur = conn.cursor()
|
|
|
|
|
+ cur.execute(query, (maintainer,))
|
|
|
|
|
+ discord = cur.fetchone()['discord']
|
|
|
|
|
+ conn.close()
|
|
|
message_json = {"content": message}
|
|
message_json = {"content": message}
|
|
|
response = requests.post(discord, json=message_json)
|
|
response = requests.post(discord, json=message_json)
|
|
|
if response.status_code in [200, 204]:
|
|
if response.status_code in [200, 204]:
|
|
|
print("Webhook executed")
|
|
print("Webhook executed")
|
|
|
else:
|
|
else:
|
|
|
print("status code {}: {}".format(response.status_code, response.content.decode("utf-8")))
|
|
print("status code {}: {}".format(response.status_code, response.content.decode("utf-8")))
|
|
|
- if response.status_code == int(429):
|
|
|
|
|
- sys.exit(1)
|
|
|
|
|
- conn.close()
|
|
|
|
|
|
|
+ time.sleep(10)
|
|
|
|
|
|
|
|
def update_value(maintainer, player, property, new_value):
|
|
def update_value(maintainer, player, property, new_value):
|
|
|
print(f"update_value({maintainer}, {player}, {property}, {new_value})")
|
|
print(f"update_value({maintainer}, {player}, {property}, {new_value})")
|
|
@@ -78,7 +84,8 @@ def cron():
|
|
|
# pprint(faction_json)
|
|
# pprint(faction_json)
|
|
|
if 'error' in player_json:
|
|
if 'error' in player_json:
|
|
|
print(f"{row['maintainer']}")
|
|
print(f"{row['maintainer']}")
|
|
|
- pprint(faction_json)
|
|
|
|
|
|
|
+ pprint(player_json)
|
|
|
|
|
+ _send(row['maintainer'], '```'+pformat(player_json)+'```')
|
|
|
break
|
|
break
|
|
|
|
|
|
|
|
# Check for changes
|
|
# Check for changes
|