Parse video objects less stoatily The https://github.com/bear/python-twitter API throws away the extended-information field in which the name of the video file is stored; so parse the JSON again ourselves to get hold of it. Pick the highest bit rate MP4 video. Throw away the old ad-hoc mangling of video_thumb urls; that is no longer needed. Signed-off-by: Tom Womack <tom@womack.net> Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk> --- v2: Fix logic error: When tweet contains multiple media, handle videos as videos and non-videos as non-videos. Resulting patch has rather different organisation and does less violence to the original code. Commit message changes: Mention deletion of tweet_video_thumb hack Style fixes and changes: Do not add a comment about the new import Use .get(DEFVAL) rather than nesting in if KEY in VAL, throughout Reformat new comment about JSON parsing to 80 columns Use ' rather than " for protocol elements such as hash keys Use split rather than a regexp to trim ? part from url Comments say "we" do something, not "I". When searching for the best, have a single `best' variable Divide float by float not int Adjust new replacement string construction to be more natural Be consistent about spaces around ==
coding style: Whitespace fixes in tweet handling Remove unidiomatic spaces inside ( ). Remove a blank line in an unusual place. No functional change. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
blame: Allow `~blame #last 2' etc. Ie, ~blame #last 1 = ~blame #last ~blame #last 2 = the last-but-one fish ~blame #last 3 = the last-but-two fish etc. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk> --- v2: Fixed off-by-one error in commit message.
blame: Remember last 10 trouts, not just 1 No functional change yet. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk> --- v2: Fixed wrong-end error in array manipulation.
blameq: Rename fish variable to fishpond This is now always an instance of FishPond. Using the same name as elsewhere in commands.py is less confusing. No functional change. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
blame: Move .last* update into a method The code in troutq and blameq is very clone and hack. This change reduces it very slightly so that I can make my next change in only one place. No functional change. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Make class vars into instance vars Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
FishPond: introduce new class and use in Servus-chiark The configuration class `fish' appears in every bot, but it also contains initial values of state variables used by the implementation. Move those into their own class, and make it a base class of Servus-chiark's pond. Since we are duck typing, it is OK to not yet update the other bots. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
blame: Print the filename with blame #last In principle we could have got this from "git blame" but (1) that makes parsing this more annoying and (2) by rights this should come from the fish cfg so that it can be a display name at some point. The main effect is to print something like: 13:41 <Servus> Modified flirts 2011-05-31: new fish from Alice rather than: 13:41 <Servus> Modified 2011-05-31: new fish from Alice I have not taken the trouble to touch the three open-coded special cases for blame #trouts etc. I thought that was beyond the call of duty. In those cases it will print: 13:41 <Servus> Modified fish? 2011-05-31: new fish from Alice Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
blame: Put the filename in the loadblame result We are going to use this to say what kind of fish it was, in ~blame #last. We also need to change the two places where this is destructured. No functional change. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
blame #last: Blame the right thing Previously this would search all the blame databases. This is wrong, it should search the one corresponding to the last fish. Now that we have last_cfg, and the db info is in the cfg, we can do that. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
blame: Move blame db information into the cfg These should never have been separate. We abolish the ad-hoc tbdb, fbdbk etc. variables. Instead, we put this all in the cfg. It is OK to extend the cfg since the code does not destructure it but instead always indexes it. So bot instances without blame will not mind. blameq needs to fish it out again for the benefit of the open-coded conditions on "#trouts" etc. I'm not fixing that right now. The deleted lines like this tbdb,tbdbk=loadblame("trouts") have different variable names than the inserted lines like this tdb,tdbk = cfgs[0][7] because, unaccountably, the global variable names are different to the local variables inside blameq. No functional change. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
fish: Pass cfgs to blameq This open-coding of three separate things, with blameq having magic knowledge of which one is which, is completely wrong. blameq should take a list. The various Xdb Xdbk should in the cfgs too. A step towards this is for blameq to get the cfgs. No functional change. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
fish: track last_cfg too No-one uses this yet. So no functional change. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Output the date of first mention, not the current date ...this is in the code path where the URL was mentioned on a previous date, so we should output the date of first mention (self.localfirst) not the current date (n).
strip more garbage out of twitter urls (esp the ?s=[:digits:]) tracking code - thanks cjwatson
Add blame-filtering This simply works on the md5 of the offending commit message, and replaces it with new text. blame_filter.py is a simple dictionary of md5: replacement pairs; it is not committed itself (and is ignored by git)
0-pad times (so 13:03 rather than 13:3)
Adjust url-observation, per chiark.irc discussion Servus now describes URLs without adjective, as these were felt to be discouraging. Further, it won't mention a URL within 5 minutes of its previous mention. Time is now given as a timestamp, rather than the "about X minutes/hours ago"
Don't remark on URLs that are repeated after a short period If a URL has been mentioned in the recent past, then it'll be obviously visible in-channel, and it was probably a mistake (e.g. mentioning a URL you meant to ~twit), so no need to comment on it.