forked from jason-green-io/littlepod
/
minecraft-maildrops.py
executable file
·111 lines (73 loc) · 3.39 KB
/
minecraft-maildrops.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/python3
import datetime
import yaml
import sqlite3
import sys
import codecs
from itertools import groupby
sys.path.append("/minecraft")
import showandtellraw
import vanillabean
with open('/minecraft/host/config/server.yaml', 'r') as configfile: config = yaml.load(configfile)
dbfile = config['dbfile']
servername = config['name']
URL = config['URL']
webdata = config["webdata"]
serverName = "<aqua^\<><green^{}><aqua^\>>".format(servername)
worlddict = { "o" : ["overworld", "0"], "n" : ["nether", "2"], "e" : ["end", "1"] }
def updatePois():
conn = sqlite3.connect(dbfile)
cur = conn.cursor()
cur.execute("SELECT * FROM pois order by type")
pois = cur.fetchall()
cur.execute("SELECT coords, name, desc, slots, hidden, inverted FROM maildrop WHERE inverted = 0 and hidden = 0 ORDER BY name COLLATE NOCASE")
maildrops = cur.fetchall()
conn.commit()
conn.close()
with codecs.open(webdata + "/pois.md", "w", "utf-8") as file:
file.write("""#map index\n""")
for poiType, poiList in groupby(pois, lambda x: x[1]):
# print(repr(poiType.strip().strip("*")))
file.write("""## {}
|name|
|:-|
""".format(poiType.replace("*", "\*").replace("_", "\_")))
for poi in poiList:
dim, coords = poi[0].split(",",1)
URLcoords = coords.replace(",", "/")
link = "http://{}/map/#/{}/-2/{}/0".format(URL, URLcoords, worlddict[dim][1])
lines = " ".join([ poi[2], poi[3], poi[4]]).strip()
text = lines if lines else "{} {}".format(worlddict[dim][0], coords)
print(repr(text))
webline = u"|[{}]({})|\n".format(text, link)
file.write(webline)
file.write("""## {}
|player|name|
|:-|:-|
""".format("old style maildrops"))
for mail in maildrops:
dimcoords, boxname, desc, slots, hidden, inverted = mail
dim, coords = dimcoords.split(",",1)
URLcoords = coords.replace(",", "/")
link = "http://{}/map/#/{}/-2/{}/0".format(URL, URLcoords, worlddict[dim][1])
webline = u"|{}|[{}]({})|\n".format(boxname, desc if desc else "{} {}".format(worlddict[dim][0], coords), link)
file.write(webline)
# print(webline)
def sendMaildrops():
conn = sqlite3.connect(dbfile)
cur = conn.cursor()
cur.execute("SELECT * FROM maildrop natural join onlineplayers WHERE inverted = 0 and slots > 0 COLLATE NOCASE")
maildrop = cur.fetchall()
cur.execute("SELECT * FROM maildrop natural join onlineplayers WHERE inverted = 1 and slots = 0 COLLATE NOCASE")
maildropinv = cur.fetchall()
for mail in maildrop + maildropinv:
dimcoords, boxname, desc, slots, hidden, inverted = mail
dim, coords = dimcoords.split(",",1)
URLcoords = coords.replace(",", "/")
toserver = '/tellraw ' + boxname + ' ' + showandtellraw.tojson(serverName + ' {{Maildrop [_{}_|http://{}/map/#/{}/-1/{}/0]~{} {}}} {}'.format(desc if desc else "{} {}".format(worlddict[dim][0], coords), URL, URLcoords, worlddict[dim][1], worlddict[dim][0], coords, "has {} items".format(slots) if slots else "is empty") )
#vanillabean.send( toserver )
# print(toserver)
conn.commit()
conn.close()
#sendMaildrops()
updatePois()