コード例 #1
0
    def on_notification(self, conn, event, respond_to):
        """Handle notification messages from Twitch, sending the message up to the web"""
        log.info("Notification: %s" % event.arguments[0])
        subscribe_match = self.re_subscription.match(event.arguments[0])
        if subscribe_match and irc.client.is_channel(event.target):
            # Don't highlight the same sub via both the chat and the API
            if subscribe_match.group(1).lower() not in self.lastsubs:
                self.on_subscriber(conn, event.target,
                                   subscribe_match.group(1), time.time())
            return

        subscribe_match = self.re_resubscription.match(event.arguments[0])
        if subscribe_match and irc.client.is_channel(event.target):
            if subscribe_match.group(1).lower() not in self.lastsubs:
                self.on_subscriber(conn,
                                   event.target,
                                   subscribe_match.group(1),
                                   time.time(),
                                   monthcount=int(subscribe_match.group(2)))
            return

        notifyparams = {
            'apipass': config['apipass'],
            'message': event.arguments[0],
            'eventtime': time.time(),
        }
        if irc.client.is_channel(event.target):
            notifyparams['channel'] = event.target[1:]
        utils.api_request('notifications/newmessage', notifyparams, 'POST')
コード例 #2
0
    def on_subscriber(self,
                      conn,
                      channel,
                      user,
                      eventtime,
                      logo=None,
                      monthcount=None):
        notifyparams = {
            'apipass': config['apipass'],
            'message': "%s just subscribed!" % user,
            'eventtime': eventtime,
            'subuser': user,
            'channel': channel,
        }

        if logo is None:
            try:
                channel_info = twitch.get_info(user)
            except:
                pass
            else:
                if channel_info.get('logo'):
                    notifyparams['avatar'] = channel_info['logo']
        else:
            notifyparams['avatar'] = logo

        if monthcount is not None:
            notifyparams['monthcount'] = monthcount

        # have to get this in a roundabout way as datetime.date.today doesn't take a timezone argument
        today = datetime.datetime.now(config['timezone']).date().toordinal()
        if today != storage.data.get("storm", {}).get("date"):
            storage.data["storm"] = {
                "date": today,
                "count": 0,
            }
        storage.data["storm"]["count"] += 1
        self.lastsubs.append(user.lower())
        self.lastsubs = self.lastsubs[-10:]
        storage.save()
        conn.privmsg(
            channel,
            "lrrSPOT Thanks for subscribing, %s! (Today's storm count: %d)" %
            (notifyparams['subuser'], storage.data["storm"]["count"]))
        utils.api_request('notifications/newmessage', notifyparams, 'POST')

        self.subs.add(user.lower())
        storage.data['subs'] = list(self.subs)
        storage.save()
コード例 #3
0
ファイル: __init__.py プロジェクト: keab42/lrrbot
    def on_subscriber(self, conn, channel, user, eventtime, logo=None, monthcount=None):
        notifyparams = {
            "apipass": config["apipass"],
            "message": "%s just subscribed!" % user,
            "eventtime": eventtime,
            "subuser": user,
            "channel": channel,
        }

        if logo is None:
            try:
                channel_info = twitch.get_info(user)
            except:
                pass
            else:
                if channel_info.get("logo"):
                    notifyparams["avatar"] = channel_info["logo"]
        else:
            notifyparams["avatar"] = logo

        if monthcount is not None:
            notifyparams["monthcount"] = monthcount

            # have to get this in a roundabout way as datetime.date.today doesn't take a timezone argument
        today = datetime.datetime.now(config["timezone"]).date().toordinal()
        if today != storage.data.get("storm", {}).get("date"):
            storage.data["storm"] = {"date": today, "count": 0}
        storage.data["storm"]["count"] += 1
        self.lastsubs.append(user.lower())
        self.lastsubs = self.lastsubs[-10:]
        storage.save()
        conn.privmsg(
            channel,
            "lrrSPOT Thanks for subscribing, %s! (Today's storm count: %d)"
            % (notifyparams["subuser"], storage.data["storm"]["count"]),
        )
        utils.api_request("notifications/newmessage", notifyparams, "POST")

        self.subs.add(user.lower())
        storage.data["subs"] = list(self.subs)
        storage.save()
コード例 #4
0
ファイル: main.py プロジェクト: warandpeace/lrrbot
	def on_subscriber(self, conn, channel, user, eventtime, logo=None, monthcount=None):
		notifyparams = {
			'apipass': config['apipass'],
			'message': "%s just subscribed!" % user,
			'eventtime': eventtime,
			'subuser': user,
			'channel': channel,
		}

		if logo is None:
			try:
				channel_info = twitch.get_info(user)
			except:
				pass
			else:
				if channel_info.get('logo'):
					notifyparams['avatar'] = channel_info['logo']
		else:
			notifyparams['avatar'] = logo

		if monthcount is not None:
			notifyparams['monthcount'] = monthcount

		# have to get this in a roundabout way as datetime.date.today doesn't take a timezone argument
		today = datetime.datetime.now(config['timezone']).date().toordinal()
		if today != storage.data.get("storm",{}).get("date"):
			storage.data["storm"] = {
				"date": today,
				"count": 0,
			}
		storage.data["storm"]["count"] += 1
		self.lastsubs.append(user.lower())
		self.lastsubs = self.lastsubs[-10:]
		storage.save()
		conn.privmsg(channel, "lrrSPOT Thanks for subscribing, %s! (Today's storm count: %d)" % (notifyparams['subuser'], storage.data["storm"]["count"]))
		utils.api_request('notifications/newmessage', notifyparams, 'POST')

		self.subs.add(user.lower())
		storage.data['subs'] = list(self.subs)
		storage.save()
コード例 #5
0
ファイル: __init__.py プロジェクト: keab42/lrrbot
    def on_notification(self, conn, event, respond_to):
        """Handle notification messages from Twitch, sending the message up to the web"""
        log.info("Notification: %s" % event.arguments[0])
        subscribe_match = self.re_subscription.match(event.arguments[0])
        if subscribe_match and irc.client.is_channel(event.target):
            # Don't highlight the same sub via both the chat and the API
            if subscribe_match.group(1).lower() not in self.lastsubs:
                self.on_subscriber(conn, event.target, subscribe_match.group(1), time.time())
            return

        subscribe_match = self.re_resubscription.match(event.arguments[0])
        if subscribe_match and irc.client.is_channel(event.target):
            if subscribe_match.group(1).lower() not in self.lastsubs:
                self.on_subscriber(
                    conn, event.target, subscribe_match.group(1), time.time(), monthcount=int(subscribe_match.group(2))
                )
            return

        notifyparams = {"apipass": config["apipass"], "message": event.arguments[0], "eventtime": time.time()}
        if irc.client.is_channel(event.target):
            notifyparams["channel"] = event.target[1:]
        utils.api_request("notifications/newmessage", notifyparams, "POST")