Skip to content

Commit

Permalink
added option allowing you to turn off the custom created embed (you c…
Browse files Browse the repository at this point in the history
…an rely on Discord's autoembed instead). Expanded custom_message functionality. Now accepts placeholder values^
  • Loading branch information
NNTin committed Nov 4, 2020
1 parent 1f6da33 commit 7273540
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 14 deletions.
16 changes: 10 additions & 6 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,24 @@
"description": "Include retweets?\nExample: `False`\nWhether the bot should show retweets.",
"value": "true"
},
"IncludeAttachment": {
"INCLUDE_USER_REPLY": {
"description": "Include replies **FROM** your tracked twitter user to other twitter users\nExample: `True`",
"value": "true"
},
"INCLUDE_ATTACHMENT": {
"description": "Include attachments?\nExample: `False`\nIf the tweet contains media the bot will try to attach an image.",
"value": "true"
},
"IncludeQuote": {
"description": "Include retweets?\nExample: `False`\nThis requires INCLUDE_RETWEET True. Shows the original tweet as an additional field in the embed.",
"INCLUDE_QUOTE": {
"description": "Include quotes?\nExample: `False`\nThis requires INCLUDE_RETWEET True. Shows the original tweet as an additional field in the embed.",
"value": "true"
},
"INCLUDE_USER_REPLY": {
"description": "Include replies **FROM** your tracked twitter user to other twitter users\nExample: `True`",
"CREATE_EMBED": {
"description": "Recommended set to true, unless you don't want to see the custom embed. Definitely turn it off if you are relying on Discord's autoembed feature.",
"value": "true"
},
"CUSTOM_MESSAGE": {
"description": "OPTIONAL: Custom message. Useful for pinging @everyone, a role or individual discord members.\nExample: `A new tweet arived pinging role <@&123456> and user <@123456>`\nWith 123456 being the role or user id. You can get them by e.g. typing `\\@Linley#8686` the backslash \\ is important!",
"description": "OPTIONAL: Custom message. Useful if you want to create your own text, ping @everyone or certain roles or rely on Discord's autoembed. Available placeholders are: `url`, `user`, `text`.\nExample: `Hey @everyone, {user} just tweeted {text}. Click on the tweet here {url}`",
"required": false
},
"KEYWORDS": {
Expand Down
10 changes: 10 additions & 0 deletions bot/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Discord:
IncludeUserReply: ${INCLUDE_USER_REPLY!b}
IncludeAttachment: ${INCLUDE_ATTACHMENT!b}
IncludeQuote: ${INCLUDE_QUOTE!b}
CreateEmbed: ${CREATE_EMBED!b}
custom_message: ${CUSTOM_MESSAGE}
keyword_sets: ${KEYWORDS!ll}
blackword_sets: ${BLACKWORDS!ll}
Expand All @@ -56,6 +57,7 @@ Discord:
IncludeUserReply: ${INCLUDE_USER_REPLY_2!b}
IncludeAttachment: ${INCLUDE_ATTACHMENT_2!b}
IncludeQuote: ${INCLUDE_QUOTE_2!b}
CreateEmbed: ${CREATE_EMBED_2!b}
custom_message: ${CUSTOM_MESSAGE_2}
keyword_sets: ${KEYWORDS_2!ll}
blackword_sets: ${BLACKWORDS_2!ll}
Expand All @@ -71,6 +73,7 @@ Discord:
IncludeUserReply: ${INCLUDE_USER_REPLY_3!b}
IncludeAttachment: ${INCLUDE_ATTACHMENT_3!b}
IncludeQuote: ${INCLUDE_QUOTE_3!b}
CreateEmbed: ${CREATE_EMBED_3!b}
custom_message: ${CUSTOM_MESSAGE_3}
keyword_sets: ${KEYWORDS_3!ll}
blackword_sets: ${BLACKWORDS_3!ll}
Expand All @@ -86,6 +89,7 @@ Discord:
IncludeUserReply: ${INCLUDE_USER_REPLY_4!b}
IncludeAttachment: ${INCLUDE_ATTACHMENT_4!b}
IncludeQuote: ${INCLUDE_QUOTE_4!b}
CreateEmbed: ${CREATE_EMBED_4!b}
custom_message: ${CUSTOM_MESSAGE_4}
keyword_sets: ${KEYWORDS_4!ll}
blackword_sets: ${BLACKWORDS_4!ll}
Expand All @@ -101,6 +105,7 @@ Discord:
IncludeUserReply: ${INCLUDE_USER_REPLY_5!b}
IncludeAttachment: ${INCLUDE_ATTACHMENT_5!b}
IncludeQuote: ${INCLUDE_QUOTE_5!b}
CreateEmbed: ${CREATE_EMBED_5!b}
custom_message: ${CUSTOM_MESSAGE_5}
keyword_sets: ${KEYWORDS_5!ll}
blackword_sets: ${BLACKWORDS_5!ll}
Expand All @@ -116,6 +121,7 @@ Discord:
IncludeUserReply: ${INCLUDE_USER_REPLY_6!b}
IncludeAttachment: ${INCLUDE_ATTACHMENT_6!b}
IncludeQuote: ${INCLUDE_QUOTE_6!b}
CreateEmbed: ${CREATE_EMBED_6!b}
custom_message: ${CUSTOM_MESSAGE_6}
keyword_sets: ${KEYWORDS_6!ll}
blackword_sets: ${BLACKWORDS_6!ll}
Expand All @@ -131,6 +137,7 @@ Discord:
IncludeUserReply: ${INCLUDE_USER_REPLY_7!b}
IncludeAttachment: ${INCLUDE_ATTACHMENT_7!b}
IncludeQuote: ${INCLUDE_QUOTE_7!b}
CreateEmbed: ${CREATE_EMBED_7!b}
custom_message: ${CUSTOM_MESSAGE_7}
keyword_sets: ${KEYWORDS_7!ll}
blackword_sets: ${BLACKWORDS_7!ll}
Expand All @@ -146,6 +153,7 @@ Discord:
IncludeUserReply: ${INCLUDE_USER_REPLY_8!b}
IncludeAttachment: ${INCLUDE_ATTACHMENT_8!b}
IncludeQuote: ${INCLUDE_QUOTE_8!b}
CreateEmbed: ${CREATE_EMBED_8!b}
custom_message: ${CUSTOM_MESSAGE_8}
keyword_sets: ${KEYWORDS_8!ll}
blackword_sets: ${BLACKWORDS_8!ll}
Expand All @@ -161,6 +169,7 @@ Discord:
IncludeUserReply: ${INCLUDE_USER_REPLY_9!b}
IncludeAttachment: ${INCLUDE_ATTACHMENT_9!b}
IncludeQuote: ${INCLUDE_QUOTE_9!b}
CreateEmbed: ${CREATE_EMBED_9!b}
custom_message: ${CUSTOM_MESSAGE_9}
keyword_sets: ${KEYWORDS_9!ll}
blackword_sets: ${BLACKWORDS_9!ll}
Expand All @@ -176,6 +185,7 @@ Discord:
IncludeUserReply: ${INCLUDE_USER_REPLY_10!b}
IncludeAttachment: ${INCLUDE_ATTACHMENT_10!b}
IncludeQuote: ${INCLUDE_QUOTE_10!b}
CreateEmbed: ${CREATE_EMBED_10!b}
custom_message: ${CUSTOM_MESSAGE_10}
keyword_sets: ${KEYWORDS_10!ll}
blackword_sets: ${BLACKWORDS_10!ll}
Expand Down
1 change: 0 additions & 1 deletion bot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def _on_status(self, status):

for data_discord in self.config_discord:
p = Processor(status_tweet=data, discord_config=data_discord)
p.get_text()

if (
not p.worth_posting_follow()
Expand Down
26 changes: 21 additions & 5 deletions bot/utils/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ def __init__(self, status_tweet, discord_config):
self.status_tweet = status_tweet
self.discord_config = discord_config
self.text = ""
self.url = ""
self.user = ""
self.embed = None
self.initialize()

def worth_posting_location(self):
if (
Expand Down Expand Up @@ -194,7 +197,7 @@ def worth_posting_follow(self):
include_retweet=self.discord_config.get("IncludeRetweet", True),
)

def get_text(self):
def initialize(self):
if "retweeted_status" in self.status_tweet:
if "extended_tweet" in self.status_tweet["retweeted_status"]:
self.text = self.status_tweet["retweeted_status"]["extended_tweet"]["full_text"]
Expand Down Expand Up @@ -244,7 +247,10 @@ def get_text(self):
"[#%s](https://twitter.com/hashtag/%s)" % (hashtag["text"], hashtag["text"]),
)
self.text = unescape(self.text)
return self.text
self.url = "https://twitter.com/{}/status/{}".format(
self.status_tweet["user"]["screen_name"], self.status_tweet["id_str"]
)
self.user = self.status_tweet["user"]["name"]

def keyword_set_present(self):
return keyword_set_present(self.discord_config.get("keyword_sets", [[""]]), self.text)
Expand Down Expand Up @@ -392,9 +398,19 @@ def send_message(self, wh_url):
int(match.group("id")), match.group("token"), adapter=RequestsWebhookAdapter()
)
try:
webhook.send(
embed=self.embed, content=self.discord_config.get("custom_message", None)
)
if self.discord_config.get("CreateEmbed", True):
webhook.send(
embed=self.embed,
content=self.discord_config.get("custom_message", None).format(
user=self.user, text=self.text, url=self.url
),
)
else:
webhook.send(
content=self.discord_config.get("custom_message", None).format(
user=self.user, text=self.text, url=self.url
)
)
except discord.errors.NotFound as error:
print(
f"---------Error---------\n"
Expand Down
3 changes: 2 additions & 1 deletion bot/utils/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ def pprint(config):
("Include Reply To User", instance.get("IncludeReplyToUser", True)),
("Include User Reply", instance.get("IncludeUserReply", True)),
("Include Retweet", instance.get("IncludeRetweet", True)),
("Include Quote", instance.get("IncludeQuote", True)),
("Include Attachment", instance.get("IncludeAttachment", True)),
("Include Quote", instance.get("IncludeQuote", True)),
("Create Embed", instance.get("CreateEmbed", True)),
("Custom Message", True if instance.get("custom_message", "") is not "" else False),
("Keyword Sets", True if instance.get("keyword_sets", "") is not "" else False),
("Blackword Sets", True if instance.get("blackword_sets", "") is not "" else False),
Expand Down
5 changes: 4 additions & 1 deletion tests/test_config/config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,13 @@
"IncludeUserReply": {
"type": "boolean"
},
"IncludeAttachment": {
"type": "boolean"
},
"IncludeQuote": {
"type": "boolean"
},
"IncludeAttachment": {
"CreateEmbed": {
"type": "boolean"
}
},
Expand Down

0 comments on commit 7273540

Please sign in to comment.