示例#1
0
def gift(args):
    user = globals.CURRENT_USER
    recipient = args[0].lower().lstrip("@")
    channel = globals.CURRENT_CHANNEL
    try:
        amount = abs(int(args[1]))
    except:
        return "Amount has to be a number!"
    if recipient == user:
        return "You can't gift yourself cash!"
    db = Database()
    if db.get_user(user, channel):
        if db.get_user(user, channel)[2] >= amount and db.get_user(
                recipient, channel):
            db.modify_points(recipient, channel, amount)
            db.modify_points(user, channel, amount * -1)
            return "{0} cash has been debited to {1}!".format(amount, recipient)
        else:
            return "Those numbers just don't add up. Check your spelling!"
    else:
        return "You don't even have any cash!"
示例#2
0
def join():
    channel = globals.CURRENT_CHANNEL
    user = globals.CURRENT_USER
    db = Database()
    g = Gamble(channel)
    if g.check_gamble() is not None:
        user_is_already_gambling = g.get_gamble_user(user)
        if user_is_already_gambling:
            return "You're already gambling. Perhaps you need a 12 step program?"
        points = globals.channel_info[
            globals.CURRENT_CHANNEL]['gamble']["points"]
        if db.get_user(user, channel):
            if db.get_user(user, channel)[2] < points:
                return "You don't have enough cash!"
        else:
            return "You've got no cash!"
        globals.channel_info[
            globals.CURRENT_CHANNEL]['gamble']["users"][user] = True
        return "{0} has joined the action and is on the hook for {1} cash!".format(
            user, points)
    else:
        return "There's no gamble to join. Start one with '!gamble [amount]'!"
示例#3
0
def join():
    channel = globals.CURRENT_CHANNEL
    user = globals.CURRENT_USER
    db = Database()
    g = Gamble(channel)
    if g.check_gamble() is not None:
        user_is_already_gambling = g.get_gamble_user(user)
        if user_is_already_gambling:
            return "You're already gambling. Perhaps you need a 12 step program?"
        points = globals.channel_info[globals.CURRENT_CHANNEL][
            'gamble']["points"]
        if db.get_user(user, channel):
            if db.get_user(user, channel)[2] < points:
                return "You don't have enough cash!"
        else:
            return "You've got no cash!"
        globals.channel_info[globals.CURRENT_CHANNEL]['gamble'][
            "users"][user] = True
        return "{0} has joined the action and is on the hook for {1} cash!".format(
            user, points)
    else:
        return "There's no gamble to join. Start one with '!gamble [amount]'!"
示例#4
0
def gift(args):
    user = globals.CURRENT_USER
    recipient = args[0].lower().lstrip("@")
    channel = globals.CURRENT_CHANNEL
    try:
        amount = abs(int(args[1]))
    except:
        return "Amount has to be a number!"
    if recipient == user:
        return "You can't gift yourself cash!"
    db = Database()
    if db.get_user(user, channel):
        if db.get_user(user, channel)[2] >= amount and db.get_user(
                recipient, channel):
            db.modify_points(recipient, channel, amount)
            db.modify_points(user, channel, amount * -1)
            return "{0} cash has been debited to {1}!".format(
                amount, recipient)
        else:
            return "Those numbers just don't add up. Check your spelling!"
    else:
        return "You don't even have any cash!"
示例#5
0
def gamble(args):
    db = Database()
    try:
        points = int(args[0])
    except:
        return "The points you gamble have to be a number!"
    if points < 10:
        return "The minimum buy-in amount is 10 cash!"
    channel = globals.CURRENT_CHANNEL
    user = globals.CURRENT_USER
    delay = 60
    if db.get_user(user, channel):
        if db.get_user(user, channel)[2] < points:
            return "You don't have enough cash!"
    else:
        return "You've got no cash!"
    g = Gamble(channel)
    if g.check_gamble() is None:
        globals.channel_info[channel]['gamble']["users"][
            user] = points
        initialize(channel, user, delay, points)
    else:
        return "There is already a gamble in progress!"
示例#6
0
class Cash:
    def __init__(self, channel):
        self.db = Database()
        self.channel = channel

    def add_all(self, points):
        user_dict, all_users = get_dict_for_users(self.channel)
        self.db.add_user(all_users, self.channel)
        for user in all_users:
            self.db.modify_points([user], self.channel, points)
        return {"users": all_users, "channel": self.channel, "points": points}

    def add(self, users, points):
        self.db.add_user(users, self.channel)
        self.db.modify_points(users[0], self.channel, points)
        return {"user": users[0], "channel": self.channel, "points": points}

    def modify(self, users, points):
        self.db.add_user(users, self.channel)
        self.db.modify_points(users[0], self.channel, points)
        return {"user": users[0], "channel": self.channel, "points": points}

    def get(self, user):
        # (3, u'testuser', 5, u'mod')
        user_data = self.db.get_user(user, self.channel)
        if user_data:
            return {
                "user": user_data[1],
                "channel": self.channel,
                "points": user_data[2]
            }
        else:
            return {"user": user, "channel": self.channel, "points": 0}

    def rank(self, user):
        user_data = self.db.get_cash_rank(user, self.channel)
        if user_data:
            return {
                "user": user_data[0],
                "channel": self.channel,
                "points": user_data[1],
                "rank": user_data[3]
            }
        else:
            return {
                "user": user,
                "channel": self.channel,
                "points": 0,
                "rank": None
            }
示例#7
0
class Cash:
    def __init__(self, channel):
        self.db = Database()
        self.channel = channel

    def add_all(self, points):
        user_dict, all_users = get_dict_for_users(self.channel)
        self.db.add_user(all_users, self.channel)
        for user in all_users:
            self.db.modify_points([user], self.channel, points)
        return {"users": all_users, "channel": self.channel, "points": points}

    def add(self, users, points):
        self.db.add_user(users, self.channel)
        self.db.modify_points(users[0], self.channel, points)
        return {"user": users[0], "channel": self.channel, "points": points}

    def modify(self, users, points):
        self.db.add_user(users, self.channel)
        self.db.modify_points(users[0], self.channel, points)
        return {"user": users[0], "channel": self.channel, "points": points}

    def get(self, user):
        # (3, u'testuser', 5, u'mod')
        user_data = self.db.get_user(user, self.channel)
        if user_data:
            return {
                "user": user_data[1], "channel": self.channel,
                "points": user_data[2]
                }
        else:
            return {"user": user, "channel": self.channel, "points": 0}

    def rank(self, user):
        user_data = self.db.get_cash_rank(user, self.channel)
        if user_data:
            return {
                "user": user_data[0], "channel": self.channel,
                "points": user_data[1], "rank": user_data[3]
                }
        else:
            return {
                "user": user, "channel": self.channel, "points": 0,
                "rank": None
                }
示例#8
0
def win(args):
    db = Database()
    channel = globals.CURRENT_CHANNEL
    bets = db.are_bets(channel)[0]

    if bets:
        username = globals.CURRENT_USER

        if db.get_user(username) == None:
            db.add_user([username])
            db.modify_points(username, 1000)

        current_points = db.get_points(username)[0]

        if (args[0][-1] == "%"):
            try:
                percentage = int(args[0].strip("%"))
            except Exception as error:
                print error
                return "Sorry, but your betting amount should be a number or a percentage"
            if percentage > 100:
                return "Sorry, but you can't bet more than a 100%"
            else:
                multiply = float(percentage) / 100
                amount = int(current_points * multiply)

        else:
            try:
                amount = int(args[0])
            except Exception as error:
                print error
                return "Sorry, but your betting amount should be a number or a percentage"
            if amount > current_points:
                return "You currently have {0} points, use them wisely.".format(
                    current_points)

        date = datetime.strftime(datetime.utcnow(), "%Y %m %d %H %M %S")
        db.add_bidder(channel, username, amount, "win", date)
        db.modify_points(username, -amount)
        return "Bet successfully placed! You bet {0} that {1} will win".format(
            amount, channel)

    else:
        return "Sorry, bets were not started yet"
示例#9
0
def lose(args):
    db = Database()
    channel = globals.CURRENT_CHANNEL
    bets = db.are_bets(channel)[0]
    
    if bets:
        username = globals.CURRENT_USER
        
        if db.get_user(username) == None:
            db.add_user([username])
            db.modify_points(username, 1000)
        
        current_points = db.get_points(username)[0]
        
        if (args[0][-1] == "%"):
            try:
                percentage = int(args[0].strip("%"))
            except Exception as error:
                print error
                return "Sorry, but your betting amount should be a number or a percentage"
            if percentage > 100:
                return "Sorry, but you can't bet more than a 100%"
            else:
                multiply = float(percentage) / 100
                amount = int(current_points * multiply)
           
        else:
            try:
               amount = int(args[0])
            except Exception as error:
                print error
                return "Sorry, but your betting amount should be a number or a percentage"
            if amount > current_points:
                return "You currently have {0} points, use them wisely.".format(current_points)
        
        date = datetime.strftime(datetime.utcnow(), "%Y %m %d %H %M %S") 
        db.add_bidder(channel, username, amount, "lose", date)
        db.modify_points(username, -amount)
        return "Bet successfully placed! You bet {0} that {1} will lose".format(amount, channel)
        
    else:
        return "Sorry, bets were not started yet"