aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorGravatar jesopo2019-05-22 19:42:52 +0100
committerGravatar jesopo2019-05-22 19:42:52 +0100
commitaa75f4ef05954939200edb62fd3d63b89c8a0763 (patch)
tree0a18f9a4f89e856f32bc0da38d873da1ab66a21a /modules
parentRefactor tweet-formatting logic in to it's own functions (diff)
signature
Implement auto-tweet setting to get tweet info automatically
Diffstat (limited to 'modules')
-rw-r--r--modules/tweets.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/modules/tweets.py b/modules/tweets.py
index edf4a54c..784311fb 100644
--- a/modules/tweets.py
+++ b/modules/tweets.py
@@ -10,6 +10,9 @@ from src import ModuleManager, utils
REGEX_TWITTERURL = re.compile(
"https?://(?:www\.)?twitter.com/[^/]+/status/(\d+)", re.I)
+@utils.export("channelset", {"setting": "auto-tweet",
+ "help": "Enable/disable automatically getting tweet info",
+ "validate": utils.bool_or_none})
class Module(ModuleManager.BaseModule):
_name = "Twitter"
@@ -97,3 +100,16 @@ class Module(ModuleManager.BaseModule):
event["stderr"].write("Invalid tweet identifiers provided")
else:
event["stderr"].write("No tweet provided to get information about")
+
+ @utils.hook("command.regex", pattern=REGEX_TWITTERURL)
+ def regex(self, event):
+ """
+ :command: tweet
+ """
+ if event["target"].get_setting("auto-tweet", False):
+ event.eat()
+ tweet_id = event["match"].group(1)
+ tweet = self._from_id(tweet_id)
+ if tweet:
+ tweet_str = self._format_tweet(tweet)
+ event["stdout"].write(tweet_str)