Skip to content

Commit a360e53

Browse files
Extra Commands for Clips
**TwitchCache.java** - Store the most viewed clip and last clip in the DB. **clipHandler.js** - Added !lastclip and !topclip - Displays the last clip captures and the top clip in the past day **handlers-clipHandler.js** - Added language entries for new commands
1 parent 8108a42 commit a360e53

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

javascript-source/handlers/clipHandler.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
$.setIniDbBoolean('clipsSettings', 'toggle', toggle);
5757
$.say($.whisperPrefix(sender) + (toggle ? $.lang.get('cliphandler.toggle.on') : $.lang.get('cliphandler.toggle.off')));
5858
}
59-
6059

6160
/*
6261
* @commandpath clipsmessage - Sets a message for when someone creates a clip.
@@ -71,14 +70,34 @@
7170
$.setIniDbString('clipsSettings', 'message', message);
7271
$.say($.whisperPrefix(sender) + $.lang.get('cliphandler.message.set', message));
7372
}
73+
74+
/*
75+
* @commandpath lastclip - Displays information about the last clip captured.
76+
*/
77+
if (command.equalsIgnoreCase('lastclip')) {
78+
var url = $.getIniDbString('streamInfo', 'last_clip_url', $.lang.get('cliphandler.noclip'));
79+
$.say($.whisperPrefix(sender) + $.lang.get('cliphandler.lastclip', url));
80+
}
81+
82+
/*
83+
* @commandpath topclip - Displays the top clip from the past day.
84+
*/
85+
if (command.equalsIgnoreCase('topclip')) {
86+
var url = $.getIniDbString('streamInfo', 'most_viewed_clip_url', $.lang.get('cliphandler.noclip'));
87+
$.say($.whisperPrefix(sender) + $.lang.get('cliphandler.topclip', url));
88+
}
7489
});
7590

7691
/*
7792
* @event initReady
7893
*/
7994
$.bind('initReady', function() {
80-
$.registerChatCommand('./handlers/clipHandler.js', 'clipstoggle', 1);
81-
$.registerChatCommand('./handlers/clipHandler.js', 'clipsmessage', 1);
95+
if ($.bot.isModuleEnabled('./handlers/clipHandler.js')) {
96+
$.registerChatCommand('./handlers/clipHandler.js', 'clipstoggle', 1);
97+
$.registerChatCommand('./handlers/clipHandler.js', 'clipsmessage', 1);
98+
$.registerChatCommand('./handlers/clipHandler.js', 'lastclip', 7);
99+
$.registerChatCommand('./handlers/clipHandler.js', 'topclip', 7);
100+
}
82101
});
83102

84103
$.reloadClips = reloadClips;

javascript-source/lang/english/handlers/handlers-clipHandler.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ $.lang.register('cliphandler.toggle.off', 'Clips announcements have been disable
22
$.lang.register('cliphandler.toggle.on', 'Clips announcements have been enabled.');
33
$.lang.register('cliphandler.message.usage', 'Usage: !clipsmessage (message) - Tags: (name), (url)');
44
$.lang.register('cliphandler.message.set', 'Clips message has been set to: $1.');
5+
$.lang.register('cliphandler.noclip', 'No clip found');
6+
$.lang.register('cliphandler.lastclip', 'Last Clip: $1');
7+
$.lang.register('cliphandler.topclip', 'Today\'s Most Viewed Clip: $1');

source/tv/phantombot/cache/TwitchCache.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ private void updateClips() {
185185
if (clipsObj.has("clips")) {
186186
JSONArray clipsData = clipsObj.getJSONArray("clips");
187187
if (clipsData.length() > 0) {
188+
setDBString("most_viewed_clip_url", clipsData.getJSONObject(0).getString("url");
188189
String lastTrackingIdStr = getDBString("last_clips_tracking_id");
189190
int lastTrackingId = (lastTrackingIdStr == null ? 0 : Integer.parseInt(lastTrackingIdStr));
190191
largestTrackingId = lastTrackingId;
@@ -203,6 +204,7 @@ private void updateClips() {
203204

204205
if (clipURL.length() > 0) {
205206
setDBString("last_clips_tracking_id", String.valueOf(largestTrackingId));
207+
setDBString("last_clip_url", clipURL);
206208
EventBus.instance().postAsync(new TwitchClipEvent(clipURL, creator, getChannel()));
207209
}
208210
}

0 commit comments

Comments
 (0)