]> jfr.im git - irc/rizon/acid.git/blobdiff - pyva/pyva/src/main/python/internets/internets.py
Send large multi line output per notice. Fixes #62
[irc/rizon/acid.git] / pyva / pyva / src / main / python / internets / internets.py
index 33d94c20aa755489ba047d42dcd26621b8d0b890..3bae93c106eb5d914c8da40d3c8b889b7e3e07d0 100644 (file)
@@ -17,9 +17,9 @@ from pyva import *
 from core import *
 from plugin import *
 import mythreading as threading
-from pseudoclient import sys_antiflood, sys_log, sys_options, cmd_manager, inviteable
+from pseudoclient import sys_antiflood, sys_log, sys_options, cmd_manager, inviteable, argparser
 
-import cmd_admin, cmd_private, cmd_user, erepparser, internets_channels, internets_users, sys_auth
+import cmd_admin, cmd_private, cmd_user, internets_channels, internets_users, sys_auth
 from api import bing, calc, google, imdb, ipinfo, lastfm, quotes, urbandictionary, urls, weather, wolfram, words, steam, twitch
 from internets_utils import *
 from api.steam import SteamUser
@@ -78,6 +78,12 @@ class internets(
                        self.log.exception("Error reading 'internets:outputlimit' configuration option: %s" % err)
                        raise
 
+               try:
+                       self.max_line_length = int(self.config.get('internets').get('maxlinelength'))
+               except Exception, err:
+                       self.log.exception("Error reading 'internets:maxlinelength' configuration option: %s" % err)
+                       raise
+
                self.bind_admin_commands()
 
        def start_threads(self):
@@ -120,7 +126,7 @@ class internets(
                                self.log.exception('Error initializing internets bing API (%s)' % err)
                        self.nsp = calc.NumericStringParser()
                        self.google = google.Google(self.config.get('internets').get('key_google'), self.config.get('internets').get('yt_parse_delay'))
-                       self.imdb = imdb.Imdb()
+                       self.imdb = imdb.Imdb(self.config.get('internets').get('key_imdb'))
                        self.ipinfo = ipinfo.IpInfo(self.config.get('internets').get('key_ipinfodb'))
                        self.lastfm = lastfm.LastFm(self.config.get('internets').get('key_lastfm'))
                        self.quotes = quotes.Quotes(self.config.get('internets').get('key_fml'))
@@ -192,7 +198,10 @@ class internets(
 
        def msg(self, target, message):
                if message != '':
-                       Acidictive.privmsg(self.nick, target, format_ascii_irc(message))
+                       if len(message) > 450: # from Protocol.privmsg -> long, do not spam chan
+                               Acidictive.notice(self.nick, target, format_ascii_irc(message))
+                       else:
+                               Acidictive.privmsg(self.nick, target, format_ascii_irc(message))
 
        def multimsg(self, target, count, intro, separator, pieces, outro = ''):
                cur = 0
@@ -315,10 +324,16 @@ class internets(
                        # It's not a command
                        return
 
-               if not self.users.is_banned(User.findUser(source)['nick']) and target[0] == '#':
-                       if 'youtu' in message and self.channels[target].youtube_info:
-                               # both 'youtube.com' and 'youtu.be' get caught
-                               threading.deferToThread(cmd_user.onPrivmsg_regex_youtube, self, source, target, message)
+               if not target in self.channels:
+                       return
+
+               # both 'youtube.com' and 'youtu.be' get caught
+               if not 'youtu' in message or not self.channels[target].youtube_info:
+                       return
+
+               sourceNick = User.findUser(source)['nick']
+               if not self.users.is_banned(sourceNick) and not self.antiflood.check_user(sourceNick, 'ytinfo', '') and target[0] == '#':
+                       threading.deferToThread(cmd_user.onPrivmsg_regex_youtube, self, source, target, message)
 
        def onChanModes(self, prefix, channel, modes):
                if not self.initialized: