aa-killtracker 0.14.0__py3-none-any.whl → 0.16.0__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.
@@ -1,7 +1,7 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: aa-killtracker
3
- Version: 0.14.0
4
- Summary: "An app for running killmail trackers with Alliance Auth and Discord.
3
+ Version: 0.16.0
4
+ Summary: An app for running killmail trackers with Alliance Auth and Discord.
5
5
  Author-email: Erik Kalkoken <kalkoken87@gmail.com>
6
6
  Requires-Python: >=3.8
7
7
  Description-Content-Type: text/markdown
@@ -19,6 +19,7 @@ Classifier: Programming Language :: Python :: 3.10
19
19
  Classifier: Programming Language :: Python :: 3.11
20
20
  Classifier: Topic :: Internet :: WWW/HTTP
21
21
  Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
22
+ License-File: LICENSE
22
23
  Requires-Dist: allianceauth-app-utils>=1.19.0
23
24
  Requires-Dist: allianceauth>=3
24
25
  Requires-Dist: dacite
@@ -90,6 +91,8 @@ And here is how posted killmails look on Discord:
90
91
 
91
92
  2. Killtracker needs the app [django-eveuniverse](https://gitlab.com/ErikKalkoken/django-eveuniverse) to function. Please make sure it is installed, before continuing.
92
93
 
94
+ 3. Killtracker will generate a lot of tasks. For optimal performance we recommend a threads-based configuration of your celery workers. Please see [this guide](https://aa-memberaudit.readthedocs.io/en/latest/operations.html#configuring-celery-workers) for details.
95
+
93
96
  ### Step 2 - Install app
94
97
 
95
98
  Make sure you are in the virtual environment (venv) of your Alliance Auth installation. Then install the newest release from PyPI:
@@ -179,6 +182,8 @@ To test that your webhook works correctly you can send a test notification.
179
182
 
180
183
  Next you can create your trackers under **Tracker**. Make sure you link each tracker to the right webhook. Once you save a tracker that is **enabled** it will start working.
181
184
 
185
+ >**Hint**:<br>A common mistake is to set both attacker alliance and victim alliance to your alliance in the same tracker. This will only match awox kills though, which is usually not what you want. Instead create separate trackers to capture kills and losses for your alliance.
186
+
182
187
  As final test that your setup is correct you may want to create a "Catch all" tracker. for that just create a new tracker without any conditions and it will forward all killmails to your Discord channel as they are received.
183
188
 
184
189
  Congratulations you are now ready to use killtracker!
@@ -1,5 +1,5 @@
1
- killtracker/__init__.py,sha256=qmlkoj0QbgRePuQ6rH64unfUejmQPj_Ebs9EzZSrYAs,356
2
- killtracker/admin.py,sha256=CHudWND2slzqCt046xdf2lzhFaAuEsNKiF7ptaXm1wQ,13696
1
+ killtracker/__init__.py,sha256=rJv9uVGH-1GPu-1zVtAt6rCtJD7KpgmLO2CZcFWboSg,355
2
+ killtracker/admin.py,sha256=s_O86Ct4prno0cQJE8otumCEqgkZ7H3Q_GFptEOTI_c,14103
3
3
  killtracker/app_settings.py,sha256=aN93musXOQ0AAVVWz67oSy9ryEiNXrcCCz6G2NlJ5QQ,3608
4
4
  killtracker/apps.py,sha256=CfmDvqVXmoy6sumpjXKldhSlJt5xDiQW3XLBfCqH3-c,307
5
5
  killtracker/constants.py,sha256=W7-VARE3B4_sdzV_9k7qunUzlxTcdSAeSp_ZJVnbUhw,2514
@@ -10,7 +10,7 @@ killtracker/providers.py,sha256=smkZe_rKHkZeWFzJ0RhIhJVcbrZUpLYR5fKCge-dpXY,348
10
10
  killtracker/tasks.py,sha256=u_ZAOEeFZWW6qpWcB0HCzgbN0VjA1ZZDHdKPJGHKl0U,7884
11
11
  killtracker/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
12
  killtracker/core/discord_messages.py,sha256=mOKiMWq-3WnaSUFbfgVmlkAedGTZ7OWcVxLp7n58-Z0,14132
13
- killtracker/core/killmails.py,sha256=V8mXnp0rVqS3EcHgwU4BWq_h900B0dfGbdgAqvPOTSI,20306
13
+ killtracker/core/killmails.py,sha256=v7ciMSPHyIg4L4d-Q8UECuqJShfxfd3g_sdfRnKKSPY,20499
14
14
  killtracker/management/commands/killtracker_load_eve.py,sha256=5P2wr6LU-EMl9_gG-DKP2yw3eFXOU7ApeuGAWEbvCKk,1159
15
15
  killtracker/migrations/0001_initial_new.py,sha256=WszI5DmNFtk45IZ2Zul3_Ak-VXmye9ffJKFAsGIxoXA,27818
16
16
  killtracker/migrations/0001_squashed_all.py,sha256=KXwOcRayjGGGmleg7-aTcXeIi-92Mn4BaGkEY3iE9Vc,26221
@@ -18,6 +18,7 @@ killtracker/migrations/0002_fix_webhook_notes_field.py,sha256=c_Uymy3K_NSwuZzoKZ
18
18
  killtracker/migrations/0002_tracker_require_attackers_weapon_groups_and_more.py,sha256=zLBGMxzxha4cq9SX3yKuJA6y7yGQJ7B0TB3G9MtUfFI,1184
19
19
  killtracker/migrations/0003_add_state_clauses.py,sha256=J0AwRYrmiSAmkpui-p637k_aVa404ED2nvw_mVEsY7g,1663
20
20
  killtracker/migrations/0003_optimize_tracker_form.py,sha256=Q_5ArFB1mxCShgoV3CwpSAgP7DM2xR9Vr_fo92MozH0,3623
21
+ killtracker/migrations/0004_add_faction_clauses.py,sha256=w6LIodDScd-CWGVPs8pyV1kTWszj74w6CSQC6--bHlI,2433
21
22
  killtracker/migrations/0004_django4_update.py,sha256=fOgbzWr6gMZWYr9Q-Ozg9mHxeUxY1VhuqBvyXv60pAg,7542
22
23
  killtracker/migrations/0005_add_final_blow_clause_and_more.py,sha256=XvaXUChQkcARcP-o8xTQ1inbc5l9IiAmUXuWY1UqzGQ,15550
23
24
  killtracker/migrations/0006_evetypeplus.py,sha256=SpaxJKA5mwnELVtUPFmDcp5Ws1CVono5Fzn2ZuiTZfg,569
@@ -27,7 +28,7 @@ killtracker/migrations/0009_remove_old_models.py,sha256=bDIz0hywpFKbHYhdXFXzra5D
27
28
  killtracker/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
28
29
  killtracker/models/__init__.py,sha256=WL6VD9MK7EsZot_RLPz0nX8WxJkp7RtQpw_mYpnVqu8,188
29
30
  killtracker/models/killmails.py,sha256=CCdrHkwUSoTOGqavG-TpMxDRleF9UEacOTui8v3-VT8,5181
30
- killtracker/models/trackers.py,sha256=2ShkcH8CPix0EszHg-jxZZaJSM5iZUfjPWBEPxIPoOw,28791
31
+ killtracker/models/trackers.py,sha256=t3pm29UW_0JqBgHbU0Xx1qgLyft7_EjNtKCJ37OM_fE,31188
31
32
  killtracker/models/webhooks.py,sha256=hh1mYE4pBU26YFawkv1z-j4uyX8aT25B0crOTsocSSY,8268
32
33
  killtracker/static/killtracker/killtracker_logo.png,sha256=3jc9zmYHqP60Np5piP5RfkX0_II-315DNjZ4FRGbqKc,74625
33
34
  killtracker/static/killtracker/zkb_icon.png,sha256=wuVfgyTbTs9qS4KGbDAH3Q9KVPgHqYV5eaVrjEmTjsE,328
@@ -41,10 +42,10 @@ killtracker/tests/test_tasks.py,sha256=ZDoCUBd-1kSOKrvSeTrlDaSGFmzHieT5ef0iBz6nr
41
42
  killtracker/tests/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
42
43
  killtracker/tests/core/test_discord_messages_1.py,sha256=1cYpj4E9pNqQOeE7yWeV1mme-JYGIHfSIibOauEHi88,3101
43
44
  killtracker/tests/core/test_discord_messages_2.py,sha256=AppA_FUFQA5I35UKjaEwn_ZQcnscqillR1SIo1unwJg,4774
44
- killtracker/tests/core/test_killmails.py,sha256=GdU5glj9as4l17GQpzZvNCaXzLM2fP2LLhbF7JOUogU,14148
45
+ killtracker/tests/core/test_killmails.py,sha256=OFV6EbERi0UyMzXblLsNoJrPbLSIgtA27Wt9vGwOYd8,14349
45
46
  killtracker/tests/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
46
47
  killtracker/tests/models/test_killmails.py,sha256=0ytwIGbTPb1OTzmK8B9VnR1ylxMuaYtp2tvCXzNOwNc,8293
47
- killtracker/tests/models/test_trackers_1.py,sha256=h9RNQ8h4bCf_LsbyO-wycbFn3WcmADZS4qnmo2B1RMo,35242
48
+ killtracker/tests/models/test_trackers_1.py,sha256=_ARZKBrQz0QF6_OZEOFOsTqNdfflz7wWenAT-T35nqU,42771
48
49
  killtracker/tests/models/test_trackers_2.py,sha256=FmtaWBjV32NlIjYPaG5Kh87oES5ChoDMVJ4ol2uWopE,5404
49
50
  killtracker/tests/models/test_webhook.py,sha256=E4BgmQw9mI5ZenV6ncYHbBonlEeWvvdilAS8IKFkbjw,5246
50
51
  killtracker/tests/testdata/__init__.py,sha256=9aQhf8V-DseZMWjJ_QMXOba6CypoHFSVpYRZEUh-oFc,212
@@ -53,13 +54,13 @@ killtracker/tests/testdata/evealliances.json,sha256=i6udrtUnWQjn71Iw17WWz9Eb1fdG
53
54
  killtracker/tests/testdata/evecorporations.json,sha256=Hk4WuplZl69rQcquOU-15lgUyvHRMZW0fnYfKz8oeWw,1229
54
55
  killtracker/tests/testdata/eveentities.json,sha256=0yStlAMEhednEiMKvKOYFsyRovtsGxw6IpWAyvnQXv4,1459
55
56
  killtracker/tests/testdata/eveuniverse.json,sha256=JagrJ-asKlkxrqj3dtAth6d5bhIpeEmlvBHgXjLTMSI,36117
56
- killtracker/tests/testdata/factories.py,sha256=xCspEV2hC5f5hwaIELFEtF6Y6mrtt36MxaXKJPdVTtc,10390
57
+ killtracker/tests/testdata/factories.py,sha256=WqmIthF6kgrdQrV5CSlub4hBYo42lC_8UORzZ8sGAp0,11019
57
58
  killtracker/tests/testdata/helpers.py,sha256=5T35ITnh16pTswR1O4t4IdVSpokC3x8_Me_vk3CgBB8,4741
58
59
  killtracker/tests/testdata/killmails.json,sha256=HKfpXQJ_ikymBSewh4wWixYpLwC3kNBqi04cCms1AjA,45366
59
60
  killtracker/tests/testdata/load_eveuniverse.py,sha256=FitVc12E_ob56ezK5Y1q07Kbyc7N8poHiCNaLRGU4Jg,388
60
61
  killtracker/tools/drop_tables_killtracker.sql,sha256=fJrGY23NKRunpYC3hI-klFkWub4sBuhfP8TaT__zjPg,1726
61
- killtracker/tools/generate_conditions_text.py,sha256=CiXBtaH2KY6JHpuxNlGmxLI6GsvxKKBX5xhXsSz3Rno,768
62
- aa_killtracker-0.14.0.dist-info/LICENSE,sha256=XZiwB_S_40_HhnvLg5xvtBb3g1oGjPrk0rpFwk8iInE,1070
63
- aa_killtracker-0.14.0.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
64
- aa_killtracker-0.14.0.dist-info/METADATA,sha256=3RNa9LwqMBs6kQUdcSusm5qm883oTXuz1z1brXzRxqA,13380
65
- aa_killtracker-0.14.0.dist-info/RECORD,,
62
+ killtracker/tools/generate_conditions_text.py,sha256=LxAtTQIX-IbuqaNDMV1XHhq5AbrrlwxLWgXa1M7DWQo,767
63
+ aa_killtracker-0.16.0.dist-info/licenses/LICENSE,sha256=XZiwB_S_40_HhnvLg5xvtBb3g1oGjPrk0rpFwk8iInE,1070
64
+ aa_killtracker-0.16.0.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
65
+ aa_killtracker-0.16.0.dist-info/METADATA,sha256=Oklfjd1Nn8qBPS33Smq7i5jGPyNgQon-aZQZH62BD4E,13946
66
+ aa_killtracker-0.16.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: flit 3.9.0
2
+ Generator: flit 3.12.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
killtracker/__init__.py CHANGED
@@ -1,9 +1,9 @@
1
- """"An app for running killmail trackers with Alliance Auth and Discord."""
1
+ """An app for running killmail trackers with Alliance Auth and Discord."""
2
2
 
3
3
  # pylint: disable = invalid-name
4
4
  default_app_config = "killtracker.apps.KillmailsConfig"
5
5
 
6
- __version__ = "0.14.0"
6
+ __version__ = "0.16.0"
7
7
  __title__ = "Killtracker"
8
8
 
9
9
  APP_NAME = "aa-killtracker"
killtracker/admin.py CHANGED
@@ -101,13 +101,17 @@ class TrackerAdmin(admin.ModelAdmin):
101
101
  "require_constellations",
102
102
  "require_solar_systems",
103
103
  "exclude_attacker_alliances",
104
- "exclude_attacker_corporations",
104
+ "exclude_victim_alliances",
105
+ "require_victim_alliances",
105
106
  "require_attacker_alliances",
107
+ "exclude_attacker_corporations",
106
108
  "require_attacker_corporations",
107
- "require_victim_alliances",
108
- "exclude_victim_alliances",
109
- "require_victim_corporations",
110
109
  "exclude_victim_corporations",
110
+ "require_victim_corporations",
111
+ "exclude_attacker_factions",
112
+ "require_attacker_factions",
113
+ "exclude_victim_factions",
114
+ "require_victim_factions",
111
115
  "require_attackers_ship_types",
112
116
  "require_attackers_ship_groups",
113
117
  "require_attackers_weapon_groups",
@@ -118,6 +122,7 @@ class TrackerAdmin(admin.ModelAdmin):
118
122
  filter_horizontal = (
119
123
  "exclude_attacker_states",
120
124
  "require_attacker_states",
125
+ "exclude_victim_states",
121
126
  "require_victim_states",
122
127
  "ping_groups",
123
128
  )
@@ -154,28 +159,33 @@ class TrackerAdmin(admin.ModelAdmin):
154
159
  },
155
160
  ),
156
161
  (
157
- "Organizations",
162
+ "Attackers",
158
163
  {
159
164
  "fields": (
160
- "exclude_attacker_alliances",
161
- "exclude_attacker_corporations",
162
165
  "require_attacker_alliances",
166
+ "exclude_attacker_alliances",
163
167
  "require_attacker_corporations",
168
+ "exclude_attacker_corporations",
169
+ "require_attacker_factions",
170
+ "exclude_attacker_factions",
171
+ "require_attacker_states",
172
+ "exclude_attacker_states",
164
173
  "require_attacker_organizations_final_blow",
165
- "require_victim_alliances",
166
- "exclude_victim_alliances",
167
- "require_victim_corporations",
168
- "exclude_victim_corporations",
169
174
  ),
170
175
  },
171
176
  ),
172
177
  (
173
- "Auth State",
178
+ "Victims",
174
179
  {
175
180
  "fields": (
176
- "exclude_attacker_states",
177
- "require_attacker_states",
181
+ "require_victim_alliances",
182
+ "exclude_victim_alliances",
183
+ "require_victim_corporations",
184
+ "exclude_victim_corporations",
185
+ "require_victim_factions",
186
+ "exclude_victim_factions",
178
187
  "require_victim_states",
188
+ "exclude_victim_states",
179
189
  ),
180
190
  },
181
191
  ),
@@ -38,7 +38,7 @@ from killtracker.providers import esi
38
38
 
39
39
  logger = LoggerAddTag(get_extension_logger(__name__), __title__)
40
40
 
41
- ZKB_REDISQ_URL = "https://redisq.zkillboard.com/listen.php"
41
+ ZKB_REDISQ_URL = "https://zkillredisq.stream/listen.php"
42
42
  ZKB_API_URL = "https://zkillboard.com/api/"
43
43
  ZKB_KILLMAIL_BASEURL = "https://zkillboard.com/kill/"
44
44
  REQUESTS_TIMEOUT = (5, 30)
@@ -97,6 +97,7 @@ class KillmailAttacker(_KillmailCharacter):
97
97
  @dataclass
98
98
  class KillmailPosition(_KillmailBase):
99
99
  "A position for a killmail."
100
+
100
101
  x: Optional[float] = None
101
102
  y: Optional[float] = None
102
103
  z: Optional[float] = None
@@ -182,6 +183,10 @@ class Killmail(_KillmailBase):
182
183
  """Return distinct character IDs of all attackers."""
183
184
  return {obj.character_id for obj in self.attackers if obj.character_id}
184
185
 
186
+ def attackers_distinct_faction_ids(self) -> Set[int]:
187
+ """Return distinct faction IDs of all attackers."""
188
+ return {obj.faction_id for obj in self.attackers if obj.faction_id}
189
+
185
190
  def attackers_ship_type_ids(self) -> List[int]:
186
191
  """Returns ship type IDs of all attackers with duplicates."""
187
192
  return [obj.ship_type_id for obj in self.attackers if obj.ship_type_id]
@@ -0,0 +1,69 @@
1
+ # Generated by Django 4.0.10 on 2024-07-04 12:40
2
+
3
+ from django.db import migrations, models
4
+
5
+
6
+ class Migration(migrations.Migration):
7
+ dependencies = [
8
+ ("authentication", "0021_alter_userprofile_language"),
9
+ ("eveonline", "0017_alliance_and_corp_names_are_not_unique"),
10
+ ("killtracker", "0003_optimize_tracker_form"),
11
+ ]
12
+
13
+ operations = [
14
+ migrations.AddField(
15
+ model_name="tracker",
16
+ name="exclude_attacker_factions",
17
+ field=models.ManyToManyField(
18
+ blank=True,
19
+ default=None,
20
+ help_text="Exclude killmails with attackers from one of these factions. ",
21
+ related_name="+",
22
+ to="eveonline.evefactioninfo",
23
+ ),
24
+ ),
25
+ migrations.AddField(
26
+ model_name="tracker",
27
+ name="exclude_victim_factions",
28
+ field=models.ManyToManyField(
29
+ blank=True,
30
+ default=None,
31
+ help_text="Exclude killmails where the victim belongs to one of these factions. ",
32
+ related_name="+",
33
+ to="eveonline.evefactioninfo",
34
+ ),
35
+ ),
36
+ migrations.AddField(
37
+ model_name="tracker",
38
+ name="exclude_victim_states",
39
+ field=models.ManyToManyField(
40
+ blank=True,
41
+ default=None,
42
+ help_text="Exclude killmails where the victim belongs to one of these Auth states. ",
43
+ related_name="+",
44
+ to="authentication.state",
45
+ ),
46
+ ),
47
+ migrations.AddField(
48
+ model_name="tracker",
49
+ name="require_attacker_factions",
50
+ field=models.ManyToManyField(
51
+ blank=True,
52
+ default=None,
53
+ help_text="Only include killmails with attackers from one of these factions. ",
54
+ related_name="+",
55
+ to="eveonline.evefactioninfo",
56
+ ),
57
+ ),
58
+ migrations.AddField(
59
+ model_name="tracker",
60
+ name="require_victim_factions",
61
+ field=models.ManyToManyField(
62
+ blank=True,
63
+ default=None,
64
+ help_text="Only include killmails where the victim belongs to one of these factions. ",
65
+ related_name="+",
66
+ to="eveonline.evefactioninfo",
67
+ ),
68
+ ),
69
+ ]
@@ -17,7 +17,11 @@ from eveuniverse.models import (
17
17
  )
18
18
 
19
19
  from allianceauth.authentication.models import State
20
- from allianceauth.eveonline.models import EveAllianceInfo, EveCorporationInfo
20
+ from allianceauth.eveonline.models import (
21
+ EveAllianceInfo,
22
+ EveCorporationInfo,
23
+ EveFactionInfo,
24
+ )
21
25
  from allianceauth.services.hooks import get_extension_logger
22
26
  from app_utils.logging import LoggerAddTag
23
27
 
@@ -170,6 +174,25 @@ class Tracker(models.Model):
170
174
  blank=True,
171
175
  help_text="Only include killmails with attackers from one of these alliances. ",
172
176
  )
177
+ require_victim_alliances = models.ManyToManyField(
178
+ EveAllianceInfo,
179
+ related_name="+",
180
+ default=None,
181
+ blank=True,
182
+ help_text=(
183
+ "Only include killmails where the victim belongs "
184
+ "to one of these alliances. "
185
+ ),
186
+ )
187
+ exclude_victim_alliances = models.ManyToManyField(
188
+ EveAllianceInfo,
189
+ related_name="+",
190
+ default=None,
191
+ blank=True,
192
+ help_text=(
193
+ "Exclude killmails where the victim belongs to one of these alliances. "
194
+ ),
195
+ )
173
196
  exclude_attacker_corporations = models.ManyToManyField(
174
197
  EveCorporationInfo,
175
198
  related_name="+",
@@ -196,6 +219,25 @@ class Tracker(models.Model):
196
219
  "has the final blow."
197
220
  ),
198
221
  )
222
+ require_victim_corporations = models.ManyToManyField(
223
+ EveCorporationInfo,
224
+ related_name="+",
225
+ default=None,
226
+ blank=True,
227
+ help_text=(
228
+ "Only include killmails where the victim belongs "
229
+ "to one of these corporations. "
230
+ ),
231
+ )
232
+ exclude_victim_corporations = models.ManyToManyField(
233
+ EveCorporationInfo,
234
+ related_name="+",
235
+ default=None,
236
+ blank=True,
237
+ help_text=(
238
+ "Exclude killmails where the victim belongs to one of these corporations. "
239
+ ),
240
+ )
199
241
  exclude_attacker_states = models.ManyToManyField(
200
242
  State,
201
243
  related_name="+",
@@ -216,52 +258,58 @@ class Tracker(models.Model):
216
258
  "to users with these Auth states. "
217
259
  ),
218
260
  )
219
- require_victim_alliances = models.ManyToManyField(
220
- EveAllianceInfo,
261
+ exclude_victim_states = models.ManyToManyField(
262
+ State,
221
263
  related_name="+",
222
264
  default=None,
223
265
  blank=True,
224
266
  help_text=(
225
- "Only include killmails where the victim belongs "
226
- "to one of these alliances. "
267
+ "Exclude killmails where the victim belongs to one of these Auth states. "
227
268
  ),
228
269
  )
229
- exclude_victim_alliances = models.ManyToManyField(
230
- EveAllianceInfo,
270
+ require_victim_states = models.ManyToManyField(
271
+ State,
231
272
  related_name="+",
232
273
  default=None,
233
274
  blank=True,
234
275
  help_text=(
235
- "Exclude killmails where the victim belongs to one of these alliances. "
276
+ "Only include killmails where the victim characters belong "
277
+ "to users with these Auth states. "
236
278
  ),
237
279
  )
238
- require_victim_corporations = models.ManyToManyField(
239
- EveCorporationInfo,
280
+ exclude_attacker_factions = models.ManyToManyField(
281
+ EveFactionInfo,
282
+ related_name="+",
283
+ default=None,
284
+ blank=True,
285
+ help_text="Exclude killmails with attackers from one of these factions. ",
286
+ )
287
+ require_attacker_factions = models.ManyToManyField(
288
+ EveFactionInfo,
240
289
  related_name="+",
241
290
  default=None,
242
291
  blank=True,
243
292
  help_text=(
244
- "Only include killmails where the victim belongs "
245
- "to one of these corporations. "
293
+ "Only include killmails with attackers from one of these factions. "
246
294
  ),
247
295
  )
248
- exclude_victim_corporations = models.ManyToManyField(
249
- EveCorporationInfo,
296
+ require_victim_factions = models.ManyToManyField(
297
+ EveFactionInfo,
250
298
  related_name="+",
251
299
  default=None,
252
300
  blank=True,
253
301
  help_text=(
254
- "Exclude killmails where the victim belongs to one of these corporations. "
302
+ "Only include killmails where the victim belongs "
303
+ "to one of these factions. "
255
304
  ),
256
305
  )
257
- require_victim_states = models.ManyToManyField(
258
- State,
306
+ exclude_victim_factions = models.ManyToManyField(
307
+ EveFactionInfo,
259
308
  related_name="+",
260
309
  default=None,
261
310
  blank=True,
262
311
  help_text=(
263
- "Only include killmails where the victim characters belong "
264
- "to users with these Auth states. "
312
+ "Exclude killmails where the victim belongs to one of these factions. "
265
313
  ),
266
314
  )
267
315
  identify_fleets = models.BooleanField(
@@ -506,6 +554,7 @@ class Tracker(models.Model):
506
554
  is_matching = self._match_value(killmail, is_matching)
507
555
  is_matching, jumps, distance = self._match_geography(killmail, is_matching)
508
556
  is_matching = self._match_attackers(killmail, is_matching)
557
+ is_matching = self._match_states(killmail, is_matching)
509
558
  is_matching, matching_ship_type_ids = self._match_attacker_ships(
510
559
  killmail, is_matching, matching_ship_type_ids
511
560
  )
@@ -641,6 +690,16 @@ class Tracker(models.Model):
641
690
  corporation_id__in=killmail.attackers_distinct_corporation_ids()
642
691
  ).exists()
643
692
 
693
+ if is_matching and self.require_attacker_factions.exists():
694
+ is_matching = self.require_attacker_factions.filter(
695
+ faction_id__in=killmail.attackers_distinct_faction_ids()
696
+ ).exists()
697
+
698
+ if is_matching and self.exclude_attacker_factions.exists():
699
+ is_matching = self.exclude_attacker_factions.exclude(
700
+ faction_id__in=killmail.attackers_distinct_faction_ids()
701
+ ).exists()
702
+
644
703
  if is_matching:
645
704
  if self.require_attacker_organizations_final_blow:
646
705
  attacker_final_blow = killmail.attacker_final_blow()
@@ -668,6 +727,9 @@ class Tracker(models.Model):
668
727
  corporation_id__in=killmail.attackers_distinct_corporation_ids()
669
728
  ).exists()
670
729
 
730
+ return is_matching
731
+
732
+ def _match_states(self, killmail: Killmail, is_matching: bool) -> bool:
671
733
  if is_matching and self.require_attacker_states.exists():
672
734
  is_matching = User.objects.filter(
673
735
  profile__state__in=list(self.require_attacker_states.all()),
@@ -684,6 +746,14 @@ class Tracker(models.Model):
684
746
  ),
685
747
  ).exists()
686
748
 
749
+ if is_matching and self.require_victim_states.exists():
750
+ is_matching = User.objects.filter(
751
+ profile__state__in=list(self.require_victim_states.all()),
752
+ character_ownerships__character__character_id=(
753
+ killmail.victim.character_id
754
+ ),
755
+ ).exists()
756
+
687
757
  return is_matching
688
758
 
689
759
  def _match_attacker_ships(
@@ -765,12 +835,14 @@ class Tracker(models.Model):
765
835
  corporation_id=killmail.victim.corporation_id
766
836
  ).exists()
767
837
 
768
- if is_matching and self.require_victim_states.exists():
769
- is_matching = User.objects.filter(
770
- profile__state__in=list(self.require_victim_states.all()),
771
- character_ownerships__character__character_id=(
772
- killmail.victim.character_id
773
- ),
838
+ if is_matching and self.require_victim_factions.exists():
839
+ is_matching = self.require_victim_factions.filter(
840
+ faction_id=killmail.victim.faction_id
841
+ ).exists()
842
+
843
+ if is_matching and self.exclude_victim_factions.exists():
844
+ is_matching = self.exclude_victim_factions.exclude(
845
+ faction_id=killmail.victim.faction_id
774
846
  ).exists()
775
847
 
776
848
  return is_matching
@@ -262,6 +262,12 @@ class TestKillmailBasics(NoSocketsTestCase):
262
262
  # then
263
263
  self.assertSetEqual(set(result), {3001})
264
264
 
265
+ def test_should_return_attacker_faction_ids(self):
266
+ # when
267
+ result = self.killmail.attackers_distinct_faction_ids()
268
+ # then
269
+ self.assertSetEqual(set(result), {500001})
270
+
265
271
  def test_should_return_attacker_corporation_ids(self):
266
272
  # when
267
273
  result = self.killmail.attackers_distinct_corporation_ids()
@@ -14,19 +14,25 @@ from eveuniverse.models import (
14
14
  EveType,
15
15
  )
16
16
 
17
- from allianceauth.eveonline.models import EveAllianceInfo, EveCorporationInfo
17
+ from allianceauth.eveonline.models import EveAllianceInfo
18
18
  from allianceauth.tests.auth_utils import AuthUtils
19
19
  from app_utils.esi_testing import BravadoOperationStub
20
+ from app_utils.testdata_factories import (
21
+ EveAllianceInfoFactory,
22
+ EveCorporationInfoFactory,
23
+ )
20
24
  from app_utils.testing import NoSocketsTestCase, add_character_to_user_2
21
25
 
22
26
  from killtracker.constants import EveGroupId
23
27
  from killtracker.core.killmails import Killmail, _EntityCount
24
28
  from killtracker.models import Tracker
25
29
  from killtracker.tests.testdata.factories import (
30
+ EveFactionInfoFactory,
26
31
  KillmailAttackerFactory,
27
32
  KillmailFactory,
28
33
  KillmailVictimFactory,
29
34
  TrackerFactory,
35
+ WebhookFactory,
30
36
  )
31
37
  from killtracker.tests.testdata.helpers import LoadTestDataMixin, load_killmail
32
38
 
@@ -175,66 +181,6 @@ class TestTrackerCalculate(LoadTestDataMixin, NoSocketsTestCase):
175
181
  expected = {10000102, 10000103}
176
182
  self.assertSetEqual(results, expected)
177
183
 
178
- def test_can_filter_attacker_alliance(self):
179
- killmail_ids = {10000001, 10000002, 10000003, 10000004, 10000005}
180
- tracker = TrackerFactory(webhook=self.webhook_1)
181
- tracker.exclude_attacker_alliances.add(
182
- EveAllianceInfo.objects.get(alliance_id=3001)
183
- )
184
- results = self._matching_killmail_ids(tracker, killmail_ids)
185
- expected = {10000005}
186
- self.assertSetEqual(results, expected)
187
-
188
- def test_can_filter_attacker_corporation(self):
189
- killmail_ids = {10000003, 10000004, 10000005}
190
- tracker = TrackerFactory(webhook=self.webhook_1)
191
- tracker.exclude_attacker_corporations.add(
192
- EveCorporationInfo.objects.get(corporation_id=2001)
193
- )
194
- results = self._matching_killmail_ids(tracker, killmail_ids)
195
- expected = {10000005}
196
- self.assertSetEqual(results, expected)
197
-
198
- def test_can_required_attacker_alliance(self):
199
- killmail_ids = {10000001, 10000002, 10000003, 10000004, 10000005}
200
- tracker = TrackerFactory(webhook=self.webhook_1)
201
- tracker.require_attacker_alliances.add(
202
- EveAllianceInfo.objects.get(alliance_id=3011)
203
- )
204
- results = self._matching_killmail_ids(tracker, killmail_ids)
205
- expected = {10000005}
206
- self.assertSetEqual(results, expected)
207
-
208
- def test_can_required_attacker_corporation(self):
209
- killmail_ids = {10000003, 10000004, 10000005}
210
- tracker = TrackerFactory(webhook=self.webhook_1)
211
- tracker.require_attacker_corporations.add(
212
- EveCorporationInfo.objects.get(corporation_id=2011)
213
- )
214
- results = self._matching_killmail_ids(tracker, killmail_ids)
215
- expected = {10000005}
216
- self.assertSetEqual(results, expected)
217
-
218
- def test_can_required_victim_alliances(self):
219
- killmail_ids = {10000001, 10000002, 10000003, 10000004, 10000005}
220
- tracker = TrackerFactory(webhook=self.webhook_1)
221
- tracker.require_victim_alliances.add(
222
- EveAllianceInfo.objects.get(alliance_id=3001)
223
- )
224
- results = self._matching_killmail_ids(tracker, killmail_ids)
225
- expected = {10000005}
226
- self.assertSetEqual(results, expected)
227
-
228
- def test_can_required_victim_corporation(self):
229
- killmail_ids = {10000003, 10000004, 10000005}
230
- tracker = TrackerFactory(webhook=self.webhook_1)
231
- tracker.require_victim_corporations.add(
232
- EveCorporationInfo.objects.get(corporation_id=2001)
233
- )
234
- results = self._matching_killmail_ids(tracker, killmail_ids)
235
- expected = {10000005}
236
- self.assertSetEqual(results, expected)
237
-
238
184
  def test_can_filter_nullsec_and_attacker_alliance(self):
239
185
  killmail_ids = {10000001, 10000002, 10000003, 10000004, 10000005}
240
186
  tracker = TrackerFactory(exclude_null_sec=True, webhook=self.webhook_1)
@@ -371,205 +317,443 @@ class TestTrackerCalculate(LoadTestDataMixin, NoSocketsTestCase):
371
317
 
372
318
 
373
319
  class TestTrackerCalculate2(LoadTestDataMixin, NoSocketsTestCase):
374
- def test_should_accept_with_require_attacker_alliances(self):
375
- attacker = KillmailAttackerFactory(alliance_id=3011)
320
+ def test_should_deny_when_value_is_below_minimum(self):
321
+ killmail = KillmailFactory(zkb__total_value=50_000_000)
322
+ tracker = TrackerFactory(require_min_value=51, webhook=self.webhook_1)
323
+ # when
324
+ result = tracker.process_killmail(killmail)
325
+ # then
326
+ self.assertIsNone(result)
327
+
328
+ def test_should_threat_no_value_as_zero(self):
329
+ killmail = KillmailFactory(zkb__total_value=None)
330
+ tracker = TrackerFactory(require_min_value=51, webhook=self.webhook_1)
331
+ # when
332
+ result = tracker.process_killmail(killmail)
333
+ # then
334
+ self.assertIsNone(result)
335
+
336
+ def test_should_accept_with_require_attacker_weapon_group(self):
337
+ attacker = KillmailAttackerFactory(weapon_type_id=2977)
376
338
  killmail = KillmailFactory(attackers=[attacker])
377
339
  tracker = TrackerFactory(webhook=self.webhook_1)
378
- tracker.require_attacker_alliances.add(
379
- EveAllianceInfo.objects.get(alliance_id=3011)
340
+ tracker.require_attackers_weapon_groups.add(
341
+ EveGroup.objects.get(id=EveGroupId.PROJECTILE_WEAPON)
380
342
  )
381
343
  # when
382
344
  result = tracker.process_killmail(killmail)
383
345
  # then
384
- self.assertIsNotNone(result)
346
+ self.assertEqual(killmail.id, result.id)
385
347
 
386
- def test_should_deny_with_require_attacker_alliances(self):
387
- attacker = KillmailAttackerFactory(alliance_id=3010)
348
+ def test_should_deny_with_require_attacker_weapon_group(self):
349
+ attacker = KillmailAttackerFactory(weapon_type_id=2488)
388
350
  killmail = KillmailFactory(attackers=[attacker])
389
351
  tracker = TrackerFactory(webhook=self.webhook_1)
390
- tracker.require_attacker_alliances.add(
391
- EveAllianceInfo.objects.get(alliance_id=3011)
352
+ tracker.require_attackers_weapon_groups.add(
353
+ EveGroup.objects.get(id=EveGroupId.PROJECTILE_WEAPON)
392
354
  )
393
355
  # when
394
356
  result = tracker.process_killmail(killmail)
395
357
  # then
396
358
  self.assertIsNone(result)
397
359
 
398
- def test_should_accept_with_require_attacker_corporations(self):
399
- attacker = KillmailAttackerFactory(corporation_id=2011)
360
+ def test_should_accept_with_require_attacker_weapon_type(self):
361
+ attacker = KillmailAttackerFactory(weapon_type_id=2977)
400
362
  killmail = KillmailFactory(attackers=[attacker])
401
363
  tracker = TrackerFactory(webhook=self.webhook_1)
402
- tracker.require_attacker_corporations.add(
403
- EveCorporationInfo.objects.get(corporation_id=2011)
404
- )
364
+ tracker.require_attackers_weapon_types.add(EveType.objects.get(id=2977))
405
365
  # when
406
366
  result = tracker.process_killmail(killmail)
407
367
  # then
408
- self.assertIsNotNone(result)
368
+ self.assertEqual(killmail.id, result.id)
409
369
 
410
- def test_should_deny_with_require_attacker_corporations(self):
411
- attacker = KillmailAttackerFactory(corporation_id=2001)
370
+ def test_should_deny_with_require_attacker_weapon_type(self):
371
+ attacker = KillmailAttackerFactory(weapon_type_id=2488)
412
372
  killmail = KillmailFactory(attackers=[attacker])
413
373
  tracker = TrackerFactory(webhook=self.webhook_1)
414
- tracker.require_attacker_corporations.add(
415
- EveCorporationInfo.objects.get(corporation_id=2011)
374
+ tracker.require_attackers_weapon_types.add(EveType.objects.get(id=2977))
375
+ # when
376
+ result = tracker.process_killmail(killmail)
377
+ # then
378
+ self.assertIsNone(result)
379
+
380
+
381
+ class TestTrackerCalculateAlliances(NoSocketsTestCase):
382
+ @classmethod
383
+ def setUpClass(cls):
384
+ super().setUpClass()
385
+ cls.alliance_1 = EveAllianceInfoFactory()
386
+ cls.alliance_2 = EveAllianceInfoFactory()
387
+ cls.webhook = WebhookFactory()
388
+
389
+ def test_should_accept_with_require_attacker_alliances(self):
390
+ attacker = KillmailAttackerFactory(alliance_id=self.alliance_1.alliance_id)
391
+ killmail = KillmailFactory(attackers=[attacker])
392
+ tracker = TrackerFactory(webhook=self.webhook)
393
+ tracker.require_attacker_alliances.add(self.alliance_1)
394
+ # when
395
+ result = tracker.process_killmail(killmail)
396
+ # then
397
+ self.assertIsNotNone(result)
398
+
399
+ def test_should_deny_with_require_attacker_alliances(self):
400
+ attacker = KillmailAttackerFactory(alliance_id=self.alliance_2.alliance_id)
401
+ killmail = KillmailFactory(attackers=[attacker])
402
+ tracker = TrackerFactory(webhook=self.webhook)
403
+ tracker.require_attacker_alliances.add(self.alliance_1)
404
+ # when
405
+ result = tracker.process_killmail(killmail)
406
+ # then
407
+ self.assertIsNone(result)
408
+
409
+ def test_should_accept_with_exclude_attacker_alliances(self):
410
+ attacker = KillmailAttackerFactory(alliance_id=self.alliance_2.alliance_id)
411
+ killmail = KillmailFactory(attackers=[attacker])
412
+ tracker = TrackerFactory(webhook=self.webhook)
413
+ tracker.exclude_attacker_alliances.add(self.alliance_1)
414
+ # when
415
+ result = tracker.process_killmail(killmail)
416
+ # then
417
+ self.assertIsNotNone(result)
418
+
419
+ def test_should_deny_with_exclude_attacker_alliances(self):
420
+ attacker = KillmailAttackerFactory(alliance_id=self.alliance_1.alliance_id)
421
+ killmail = KillmailFactory(attackers=[attacker])
422
+ tracker = TrackerFactory(webhook=self.webhook)
423
+ tracker.exclude_attacker_alliances.add(self.alliance_1)
424
+ # when
425
+ result = tracker.process_killmail(killmail)
426
+ # then
427
+ self.assertIsNone(result)
428
+
429
+ def test_should_accept_when_required_attacker_alliance_has_final_blow(self):
430
+ attacker = KillmailAttackerFactory(
431
+ alliance_id=self.alliance_1.alliance_id, is_final_blow=True
432
+ )
433
+ killmail = KillmailFactory(attackers=[attacker])
434
+ tracker = TrackerFactory(
435
+ require_attacker_organizations_final_blow=True, webhook=self.webhook
436
+ )
437
+ tracker.require_attacker_alliances.add(self.alliance_1)
438
+ # when
439
+ result = tracker.process_killmail(killmail)
440
+ # then
441
+ self.assertIsNotNone(result)
442
+
443
+ def test_should_deny_when_required_attacker_alliance_has_not_final_blow(self):
444
+ attacker_1 = KillmailAttackerFactory(
445
+ alliance_id=self.alliance_1.alliance_id, is_final_blow=False
416
446
  )
447
+ attacker_2 = KillmailAttackerFactory(
448
+ alliance_id=self.alliance_2.alliance_id, is_final_blow=True
449
+ )
450
+ killmail = KillmailFactory(attackers=[attacker_1, attacker_2])
451
+ tracker = TrackerFactory(
452
+ require_attacker_organizations_final_blow=True, webhook=self.webhook
453
+ )
454
+ tracker.require_attacker_alliances.add(self.alliance_1)
417
455
  # when
418
456
  result = tracker.process_killmail(killmail)
419
457
  # then
420
458
  self.assertIsNone(result)
421
459
 
422
- def test_should_deny_with_exclude_victim_corporation(self):
423
- victim = KillmailVictimFactory(corporation_id=2001)
460
+ def test_should_deny_with_require_victim_alliance(self):
461
+ victim = KillmailVictimFactory(alliance_id=self.alliance_2.alliance_id)
424
462
  killmail = KillmailFactory(victim=victim)
425
- tracker = TrackerFactory(webhook=self.webhook_1)
426
- tracker.exclude_victim_corporations.add(
427
- EveCorporationInfo.objects.get(corporation_id=2001)
428
- )
463
+ tracker = TrackerFactory(webhook=self.webhook)
464
+ tracker.require_victim_alliances.add(self.alliance_1)
429
465
  # when
430
466
  result = tracker.process_killmail(killmail)
431
467
  # then
432
468
  self.assertIsNone(result)
433
469
 
434
- def test_should_accept_with_exclude_victim_corporation(self):
435
- victim = KillmailVictimFactory(corporation_id=2002)
470
+ def test_should_accept_with_require_victim_alliance(self):
471
+ victim = KillmailVictimFactory(alliance_id=self.alliance_1.alliance_id)
436
472
  killmail = KillmailFactory(victim=victim)
437
- tracker = TrackerFactory(webhook=self.webhook_1)
438
- tracker.exclude_victim_corporations.add(
439
- EveCorporationInfo.objects.get(corporation_id=2001)
440
- )
473
+ tracker = TrackerFactory(webhook=self.webhook)
474
+ tracker.require_victim_alliances.add(self.alliance_1)
441
475
  # when
442
476
  result = tracker.process_killmail(killmail)
443
477
  # then
444
478
  self.assertIsNotNone(result)
445
479
 
446
480
  def test_should_deny_with_exclude_victim_alliance(self):
447
- victim = KillmailVictimFactory(alliance_id=3001)
481
+ victim = KillmailVictimFactory(alliance_id=self.alliance_1.alliance_id)
448
482
  killmail = KillmailFactory(victim=victim)
449
- tracker = TrackerFactory(webhook=self.webhook_1)
450
- tracker.exclude_victim_alliances.add(
451
- EveAllianceInfo.objects.get(alliance_id=3001)
452
- )
483
+ tracker = TrackerFactory(webhook=self.webhook)
484
+ tracker.exclude_victim_alliances.add(self.alliance_1)
453
485
  # when
454
486
  result = tracker.process_killmail(killmail)
455
487
  # then
456
488
  self.assertIsNone(result)
457
489
 
458
490
  def test_should_accept_with_exclude_victim_alliance(self):
459
- victim = KillmailVictimFactory(alliance_id=3002)
491
+ victim = KillmailVictimFactory(alliance_id=self.alliance_2.alliance_id)
460
492
  killmail = KillmailFactory(victim=victim)
461
- tracker = TrackerFactory(webhook=self.webhook_1)
462
- tracker.exclude_victim_alliances.add(
463
- EveAllianceInfo.objects.get(alliance_id=3001)
464
- )
493
+ tracker = TrackerFactory(webhook=self.webhook)
494
+ tracker.exclude_victim_alliances.add(self.alliance_1)
465
495
  # when
466
496
  result = tracker.process_killmail(killmail)
467
497
  # then
468
498
  self.assertIsNotNone(result)
469
499
 
470
- def test_should_accept_when_attacker_alliance_has_final_blow(self):
471
- attacker = KillmailAttackerFactory(alliance_id=3011, is_final_blow=True)
500
+
501
+ class TestTrackerCalculateCorporations(NoSocketsTestCase):
502
+ @classmethod
503
+ def setUpClass(cls):
504
+ super().setUpClass()
505
+ cls.corporation_1 = EveCorporationInfoFactory()
506
+ cls.corporation_2 = EveCorporationInfoFactory()
507
+ cls.webhook = WebhookFactory()
508
+
509
+ def test_should_accept_with_require_attacker_corporations(self):
510
+ attacker = KillmailAttackerFactory(
511
+ corporation_id=self.corporation_1.corporation_id
512
+ )
472
513
  killmail = KillmailFactory(attackers=[attacker])
473
- tracker = TrackerFactory(
474
- require_attacker_organizations_final_blow=True, webhook=self.webhook_1
514
+ tracker = TrackerFactory(webhook=self.webhook)
515
+ tracker.require_attacker_corporations.add(self.corporation_1)
516
+ # when
517
+ result = tracker.process_killmail(killmail)
518
+ # then
519
+ self.assertIsNotNone(result)
520
+
521
+ def test_should_deny_with_require_attacker_corporations(self):
522
+ attacker = KillmailAttackerFactory(
523
+ corporation_id=self.corporation_2.corporation_id
475
524
  )
476
- tracker.require_attacker_alliances.add(
477
- EveAllianceInfo.objects.get(alliance_id=3011)
525
+ killmail = KillmailFactory(attackers=[attacker])
526
+ tracker = TrackerFactory(webhook=self.webhook)
527
+ tracker.require_attacker_corporations.add(self.corporation_1)
528
+ # when
529
+ result = tracker.process_killmail(killmail)
530
+ # then
531
+ self.assertIsNone(result)
532
+
533
+ def test_should_accept_with_exclude_attacker_corporations(self):
534
+ attacker = KillmailAttackerFactory(
535
+ corporation_id=self.corporation_2.corporation_id
478
536
  )
537
+ killmail = KillmailFactory(attackers=[attacker])
538
+ tracker = TrackerFactory(webhook=self.webhook)
539
+ tracker.exclude_attacker_corporations.add(self.corporation_1)
479
540
  # when
480
541
  result = tracker.process_killmail(killmail)
481
542
  # then
482
543
  self.assertIsNotNone(result)
483
544
 
484
- def test_should_accept_when_attacker_corporation_has_final_blow(self):
485
- attacker = KillmailAttackerFactory(corporation_id=2011, is_final_blow=True)
545
+ def test_should_deny_with_exclude_attacker_corporations(self):
546
+ attacker = KillmailAttackerFactory(
547
+ corporation_id=self.corporation_1.corporation_id
548
+ )
486
549
  killmail = KillmailFactory(attackers=[attacker])
487
- tracker = TrackerFactory(
488
- require_attacker_organizations_final_blow=True, webhook=self.webhook_1
550
+ tracker = TrackerFactory(webhook=self.webhook)
551
+ tracker.exclude_attacker_corporations.add(self.corporation_1)
552
+ # when
553
+ result = tracker.process_killmail(killmail)
554
+ # then
555
+ self.assertIsNone(result)
556
+
557
+ def test_should_accept_when_required_attacker_corporation_has_final_blow(self):
558
+ attacker = KillmailAttackerFactory(
559
+ corporation_id=self.corporation_1.corporation_id, is_final_blow=True
489
560
  )
490
- tracker.require_attacker_corporations.add(
491
- EveCorporationInfo.objects.get(corporation_id=2011)
561
+ killmail = KillmailFactory(attackers=[attacker])
562
+ tracker = TrackerFactory(
563
+ require_attacker_organizations_final_blow=True, webhook=self.webhook
492
564
  )
565
+ tracker.require_attacker_corporations.add(self.corporation_1)
493
566
  # when
494
567
  result = tracker.process_killmail(killmail)
495
568
  # then
496
569
  self.assertIsNotNone(result)
497
570
 
498
- def test_should_deny_when_attacker_corporation_has_not_has_final_blow(self):
499
- attacker_1 = KillmailAttackerFactory(corporation_id=2011, is_final_blow=False)
500
- attacker_2 = KillmailAttackerFactory(corporation_id=2001, is_final_blow=True)
571
+ def test_should_deny_when_required_attacker_corporation_has_not_has_final_blow(
572
+ self,
573
+ ):
574
+ attacker_1 = KillmailAttackerFactory(
575
+ corporation_id=self.corporation_1.corporation_id, is_final_blow=False
576
+ )
577
+ attacker_2 = KillmailAttackerFactory(
578
+ corporation_id=self.corporation_2.corporation_id, is_final_blow=True
579
+ )
501
580
  killmail = KillmailFactory(attackers=[attacker_1, attacker_2])
502
581
  tracker = TrackerFactory(
503
- require_attacker_organizations_final_blow=True, webhook=self.webhook_1
504
- )
505
- tracker.require_attacker_corporations.add(
506
- EveCorporationInfo.objects.get(corporation_id=2011)
582
+ require_attacker_organizations_final_blow=True, webhook=self.webhook
507
583
  )
584
+ tracker.require_attacker_corporations.add(self.corporation_1)
508
585
  # when
509
586
  result = tracker.process_killmail(killmail)
510
587
  # then
511
588
  self.assertIsNone(result)
512
589
 
513
- def test_should_deny_when_value_is_below_minimum(self):
514
- killmail = KillmailFactory(zkb__total_value=50_000_000)
515
- tracker = TrackerFactory(require_min_value=51, webhook=self.webhook_1)
590
+ def test_should_deny_with_require_victim_corporation(self):
591
+ victim = KillmailVictimFactory(corporation_id=self.corporation_2.corporation_id)
592
+ killmail = KillmailFactory(victim=victim)
593
+ tracker = TrackerFactory(webhook=self.webhook)
594
+ tracker.require_victim_corporations.add(self.corporation_1)
516
595
  # when
517
596
  result = tracker.process_killmail(killmail)
518
597
  # then
519
598
  self.assertIsNone(result)
520
599
 
521
- def test_should_threat_no_value_as_zero(self):
522
- killmail = KillmailFactory(zkb__total_value=None)
523
- tracker = TrackerFactory(require_min_value=51, webhook=self.webhook_1)
600
+ def test_should_accept_with_require_victim_corporation(self):
601
+ victim = KillmailVictimFactory(corporation_id=self.corporation_1.corporation_id)
602
+ killmail = KillmailFactory(victim=victim)
603
+ tracker = TrackerFactory(webhook=self.webhook)
604
+ tracker.require_victim_corporations.add(self.corporation_1)
605
+ # when
606
+ result = tracker.process_killmail(killmail)
607
+ # then
608
+ self.assertIsNotNone(result)
609
+
610
+ def test_should_deny_with_exclude_victim_corporation(self):
611
+ victim = KillmailVictimFactory(corporation_id=self.corporation_1.corporation_id)
612
+ killmail = KillmailFactory(victim=victim)
613
+ tracker = TrackerFactory(webhook=self.webhook)
614
+ tracker.exclude_victim_corporations.add(self.corporation_1)
524
615
  # when
525
616
  result = tracker.process_killmail(killmail)
526
617
  # then
527
618
  self.assertIsNone(result)
528
619
 
529
- def test_should_accept_with_require_attacker_weapon_group(self):
530
- attacker = KillmailAttackerFactory(weapon_type_id=2977)
620
+ def test_should_accept_with_exclude_victim_corporation(self):
621
+ victim = KillmailVictimFactory(corporation_id=self.corporation_2.corporation_id)
622
+ killmail = KillmailFactory(victim=victim)
623
+ tracker = TrackerFactory(webhook=self.webhook)
624
+ tracker.exclude_victim_corporations.add(self.corporation_1)
625
+ # when
626
+ result = tracker.process_killmail(killmail)
627
+ # then
628
+ self.assertIsNotNone(result)
629
+
630
+
631
+ class TestTrackerCalculateFactions(NoSocketsTestCase):
632
+ @classmethod
633
+ def setUpClass(cls):
634
+ super().setUpClass()
635
+ cls.faction_1 = EveFactionInfoFactory()
636
+ cls.faction_2 = EveFactionInfoFactory()
637
+ cls.webhook = WebhookFactory()
638
+
639
+ def test_should_accept_with_require_attacker_factions(self):
640
+ attacker = KillmailAttackerFactory(faction_id=self.faction_1.faction_id)
531
641
  killmail = KillmailFactory(attackers=[attacker])
532
- tracker = TrackerFactory(webhook=self.webhook_1)
533
- tracker.require_attackers_weapon_groups.add(
534
- EveGroup.objects.get(id=EveGroupId.PROJECTILE_WEAPON)
535
- )
642
+ tracker = TrackerFactory(webhook=self.webhook)
643
+ tracker.require_attacker_factions.add(self.faction_1)
536
644
  # when
537
645
  result = tracker.process_killmail(killmail)
538
646
  # then
539
- self.assertEqual(killmail.id, result.id)
647
+ self.assertIsNotNone(result)
540
648
 
541
- def test_should_deny_with_require_attacker_weapon_group(self):
542
- attacker = KillmailAttackerFactory(weapon_type_id=2488)
649
+ def test_should_deny_with_require_attacker_factions(self):
650
+ attacker = KillmailAttackerFactory(faction_id=self.faction_1.faction_id)
543
651
  killmail = KillmailFactory(attackers=[attacker])
544
- tracker = TrackerFactory(webhook=self.webhook_1)
545
- tracker.require_attackers_weapon_groups.add(
546
- EveGroup.objects.get(id=EveGroupId.PROJECTILE_WEAPON)
547
- )
652
+ tracker = TrackerFactory(webhook=self.webhook)
653
+ tracker.require_attacker_factions.add(self.faction_2)
548
654
  # when
549
655
  result = tracker.process_killmail(killmail)
550
656
  # then
551
657
  self.assertIsNone(result)
552
658
 
553
- def test_should_accept_with_require_attacker_weapon_type(self):
554
- attacker = KillmailAttackerFactory(weapon_type_id=2977)
659
+ def test_should_accept_with_exclude_attacker_factions(self):
660
+ attacker = KillmailAttackerFactory(faction_id=self.faction_1.faction_id)
555
661
  killmail = KillmailFactory(attackers=[attacker])
556
- tracker = TrackerFactory(webhook=self.webhook_1)
557
- tracker.require_attackers_weapon_types.add(EveType.objects.get(id=2977))
662
+ tracker = TrackerFactory(webhook=self.webhook)
663
+ tracker.exclude_attacker_factions.add(self.faction_2)
558
664
  # when
559
665
  result = tracker.process_killmail(killmail)
560
666
  # then
561
- self.assertEqual(killmail.id, result.id)
667
+ self.assertIsNotNone(result)
562
668
 
563
- def test_should_deny_with_require_attacker_weapon_type(self):
564
- attacker = KillmailAttackerFactory(weapon_type_id=2488)
669
+ def test_should_deny_with_exclude_attacker_factions(self):
670
+ attacker = KillmailAttackerFactory(faction_id=self.faction_1.faction_id)
565
671
  killmail = KillmailFactory(attackers=[attacker])
566
- tracker = TrackerFactory(webhook=self.webhook_1)
567
- tracker.require_attackers_weapon_types.add(EveType.objects.get(id=2977))
672
+ tracker = TrackerFactory(webhook=self.webhook)
673
+ tracker.exclude_attacker_factions.add(self.faction_1)
674
+ # when
675
+ result = tracker.process_killmail(killmail)
676
+ # then
677
+ self.assertIsNone(result)
678
+
679
+ def test_should_accept_with_require_victim_factions(self):
680
+ victim = KillmailVictimFactory(faction_id=self.faction_1.faction_id)
681
+ killmail = KillmailFactory(victim=victim)
682
+ tracker = TrackerFactory(webhook=self.webhook)
683
+ tracker.require_victim_factions.add(self.faction_1)
684
+ # when
685
+ result = tracker.process_killmail(killmail)
686
+ # then
687
+ self.assertIsNotNone(result)
688
+
689
+ def test_should_deny_with_require_victim_factions(self):
690
+ victim = KillmailVictimFactory(faction_id=self.faction_1.faction_id)
691
+ killmail = KillmailFactory(victim=victim)
692
+ tracker = TrackerFactory(webhook=self.webhook)
693
+ tracker.require_victim_factions.add(self.faction_2)
568
694
  # when
569
695
  result = tracker.process_killmail(killmail)
570
696
  # then
571
697
  self.assertIsNone(result)
572
698
 
699
+ def test_should_accept_with_exclude_victim_factions(self):
700
+ victim = KillmailVictimFactory(faction_id=self.faction_1.faction_id)
701
+ killmail = KillmailFactory(victim=victim)
702
+ tracker = TrackerFactory(webhook=self.webhook)
703
+ tracker.exclude_victim_factions.add(self.faction_2)
704
+ # when
705
+ result = tracker.process_killmail(killmail)
706
+ # then
707
+ self.assertIsNotNone(result)
708
+
709
+ def test_should_deny_with_exclude_victim_factions(self):
710
+ victim = KillmailVictimFactory(faction_id=self.faction_1.faction_id)
711
+ killmail = KillmailFactory(victim=victim)
712
+ tracker = TrackerFactory(webhook=self.webhook)
713
+ tracker.exclude_victim_factions.add(self.faction_1)
714
+ # when
715
+ result = tracker.process_killmail(killmail)
716
+ # then
717
+ self.assertIsNone(result)
718
+
719
+
720
+ # class TestTrackerCalculateStates(NoSocketsTestCase):
721
+ # @classmethod
722
+ # def setUpClass(cls):
723
+ # super().setUpClass()
724
+ # cls.user = UserMainFactory()
725
+ # cls.corporation_1 = EveCorporationInfoFactory()
726
+ # cls.state_1 = AuthUtils.create_state("state_1", priority=200)
727
+ # cls.state_1.member_corporations.add(cls.corporation_1)
728
+ # cls.corporation_2 = EveCorporationInfoFactory()
729
+ # cls.state_2 = AuthUtils.create_state("state_2", priority=150)
730
+ # cls.state_2.member_corporations.add(cls.corporation_2)
731
+ # cls.webhook = WebhookFactory()
732
+
733
+ # def test_should_accept_with_require_attacker_states(self):
734
+ # attacker = KillmailAttackerFactory(
735
+ # corporation_id=self.corporation_1.corporation_id
736
+ # )
737
+ # killmail = KillmailFactory(attackers=[attacker])
738
+ # tracker = TrackerFactory(webhook=self.webhook)
739
+ # tracker.require_attacker_states.add(self.state_1)
740
+ # # when
741
+ # result = tracker.process_killmail(killmail)
742
+ # # then
743
+ # self.assertIsNotNone(result)
744
+
745
+ # def test_should_deny_with_require_attacker_states(self):
746
+ # attacker = KillmailAttackerFactory(
747
+ # corporation_id=self.corporation_2.corporation_id
748
+ # )
749
+ # killmail = KillmailFactory(attackers=[attacker])
750
+ # tracker = TrackerFactory(webhook=self.webhook)
751
+ # tracker.require_attacker_states.add(self.state_1)
752
+ # # when
753
+ # result = tracker.process_killmail(killmail)
754
+ # # then
755
+ # self.assertIsNotNone(result)
756
+
573
757
 
574
758
  @patch(MODELS_PATH + ".trackers.EveSolarSystem.jumps_to")
575
759
  class TestTrackerCalculateTrackerInfo(LoadTestDataMixin, NoSocketsTestCase):
@@ -6,9 +6,12 @@ from typing import Generic, Set, TypeVar
6
6
  import factory
7
7
  import factory.fuzzy
8
8
 
9
+ from django.db.models import Max
9
10
  from django.utils.timezone import now
10
11
  from eveuniverse.models import EveEntity
11
12
 
13
+ from allianceauth.eveonline.models import EveFactionInfo
14
+
12
15
  from killtracker.app_settings import KILLTRACKER_KILLMAIL_MAX_AGE_FOR_TRACKER
13
16
  from killtracker.constants import EveCategoryId
14
17
  from killtracker.core.killmails import (
@@ -111,6 +114,26 @@ class BaseMetaFactory(Generic[T], factory.base.FactoryMetaClass):
111
114
  return super().__call__(*args, **kwargs)
112
115
 
113
116
 
117
+ class EveFactionInfoFactory(
118
+ factory.django.DjangoModelFactory, metaclass=BaseMetaFactory[EveFactionInfo]
119
+ ):
120
+ """Generate an EveFactionInfo object."""
121
+
122
+ class Meta:
123
+ model = EveFactionInfo
124
+ django_get_or_create = ("faction_id", "faction_name")
125
+
126
+ faction_name = factory.Faker("catch_phrase")
127
+
128
+ @factory.lazy_attribute
129
+ def faction_id(self):
130
+ last_id = (
131
+ EveFactionInfo.objects.aggregate(Max("faction_id"))["faction_id__max"]
132
+ or 500_000
133
+ )
134
+ return last_id + 1
135
+
136
+
114
137
  class KillmailCharacterFactory(
115
138
  factory.Factory, metaclass=BaseMetaFactory[_KillmailCharacter]
116
139
  ):
@@ -1,5 +1,5 @@
1
1
  # flake8: noqa
2
- """ this generated the list of current tracker conditions for the documentation"""
2
+ """this generated the list of current tracker conditions for the documentation"""
3
3
 
4
4
  # init and setup django project
5
5
  import inspect