Skip to content

Commit

Permalink
widget/followers: add latest followers widget #142
Browse files Browse the repository at this point in the history
  • Loading branch information
sogehige committed Mar 30, 2017
1 parent cda2a24 commit 2ffc111
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 2 deletions.
23 changes: 23 additions & 0 deletions libs/widgets/followers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict'

function FollowersWidget () {
global.configuration.register('followersWidgetShow', 'core.no-response', 'number', 5)
global.configuration.register('followersWidgetFontSize', 'core.no-response', 'number', 20)

global.panel.addWidget('followers', 'widget-title-latest-followers', 'user')
global.panel.socketListening(this, 'followers.latest.get', this.emitLatestFollowers)
global.panel.socketListening(this, 'followers.configuration.get', this.sendConfiguration)
}

FollowersWidget.prototype.sendConfiguration = function (self, socket) {
socket.emit('followers.configuration', {
followersWidgetShow: global.configuration.getValue('followersWidgetShow'),
followersWidgetFontSize: global.configuration.getValue('followersWidgetFontSize')
})
}

FollowersWidget.prototype.emitLatestFollowers = function (self, socket) {
socket.emit('followers.latest', global.users.cachedLatestFollowers)
}

module.exports = new FollowersWidget()
7 changes: 6 additions & 1 deletion locales/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"lang-selected": "Bot je nyni prepnuty do cestiny",
"command-parse": "Promin, (sender), ale tento prikaz neni spravne, pouzij",
"error": "Promin, (sender), ale neco se pokazilo!",
"no-response": "",
"api": {
"error": "(sender), neco se pokazilo v API!",
"not-available": "nedostupne"
Expand Down Expand Up @@ -170,14 +171,18 @@
"search-by-username": "Vyhledat podle uživ. jm.",
"create-and-use-a-new-game": "Vytvoř a použij novou hru",
"create-and-use-a-new-title": "Vytvoř a použij nový název",
"followers-show-number": "Zobrazit",
"followers-show": "followerů",
"followers-size": "Velikost fontu",
"widget-title-bets": "SÁZKY",
"widget-title-chat": "CHAT",
"widget-title-clips": "POSLEDNÍ KLIPY",
"widget-title-queue": "FRONTA",
"widget-title-raffles": "TOMBOLA",
"widget-title-soundboard": "SOUNDBOARD",
"widget-title-monitor": "TWITCH STREAM MONITOR",
"widget-title-ytplayer": "PŘEHRÁVAČ HUDBY"
"widget-title-ytplayer": "PŘEHRÁVAČ HUDBY",
"widget-title-latest-followers": "NEJNOVĚJŠÍ FOLLOWEŘI"
},
"raffle": {
"announceInterval": "Otevrene raffle budou oznamovany kazdych (value) minut",
Expand Down
7 changes: 6 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"lang-selected": "Bot language is currently set to english",
"command-parse": "Sorry, (sender), but this command is not correct, use",
"error": "Sorry, (sender), but something went wrong!",
"no-response": "",
"api": {
"error": "(sender), API is not responding correctly!",
"not-available": "not available"
Expand Down Expand Up @@ -170,14 +171,18 @@
"search-by-username": "Search by username",
"create-and-use-a-new-game": "Create and use a new game",
"create-and-use-a-new-title": "Create and use a new title",
"followers-show-number": "Show",
"followers-show": "followers",
"followers-size": "Font size",
"widget-title-bets": "BETS",
"widget-title-chat": "CHAT",
"widget-title-clips": "LATEST CLIPS",
"widget-title-queue": "QUEUE",
"widget-title-raffles": "RAFFLES",
"widget-title-soundboard": "SOUNDBOARD",
"widget-title-monitor": "TWITCH STREAM MONITOR",
"widget-title-ytplayer": "MUSIC PLAYER"
"widget-title-ytplayer": "MUSIC PLAYER",
"widget-title-latest-followers": "LATEST FOLLOWERS"
},
"raffle": {
"announceInterval": "Opened raffles will be announced every (value) minute",
Expand Down
77 changes: 77 additions & 0 deletions public/widgets/followers.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<div class="widget">
<h6 data-lang="widget-title-latest-followers"></h6>
<ul class="nav nav-pills" role="tablist">
<li role="presentation" class="active">
<a href="#followers-main" aria-controls="home" role="tab" data-toggle="tab" title="Latest Followers">
<i class="fa fa-user" aria-hidden="true"></i>
</a>
</li>
<li role="presentation">
<a href="#followers-settings" aria-controls="home" role="tab" data-toggle="tab" title="Settings">
<i class="fa fa-cog" aria-hidden="true"></i>
</a>
</li>
</ul>

<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="followers-main">
<div id="followers-widget"></div>
</div> <!-- /MAIN -->

<div role="tabpanel" class="tab-pane" id="followers-settings">
<div class="input-group">
<span class="input-group-addon" data-lang="followers-show-number"></span>
<input type="text" class="form-control" id="followersShow">
<span class="input-group-addon" data-lang="followers-show"></span>
</div>
<div class="input-group">
<span class="input-group-addon" data-lang="followers-size"></span>
<input type="text" class="form-control" id="followersSize">
</div>
<button type="button" class="btn btn-danger btn-block" onclick="deleteWidget('followers')" style="margin-top: 20px;" data-lang="remove-widget"></button>
</div> <!-- /SETTINGS -->
</div>

<script>
if (!_.isUndefined(IFollowers)) window.clearInterval(IFollowers)
var IFollowers = setInterval(function() { socket.emit('followers.latest.get') }, 2000)

socket.emit('followers.configuration.get')
socket.off('followers.configuration')
socket.on('followers.configuration', function(data) {
$("#followersShow").val(data.followersWidgetShow)
$("#followersSize").val(data.followersWidgetFontSize)
})

socket.off('followers.latest')
socket.on('followers.latest', function (items) {
$("#followers-widget").empty()
var toShow = $("#followersShow").val()
var output = ''
_.each(items, function(item, index) {
if (index < toShow) {
output += '<p class="text-center text-uppercase" style="font-size: ' + $('#followersSize').val() + 'px">' + item + '</p>'
} else return false
})
$("#followers-widget").html(output)
})

var $followersShow = $('#followersShow')
$followersShow.off()
$followersShow.on('focusout', function() {
var value = $followersShow.val()
var data = {}
data['followersWidgetShow'] = value
socket.emit('saveConfiguration', data)
})

var $followersSize = $('#followersSize')
$followersSize.off()
$followersSize.on('focusout', function() {
var value = $followersSize.val()
var data = {}
data['followersWidgetFontSize'] = value
socket.emit('saveConfiguration', data)
})
</script>

0 comments on commit 2ffc111

Please sign in to comment.