@@ -8,27 +8,29 @@ class IOU(Plugin):
88 db_owage = Plugin .use ('mongodb' , collection = 'owage' )
99
1010 def setup (self ):
11+ '''
12+ In case for some reason, the db isn't initialised, makes sure that it is
13+ (and because a mongodb doesn't exist if it doesn't have a document, makes sure there is one.)
14+ Should really only be called once, ever.
15+ '''
1116 super (IOU , self ).setup ()
1217
13- #check if owage already exists
14- if self .db_owage .find_one (" example" ):
18+ #Check if owage already exists.
19+ if self .db_owage .find_one (' example' ):
1520 self .initialised = True
1621 return
1722
18- #if owage doesn't exist yet, we want to make it
23+ #If owage doesn't exist yet, we want to make it.
1924 self .initialised = False
20-
21- self .blankuser = {"_id" : "example" , "owee_nick" : 0 }
22-
25+ self .blankuser = {'_id' : 'example' , 'owee_nick' : 0 }
2326 x = self .db_owage .insert (self .blankuser )
2427
2528 def get_owage (self , nick , owee_name ):
2629 all_owed = self .db_owage .find_one (nick )
27- if all_owed :
28- if owee_name in all_owed :
30+ if all_owed and owee_name in all_owed :
2931 return all_owed [owee_name ]/ 100
3032 return 0
31- return 0 #this is what I keep recieving
33+ return 0
3234
3335 def update_owage (self , nick , owee_name , amount ):
3436 all_owed = self .db_owage .find_one (nick )
@@ -42,28 +44,19 @@ def update_owage(self, nick, owee_name, amount):
4244 else :
4345 all_owed = {"_id" : nick , owee_name : int (amount * 100 )}
4446
45- self .db_owage .insert_one (all_owed ) #inserts updated value into db
46- return self .get_owage (nick , owee_name ) #returns the updated amount
47-
48- def get_all_nicks (self ):
49- cursor = self .db_owage .find ()
50- nicks = []
51- for document in cursor :
52- nicks += cursor ["_id" ]
53- return nicks
54-
47+ self .db_owage .insert_one (all_owed )
48+ return self .get_owage (nick , owee_name )
5549
5650
57- @Plugin .command ('IOU' , help = ('IOU <nick>: returns what you owe to that person '
58- '| IOU <nick> <amount> adds the amount (in pounds) to what you alread owe that person' ))
59- @Plugin .command ('iou' , help = ('equivalent to IOU' ))
51+ @Plugin .command ('iou' , help = ('iou <nick>: returns what you owe to that person '
52+ '| iou <nick> <amount> adds the amount (in pounds) to what you alread owe that person' ))
6053 def iou (self , e ):
6154 nick_ = nick (e ['user' ]).strip ('<' )
6255 nick_ = nick_ .strip ('>' )
6356 request = e ['data' ]
64- request_words = request .split (" " )
57+ request_words = request .split ()
6558 res = None
66- if request .strip (" " ) == "" :
59+ if request .strip () == '' :
6760 e .reply ('Could not parse - please refer to help iou' )
6861 return
6962
@@ -72,8 +65,9 @@ def iou(self, e):
7265 float (request_words [1 ])
7366 except ValueError :
7467 e .reply ('Please use an actual number' )
75- if not (- 2 ** 48 < int (request_words [1 ]) < 2 ** 48 ):
76- e .reply ('stop with the fuckoff big integers' )
68+ if not (- 2 ** 48 < int (request_words [1 ]) < 2 ** 48 ):
69+ #MongoDB has an 64-bit limit, enforcing a somewhat smaller limit just in case.
70+ e .reply ('please use a smaller integer.' )
7771 return
7872 res = self .update_owage (nick_ , request_words [0 ], float (request_words [1 ]))
7973 if len (request_words ) == 1 :
@@ -87,23 +81,20 @@ def iou(self, e):
8781 e .reply ('you owe {} £{:.02f}.' .format (request_words [0 ], res ))
8882 return
8983
90-
91- #forgetting this for now because I'm just hitting a brick wall
92- @Plugin .command ('IAmOwed' , help = ('Iamowed <nick> tells you what nick owes you' ))
93- @Plugin .command ('iamowed' , help = ('Iamowed <nick> tells you what nick owes you' ))
94- #hey froman transitivity when
84+
85+ @Plugin .command ('iamowed' , help = ('iamowed <nick> tells you what nick owes you' ))
9586 def iamowed (self , e ):
9687 nick_ = nick (e ['user' ]).strip ('<' )
9788 nick_ = nick_ .strip ('>' )
9889 request = e ['data' ]
99- if request .strip (" " ) == "" :
100- e .reply ('Could not parse - please refer to help IAmOwed ' )
90+ if request .strip () == '' :
91+ e .reply ('Could not parse - please refer to help iamowed ' )
10192 return
102- request_words = request .split (" " )
93+ request_words = request .split ()
10394 res = None
10495 if len (request_words ) == 1 :
10596 res = self .get_owage (str ((request_words [0 ])), nick_ )
10697 e .reply ('{} owes you £{}' .format (request , res ))
10798 return
108- e .reply ('could not parse - please refer to help IAmOwed ' )
99+ e .reply ('could not parse - please refer to help iamowed ' )
109100 return
0 commit comments