Skip to content

Commit

Permalink
current state
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtOfCode- committed Jun 30, 2015
1 parent 2066b89 commit e0d4006
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
10 changes: 8 additions & 2 deletions Commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import random
import sys
from datetime import datetime
import Points


def command_alive(args, msg, event):
Expand Down Expand Up @@ -66,6 +67,11 @@ def command_xkcd(args, msg, event):
except:
return "Invalid arguments."
return "http://xkcd.com/%i/" % id_
def command_points(args, msg, event):
return event.user.name
if len(args) < 2:
return "Not enough arguments."
if args[1] == "give":
return Points.give_points(args, msg, event)
elif args[1] == "get":
return Points.get_points(args, msg, event)
47 changes: 43 additions & 4 deletions Points.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,51 @@
Points = {
# "username": 100
# Format is key username, value points
# Format is key username: value points
}

def change_points(user, amount):
if not hasattr(Points, user):
setattr(Points, user, 0)
if (Points.user + amount) < 0:
return "Can't perform an action that would take the total for " + user + " under 0."
else:
Points.user += amount
return "Changed points for " + user + " by " + str(amount) + ". New total: " + str(Points.user)

def give_points(args, msg, event):
if len(args) < 4:
return "Not enough arguments."

user = args[2]
amount = args[3]

if str_contains(amount, "-"):
return "You cannot take points from another user."
try:
amount = int(amount)
except:
return "Invalid amount."

negAmount = -amount;
negUser = event.user.name

change_points(user, amount)
change_points(negUser, negAmount)

def get_points(args, msg, event):
user = ""
if len(args) == 2:
user = event.user.name
elif len(args) >= 3:
user = args[2]
if hasattr(Points, user):
if (Points.user + amount) < 0:
return ""
return Points.user
else:
setattr(Points, user, amount)
return 0

def str_contains(str, needle):
chars = str.split("")
for i in range len(chars):
if chars[i] == needle:
return True
return False

0 comments on commit e0d4006

Please sign in to comment.