Fix for mrelay - some bots are sending malformed messages, caused by wrong usage of their modules.
Accessing an external service through the bot for gathering tower data is nolonger supported; and should be done via external scripts. Fix for callers, and missing alias'es for loot tables. !accounts will only show mains now. the character order of all alt lists has been reversed: [main] high => low instead of [main] low => high !account add <name> also marks accounts as type 0, if an account gets re-enabled. might cause strange behaviour with member-logs, if used in onlinebots. Member type is being displayed in !account now. [Member (X)]
This commit is contained in:
@@ -346,17 +346,17 @@ class TowerAttackController:
|
||||
def format_battle_info(self, row, t):
|
||||
blob = ""
|
||||
defeated = " - <notice>Defeated!</notice>" if row.is_finished else ""
|
||||
blob += "Site: <highlight>%s %s</highlight>\n" % (row.short_name, row.site_number or "?")
|
||||
blob += "Defender: <highlight>%s</highlight> (%s)%s\n" % (row.def_org_name, row.def_faction, defeated)
|
||||
blob += "Last Activity: %s\n" % self.format_timestamp(row.last_updated, t)
|
||||
blob += f"Site: <highlight>{row.short_name} {row.site_number or '?'}</highlight>\n"
|
||||
blob += f"Defender: <highlight>{row.def_org_name}</highlight> ({row.def_faction}){defeated}\n"
|
||||
blob += f"Last Activity: {self.format_timestamp(row.last_updated, t)}\n"
|
||||
return blob
|
||||
|
||||
def format_timestamp(self, t, current_t):
|
||||
return "<highlight>%s</highlight> (%s ago)" % (
|
||||
self.util.format_datetime(t), self.util.time_to_readable(current_t - t))
|
||||
return f"<highlight>{self.util.format_datetime(t)}</highlight> " \
|
||||
f"({self.util.time_to_readable(current_t - t)} ago)"
|
||||
|
||||
def get_chat_command(self, page):
|
||||
return "/tell <myname> attacks --page=%d" % page
|
||||
return f"/tell <myname> attacks --page={page}"
|
||||
|
||||
def check_for_all_towers_channel(self):
|
||||
if not self.public_channel_service.get_channel_name(TowerController.ALL_TOWERS_ID):
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
import sys
|
||||
import time
|
||||
|
||||
from mysql.connector.cursor import CursorBase
|
||||
from requests import Session
|
||||
|
||||
from conf.config import BotConfig
|
||||
from core.aochat.BaseModule import BaseModule
|
||||
from core.db import DB
|
||||
from core.decorators import instance, timerevent, event, setting
|
||||
from core.decorators import instance, event, setting
|
||||
from core.igncore import IgnCore
|
||||
from core.job_scheduler import JobScheduler
|
||||
from core.setting_types import BooleanSettingType
|
||||
from core.text import Text
|
||||
from core.igncore import IgnCore
|
||||
from core.util import Util
|
||||
from modules.core.accounting.services.account_service import AccountService
|
||||
from modules.raidbot.tower.tower_controller import TowerController
|
||||
@@ -34,13 +29,6 @@ class TowerService(BaseModule):
|
||||
self.job_scheduler: JobScheduler = registry.get_instance("job_scheduler")
|
||||
self.account_service: AccountService = registry.get_instance("account_service")
|
||||
|
||||
mod = __import__(f'conf.{sys.argv[1]}', fromlist=['BotConfig'])
|
||||
config: BotConfig = getattr(mod, 'BotConfig')
|
||||
if hasattr(config, "tower_url"):
|
||||
self.tower_url = config.tower_url
|
||||
else:
|
||||
self.tower_url = None
|
||||
|
||||
def pre_start(self):
|
||||
self.db.shared.exec("CREATE TABLE IF NOT EXISTS towers("
|
||||
"pf_id int not null, "
|
||||
@@ -90,6 +78,9 @@ class TowerService(BaseModule):
|
||||
self.prepare_nw_warn(row.pf_id, row.site)
|
||||
|
||||
elif event_data.type == "terminated":
|
||||
# DEBUG: terminated sites.. behave strange.
|
||||
# for that reason, we'll just output these events to the console, but not the log.
|
||||
print(event_data)
|
||||
field = self.db.query("SELECT * FROM towers t where t.org_name=? and t.pf_id=?",
|
||||
[event_data.loser.org_name, event_data.playfield.id])
|
||||
if len(field) == 1:
|
||||
@@ -115,57 +106,6 @@ class TowerService(BaseModule):
|
||||
self.prepare_nw_warn(event_data.playfield.id, "(<red>UKN</red>)",
|
||||
f"(<red>UKN</red>) PO: {event_data.loser.org_name}|{event_data.loser.faction}")
|
||||
|
||||
@timerevent(budatime="4h", description="fetch the towerAPI cache", is_enabled=False)
|
||||
def fetch_tower_update(self, _1, _2):
|
||||
if self.tower_url:
|
||||
#
|
||||
# ONLY Access the API's via Tor... Tyrence is shadow-banning every IP Subnet
|
||||
# accessing it multiple times/hour whenever the limit parameter is being used....
|
||||
# ?limit is a parameter not documented anywhere, but allows pulling the whole list
|
||||
# On other API implementations this parameter has no effect,
|
||||
# as the server always responds with the full list.
|
||||
|
||||
# In the Future, this Event will get moved to an external process,
|
||||
# which maintains the tower Cache for all connected bots,
|
||||
# like it has been done with the Worldboss timers.
|
||||
from torpy.http.requests import TorRequests
|
||||
with TorRequests() as tor_request:
|
||||
with tor_request.get_session(1) as session:
|
||||
session: Session
|
||||
r = session.get(self.tower_url)
|
||||
if not r:
|
||||
return
|
||||
if data := r.json()["results"]:
|
||||
blob = []
|
||||
for row in data:
|
||||
blob.append((row["playfield_id"], row["site_number"], row["ql"],
|
||||
row["x_coord"], row["y_coord"],
|
||||
row["org_id"], row['org_name'], row['faction'],
|
||||
row["close_time"], row["created_at"],
|
||||
row["enabled"]))
|
||||
|
||||
with self.db.lock:
|
||||
with self.db.pool.get_connection() as conn:
|
||||
with conn.cursor(dictionary=True) as cur:
|
||||
cur: CursorBase
|
||||
cur.executemany(
|
||||
"INSERT INTO towers (pf_id, site_number, "
|
||||
"ql, x_coord, y_coord, org_id, org_name, "
|
||||
"faction, close_time, planted, enabled) "
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE "
|
||||
"org_id=VALUE(org_id), "
|
||||
"org_name=VALUE(org_name), "
|
||||
"faction=VALUE(faction), "
|
||||
"close_time=VALUE(close_time),"
|
||||
"ql=VALUE(ql),"
|
||||
"planted=VALUE(planted) ", blob)
|
||||
rem = []
|
||||
for key, value in enumerate(sorted(self.attack_hot, key=lambda k: k['hot'])):
|
||||
if value['hot'] < time.time():
|
||||
rem.append(key)
|
||||
for key in reversed(rem):
|
||||
self.attack_hot.pop(key)
|
||||
|
||||
def day_time(self, day_t):
|
||||
if day_t > 86400:
|
||||
day_t -= 86400
|
||||
|
||||
Reference in New Issue
Block a user