]> jfr.im git - irc/rizon/acid.git/commitdiff
pyva: De-duplicate join/part code across modules
authorMilos <redacted>
Thu, 23 Oct 2014 21:21:55 +0000 (23:21 +0200)
committerMichiel <redacted>
Tue, 21 Apr 2015 14:55:52 +0000 (16:55 +0200)
pyva/pyva/src/main/python/erepublik/erepublik.py
pyva/pyva/src/main/python/esim/esim.py
pyva/pyva/src/main/python/internets/internets.py
pyva/pyva/src/main/python/limitserv/limitserv.py
pyva/pyva/src/main/python/pseudoclient/inviteable.py
pyva/pyva/src/main/python/quotes/quotes.py
pyva/pyva/src/main/python/trivia/trivia.py

index 4dc428a7f58873bec53e60ca24c3c680af710b02..c478e6db17a2139a2340646444fcc067ff001562 100644 (file)
@@ -12,7 +12,7 @@ import types
 from istring import istring
 from datetime import datetime
 from decimal import Decimal, InvalidOperation
-from pseudoclient import sys_options, sys_log, sys_antiflood
+from pseudoclient import sys_options, sys_log, sys_antiflood, inviteable
 from utils import *
 
 from pyva import *
@@ -28,9 +28,11 @@ from api import citizen, company, country, feed, region
 import pyva_net_rizon_acid_core_Acidictive as Acidictive
 import pyva_net_rizon_acid_core_AcidCore as AcidCore
 import pyva_net_rizon_acid_core_User as User
-import pyva_net_rizon_acid_core_Channel as Channel
 
-class erepublik(AcidPlugin):
+class erepublik(
+       AcidPlugin,
+       inviteable.InviteablePseudoclient
+):
        initialized = False
 
        def bind_function(self, function):
@@ -144,16 +146,6 @@ class erepublik(AcidPlugin):
                        self.options.stop()
                        self.options.db_close()
 
-       def join(self, channel):
-               me = User.findUser(self.nick)
-               me.joinChan(channel)
-
-       def part(self, channel):
-               me = User.findUser(self.nick)
-               chan = Channel.findChannel(channel)
-               if chan:
-                       me.partChan(chan)
-
        def errormsg(self, target, message):
                self.msg(target, '@b@c4Error:@o %s' % message)
 
@@ -299,54 +291,6 @@ class erepublik(AcidPlugin):
                        self.channels.remove(channel)
                        self.elog.request('Channel @b%s@b was dropped. Deleting it.' % channel)
 
-       def onNotice(self, source, target, message):
-               if not self.initialized:
-                       return
-
-               me = User.findUser(self.nick)
-               user = User.findUser(target)
-               userinfo = User.findUser(source)
-
-               if me != user or (userinfo != None and userinfo['nick'] != 'ChanServ'):
-                       return
-
-               try:
-                       msg = message.strip()
-               except:
-                       return
-
-               if msg.startswith('[#'): #It's a channel welcome message. Let's ignore it.
-                       return
-
-               self.elog.chanserv('%s' % msg)
-               sp = msg.split(' ')
-
-               if userinfo == None:
-                       if 'tried to kick you from' in msg:
-                               nick = strip_ascii_irc(sp[1])
-                               channel = strip_ascii_irc(sp[7])
-                               self.notice(nick, 'To remove this bot (must be channel founder): @b/msg %s remove %s@b' % (self.nick, channel))
-
-                       return
-
-               if "isn't registered" in msg:
-                       self.auth.reject_not_registered(strip_ascii_irc(sp[1]))
-                       return
-
-               if len(sp) < 6:
-                       return
-
-               if 'inviting' in sp[2]: #It's an invite notice. Let's ignore it.
-                       return
-
-               nick = strip_ascii_irc(sp[0])
-               channel = sp[5][0:len(sp[5]) - 1]
-
-               if 'Founder' in sp[2]:
-                       self.auth.accept(nick)
-               else:
-                       self.auth.reject_not_founder(nick, channel)
-
        def onPrivmsg(self, source, target, message):
                if not self.initialized:
                        return
index e1f6adbc2a2eff24292e3c3f86614388af22da2f..397a4953689f546e3e2dd0aa9a8971cf9d1b4bd1 100644 (file)
@@ -13,7 +13,7 @@ import types
 from istring import istring
 from datetime import datetime
 from decimal import Decimal, InvalidOperation
-from pseudoclient import sys_options, sys_log, cmd_manager, sys_antiflood
+from pseudoclient import sys_options, sys_log, cmd_manager, sys_antiflood, inviteable
 from utils import *
 
 from pyva import *
@@ -27,9 +27,11 @@ import cmd_admin, cmd_private, cmd_user, esimparser, sys_auth, esim_users, esim_
 import pyva_net_rizon_acid_core_Acidictive as Acidictive
 import pyva_net_rizon_acid_core_AcidCore as AcidCore
 import pyva_net_rizon_acid_core_User as User
-import pyva_net_rizon_acid_core_Channel as Channel
 
-class esim(AcidPlugin):
+class esim(
+       AcidPlugin,
+       inviteable.InviteablePseudoclient
+):
        def bind_function(self, function):
                func = types.MethodType(function, self, esim)
                setattr(esim, function.__name__, func)
@@ -138,16 +140,6 @@ class esim(AcidPlugin):
                        self.options.stop()
                        self.options.db_close()
 
-       def join(self, channel):
-               me = User.findUser(self.nick)
-               me.joinChan(channel)
-
-       def part(self, channel):
-               me = User.findUser(self.nick)
-               chan = Channel.findChannel(channel)
-               if chan:
-                       me.partChan(chan)
-
        def errormsg(self, target, message):
                self.msg(target, '@b@c4Error:@o %s' % message)
 
@@ -292,54 +284,6 @@ class esim(AcidPlugin):
                        self.channels.remove(channel)
                        self.elog.request('Channel @b%s@b was dropped. Deleting it.' % channel)
 
-       def onNotice(self, source, target, message):
-               if not self.initialized:
-                       return
-
-               me = User.findUser(self.nick)
-               user = User.findUser(target)
-               userinfo = User.findUser(source)
-
-               if me != user or (userinfo != None and userinfo['nick'] != 'ChanServ'):
-                       return
-
-               try:
-                       msg = message.strip()
-               except:
-                       return
-
-               if msg.startswith('[#'): #It's a channel welcome message. Let's ignore it.
-                       return
-
-               self.elog.chanserv('%s' % msg)
-               sp = msg.split(' ')
-
-               if userinfo == None:
-                       if 'tried to kick you from' in msg:
-                               nick = strip_ascii_irc(sp[1])
-                               channel = strip_ascii_irc(sp[7])
-                               self.notice(nick, 'To remove this bot (must be channel founder): @b/msg %s remove %s@b' % (self.nick, channel))
-
-                       return
-
-               if "isn't registered" in msg:
-                       self.auth.reject_not_registered(strip_ascii_irc(sp[1]))
-                       return
-
-               if len(sp) < 6:
-                       return
-
-               if 'inviting' in sp[2]: #It's an invite notice. Let's ignore it.
-                       return
-
-               nick = strip_ascii_irc(sp[0])
-               channel = sp[5][0:len(sp[5]) - 1]
-
-               if 'Founder' in sp[2]:
-                       self.auth.accept(nick)
-               else:
-                       self.auth.reject_not_founder(nick, channel)
-
        def onPrivmsg(self, source, target, message):
                if not self.initialized:
                        return
index 7d4226e2f6f9335962c68160c61a0746e1625b01..a95230656bd8ee73ca8f06ab9e2ea6266bbd13d2 100644 (file)
@@ -27,7 +27,6 @@ from api.steam import SteamUser
 import pyva_net_rizon_acid_core_Acidictive as Acidictive
 import pyva_net_rizon_acid_core_AcidCore as AcidCore
 import pyva_net_rizon_acid_core_User as User
-import pyva_net_rizon_acid_core_Channel as Channel
 
 class internets(
        AcidPlugin,
@@ -172,16 +171,6 @@ class internets(
                        self.options.stop()
                        self.options.db_close()
 
-       def join(self, channel):
-               me = User.findUser(self.nick)
-               me.joinChan(channel)
-
-       def part(self, channel):
-               me = User.findUser(self.nick)
-               chan = Channel.findChannel(channel)
-               if chan:
-                       me.partChan(chan)
-
        def errormsg(self, target, message):
                self.msg(target, '@b@c4Error:@o %s' % message)
 
index d61fc3f4f3d9629e3559b9fa3d64e54ec1db4c3c..3c61778ef82de465822e04c730d7f23f152eb154 100644 (file)
@@ -128,15 +128,8 @@ class limitserv(
                        self.limit_monitor.stop()
                        
        def join(self, channel):
-               me = User.findUser(self.nick)
-               me.joinChan(channel)
-               self.msg('ChanServ', 'OP %s' % channel)                   # and the channel is not empty. For now, use /cs op
-
-       def part(self, channel):
-               me = User.findUser(self.nick)
-               chan = Channel.findChannel(channel)
-               if chan:
-                       me.partChan(chan)
+               super(limitserv, self).join(channel)
+               self.msg('ChanServ', 'OP %s' % channel) # and the channel is not empty. For now, use /cs op
 
        def msg(self, target, message):
                if message != '':
index 085efcfb98dfff1c3afe46800b6c8a93f0368f29..b0c17ffe072d4813191da90288eec25a3a4780ad 100644 (file)
@@ -12,6 +12,7 @@ from utils import strip_ascii_irc
 from core import anope_major
 
 import pyva_net_rizon_acid_core_User as User
+import pyva_net_rizon_acid_core_Channel as Channel
 
 #---------------------------------------------------------------------#
 # this is terrible 
@@ -85,6 +86,16 @@ class InviteablePseudoclient(object):
        def do_accept(self, nick, channel):
                self.auth.accept(nick)
 
+       def join(self, channel):
+               me = User.findUser(self.nick)
+               me.joinChan(channel)
+
+       def part(self, channel):
+               me = User.findUser(self.nick)
+               chan = Channel.findChannel(channel)
+               if chan:
+                       me.partChan(chan)
+
        def onNotice(self, source, target, message):
                if not self.initialized:
                        return
index e3d6a01708989e11ddc0bef4593ac04db6a49407..0a9453145fd1454a166693f6eccf3689783ebc23 100644 (file)
@@ -119,15 +119,11 @@ class quotes(
                        self.options.db_close()
 
        def join(self, channel):
-               me = User.findUser(self.nick)
-               me.joinChan(channel)
+               super(quotes, self).join(channel)
                self.dbp.execute("INSERT IGNORE INTO quotes_chans(name) VALUES(%s)", (str(channel),))
 
        def part(self, channel):
-               me = User.findUser(self.nick)
-               chan = Channel.findChannel(channel)
-               if chan:
-                       me.partChan(chan)
+               super(quotes, self).part(channel)
 
                self.dbp.execute("DELETE FROM quotes_quotes WHERE channel=%s", (self.get_cid(channel),))
                self.dbp.execute("DELETE FROM quotes_chans WHERE name=%s", (str(channel),))
index 562d067e6c7e0cbf02c98ad9af7cbf7e4a61e86f..f9f630009d75c7217ea6f5f68f1b847e2ab82041 100644 (file)
@@ -22,7 +22,6 @@ import cmd_admin, sys_auth, trivia_engine
 import pyva_net_rizon_acid_core_Acidictive as Acidictive
 import pyva_net_rizon_acid_core_AcidCore as AcidCore
 import pyva_net_rizon_acid_core_User as User
-import pyva_net_rizon_acid_core_Channel as Channel
 
 class trivia(
        AcidPlugin,
@@ -144,15 +143,11 @@ class trivia(
                self.trivias.clear()
 
        def join(self, channel):
-               me = User.findUser(self.nick)
-               me.joinChan(channel)
+               super(trivia, self).join(channel)
                self.dbp.execute("INSERT IGNORE INTO trivia_chans(name) VALUES(%s)", (str(channel),))
 
        def part(self, channel):
-               me = User.findUser(self.nick)
-               chan = Channel.findChannel(channel)
-               if chan:
-                       me.partChan(chan)
+               super(trivia, self).part(channel)
 
                self.stop_trivia(channel, True)
                self.dbp.execute("DELETE FROM trivia_chans WHERE name=%s", (str(channel),))