]> 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 32fb1fa10c1db4f3a013efafc906ac07c1391869..3bae93c106eb5d914c8da40d3c8b889b7e3e07d0 100644 (file)
@@ -17,10 +17,10 @@ from pyva import *
 from core import *
 from plugin import *
 import mythreading as threading
-from pseudoclient import sys_antiflood, sys_auth, sys_channels, sys_log, sys_options, cmd_manager, inviteable
+from pseudoclient import sys_antiflood, sys_log, sys_options, cmd_manager, inviteable, argparser
 
-import cmd_admin, cmd_user, erepparser, internets_users
-from api import bing, calc, google, imdb, ipinfo, lastfm, quotes, urbandictionary, urls, weather, wolfram, words, steam
+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
 
@@ -72,6 +72,18 @@ class internets(
                        self.log.exception("Error reading 'internets:channel' configuration option: %s" % err)
                        raise
 
+               try:
+                       self.output_limit = int(self.config.get('internets').get('outputlimit'))
+               except Exception, err:
+                       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):
@@ -88,6 +100,7 @@ class internets(
 
                        self.options = sys_options.OptionManager(self)
                        self.elog = sys_log.LogManager(self)
+                       self.commands_private = cmd_private.PrivateCommandManager()
                        self.commands_user = cmd_user.UserCommandManager()
                except Exception, err:
                        self.log.exception('Error initializing core subsystems for internets module (%s)' % err)
@@ -96,9 +109,9 @@ class internets(
                self.elog.debug('Started core subsystems.')
 
                try:
-                       self.channels = sys_channels.ChannelManager(self)
+                       self.channels = internets_channels.InternetsChannelManager(self)
                        self.users = internets_users.InternetsUserManager(self)
-                       self.auth = sys_auth.AuthManager(self)
+                       self.auth = sys_auth.InternetsAuthManager(self)
                        self.antiflood = sys_antiflood.AntiFloodManager(self)
                except Exception, err:
                        self.log.exception('Error initializing subsystems for internets module (%s)' % err)
@@ -112,8 +125,8 @@ class internets(
                        except Exception, err:
                                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.imdb = imdb.Imdb()
+                       self.google = google.Google(self.config.get('internets').get('key_google'), self.config.get('internets').get('yt_parse_delay'))
+                       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'))
@@ -123,6 +136,7 @@ class internets(
                        self.wolfram = wolfram.Wolfram(self.config.get('internets').get('key_wolframalpha'))
                        self.wordnik = words.Words(self.config.get('internets').get('key_wordnik'))
                        self.steam = steam.Steam(self.config.get('internets').get('key_steam'))
+                       self.twitch = twitch.Twitch()
                except Exception, err:
                        self.log.exception('Error initializing internets module (%s)' % err)
                        raise
@@ -184,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
@@ -222,7 +239,7 @@ class internets(
 
                self.elog.command('%s%s > %s' % (sender, ':%s' % channel if channel != sender else '', full_command))
 
-               parser = erepparser.ErepublikParser(add_help_option = False, option_class = erepparser.ErepublikParserOption)
+               parser = argparser.ArgumentParser(add_help_option = False, option_class = argparser.ArgumentParserOption)
                cmd_type = cmd[1]
                cmd_args = cmd[3]
 
@@ -232,8 +249,12 @@ class internets(
                        parser.add_option(cmd_arg[1], '--' + cmd_arg[0], **cmd_arg[3])
 
                try:
+                       argument = argument.lstrip()
+                       if len(argument) > 1:
+                               if argument[0] == '-' and argument[1] != '-' and not cmd_args:
+                                       argument = '-- ' + argument
                        (popts, pargs) = parser.parse_args(args = argument.split(' '))
-               except erepparser.ErepublikParserError, err:
+               except argparser.ArgumentParserError, err:
                        self.msg(channel, str(err)) #TODO: Avoid str, use unicode.
                        parser.destroy()
                        self.elog.debug('Parsed command @b%s@b: invalid options.' % full_command)
@@ -298,6 +319,22 @@ class internets(
                parser.destroy()
                self.elog.debug('Parsed command @b%s@b: execution terminated.' % full_command)
 
+       def onPrivmsg(self, source, target, message):
+               if not super(internets, self).onPrivmsg(source, target, message):
+                       # It's not a command
+                       return
+
+               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:
                        return