mirror of
https://gitlab.com/oloturia/damastodon.git
synced 2025-01-07 22:17:15 +01:00
Merge branch 'master' into 'main'
Master See merge request oloturia/damastodon!9
This commit is contained in:
commit
e7e781e6a6
2 changed files with 17 additions and 3 deletions
|
@ -9,6 +9,7 @@ import os
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
|
import logging
|
||||||
|
|
||||||
#configuration server
|
#configuration server
|
||||||
api_url = sys.argv[1]
|
api_url = sys.argv[1]
|
||||||
|
@ -26,6 +27,8 @@ black_norm="◾ "
|
||||||
black_knight="⚫ "
|
black_knight="⚫ "
|
||||||
empty="🟦 "
|
empty="🟦 "
|
||||||
|
|
||||||
|
#logging config
|
||||||
|
logging.basicConfig(filename="/tmp/dama.log",level=logging.DEBUG)
|
||||||
|
|
||||||
def cleanHTML(raw):
|
def cleanHTML(raw):
|
||||||
cleanText = re.sub(CLEANR, '',raw)
|
cleanText = re.sub(CLEANR, '',raw)
|
||||||
|
@ -73,6 +76,7 @@ def check_message(notification):
|
||||||
start = pickle.load(f)
|
start = pickle.load(f)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
mastodon.status_post("Hello @"+account+" \n unfortunately, your savegame is corrupted or missing",visibility="direct") #The file has moved or corrupted
|
mastodon.status_post("Hello @"+account+" \n unfortunately, your savegame is corrupted or missing",visibility="direct") #The file has moved or corrupted
|
||||||
|
logging.warning("%s file not found",account)
|
||||||
return
|
return
|
||||||
if start != "WAIT":
|
if start != "WAIT":
|
||||||
mastodon.status_post("Hello @"+account+" \n your request is not valid",visibility="direct") #The user that challenged us is playing a game with someone else
|
mastodon.status_post("Hello @"+account+" \n your request is not valid",visibility="direct") #The user that challenged us is playing a game with someone else
|
||||||
|
@ -101,7 +105,13 @@ def check_message(notification):
|
||||||
return
|
return
|
||||||
else: #We are in a game, so movements are parsed and lobby commands are disabled
|
else: #We are in a game, so movements are parsed and lobby commands are disabled
|
||||||
with open(save_position+account,"rb") as f:
|
with open(save_position+account,"rb") as f:
|
||||||
start = pickle.load(f)
|
try:
|
||||||
|
start = pickle.load(f)
|
||||||
|
except EOFError: # Something went very wrong, file is corrupt?
|
||||||
|
mastodon.status_post("Hello @"+account+" \n unfortunately, your savegame is corrupted or missing",visibility="direct") #The file has been moved or is corrupted
|
||||||
|
os.remove(save_position+account)
|
||||||
|
logging.warning("%s file corrupted",account)
|
||||||
|
return
|
||||||
if start: #The game is started, load other parameters
|
if start: #The game is started, load other parameters
|
||||||
black = pickle.load(f)
|
black = pickle.load(f)
|
||||||
white = pickle.load(f)
|
white = pickle.load(f)
|
||||||
|
@ -155,7 +165,7 @@ def check_message(notification):
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if api_url[:4] != "http":
|
if api_url[:4] != "http":
|
||||||
print("Invalid address.")
|
logging.error("Invalid address")
|
||||||
quit()
|
quit()
|
||||||
mastodon = login.login(api_url)
|
mastodon = login.login(api_url)
|
||||||
while True:
|
while True:
|
||||||
|
|
6
login.py
6
login.py
|
@ -1,8 +1,12 @@
|
||||||
from mastodon import Mastodon
|
from mastodon import Mastodon
|
||||||
|
import os
|
||||||
|
|
||||||
|
fileDir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
fileDir = fileDir +"/"
|
||||||
|
|
||||||
def login(url):
|
def login(url):
|
||||||
mastodon = Mastodon(
|
mastodon = Mastodon(
|
||||||
access_token = "DAMA.SECRET",
|
access_token = fileDir+"DAMA.SECRET",
|
||||||
api_base_url = url
|
api_base_url = url
|
||||||
)
|
)
|
||||||
return mastodon
|
return mastodon
|
||||||
|
|
Loading…
Reference in a new issue