brunogge 0.1.5__py3-none-any.whl → 0.1.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
brunogge/__init__.py CHANGED
@@ -1,6 +1,6 @@
1
1
  from .get_ws import ggs_ws
2
- from .ggs_stuff import ggs_account
3
- from .just_funcs import fakescanning
2
+ from .ggs_stuff import ggs_login, keeping
3
+ from .just_funcs import fakescanning, check_updates
4
4
  from .getconfig import getconfig
5
- __all__ = ["ggs_account", "ggs_ws", "fakescanning", "getconfig"]
6
- __version__ = "0.1.4"
5
+ __all__ = [ "ggs_ws", "ggs_login", "fakescanning", "getconfig", "keeping", "check_updates" ]
6
+ __version__ = "0.1.7"
brunogge/getconfig.py CHANGED
@@ -1,6 +1,6 @@
1
1
  from configparser import ConfigParser
2
2
  import json, os
3
- def getconfig(type:str ,savename:str ,created:str = "y") -> dict:
3
+ def getconfig(type:str ,savename:str ,created: str | None = "y") -> dict:
4
4
  if created == "y":
5
5
  config = ConfigParser()
6
6
  # Use the user’s home directory and create the config file path
@@ -29,14 +29,6 @@ def getconfig(type:str ,savename:str ,created:str = "y") -> dict:
29
29
  front_tool_ammount1 = config.getint(savename, "front_tool_ammount1") # converted to int
30
30
  front_id_2 = config.get(savename, "front_id_2")
31
31
  front_tool_ammount2 = config.getint(savename, "front_tool_ammount2") # converted to int
32
- if kid == "g":
33
- kid = "0"
34
- elif kid == "s":
35
- kid = "1"
36
- elif kid == "c":
37
- kid = "2"
38
- elif kid == "f":
39
- kid = "3"
40
32
  # Return as a dictionary
41
33
  result = {
42
34
  "nick": nick,
@@ -152,7 +144,7 @@ def config_maker_barons(savename, filename = "baronconfig.ini"):
152
144
  excluded_commanders = input_int_list("Enter excluded commanders (comma separated integers, e.g. 2,3,17. -1 if none): ")
153
145
  config.set(save_name, "excluded_commanders", excluded_commanders)
154
146
 
155
- radius_option = input("Attacking in a circle (radius) or a square (square)?\n(c/s) -> <-\b\b\b")
147
+ radius_option = "c"
156
148
  config.set(save_name, "radius_option", radius_option)
157
149
 
158
150
  distance = input_int("Distance for attacks (not preicse): ")
@@ -222,3 +214,4 @@ def config_maker_barons(savename, filename = "baronconfig.ini"):
222
214
  config.write(f)
223
215
 
224
216
  print(f"\nConfiguration saved.")
217
+ exit()
brunogge/ggs_stuff.py CHANGED
@@ -1,10 +1,10 @@
1
1
  import websockets, asyncio, random, re
2
2
  import json as json_module
3
3
  from .just_funcs import getserver
4
- async def ggs_login(ws, nick: str, pwrd: str, server: str, kid: int = "0") -> None:
4
+ async def ggs_login(ws, nick: str, pwrd: str, server: str, kid: int | None = 0) -> tuple:
5
5
 
6
6
  """
7
- Login function which logins to your account.
7
+ Login to your account and return the coordinates of your main castle.
8
8
  """
9
9
  if ws.open:
10
10
  await ws.send(f"""<msg t='sys'><body action='verChk' r='0'><ver v='166' /></body></msg>""")
@@ -46,22 +46,30 @@ async def ggs_login(ws, nick: str, pwrd: str, server: str, kid: int = "0") -> No
46
46
  await ws.send(f"%xt%{server}%kli%1%{{}}%")
47
47
  while ws.open:
48
48
  try:
49
- response = await asyncio.wait_for(ws.recv(), timeout=2)
49
+ response = await asyncio.wait_for(ws.recv(), timeout=4)
50
50
  response = response.decode('utf-8')
51
51
  if "%xt%jaa%1%0%" in response:
52
- pattern = rf"\[{kid},(\d+),(\d+),(\d+),1"
53
- match = re.search(pattern, response)
54
- cid = match.group(1)
55
- global sx, sy
56
- sx = match.group(2)
57
- sy = match.group(3)
52
+ sx_list = []
53
+ sy_list = []
54
+ cid_list = []
55
+ for i in range(4):
56
+ pattern = rf"\[{i},(\d+),(\d+),(\d+),1"
57
+ match = re.search(pattern, response)
58
+ cid = match.group(1)
59
+ sx = match.group(2)
60
+ sy = match.group(3)
61
+ sx_list.append(sx)
62
+ sy_list.append(sy)
63
+ cid_list.append(cid)
64
+ print(f"Coord {i} X: {sx}, Coord Y: {sy}")
58
65
  break
66
+
59
67
  except asyncio.TimeoutError:
60
68
  break
61
69
 
62
70
  while ws.open:
63
71
  try:
64
- response = await asyncio.wait_for(ws.recv(), timeout=3.5)
72
+ response = await asyncio.wait_for(ws.recv(), timeout=5.5)
65
73
  response = response.decode('utf-8')
66
74
  if "%xt%ffi%1%0%" in response:
67
75
  await ws.send(f"%xt%{server}%gcs%1%{{}}%")
@@ -71,11 +79,10 @@ async def ggs_login(ws, nick: str, pwrd: str, server: str, kid: int = "0") -> No
71
79
  break
72
80
  else:
73
81
  print("Connection closed, stopping login")
74
- sx = int(sx)
75
- sy = int(sy)
76
- return sx, sy, lids, cid
82
+ return sx_list, sy_list, lids, cid_list
77
83
 
78
- async def keeping(ws, server):
84
+ async def keeping(ws, server: str) -> None:
85
+ """Keep the connection alive by sending periodic messages."""
79
86
  while ws.open:
80
87
  try:
81
88
  await ws.send(f"%xt%{server}%pin%1%<RoundHouseKick>%")
@@ -85,7 +92,7 @@ async def keeping(ws, server):
85
92
  print("Connection closed, stopping keep-alive")
86
93
  break
87
94
 
88
- async def ggs_account(ws, nick, pwrd, server) -> None:
95
+ async def ggs_account(ws, nick: str, pwrd: str, server: str) -> None:
89
96
  """Login to the account and trigger next functions."""
90
97
  print("Logging in...")
91
98
  try:
@@ -96,5 +103,5 @@ async def ggs_account(ws, nick, pwrd, server) -> None:
96
103
  while ws.open:
97
104
  await asyncio.sleep(100)
98
105
  except websockets.exceptions.ConnectionClosedError:
99
- print("Theoretically you should never see this. If you do, pray for your account.")
106
+ print("Theoretically you should never see this. If you do, you may be banned, idk tho.")
100
107
 
brunogge/just_funcs.py CHANGED
@@ -1,8 +1,12 @@
1
1
  import asyncio, re
2
2
  import json as json_module
3
3
  from importlib.resources import files
4
-
5
- async def c2s_search_for(ws, c2s_code: str, waiting_time: float):
4
+ import subprocess
5
+ import sys
6
+ import requests
7
+ from packaging import version
8
+ from importlib.metadata import version as get_installed_version, PackageNotFoundError
9
+ async def c2s_search_for(ws, c2s_code: str, waiting_time: float | None = 3) -> dict | int:
6
10
  """Phrase is made from 3 letters. Returns response json or error code."""
7
11
  while True:
8
12
  try:
@@ -19,38 +23,71 @@ async def c2s_search_for(ws, c2s_code: str, waiting_time: float):
19
23
  return int(error_code)
20
24
  except asyncio.TimeoutError:
21
25
  return -1
22
-
23
- def getserver(server, full: str = "full") -> str:
24
- """
25
- Get the server URL and exname from the server list.
26
- Full -> ws for wsuri <--> ex for empireex_xyz <--> full for both wsuri and exname"""
27
26
 
27
+ def getserver(server: str, option: str | None = "full") -> str:
28
+ ''' Get the server URI and server prefix from the server list.
29
+
30
+ :option:
31
+ :full: returns both websocket uri and server prefix
32
+ :ex: returns server prefix only
33
+ :ws: returns websocket uri only
34
+ '''
28
35
  data_path = files("brunogge").joinpath("server_list.json")
29
36
  with data_path.open("r", encoding="utf-8") as f:
30
37
  data = json_module.load(f)
31
38
  wsuri = data["servers"][server]["wsuri"]
32
39
  exname = data["servers"][server]["exname"]
33
- if full == "full":
40
+ if option == "full":
34
41
  return wsuri, exname
35
- elif full == "ex":
42
+ elif option == "ex":
36
43
  return exname
37
- elif full == "ws":
44
+ elif option == "ws":
38
45
  return wsuri
39
46
 
40
- async def fakescanning(ws, server: str) -> None:
47
+ async def fakescanning(ws, server: str, kid: str | None = "0") -> None:
41
48
  """
42
- Fake scanning for the server.
43
- This function is used to hopefully avoid getting banned.
49
+ Fake scanning the map while doing other things
50
+
44
51
  """
45
52
  empireex = getserver(server, "ex")
46
53
  delays = [6, 2, 4, 2]
47
54
  while ws.open:
48
55
  for delay in delays:
49
56
  print("Fake scanned...")
50
- await ws.send(f"""%xt%{empireex}%gaa%1%{{"KID":0,"AX1":0,"AY1":0,"AX2":12,"AY2":12}}%""")
51
- await ws.send(f"""%xt%{empireex}%gaa%1%{{"KID":0,"AX1":1274,"AY1":0,"AX2":1286,"AY2":12}}%""")
52
- await ws.send(f"""%xt%{empireex}%gaa%1%{{"KID":0,"AX1":13,"AY1":0,"AX2":25,"AY2":12}}%""")
53
- await ws.send(f"""%xt%{empireex}%gaa%1%{{"KID":0,"AX1":1274,"AY1":13,"AX2":1286,"AY2":25}}%""")
54
- await ws.send(f"""%xt%{empireex}%gaa%1%{{"KID":0,"AX1":0,"AY1":13,"AX2":12,"AY2":25}}%""")
55
- await ws.send(f"""%xt%{empireex}%gaa%1%{{"KID":0,"AX1":13,"AY1":13,"AX2":25,"AY2":25}}%""")
56
- await asyncio.sleep(delay * 60)
57
+ await ws.send(f"""%xt%{empireex}%gaa%1%{{"{kid}":0,"AX1":0,"AY1":0,"AX2":12,"AY2":12}}%""")
58
+ await ws.send(f"""%xt%{empireex}%gaa%1%{{"{kid}":0,"AX1":1274,"AY1":0,"AX2":1286,"AY2":12}}%""")
59
+ await ws.send(f"""%xt%{empireex}%gaa%1%{{"{kid}":0,"AX1":13,"AY1":0,"AX2":25,"AY2":12}}%""")
60
+ await ws.send(f"""%xt%{empireex}%gaa%1%{{"{kid}":0,"AX1":1274,"AY1":13,"AX2":1286,"AY2":25}}%""")
61
+ await ws.send(f"""%xt%{empireex}%gaa%1%{{"{kid}":0,"AX1":0,"AY1":13,"AX2":12,"AY2":25}}%""")
62
+ await ws.send(f"""%xt%{empireex}%gaa%1%{{"{kid}":0,"AX1":13,"AY1":13,"AX2":25,"AY2":25}}%""")
63
+ await asyncio.sleep(delay * 60)
64
+
65
+ import subprocess
66
+ import pkg_resources
67
+ import requests
68
+
69
+ def check_updates(package_name):
70
+ try:
71
+ # Get currently installed version
72
+ installed_version = get_installed_version(package_name)
73
+ print(f"Installed version: {installed_version}")
74
+ except PackageNotFoundError:
75
+ subprocess.check_call([sys.executable, "-m", "pip", "install", package_name])
76
+ return
77
+
78
+ try:
79
+ # Get latest version from PyPI
80
+ response = requests.get(f"https://pypi.org/pypi/{package_name}/json", timeout=5)
81
+ response.raise_for_status()
82
+ latest_version = response.json()['info']['version']
83
+ print(f"Latest version on PyPI: {latest_version}")
84
+
85
+ # Compare versions
86
+ if version.parse(latest_version) > version.parse(installed_version):
87
+ print(f"Updating to version {latest_version}...")
88
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "--upgrade", package_name])
89
+ else:
90
+ return
91
+
92
+ except Exception as e:
93
+ print(f"Error checking or updating {package_name}: {e}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: brunogge
3
- Version: 0.1.5
3
+ Version: 0.1.7
4
4
  Summary: Bilbioteka Python dla Goodgame Empire.
5
5
  Author-email: WojtS & ThunderStorm <wojts8@proton.me>
6
6
  Project-URL: Homepage, https://github.com/wojtsik/brunogge
@@ -0,0 +1,11 @@
1
+ brunogge/__init__.py,sha256=_u8TClHjNx5Eee66_nmgrFu-VdQw8P9xoZ-EBipFGSo,275
2
+ brunogge/barony.py,sha256=6Xm-i5AaXa8oVQ_kzX0_tDZucoBVplF7gYTGuad6djk,14891
3
+ brunogge/get_ws.py,sha256=nPsvNReq4DzflvOItHOd3WgajAV7f3ckeZr8qRADYsI,709
4
+ brunogge/getconfig.py,sha256=6mSdy_udDDSSZaxe7y_zwI8nT-hkUdOngh8nM7A1kGg,9438
5
+ brunogge/ggs_stuff.py,sha256=vfjB5shnOHsOgyuUfRrsKs4gOfXsIGvgf_7Gu_Q6yoQ,5080
6
+ brunogge/just_funcs.py,sha256=H5cuxNYnWrs7hgr4XCM7RZRkcbFUuAiS306vIx_4nWI,3956
7
+ brunogge/server_list.json,sha256=5hZrlPH7tbFY7m1bqMMgsKiyHkGiPTnVMAW2B9WLabc,5084
8
+ brunogge-0.1.7.dist-info/METADATA,sha256=k7YezRzDfxQ6iK8XKwL4fNymlfdK_EO3Rp27Q20t8uk,328
9
+ brunogge-0.1.7.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
10
+ brunogge-0.1.7.dist-info/top_level.txt,sha256=oTTOxi0gm7TPhnipjl1nIXsYLRrnWnDzKKLCfRVhAjw,9
11
+ brunogge-0.1.7.dist-info/RECORD,,
@@ -1,11 +0,0 @@
1
- brunogge/__init__.py,sha256=MgU4caQhwriibT1fZZ0GIUMNHCa_vrqav_oQXnBFB2E,225
2
- brunogge/barony.py,sha256=6Xm-i5AaXa8oVQ_kzX0_tDZucoBVplF7gYTGuad6djk,14891
3
- brunogge/get_ws.py,sha256=nPsvNReq4DzflvOItHOd3WgajAV7f3ckeZr8qRADYsI,709
4
- brunogge/getconfig.py,sha256=Ky0faOuQSdrjLQulgPZD1uMCx2crJr_NipmVC85AtQw,9753
5
- brunogge/ggs_stuff.py,sha256=vV-blmi7lXPNh3ktmqGVb4NQO97-rHBt7hG5eN4F6go,4640
6
- brunogge/just_funcs.py,sha256=eQz_XOjfLKU532jWf_JrpQjkq-d5nVoiXJTFumW6-VA,2573
7
- brunogge/server_list.json,sha256=5hZrlPH7tbFY7m1bqMMgsKiyHkGiPTnVMAW2B9WLabc,5084
8
- brunogge-0.1.5.dist-info/METADATA,sha256=Oa73Wh3z_xu4BsFflcOCF_Mk1erHLiS_ecpt1XvfK18,328
9
- brunogge-0.1.5.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
10
- brunogge-0.1.5.dist-info/top_level.txt,sha256=oTTOxi0gm7TPhnipjl1nIXsYLRrnWnDzKKLCfRVhAjw,9
11
- brunogge-0.1.5.dist-info/RECORD,,