Added slugs
Some fixes
This commit is contained in:
parent
5493b2d9a4
commit
ec7b57260d
@ -11,94 +11,250 @@ citizen = r"[\w\(\)\-\. \d]+"
|
|||||||
|
|
||||||
|
|
||||||
class EventKind(NamedTuple):
|
class EventKind(NamedTuple):
|
||||||
|
slug: str
|
||||||
name: str
|
name: str
|
||||||
regex: re.Pattern
|
regex: re.Pattern
|
||||||
format: str
|
format: str
|
||||||
|
|
||||||
|
|
||||||
events = [
|
events = [
|
||||||
EventKind("Region attacked", re.compile(rf"(?P<invader>{country}) attacked (?P<region>{region}), (?P<defender>{country})"), "{invader} attacked {defender} ({region})"),
|
|
||||||
EventKind(
|
EventKind(
|
||||||
|
"region_attacked",
|
||||||
|
"Region attacked",
|
||||||
|
re.compile(rf"(?P<invader>{country}) attacked (?P<region>{region}), (?P<defender>{country})"),
|
||||||
|
"{invader} attacked {defender} ({region})",
|
||||||
|
),
|
||||||
|
EventKind(
|
||||||
|
"region_secured",
|
||||||
"Region secured",
|
"Region secured",
|
||||||
re.compile(rf"(?P<region>{region}) was secured by (?P<defender>{country}) in the war versus (?P<invader>{country})?"),
|
re.compile(rf"(?P<region>{region}) was secured by (?P<defender>{country}) in the war versus (?P<invader>{country})?"),
|
||||||
"{defender} defended {invader}'s attack ({region})",
|
"{defender} defended {invader}'s attack ({region})",
|
||||||
),
|
),
|
||||||
EventKind(
|
EventKind(
|
||||||
|
"region_conquered",
|
||||||
"Region conquered",
|
"Region conquered",
|
||||||
re.compile(rf"(?P<region>{region}) was conquered by (?P<invader>{country}) in the war versus (?P<defender>{country})"),
|
re.compile(rf"(?P<region>{region}) was conquered by (?P<invader>{country}) in the war versus (?P<defender>{country})"),
|
||||||
"{invader} conquered {region} from {defender}",
|
"{invader} conquered {region} from {defender}",
|
||||||
),
|
),
|
||||||
EventKind("War declared", re.compile(rf"(?P<invader>{country}) declared war on (?P<defender>{country})"), "{invader} declared war against {defender}"),
|
|
||||||
EventKind(
|
EventKind(
|
||||||
|
"war_declared",
|
||||||
|
"War declared",
|
||||||
|
re.compile(rf"(?P<invader>{country}) declared war on (?P<defender>{country})"),
|
||||||
|
"{invader} declared war against {defender}",
|
||||||
|
),
|
||||||
|
EventKind(
|
||||||
|
"war_declaration",
|
||||||
"War declaration",
|
"War declaration",
|
||||||
re.compile(rf"President of (?P<invader>{country}) proposed a war declaration against (?P<defender>{country})"),
|
re.compile(rf"President of (?P<invader>{country}) proposed a war declaration against (?P<defender>{country})"),
|
||||||
"{invader} proposed a war declaration on {defender}",
|
"{invader} proposed a war declaration on {defender}",
|
||||||
),
|
),
|
||||||
EventKind(
|
EventKind(
|
||||||
"War rejected", re.compile(rf"The proposal for declaring war against (?P<defender>{country}) was rejected."), "{current_country} rejected war declaration on {defender}"
|
"war_rejected",
|
||||||
),
|
"War rejected",
|
||||||
EventKind("MPP proposed", re.compile(rf"President of (?P<country>{country}) proposed an alliance with (?P<partner>{country})"), "{country} proposed MPP with {partner}"),
|
re.compile(rf"The proposal for declaring war against (?P<defender>{country}) was rejected."),
|
||||||
EventKind("MPP approved", re.compile(rf"(?P<country>{country}) signed an alliance with (?P<partner>{country})"), "{country} signed a MPP with {partner}"),
|
"{current_country} rejected war declaration on {defender}",
|
||||||
EventKind(
|
|
||||||
"MPP rejected", re.compile(rf"The alliance between (?P<country>{country}) and (?P<partner>{country}) was rejected"), "MPP between {country} and {partner} was rejected"
|
|
||||||
),
|
),
|
||||||
EventKind(
|
EventKind(
|
||||||
|
"mpp_proposed",
|
||||||
|
"MPP proposed",
|
||||||
|
re.compile(rf"President of (?P<country>{country}) proposed an alliance with (?P<partner>{country})"),
|
||||||
|
"{country} proposed MPP with {partner}",
|
||||||
|
),
|
||||||
|
EventKind(
|
||||||
|
"mpp_approved",
|
||||||
|
"MPP approved",
|
||||||
|
re.compile(rf"(?P<country>{country}) signed an alliance with (?P<partner>{country})"),
|
||||||
|
"{country} signed a MPP with {partner}",
|
||||||
|
),
|
||||||
|
EventKind(
|
||||||
|
"mpp_rejected",
|
||||||
|
"MPP rejected",
|
||||||
|
re.compile(rf"The alliance between (?P<country>{country}) and (?P<partner>{country}) was rejected"),
|
||||||
|
"MPP between {country} and {partner} was rejected",
|
||||||
|
),
|
||||||
|
EventKind(
|
||||||
|
"airstrike_proposed",
|
||||||
"Airstrike proposed",
|
"Airstrike proposed",
|
||||||
re.compile(rf"President of (?P<invader>{country}) proposed an airstrike against (?P<defender>{country})"),
|
re.compile(rf"President of (?P<invader>{country}) proposed an airstrike against (?P<defender>{country})"),
|
||||||
"{invader} proposed an airstrike against {defender}",
|
"{invader} proposed an airstrike against {defender}",
|
||||||
),
|
),
|
||||||
EventKind("Airstrike approved", re.compile(rf"(?P<invader>{country}) prepares an airstrike on (?P<defender>{country})"), "{invader} approved an airstrike against {defender}"),
|
|
||||||
EventKind("Airstrike rejected", re.compile(rf"The airstrike on (?P<defender>{country}) was rejected"), "{current_country} rejected the airstrike against {defender}"),
|
|
||||||
EventKind(
|
EventKind(
|
||||||
|
"airstrike_approved",
|
||||||
|
"Airstrike approved",
|
||||||
|
re.compile(rf"(?P<invader>{country}) prepares an airstrike on (?P<defender>{country})"),
|
||||||
|
"{invader} approved an airstrike against {defender}",
|
||||||
|
),
|
||||||
|
EventKind(
|
||||||
|
"airstrike_rejected",
|
||||||
|
"Airstrike rejected",
|
||||||
|
re.compile(rf"The airstrike on (?P<defender>{country}) was rejected"),
|
||||||
|
"{current_country} rejected the airstrike against {defender}",
|
||||||
|
),
|
||||||
|
EventKind(
|
||||||
|
"ne_proposed",
|
||||||
"NE proposed",
|
"NE proposed",
|
||||||
re.compile(rf"(?P<invader>{country}) has declared (?P<defender>{country}) as a Natural Enemy"),
|
re.compile(rf"(?P<invader>{country}) has declared (?P<defender>{country}) as a Natural Enemy"),
|
||||||
"{invader} proposed Natural Enemy declaration against {defender}",
|
"{invader} proposed Natural Enemy declaration against {defender}",
|
||||||
),
|
),
|
||||||
EventKind("NE approved", re.compile(rf"(?P<defender>{country}) has been proposed as Natural Enemy"), "{current_country} declared {defender} as Natural Enemy"),
|
|
||||||
EventKind("NE rejected", re.compile(rf"(?P<defender>{country}) as new Natural Enemy proposal has been rejected"), "{current_country} rejected {defender} as Natural Enemy"),
|
|
||||||
EventKind("NE stopped", re.compile(rf"(?P<defender>{country}) is no longer a Natural Enemy for (?P<invader>{country})"), "{invader} removed Natural Enemy from {defender}"),
|
|
||||||
EventKind("NE cleared", re.compile(rf"(?P<country>{country}) no longer has a Natural Enemy"), "{country} no longer has a Natural Enemy"),
|
|
||||||
EventKind("NE reset", re.compile("No Natural Enemy law has been proposed."), "{current_country} has proposed to clear Natural Enemy"),
|
|
||||||
EventKind(
|
EventKind(
|
||||||
|
"ne_approved",
|
||||||
|
"NE approved",
|
||||||
|
re.compile(rf"(?P<defender>{country}) has been proposed as Natural Enemy"),
|
||||||
|
"{current_country} declared {defender} as Natural Enemy",
|
||||||
|
),
|
||||||
|
EventKind(
|
||||||
|
"ne_rejected",
|
||||||
|
"NE rejected",
|
||||||
|
re.compile(rf"(?P<defender>{country}) as new Natural Enemy proposal has been rejected"),
|
||||||
|
"{current_country} rejected {defender} as Natural Enemy",
|
||||||
|
),
|
||||||
|
EventKind(
|
||||||
|
"ne_stopped",
|
||||||
|
"NE stopped",
|
||||||
|
re.compile(rf"(?P<defender>{country}) is no longer a Natural Enemy for (?P<invader>{country})"),
|
||||||
|
"{invader} removed Natural Enemy from {defender}",
|
||||||
|
),
|
||||||
|
EventKind(
|
||||||
|
"ne_cleared",
|
||||||
|
"NE cleared",
|
||||||
|
re.compile(rf"(?P<country>{country}) no longer has a Natural Enemy"),
|
||||||
|
"{country} no longer has a Natural Enemy",
|
||||||
|
),
|
||||||
|
EventKind(
|
||||||
|
"ne_reset",
|
||||||
|
"NE reset",
|
||||||
|
re.compile("No Natural Enemy law has been proposed."),
|
||||||
|
"{current_country} has proposed to clear Natural Enemy",
|
||||||
|
),
|
||||||
|
EventKind(
|
||||||
|
"peace_proposal",
|
||||||
"Peace proposal",
|
"Peace proposal",
|
||||||
re.compile(rf"President of (?P<defender>{country}) proposed a peace in the war against (?P<invader>{country})"),
|
re.compile(rf"President of (?P<defender>{country}) proposed a peace in the war against (?P<invader>{country})"),
|
||||||
"{defender} proposed peace against {invader}",
|
"{defender} proposed peace against {invader}",
|
||||||
),
|
),
|
||||||
EventKind("Peace proposal", re.compile(rf"(?P<defender>{country}) proposed peace in the war against (?P<invader>{country})"), "{defender} proposed peace against {invader}"),
|
|
||||||
EventKind("Peace approved", re.compile(rf"(?P<invader>{country}) signed a peace treaty with (?P<defender>{country})"), "{invader} and {defender} is not in peace"),
|
|
||||||
EventKind(
|
EventKind(
|
||||||
|
"peace_proposal",
|
||||||
|
"Peace proposal",
|
||||||
|
re.compile(rf"(?P<defender>{country}) proposed peace in the war against (?P<invader>{country})"),
|
||||||
|
"{defender} proposed peace against {invader}",
|
||||||
|
),
|
||||||
|
EventKind(
|
||||||
|
"peace_approved",
|
||||||
|
"Peace approved",
|
||||||
|
re.compile(rf"(?P<invader>{country}) signed a peace treaty with (?P<defender>{country})"),
|
||||||
|
"{invader} and {defender} is not in peace",
|
||||||
|
),
|
||||||
|
EventKind(
|
||||||
|
"peace_rejected",
|
||||||
"Peace rejected",
|
"Peace rejected",
|
||||||
re.compile(rf"The proposed peace treaty between (?P<defender>{country}) and (?P<invader>{country}) was rejected"),
|
re.compile(rf"The proposed peace treaty between (?P<defender>{country}) and (?P<invader>{country}) was rejected"),
|
||||||
"{defender} and {invader} did not sign a peace treaty",
|
"{defender} and {invader} did not sign a peace treaty",
|
||||||
),
|
),
|
||||||
EventKind(
|
EventKind(
|
||||||
"Embargo proposed", re.compile(rf"President of (?P<major>{country}) proposed to stop the trade with (?P<minor>{country})"), "{major} proposed trade embargo against {minor}"
|
"embargo_proposed",
|
||||||
|
"Embargo proposed",
|
||||||
|
re.compile(rf"President of (?P<major>{country}) proposed to stop the trade with (?P<minor>{country})"),
|
||||||
|
"{major} proposed trade embargo against {minor}",
|
||||||
),
|
),
|
||||||
EventKind("Embargo approved", re.compile(rf"(?P<major>{country}) stopped trading with (?P<minor>{country})"), "{major} declared trade ambargo against {minor}"),
|
|
||||||
EventKind("Donation proposed", re.compile(rf"A congress donation to (?P<org>{citizen}) was proposed"), "{current_country} proposed a donation to {org}"),
|
|
||||||
EventKind("Donation approved", re.compile(rf"(?P<country>{country}) made a donation to (?P<org>{citizen})"), "{current_country} approved a donation to {org}"),
|
|
||||||
EventKind("Donation rejected", re.compile(rf"The proposal for a congress donation to (?P<org>{citizen}) was rejected"), "{current_country} rejected a donation to {org}"),
|
|
||||||
EventKind("RW started", re.compile(rf"A resistance has started in (?P<region>{region})"), "Resistance war was opened in {region} ({current_country})"),
|
|
||||||
EventKind(
|
EventKind(
|
||||||
|
"embargo_approved",
|
||||||
|
"Embargo approved",
|
||||||
|
re.compile(rf"(?P<major>{country}) stopped trading with (?P<minor>{country})"),
|
||||||
|
"{major} declared trade ambargo against {minor}",
|
||||||
|
),
|
||||||
|
EventKind(
|
||||||
|
"donation_proposed",
|
||||||
|
"Donation proposed",
|
||||||
|
re.compile(rf"A congress donation to (?P<org>{citizen}) was proposed"),
|
||||||
|
"{current_country} proposed a donation to {org}",
|
||||||
|
),
|
||||||
|
EventKind(
|
||||||
|
"donation_approved",
|
||||||
|
"Donation approved",
|
||||||
|
re.compile(rf"(?P<country>{country}) made a donation to (?P<org>{citizen})"),
|
||||||
|
"{current_country} approved a donation to {org}",
|
||||||
|
),
|
||||||
|
EventKind(
|
||||||
|
"donation_rejected",
|
||||||
|
"Donation rejected",
|
||||||
|
re.compile(rf"The proposal for a congress donation to (?P<org>{citizen}) was rejected"),
|
||||||
|
"{current_country} rejected a donation to {org}",
|
||||||
|
),
|
||||||
|
EventKind(
|
||||||
|
"rw_started",
|
||||||
|
"RW started",
|
||||||
|
re.compile(rf"A resistance has started in (?P<region>{region})"),
|
||||||
|
"Resistance war was opened in {region} ({current_country})",
|
||||||
|
),
|
||||||
|
EventKind(
|
||||||
|
"res_concession",
|
||||||
"Res Concession",
|
"Res Concession",
|
||||||
re.compile(
|
re.compile(
|
||||||
rf"A Resource Concession law to //www.erepublik.com<b>(?P<target>{country})</b> "
|
rf"A Resource Concession law to //www.erepublik.com<b>(?P<target>{country})</b> "
|
||||||
+ rf'<a href="(?P<link>((https?:)?//www\.erepublik\.com)?/en/main/law/(?P<source>{country}/\d+))">has been (?P<result>.*?)</a>'
|
rf'<a href="(?P<link>((https?:)?//www\.erepublik\.com)?/en/main/law/(?P<source>{country}/\d+))">has been (?P<result>.*?)</a>'
|
||||||
),
|
),
|
||||||
"Resource Concession law between {current_country} and {target} has been {result}",
|
"Resource Concession law between {current_country} and {target} has been {result}",
|
||||||
),
|
),
|
||||||
EventKind(
|
EventKind(
|
||||||
"CP impeachment", re.compile(rf"A president impeachment against (?P<cp>{citizen}) was proposed"), "Impeachment against {cp} president of {current_country} was proposed"
|
"cp_impeachment",
|
||||||
|
"CP impeachment",
|
||||||
|
re.compile(rf"A president impeachment against (?P<cp>{citizen}) was proposed"),
|
||||||
|
"Impeachment against {cp} president of {current_country} was proposed",
|
||||||
|
),
|
||||||
|
EventKind(
|
||||||
|
"cp_impeachment",
|
||||||
|
"CP impeachment",
|
||||||
|
re.compile("The president impeachment proposal has been rejected"),
|
||||||
|
"Impeachment against president of {current_country} was rejected",
|
||||||
|
),
|
||||||
|
EventKind(
|
||||||
|
"min_wage_proposed",
|
||||||
|
"Minimum Wage proposed",
|
||||||
|
re.compile("A new minimum wage was proposed"),
|
||||||
|
"A new minimum wage in {current_country} was proposed",
|
||||||
|
),
|
||||||
|
EventKind(
|
||||||
|
"min_wage_rejected",
|
||||||
|
"Minimum Wage rejected",
|
||||||
|
re.compile("The proposal for a minimum wage change was rejected"),
|
||||||
|
"The new minimum wage proposal in {current_country} was rejected",
|
||||||
|
),
|
||||||
|
EventKind(
|
||||||
|
"worktax_approved",
|
||||||
|
"WorkTax approved",
|
||||||
|
re.compile(rf"(?P<country>{country}) now has a new Work Tax"),
|
||||||
|
"{country} has new Work Tax",
|
||||||
|
),
|
||||||
|
EventKind(
|
||||||
|
"worktax_proposed",
|
||||||
|
"WorkTax proposed",
|
||||||
|
re.compile("A new Work Tax was proposed"),
|
||||||
|
"{country} proposed a new Work Tax",
|
||||||
|
),
|
||||||
|
EventKind(
|
||||||
|
"worktax_rejected",
|
||||||
|
"WorkTax rejected",
|
||||||
|
re.compile("The proposal for a new Work Tax was rejected"),
|
||||||
|
"{country} rejected new Work Tax",
|
||||||
|
),
|
||||||
|
EventKind(
|
||||||
|
"product_tax_approved",
|
||||||
|
"Product Tax approved",
|
||||||
|
re.compile(r"Taxes for (?P<product>[\w ]+) changed"),
|
||||||
|
"{current_country} changed taxes for {product}",
|
||||||
|
),
|
||||||
|
EventKind(
|
||||||
|
"product_tax_rejected",
|
||||||
|
"Product Tax rejected",
|
||||||
|
re.compile(r"Tax proposal of tax changes for (?P<product>[\w ]+) were rejected"),
|
||||||
|
"{current_country} rejected new taxes for {product}",
|
||||||
|
),
|
||||||
|
EventKind(
|
||||||
|
"product_tax_proposed",
|
||||||
|
"Product Tax proposed",
|
||||||
|
re.compile(r"New taxes for (?P<product>[\w ]+) were proposed"),
|
||||||
|
"{current_country} proposed new taxes for {product}",
|
||||||
),
|
),
|
||||||
EventKind("CP impeachment", re.compile("The president impeachment proposal has been rejected"), "Impeachment against president of {current_country} was rejected"),
|
|
||||||
EventKind("Minimum Wage", re.compile("A new minimum wage was proposed"), "A new minimum wage in {current_country} was proposed"),
|
|
||||||
EventKind("Minimum Wage", re.compile("The proposal for a minimum wage change was rejected"), "The new minimum wage proposal in {current_country} was rejected"),
|
|
||||||
EventKind("WorkTax", re.compile(rf"(?P<country>{country}) now has a new Work Tax"), "{country} has new Work Tax"),
|
|
||||||
EventKind("WorkTax", re.compile("A new Work Tax was proposed"), "{country} proposed a new Work Tax"),
|
|
||||||
EventKind("WorkTax", re.compile("The proposal for a new Work Tax was rejected"), "{country} rejected new Work Tax"),
|
|
||||||
EventKind("Product Tax", re.compile(r"Taxes for (?P<product>[\w ]+) changed"), "{current_country} changed taxes for {product}"),
|
|
||||||
EventKind("Product Tax", re.compile(r"Tax proposal of tax changes for (?P<product>[\w ]+) were rejected"), "{current_country} rejected new taxes for {product}"),
|
|
||||||
EventKind("Product Tax", re.compile(r"New taxes for (?P<product>[\w ]+) were proposed"), "{current_country} proposed new taxes for {product}"),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
UTF_FLAG = {
|
UTF_FLAG = {
|
||||||
|
@ -144,7 +144,7 @@ class MyClient(discord.Client):
|
|||||||
logger.debug(kind.format.format(**dict(match.groupdict(), **{"current_country": country.name})))
|
logger.debug(kind.format.format(**dict(match.groupdict(), **{"current_country": country.name})))
|
||||||
is_latvia = country.id == 71
|
is_latvia = country.id == 71
|
||||||
has_latvia = any("Latvia" in v for v in values.values())
|
has_latvia = any("Latvia" in v for v in values.values())
|
||||||
is_defender = (kind.name == "Region decured" and country.name in values['defender'])
|
is_defender = kind.name == "Region ecured" and country.name in values["defender"]
|
||||||
if is_latvia and has_latvia and is_defender:
|
if is_latvia and has_latvia and is_defender:
|
||||||
text = kind.format.format(**dict(match.groupdict(), **{"current_country": country.name}))
|
text = kind.format.format(**dict(match.groupdict(), **{"current_country": country.name}))
|
||||||
title = kind.name
|
title = kind.name
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
import re
|
||||||
|
|
||||||
from sqlite_utils.db import NotFoundError
|
from sqlite_utils.db import NotFoundError
|
||||||
|
|
||||||
from dbot.db import DiscordDB
|
from dbot import constants, db
|
||||||
|
|
||||||
|
|
||||||
class TestDatabase(unittest.TestCase):
|
class TestDatabase(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.db = DiscordDB()
|
self.db = db.DiscordDB()
|
||||||
|
|
||||||
def test_member(self):
|
def test_member(self):
|
||||||
member = {"id": 1200, "name": "username"}
|
member = {"id": 1200, "name": "username"}
|
||||||
@ -43,3 +44,17 @@ class TestDatabase(unittest.TestCase):
|
|||||||
self.assertEqual(self.db.get_rss_feed_timestamp(71), 0.0)
|
self.assertEqual(self.db.get_rss_feed_timestamp(71), 0.0)
|
||||||
self.db.set_rss_feed_timestamp(71, 16000000)
|
self.db.set_rss_feed_timestamp(71, 16000000)
|
||||||
self.assertEqual(self.db.get_rss_feed_timestamp(71), 16000000.0)
|
self.assertEqual(self.db.get_rss_feed_timestamp(71), 16000000.0)
|
||||||
|
|
||||||
|
|
||||||
|
class TestRegexes(unittest.TestCase):
|
||||||
|
def test_events(self):
|
||||||
|
for event in constants.events:
|
||||||
|
self.assertTrue(isinstance(event, constants.EventKind))
|
||||||
|
self.assertTrue(event.slug)
|
||||||
|
self.assertTrue(event.name)
|
||||||
|
self.assertTrue(isinstance(event.regex, re.Pattern))
|
||||||
|
self.assertTrue(event.format)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user