Skip to content
This repository
Browse code

add command to remove numbers, close #11

  • Loading branch information...
commit 0d408a7146f48f8569176f15c838727052eee021 1 parent e751c5b
authored

Showing 2 changed files with 25 additions and 6 deletions. Show diff stats Hide diff stats

  1. 12  core.py
  2. 19  smskrupp
12  core.py
@@ -124,20 +124,20 @@ def get_group_members(self, group_id):
124 124
         return [{'id':row[0], 'number':row[1], 'alias':row[2], 'sender':(row[3]==1),
125 125
             'admin':(row[4]==1)} for row in c]
126 126
 
127  
-    def get_groups(self, phone=None, sender=None):
128  
-        ''' returns array of dicts describing groups (id, name keyword, phone)
  127
+    def get_groups(self, phone=None, number=None):
  128
+        ''' returns array of dicts describing groups (id, name keyword, phone) containing number
129 129
         '''
130 130
         c = self.cursor
131  
-        if phone and sender:
  131
+        if phone and number:
132 132
             c.execute('select g.id, g.name, g.keyword, g.phone from qq_groupMembers m '
133 133
                     +'join qq_groups g on g.id = m.groupId '
134 134
                     +'where m.number=? and g.phone=? order by g.name asc',
135  
-                    (sender,phone))
136  
-        elif sender:
  135
+                    (number,phone))
  136
+        elif number:
137 137
             c.execute('select g.id, g.name, g.keyword, g.phone from qq_groupMembers m '
138 138
                     +'join qq_groups g on g.id = m.groupId '
139 139
                     +'where m.number=? order by g.name asc',
140  
-                    (sender,))
  140
+                    (number,))
141 141
         elif phone:
142 142
             c.execute('select id,name, keyword, phone from qq_groups where phone=? order by name asc',
143 143
                     (phone,))
19  smskrupp
@@ -9,6 +9,7 @@ def usage():
9 9
     print("%s list-groups"%sys.argv[0])
10 10
     print("%s list-members <group>"%sys.argv[0])
11 11
     print("%s add-member <number> <alias> <group>"%sys.argv[0])
  12
+    print("%s rm-member <number> <group|ALL>"%sys.argv[0])
12 13
     print("%s set-sender <number> <group>"%sys.argv[0])
13 14
     print("%s set-admin <number> <group>"%sys.argv[0])
14 15
     print("%s fake-incoming <src> <phone> <msg>"%sys.argv[0])
@@ -57,6 +58,24 @@ elif sys.argv[1] == 'add-member':
57 58
     mid = data.add_number(number, alias, group_id)
58 59
     if mid == None:
59 60
         print "error: alias already exists"
  61
+elif sys.argv[1] == 'rm-member':
  62
+    if len(sys.argv) != 4:
  63
+        usage()
  64
+    number,group = sys.argv[2:]
  65
+    number = core.normalize_number(number)
  66
+    if not number:
  67
+        print "number error!"
  68
+        sys.exit(1)
  69
+    if group == "ALL":
  70
+        for g in data.get_groups(number=number):
  71
+            data.remove_number(number=number, group_id=g['id'])
  72
+    else:
  73
+        # one number
  74
+        group_id = data.get_group_id(group)
  75
+        if not group_id:
  76
+            print "group error!"
  77
+            sys.exit(1)
  78
+        mid = data.remove_number(number=number, group_id=group_id)
60 79
 elif sys.argv[1] == 'set-sender':
61 80
     if len(sys.argv) != 4:
62 81
         usage()

0 notes on commit 0d408a7

Please sign in to comment.
Something went wrong with that request. Please try again.