예제 #1
0
파일: notes.py 프로젝트: Havvy/madcow
class Main(Module):
    pattern = re.compile(u'^\s*(nb|notes?)(?:\s+(.*)$)?')
    require_addressing = True
    dbname = u'note'
    help = u'notes|nb <nick>                        show notes associated to a nick (staff only)\n\
notes|nb <nick> <note>                 add a note to a nick (staff only)'
    
    def init(self):
        self.learn = Learn(madcow=self.madcow)
        self.staff = Staff(madcow=self.madcow)
        
    def set(self, nick, target_nick, note):
        d = datetime.now()
        # append notes, don't overwrite
        old_notes = self.learn.lookup(self.dbname, target_nick) 
        notes = old_notes if old_notes else ""
        self.learn.set(self.dbname, target_nick.lower(), notes + '\n[' + d.strftime("%D") + '] [' + nick + '] ' + note)
        
    def get(self, target_nick):
        return self.learn.lookup(self.dbname, target_nick)
        
    def response(self, nick, args, kwargs):
        cmd = args[0]
        target_nick = False
        note = False
        params = []
        if args[1]:
            params = args[1].partition(' ')
        
        try:
            target_nick = params[0]
        except IndexError:
            target_nick = False
            
        try:
            note = params[2]
        except IndexError:
            note = False

        """ if nick passed, set user as staff """
        if target_nick and (self.staff.is_staff(nick) or settings.OWNER_NICK == nick):
            if note:
                self.set(nick=nick, target_nick=target_nick, note=note)
                return u'%s: Note added to %s\'s record.' % (nick, target_nick)
            else:
                notes = self.get(target_nick=target_nick)
                if notes:
                    return u'%s: Staff notes on %s\n%s' % (nick, target_nick, notes)
                else:
                    return u'%s: No notes found for %s' % (nick, target_nick)
예제 #2
0
파일: welcome.py 프로젝트: Havvy/madcow
class Main(Module):
    pattern = re.compile(u'^\s*(welcome)(?:\s+(.*)$)?')
    require_addressing = False
    help = u'welcome                         get the #stackato welcome package: links for downloads, docs, and support.\n\
welcome <nick>                   send another user the #stackato welcome package (staff only)'
    
    def init(self):
        self.staff = Staff(madcow=self.madcow)

    def response(self, nick, args, kwargs):
        kwargs[u'req'].make_private() # welcome package is always private
        cmd = args[0]
        target_nick = args[1].strip() if args[1] else None
        msg_nick = nick
            
        # only staff members & bot owner are allowed to set/change shortcuts
        if target_nick and (self.staff.is_staff(nick) or settings.OWNER_NICK == nick):
            kwargs['req'].set_sendto(target_nick)
            msg_nick = target_nick

        return u'Welcome to %s, %s!\n%s' % (kwargs[u'channel'], msg_nick, settings.WELCOME_MSG)
예제 #3
0
파일: xray.py 프로젝트: Havvy/madcow
class Main(Module):
    pattern = re.compile(u'^\s*(xray)(?:\s+(.*)$)?')
    require_addressing = False
    help = u'xray <nick>        show all staff-accessible data for <nick> (staff only)'
    
    def init(self):
        self.learn = Learn(madcow=self.madcow)
        self.staff = Staff(madcow=self.madcow)
        self.company = Company(madcow=self.madcow)
        self.realname = Realname(madcow=self.madcow)
        self.notes = Notes(madcow=self.madcow)
    
    def response(self, nick, args, kwargs):
        cmd = args[0]
        target_nick = args[1].strip()
        real_name = False
        
        # only staff members & bot owner are allowed to get xray data
        if self.staff.is_staff(nick) or settings.OWNER_NICK == nick:
            if target_nick:
                name = self.realname.get(target_nick);
                company = self.company.get(target_nick);
                notes = self.notes.get(target_nick);
                email = self.learn.lookup('email', target_nick)
                summary = ''
                if name:
                    summary = summary + 'Name: ' + name + '\n'
                if email:
                    summary = summary + 'Email: ' + email + '\n'
                if company:
                    summary = summary + 'Company: ' + company + '\n'
                if notes:
                    summary = summary + u'=' * 75 + notes + '\n'
                if summary:
                    return u'%s: Here\'s the skinny on %s\n\n%s' % (nick, target_nick, summary)
                else:
                    return u'%s: No data found for %s' % (nick, target_nick)
            else:
                return u'%s: xray only works if you tell me who to scan.' % (nick)
예제 #4
0
class Main(Module):
    pattern = re.compile(u'^\s*(welcome)(?:\s+(.*)$)?')
    require_addressing = False
    help = u'welcome                         get the #stackato welcome package: links for downloads, docs, and support.\n\
welcome <nick>                   send another user the #stackato welcome package (staff only)'

    def init(self):
        self.staff = Staff(madcow=self.madcow)

    def response(self, nick, args, kwargs):
        kwargs[u'req'].make_private()  # welcome package is always private
        cmd = args[0]
        target_nick = args[1].strip() if args[1] else None
        msg_nick = nick

        # only staff members & bot owner are allowed to set/change shortcuts
        if target_nick and (self.staff.is_staff(nick)
                            or settings.OWNER_NICK == nick):
            kwargs['req'].set_sendto(target_nick)
            msg_nick = target_nick

        return u'Welcome to %s, %s!\n%s' % (kwargs[u'channel'], msg_nick,
                                            settings.WELCOME_MSG)
예제 #5
0
파일: realname.py 프로젝트: Havvy/madcow
 def init(self):
     self.learn = Learn(madcow=self.madcow)
     self.staff = Staff(madcow=self.madcow)
예제 #6
0
파일: realname.py 프로젝트: Havvy/madcow
class Main(Module):
    pattern = re.compile(u'^\s*(names?)(?:\s+(.*)$)?')
    require_addressing = False
    dbname = u'realname'
    help = u'names                          show list of associated nicks and names (staff only)\n\
name <nick>                    show real name associated with user (staff only)\n\
name <nick> <real_name>        set real name for user (staff only)'
    
    def init(self):
        self.learn = Learn(madcow=self.madcow)
        self.staff = Staff(madcow=self.madcow)
        
    def set(self, nick, name):
        self.learn.set(self.dbname, nick.lower(), name)
        
    def unset(self, nick):
        dbm = self.learn.dbm(self.dbname)
        try:
            key = encode(nick.lower())
            if dbm.has_key(nick):
                del dbm[nick]
                return True
            return False
        finally:
            dbm.close()
    
    def get_names(self):
        name_db = self.learn.get_db('realname');
        return name_db
    
    def has_name(self, nick):
        name_db = self.get_names()
        return nick in name_db
   
    def get(self, nick):
        return self.learn.lookup(self.dbname, nick)
    
    def response(self, nick, args, kwargs):
        cmd = args[0]
        target_nick = False
        real_name = False
        params = []
        if args[1]:
            params = args[1].partition(' ')
        
        try:
            target_nick = params[0]
        except IndexError:
            target_nick = False
            
        try:
            real_name = params[2]
        except IndexError:
            real_name = False
            
        # only staff members & bot owner are allowed to get & set real_name data
        if self.staff.is_staff(nick) or settings.OWNER_NICK == nick:
            if target_nick:
                if real_name:
                    self.set(target_nick, real_name)
                    return u'%s: Setting name for %s to %s' % ( nick, target_nick, real_name )
                else:
                    name = self.get(nick=target_nick)
                    if name:
                        return u'%s: %s is %s' % ( nick, target_nick, name )
                    else:
                        return u'%s: Sorry, I don\'t who %s is.' % ( nick, target_nick )
            else:
                name_list = "\n\nRecorded names:\n"
                for user_nick, name in self.get_names().iteritems():
                    name_list = name_list + user_nick + ": " + name + "\n"
                return u'%s: %s' % (nick, name_list)
예제 #7
0
파일: welcome.py 프로젝트: Havvy/madcow
 def init(self):
     self.staff = Staff(madcow=self.madcow)
예제 #8
0
 def init(self):
     self.learn = Learn(madcow=self.madcow)
     self.staff = Staff(madcow=self.madcow)
예제 #9
0
파일: company.py 프로젝트: Havvy/madcow
class Main(Module):
    pattern = re.compile(u'^\s*(compan[y|ies])(?:\s+(.*)$)?')
    require_addressing = False
    dbname = u'company'
    help = u'companies                          list all company/nick associations (staff only)\n\
company <nick>                     show company associated with user (staff only)\n\
company <nick> <company_name>      set company information for user (staff only)'
    
    def init(self):
        self.learn = Learn(madcow=self.madcow)
        self.staff = Staff(madcow=self.madcow)
        
    def set(self, nick, company):
        self.learn.set(self.dbname, nick.lower(), company)
        
    def unset(self, nick):
        dbm = self.learn.dbm(self.dbname)
        try:
            key = encode(nick.lower())
            if dbm.has_key(nick):
                del dbm[nick]
                return True
            return False
        finally:
            dbm.close()
    
    def get_companies(self):
        company_db = self.learn.get_db('company');
        return company_db
    
    def has_company(self, nick):
        company_db = self.get_companies()
        return nick in company_db
   
    def get(self, nick):
        return self.learn.lookup(self.dbname, nick)
    
    def response(self, nick, args, kwargs):
        cmd = args[0]
        target_nick = False
        company = False
        params = []
        if args[1]:
            params = args[1].partition(' ')
        
        try:
            target_nick = params[0]
        except IndexError:
            target_nick = False
            
        try:
            company = params[2]
        except IndexError:
            company = False
            
        # only staff members & bot owner are allowed to get & set company data
        if self.staff.is_staff(nick) or settings.OWNER_NICK == nick:
            if target_nick:
                if company:
                    self.set(target_nick, company)
                    return u'%s: setting company for %s to %s' % ( nick, target_nick, company )
                else:
                    company_name = self.get(target_nick)
                    if company_name:
                        return u'%s: %s works at %s' % ( nick, target_nick, company_name )
                    else:
                        return u'%s: I don\'t know where %s works' % ( nick, target_nick )
            else:
                company_list = "\n\nRecorded companies:\n"
                for user_nick, company_name in self.get_companies().iteritems():
                    company_list = company_list + user_nick + " works at " + company_name + "\n"
                return u'%s: %s' % (nick, company_list)
예제 #10
0
class Main(Module):
    pattern = re.compile(u'^\s*(names?)(?:\s+(.*)$)?')
    require_addressing = False
    dbname = u'realname'
    help = u'names                          show list of associated nicks and names (staff only)\n\
name <nick>                    show real name associated with user (staff only)\n\
name <nick> <real_name>        set real name for user (staff only)'

    def init(self):
        self.learn = Learn(madcow=self.madcow)
        self.staff = Staff(madcow=self.madcow)

    def set(self, nick, name):
        self.learn.set(self.dbname, nick.lower(), name)

    def unset(self, nick):
        dbm = self.learn.dbm(self.dbname)
        try:
            key = encode(nick.lower())
            if dbm.has_key(nick):
                del dbm[nick]
                return True
            return False
        finally:
            dbm.close()

    def get_names(self):
        name_db = self.learn.get_db('realname')
        return name_db

    def has_name(self, nick):
        name_db = self.get_names()
        return nick in name_db

    def get(self, nick):
        return self.learn.lookup(self.dbname, nick)

    def response(self, nick, args, kwargs):
        cmd = args[0]
        target_nick = False
        real_name = False
        params = []
        if args[1]:
            params = args[1].partition(' ')

        try:
            target_nick = params[0]
        except IndexError:
            target_nick = False

        try:
            real_name = params[2]
        except IndexError:
            real_name = False

        # only staff members & bot owner are allowed to get & set real_name data
        if self.staff.is_staff(nick) or settings.OWNER_NICK == nick:
            if target_nick:
                if real_name:
                    self.set(target_nick, real_name)
                    return u'%s: Setting name for %s to %s' % (
                        nick, target_nick, real_name)
                else:
                    name = self.get(nick=target_nick)
                    if name:
                        return u'%s: %s is %s' % (nick, target_nick, name)
                    else:
                        return u'%s: Sorry, I don\'t who %s is.' % (
                            nick, target_nick)
            else:
                name_list = "\n\nRecorded names:\n"
                for user_nick, name in self.get_names().iteritems():
                    name_list = name_list + user_nick + ": " + name + "\n"
                return u'%s: %s' % (nick, name_list)
예제 #11
0
 def init(self):
     self.staff = Staff(madcow=self.madcow)
예제 #12
0
파일: company.py 프로젝트: seunboi4u/madcow
class Main(Module):
    pattern = re.compile(u'^\s*(compan[y|ies])(?:\s+(.*)$)?')
    require_addressing = False
    dbname = u'company'
    help = u'companies                          list all company/nick associations (staff only)\n\
company <nick>                     show company associated with user (staff only)\n\
company <nick> <company_name>      set company information for user (staff only)'

    def init(self):
        self.learn = Learn(madcow=self.madcow)
        self.staff = Staff(madcow=self.madcow)

    def set(self, nick, company):
        self.learn.set(self.dbname, nick.lower(), company)

    def unset(self, nick):
        dbm = self.learn.dbm(self.dbname)
        try:
            key = encode(nick.lower())
            if dbm.has_key(nick):
                del dbm[nick]
                return True
            return False
        finally:
            dbm.close()

    def get_companies(self):
        company_db = self.learn.get_db('company')
        return company_db

    def has_company(self, nick):
        company_db = self.get_companies()
        return nick in company_db

    def get(self, nick):
        return self.learn.lookup(self.dbname, nick)

    def response(self, nick, args, kwargs):
        cmd = args[0]
        target_nick = False
        company = False
        params = []
        if args[1]:
            params = args[1].partition(' ')

        try:
            target_nick = params[0]
        except IndexError:
            target_nick = False

        try:
            company = params[2]
        except IndexError:
            company = False

        # only staff members & bot owner are allowed to get & set company data
        if self.staff.is_staff(nick) or settings.OWNER_NICK == nick:
            if target_nick:
                if company:
                    self.set(target_nick, company)
                    return u'%s: setting company for %s to %s' % (
                        nick, target_nick, company)
                else:
                    company_name = self.get(target_nick)
                    if company_name:
                        return u'%s: %s works at %s' % (nick, target_nick,
                                                        company_name)
                    else:
                        return u'%s: I don\'t know where %s works' % (
                            nick, target_nick)
            else:
                company_list = "\n\nRecorded companies:\n"
                for user_nick, company_name in self.get_companies().iteritems(
                ):
                    company_list = company_list + user_nick + " works at " + company_name + "\n"
                return u'%s: %s' % (nick, company_list)
예제 #13
0
파일: xray.py 프로젝트: seunboi4u/madcow
 def init(self):
     self.learn = Learn(madcow=self.madcow)
     self.staff = Staff(madcow=self.madcow)
     self.company = Company(madcow=self.madcow)
     self.realname = Realname(madcow=self.madcow)
     self.notes = Notes(madcow=self.madcow)
예제 #14
0
파일: links.py 프로젝트: seunboi4u/madcow
class Main(Module):
    pattern = re.compile(u'^\s*(link|shortcut)s?(?:\s+(.*)$)?')
    require_addressing = False
    dbname = u'links'
    help = u'shortcuts                         show list of resource shortcuts\n\
link <shortcut>                   show link for specified shortcut \n\
link <shortcut> <url>             set link for specified shortcut (staff only)\n\
link <shortcut> delete           remove link for specified shortcut (staff only)'

    def init(self):
        self.learn = Learn(madcow=self.madcow)
        self.staff = Staff(madcow=self.madcow)

    def set(self, shortcut, url):
        self.learn.set(self.dbname, shortcut.lower(), url)

    def unset(self, shortcut):
        dbm = self.learn.dbm(self.dbname)
        try:
            key = encode(shortcut.lower())
            if dbm.has_key(shortcut):
                del dbm[shortcut]
                return True
            return False
        finally:
            dbm.close()

    def get_shortcuts(self):
        link_db = self.learn.get_db(self.dbname)
        return link_db

    def has_name(self, shortcut):
        link_db = self.get_shortcuts()
        return shortcut in link_db

    def get(self, shortcut):
        return self.learn.lookup(self.dbname, shortcut)

    def response(self, nick, args, kwargs):
        cmd = args[0]
        shortcut = False
        link = False
        params = []
        if args[1]:
            params = args[1].partition(' ')

        try:
            shortcut = params[0]
        except IndexError:
            shortcut = False

        try:
            link = params[2]
        except IndexError:
            link = False

        # only staff members & bot owner are allowed to set/change shortcuts
        if shortcut and link and (self.staff.is_staff(nick)
                                  or settings.OWNER_NICK == nick):
            if link == "delete":
                self.unset(shortcut)
                return u'%s: Okay, I\'ve deleted the link for %s.  It used to be %s, and now it\'s nothing. How sad.' % (
                    nick, shortcut, link)
            else:
                self.set(shortcut, link)
                return u'%s: Okay, I\'ve set the link for %s to %s' % (
                    nick, shortcut, link)
        elif shortcut:
            link_url = self.get(shortcut)
            if link_url:
                return u'%s: %s - %s' % (nick, shortcut, link_url)
            else:
                return u'%s: Sorry, there is no \'%s\' shortcut.' % (nick,
                                                                     shortcut)
        else:
            kwargs['req'].make_private(
            )  # don't spam the channel with all the links.  there could be a lot of them.
            links = self.get_shortcuts()
            if len(links):
                link_list = "Here are all the current shortcuts:\n"
                for shortcut, url in links.iteritems():
                    link_list = link_list + shortcut + ": " + url + "\n"
                return u'%s' % (link_list)
            else:
                return u'Sorry, no shortcuts have been defined yet.'
예제 #15
0
파일: links.py 프로젝트: Havvy/madcow
class Main(Module):
    pattern = re.compile(u'^\s*(link|shortcut)s?(?:\s+(.*)$)?')
    require_addressing = False
    dbname = u'links'
    help = u'shortcuts                         show list of resource shortcuts\n\
link <shortcut>                   show link for specified shortcut \n\
link <shortcut> <url>             set link for specified shortcut (staff only)\n\
link <shortcut> delete           remove link for specified shortcut (staff only)'
    
    def init(self):
        self.learn = Learn(madcow=self.madcow)
        self.staff = Staff(madcow=self.madcow)
        
    def set(self, shortcut, url):
        self.learn.set(self.dbname, shortcut.lower(), url)
        
    def unset(self, shortcut):
        dbm = self.learn.dbm(self.dbname)
        try:
            key = encode(shortcut.lower())
            if dbm.has_key(shortcut):
                del dbm[shortcut]
                return True
            return False
        finally:
            dbm.close()
    
    def get_shortcuts(self):
        link_db = self.learn.get_db(self.dbname);
        return link_db
    
    def has_name(self, shortcut):
        link_db = self.get_shortcuts()
        return shortcut in link_db
   
    def get(self, shortcut):
        return self.learn.lookup(self.dbname, shortcut)
    
    def response(self, nick, args, kwargs):
        cmd = args[0]
        shortcut = False
        link = False
        params = []
        if args[1]:
            params = args[1].partition(' ')
        
        try:
            shortcut = params[0]
        except IndexError:
            shortcut = False
            
        try:
            link = params[2]
        except IndexError:
            link = False
            
        # only staff members & bot owner are allowed to set/change shortcuts
        if shortcut and link and (self.staff.is_staff(nick) or settings.OWNER_NICK == nick):
            if link == "delete":
                self.unset(shortcut)
                return u'%s: Okay, I\'ve deleted the link for %s.  It used to be %s, and now it\'s nothing. How sad.' % ( nick, shortcut, link )
            else:
                self.set(shortcut, link)
                return u'%s: Okay, I\'ve set the link for %s to %s' % ( nick, shortcut, link )
        elif shortcut:
            link_url = self.get(shortcut)
            if link_url:
                return u'%s: %s - %s' % (nick, shortcut, link_url)
            else:
                return u'%s: Sorry, there is no \'%s\' shortcut.' % (nick, shortcut)
        else:
            kwargs['req'].make_private() # don't spam the channel with all the links.  there could be a lot of them.
            links = self.get_shortcuts()
            if len(links):
                link_list = "Here are all the current shortcuts:\n"
                for shortcut, url in links.iteritems():
                    link_list = link_list + shortcut + ": " + url + "\n"
                return u'%s' % (link_list)
            else:
                return u'Sorry, no shortcuts have been defined yet.'