Moved org finder to the core

Allowed viewing the most recent account logs by using !account log recent
Allowed removing of chatbots
Moved the so far hardcoded org prefixing into the DB, which allows dynamically changing them.
Fix for orgrosters; org leaves are being detected now.
This commit is contained in:
2022-02-11 15:43:48 +01:00
parent 6d6bfbc678
commit d3461ef462
10 changed files with 165 additions and 77 deletions
+22 -26
View File
@@ -16,10 +16,10 @@ from core.setting_types import BooleanSettingType
from core.text import Text
from core.util import Util
from modules.standard.helpbot.playfield_controller import PlayfieldController
# legacy(0), EU - friendly(1) or US - friendly(2) => timing
from modules.standard.tower.tower_attack_controller import TowerAttackController
from modules.standard.tower.tower_events import TowerEventController
# legacy(0), EU - friendly(1) or US - friendly(2) => timing
FIXED_TIMES = {1: 4,
2: 20}
@@ -219,7 +219,7 @@ class LandController:
blob += towers
else:
if not row.enabled:
blob += "<red>Disabled</red>\n"
blob += "<tab><red>Disabled</red>\n"
else:
blob += "<tab><red>This site is potentially unplanted</red>\n"
@@ -251,7 +251,10 @@ class LandController:
def get_towers(self, pf, site=None):
if site:
return self.db.query("""SELECT d.playfield_id AS pf_id,d.site_number, d.site_name, d.min_ql, d.max_ql, d.x_coord, d.y_coord, d.timing, d.enabled, a.tower_id, a.ql, a.close_time, a.penalty_until, a.planted, b.*, c.*, e.* FROM tower_sites d
return self.db.query("""SELECT d.playfield_id AS pf_id,d.site_number, d.site_name, d.min_ql, d.max_ql,
d.x_coord, d.y_coord, d.timing, d.enabled, a.tower_id, a.ql,
a.close_time, a.penalty_until, a.planted, b.*, c.*, e.*
FROM tower_sites d
LEFT JOIN towers a on a.pf_id = d.playfield_id and a.site_number = d.site_number
LEFT JOIN aodb b ON a.high_id = b.highid
LEFT JOIN playfields c on d.playfield_id = c.id
@@ -259,8 +262,11 @@ class LandController:
WHERE playfield_id=? AND d.site_number=? ORDER BY close_time IS NULL, ql desc""",
[pf, site])
else:
return self.db.query("""SELECT d.playfield_id AS pf_id, d.site_number, d.site_name, d.min_ql, d.max_ql, d.x_coord, d.y_coord, d.timing, d.enabled, a.tower_id, a.ql, a.close_time, a.penalty_until, a.planted, b.*, c.*, e.* FROM tower_sites d
LEFT JOIN towers a on a.pf_id = d.playfield_id and a.site_number = d.site_number
return self.db.query("""SELECT d.playfield_id AS pf_id, d.site_number, d.site_name, d.min_ql, d.max_ql,
d.x_coord, d.y_coord, d.timing, d.enabled, a.tower_id, a.ql,
a.close_time, a.penalty_until, a.planted, b.*, c.*, e.*
FROM tower_sites d
LEFT JOIN towers a on a.pf_id = d.playfield_id and a.site_number = d.site_number AND a.close_time IS NOT NULL
LEFT JOIN aodb b ON a.high_id = b.highid
LEFT JOIN playfields c on d.playfield_id = c.id
LEFT JOIN all_orgs e on a.org_id = e.org_id
@@ -270,27 +276,17 @@ class LandController:
""", [pf])
def get_towers_by_org(self, org_id):
return self.db.query(
"SELECT COUNT(CASE WHEN name LIKE '%Turret%' THEN 1 WHEN name LIKE '%SAM Battery%' THEN 1 END) turrets, "
"COUNT(CASE WHEN name LIKE '%Guard%' THEN 1 END) guard, "
"a.*, b.*, c.*, d.site_name, d.min_ql, d.max_ql, d.timing, d.enabled, e.* FROM towers a "
"LEFT JOIN aodb b ON a.high_id = b.highid "
"LEFT JOIN playfields c on a.pf_id = c.id "
"LEFT JOIN tower_sites d on a.pf_id = d.playfield_id and a.site_number = d.site_number "
"LEFT JOIN all_orgs e on a.org_id = e.org_id "
"WHERE a.org_id=? GROUP BY a.pf_id, a.site_number ORDER BY ql, close_time IS NOT NULL", [org_id])
# For some reason the Code above broke... and apparently works again now? leaving this one here, just in case.
# return self.db.query("""SELECT * FROM (SELECT COUNT(CASE WHEN name LIKE '%Turret%' THEN 1 WHEN name LIKE '%SAM Battery%' THEN 1 END) turrets,
# COUNT(CASE WHEN name LIKE '%Guard%' THEN 1 END) guard, a.pf_id, a.org_id, e.org_name, c.*, d.* FROM towers a
# LEFT JOIN aodb b ON a.high_id = b.highid
# LEFT JOIN playfields c on a.pf_id = c.id
# LEFT JOIN tower_sites d on a.pf_id = d.playfield_id and a.site_number = d.site_number
# LEFT JOIN all_orgs e on a.org_id = e.org_id
# WHERE a.org_id=? GROUP BY a.pf_id, a.site_number ORDER BY ql, close_time IS NOT NULL) t1
# LEFT JOIN
# (SELECT * from towers a WHERE a.org_id=? AND close_time IS NOT NULL) t2
# ON t1.pf_id=t2.pf_id AND t1.site_number = t2.site_number""", [org_id, org_id])
return self.db.query("""SELECT * FROM (SELECT COUNT(CASE WHEN name LIKE '%Turret%' THEN 1 WHEN name LIKE '%SAM Battery%' THEN 1 END) turrets,
COUNT(CASE WHEN name LIKE '%Guard%' THEN 1 END) guard, a.pf_id, a.org_id, e.org_name, c.*, d.* FROM towers a
LEFT JOIN aodb b ON a.high_id = b.highid
LEFT JOIN playfields c on a.pf_id = c.id
LEFT JOIN tower_sites d on a.pf_id = d.playfield_id and a.site_number = d.site_number
LEFT JOIN all_orgs e on a.org_id = e.org_id
WHERE a.org_id=? GROUP BY a.pf_id, a.site_number ORDER BY ql, close_time IS NOT NULL) t1
LEFT JOIN
(SELECT * from towers a WHERE a.org_id=? AND close_time IS NOT NULL) t2
ON t1.pf_id=t2.pf_id AND t1.site_number = t2.site_number
ORDER BY ql""", [org_id, org_id])
def find_orgs(self, search):
return self.db.query("SELECT DISTINCT a.org_name, a.org_id FROM all_orgs a "