Skip to content

Commit

Permalink
Merge branch 'dev' into pyup-update-discord.py-1.2.3-to-1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
NNTin authored Oct 6, 2020
2 parents 977ee3b + 4fa3d41 commit 9719ffe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
21 changes: 17 additions & 4 deletions bot/utils/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,28 @@
WH_REGEX = r"discord(app)?\.com\/api\/webhooks\/(?P<id>\d+)\/(?P<token>.+)"


def worth_posting_location(location, coordinates):
def worth_posting_location(location, coordinates, retweeted, include_retweet):
location = [location[i : i + 4] for i in range(0, len(location), 4)]

for box in location:
for coordinate in coordinates:
if box[0] < coordinate[0] < box[2] and box[1] < coordinate[1] < box[3]:
if not include_retweet and retweeted:
return False
return True
return False


def worth_posting_track(track, hashtags, text):
def worth_posting_track(track, hashtags, text, retweeted, include_retweet):
for t in track:
if t.startswith("#"):
if t[1:] in map(lambda x: x["text"], hashtags):
if not include_retweet and retweeted:
return False
return True
elif t in text:
if not include_retweet and retweeted:
return False
return True
return False

Expand Down Expand Up @@ -151,7 +157,10 @@ def worth_posting_location(self):
coordinates.append(c)

return worth_posting_location(
location=self.discord_config.get("location", []), coordinates=coordinates
location=self.discord_config.get("location", []),
coordinates=coordinates,
retweeted=self.status_tweet["retweeted"] or "retweeted_status" in self.status_tweet,
include_retweet=self.discord_config.get("IncludeRetweet", True),
)

def worth_posting_track(self):
Expand All @@ -167,7 +176,11 @@ def worth_posting_track(self):
)

return worth_posting_track(
track=self.discord_config.get("track", []), hashtags=hashtags, text=self.text
track=self.discord_config.get("track", []),
hashtags=hashtags,
text=self.text,
retweeted=self.status_tweet["retweeted"] or "retweeted_status" in self.status_tweet,
include_retweet=self.discord_config.get("IncludeRetweet", True),
)

def worth_posting_follow(self):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
black==18.9b0
discord.py==1.5.0
jsonschema==3.0.2
jsonschema==3.2.0
python-dotenv==0.10.3
PyYAML==5.3.1
tox==3.14.0
Expand Down

0 comments on commit 9719ffe

Please sign in to comment.