aboutsummaryrefslogtreecommitdiff
path: root/geldschieberbot.py
diff options
context:
space:
mode:
Diffstat (limited to 'geldschieberbot.py')
-rw-r--r--geldschieberbot.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/geldschieberbot.py b/geldschieberbot.py
index a2c5186..6f55696 100644
--- a/geldschieberbot.py
+++ b/geldschieberbot.py
@@ -191,6 +191,7 @@ cars pay car-name amount - pay a bill for the specified car
tanken amount [person] [car] [info] - calculate fuel costs, service charge and add them to the person's and car's balance respectively
fuck - rewind last change
+list-changes [n] [first] - list the last n changes starting at first
weekly name cmd - repeat cmd each week
monthly name cmd - repeat cmd each month
@@ -626,6 +627,63 @@ cmds["fuck"] = fuck
cmds["rewind"] = fuck
cmds["undo"] = fuck
+def list_changes(sender, args, msg):
+ if not sender in num2name:
+ return None, "you must register first"
+
+ sender_name = num2name[sender]
+
+ changes_to_list = 5
+ if len(args) >= 2:
+ try:
+ changes_to_list = int(args[1])
+ except ValueError:
+ return None, 'the amount of changes to list must be a number'
+
+
+ nchanges = len(changes[sender_name])
+ if nchanges == 0:
+ return "Nothing to list", None
+
+ first_to_list = nchanges - changes_to_list
+ if first_to_list < 0:
+ first_to_list = 0
+
+ if len(args) == 3:
+ try:
+ first_to_list = int(args[2]) - 1
+ except ValueError:
+ return None, 'the first change to list must be a number'
+
+ if first_to_list > nchanges:
+ return None, 'the first change to list is bigger than there are changes'
+
+ msg = ""
+ for i, change in enumerate(changes[sender_name]):
+ if i < first_to_list:
+ continue
+
+ if i >= first_to_list + changes_to_list:
+ # i is used to track how many changes we listed
+ # This change will not be listed so decrement i before extiting the loop.
+ i -= 1
+ break
+
+ msg += f'Change {i + 1}:\n'
+ msg += f'{" ".join(change[0])}\n'
+ for sender, recipient, amount in change[1:]:
+ msg += "{} {} {} {}\n".format(sender,
+ ("->" if amount < 0 else "<-"),
+ to_euro(abs(amount)),
+ recipient)
+
+ # prepend message header because we want to know how much changes we actually listed
+ msg = f'Changes from {sender_name} {first_to_list + 1}-{i + 1}\n' + msg
+
+ return msg, None
+
+cmds["list-changes"] = list_changes
+
def schedule(sender, args, msg):
if not sender in num2name:
return None, "you must register first"