Skip to content

Commit

Permalink
improve DosSpeedruns.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Die4Ever committed Oct 12, 2024
1 parent 8e019e8 commit 2f504a4
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 13 deletions.
11 changes: 7 additions & 4 deletions libStreamDetective/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ def CheckStreamFilter(filter, streamer, title, tags, gameName):
for f in GetFilter(filter, 'MatchString'):
if f.lower() not in title.lower():
return False
for f in GetFilter(filter, 'MatchWord'):
if not re.search(r'\b' + f + r'\b', title, flags=re.IGNORECASE):
return False
for f in GetFilter(filter, 'DontMatchWord'):
if re.search(r'\b' + f + r'\b', title, flags=re.IGNORECASE):
return False
for f in GetFilter(filter, 'DontMatchTag'):
if f.lower() in tags:
return False
Expand Down Expand Up @@ -91,10 +97,7 @@ def CheckStreamFilter(filter, streamer, title, tags, gameName):
return False

for f in GetFilter(filter, 'SearchRegex'):
found = False
if re.search(f, title, flags=re.IGNORECASE):
found = True
if not found:
if not re.search(f, title, flags=re.IGNORECASE):
return False

for f in GetFilter(filter, 'DontSearchRegex'):
Expand Down
25 changes: 17 additions & 8 deletions searches_examples/DosSpeedruns.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
[{
"SearchTags": ["DOS", "MSDOS", "DOSGaming", "DosBox", "ScummVM"],
"SearchTags": ["Speedrun", "Speedruns", "Speedrunner", "Speedrunning", "PBAttempts", "WRAttempts", "DOSSpeedrun", "DOSSpeedruns", "DOSSpeedrunning"],
"filters": [
{"MatchTag": "Speedrun"},
{"MatchTag": "Speedruns"},
{"MatchTag": "Speedrunner"},
{"MatchTag": "Speedrunning"},
{"MatchTag": "PBAttempts"},
{"MatchTag": "WRAttempts"},
{"MatchString": "speedrun"}
{"MatchTag": "DOS"},
{"MatchTag": "MSDOS"},
{"MatchTag": "DOSGame"},
{"MatchTag": "DOSGames"},
{"MatchTag": "DOSSpeedrun"},
{"MatchTag": "DOSGaming"},
{"MatchTag": "DosBox"},
{"MatchTag": "ScummVM"},
{"MatchTag": "DOSSpeedrun"},
{"MatchTag": "DOSSpeedruns"},
{"MatchTag": "DOSSpeedrunning"},
{"MatchWord": "DOS"},
{"MatchWord": "MSDOS"},
{"MatchWord": "FreeDOS"},
{"MatchWord": "DOSBox"},
{"MatchString": "DOScember"}
],
"Notifications": {
"DOSSpeedruns": { "chance": 100 }
Expand Down
35 changes: 34 additions & 1 deletion tests/filters.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import unittest
from libStreamDetective.filters import CheckStream
from pathlib import Path
import json

all_filters = {
'MatchTag': 'Randomizer',
'MatchTagName': 'Randomizer',
'MatchTagSubstring': 'Rando',
'MatchString': 'Randomi',
'MatchWord': 'Randomizer',
'DontMatchWord': 'Random',
'DontMatchTag': 'Sega',
'DontMatchString': 'Sonic',
'DontMatchTagName': 'Sega',
Expand All @@ -18,6 +22,26 @@
}

class TestFilters(unittest.TestCase):
def test_example_configs(self):
entry = {'filters': GetFilters('DosSpeedruns.json', 0)}
ret = CheckStream(entry, 'Die4Ever', 'DOS game speedruns', ['speedrun'], 'The 7th Guest')
self.assertTrue(ret)
ret = CheckStream(entry, 'Die4Ever', 'MSDOS game speedrun', ['speedrun'], 'The 7th Guest')
self.assertTrue(ret)
ret = CheckStream(entry, 'Die4Ever', 'Daily DOSe of DXRando', ['speedrun'], 'Deus Ex Randomizer')

This comment has been minimized.

Copy link
@Die4Ever

Die4Ever Oct 12, 2024

Author Collaborator

hardest part of this commit was thinking of a word that has DOS inside of it to test the new MatchWord filter

self.assertFalse(ret)

def test_match_words(self):
filters = [{'MatchWord': 'Deus Ex Randomizer'}]
entry = {'filters': filters}
ret = CheckStream(entry, 'Die4Ever', 'Deus Ex RaNdomizer Halloween speedruns', ['RaNdomizer', 'Speedrun'], 'dEUS eX')
self.assertTrue(ret)

filters = [{'DontMatchWord': 'Deus Ex Random'}]
entry = {'filters': filters}
ret = CheckStream(entry, 'Die4Ever', 'Deus Ex RaNdomizer Halloween speedruns', ['RaNdomizer', 'Speedrun'], 'dEUS eX')
self.assertTrue(ret)

def test_single_filters(self):
for (k,v) in all_filters.items():
with self.subTest(k+':'+v):
Expand Down Expand Up @@ -47,5 +71,14 @@ def positive(self, filters):

def negative(self, filters):
entry = {'filters': filters}
ret = CheckStream(entry, 'Bob Page', 'playing some Sonic and then rule the world', ['Sega'], 'sONIC')
ret = CheckStream(entry, 'Bob Page', 'playing some Sonic and other random games and then rule the world', ['Sega'], 'sONIC')
self.assertFalse(ret, 'negative')


def GetFilters(name, num):
root = Path(__file__).parent.parent
search:Path = root/'searches_examples'/name
text = search.read_text()
data = json.loads(text)
return data[num]['filters']

0 comments on commit 2f504a4

Please sign in to comment.