@@ -8,27 +8,29 @@ class IOU(Plugin):
8
8
db_owage = Plugin .use ('mongodb' , collection = 'owage' )
9
9
10
10
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
+ '''
11
16
super (IOU , self ).setup ()
12
17
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' ):
15
20
self .initialised = True
16
21
return
17
22
18
- #if owage doesn't exist yet, we want to make it
23
+ #If owage doesn't exist yet, we want to make it.
19
24
self .initialised = False
20
-
21
- self .blankuser = {"_id" : "example" , "owee_nick" : 0 }
22
-
25
+ self .blankuser = {'_id' : 'example' , 'owee_nick' : 0 }
23
26
x = self .db_owage .insert (self .blankuser )
24
27
25
28
def get_owage (self , nick , owee_name ):
26
29
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 :
29
31
return all_owed [owee_name ]/ 100
30
32
return 0
31
- return 0 #this is what I keep recieving
33
+ return 0
32
34
33
35
def update_owage (self , nick , owee_name , amount ):
34
36
all_owed = self .db_owage .find_one (nick )
@@ -42,28 +44,19 @@ def update_owage(self, nick, owee_name, amount):
42
44
else :
43
45
all_owed = {"_id" : nick , owee_name : int (amount * 100 )}
44
46
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 )
55
49
56
50
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' ))
60
53
def iou (self , e ):
61
54
nick_ = nick (e ['user' ]).strip ('<' )
62
55
nick_ = nick_ .strip ('>' )
63
56
request = e ['data' ]
64
- request_words = request .split (" " )
57
+ request_words = request .split ()
65
58
res = None
66
- if request .strip (" " ) == "" :
59
+ if request .strip () == '' :
67
60
e .reply ('Could not parse - please refer to help iou' )
68
61
return
69
62
@@ -72,8 +65,9 @@ def iou(self, e):
72
65
float (request_words [1 ])
73
66
except ValueError :
74
67
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.' )
77
71
return
78
72
res = self .update_owage (nick_ , request_words [0 ], float (request_words [1 ]))
79
73
if len (request_words ) == 1 :
@@ -87,23 +81,20 @@ def iou(self, e):
87
81
e .reply ('you owe {} £{:.02f}.' .format (request_words [0 ], res ))
88
82
return
89
83
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' ))
95
86
def iamowed (self , e ):
96
87
nick_ = nick (e ['user' ]).strip ('<' )
97
88
nick_ = nick_ .strip ('>' )
98
89
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 ' )
101
92
return
102
- request_words = request .split (" " )
93
+ request_words = request .split ()
103
94
res = None
104
95
if len (request_words ) == 1 :
105
96
res = self .get_owage (str ((request_words [0 ])), nick_ )
106
97
e .reply ('{} owes you £{}' .format (request , res ))
107
98
return
108
- e .reply ('could not parse - please refer to help IAmOwed ' )
99
+ e .reply ('could not parse - please refer to help iamowed ' )
109
100
return
0 commit comments