Пример #1
0
def cron(channel):
    import globals
    try:
        channel = channel.lstrip("#")
        from src.lib.twitch import get_stream_status, get_hosts
        from src.lib.channel_data import ChannelData
        from src.lib.queries import Database
        cd = ChannelData(channel)
        if get_stream_status():
            channel_id = cd.get_channel_id_from_db()[0]
            hosts = get_hosts(channel_id)
            unthanked_users = []
            for host in hosts:
                host_data = cd.get_channel_data_by_user(host["host_login"], "host")
                if not host_data:
                    cd.insert_channel_data(host["host_login"], "host")
                    db = Database()
                    db.add_user([host["host_login"]], channel)
                    db.modify_points(host["host_login"], channel, 100)
                    unthanked_users.append(host["host_login"])
            if len(unthanked_users) == 1:
                user = unthanked_users[0]
                resp = "Thank you {0} for the host! Here's 100 cash!".format(user)
                globals.irc.send_message("#" + channel, resp)
            elif len(unthanked_users) > 1:
                resp = "The following users are receiving 100 cash for hosting: " + ", ".join(unthanked_users) + "!"
                globals.irc.send_message("#" + channel, resp)
            elif len(unthanked_users) > 10:
                resp = "Thanks to the {0} people hosting! Each of you get 100 cash!".format(
                    len(unthanked_users))
                globals.irc.send_message("#" + channel, resp)
        else:
            cd.remove_channel_data("host")
    except Exception as error:
        print error
Пример #2
0
        def check_for_sub(channel, username, message):
            # >> :[email protected] PRIVMSG #curvyllama :KiefyWonder subscribed for 5 months in a row!
            # >> :[email protected] PRIVMSG #curvyllama :KiefyWonder just subscribed!
            # Photo_phocus just subscribed to jonsandman!
            # HermanNugent subscribed to JonSandman for 7 months in a row!
            # first sub points = 1000
            # resub = 250
            db = Database()
            try:
                channel = channel.lstrip("#")
                message_split = message.rstrip("!").split()
                subbed_user = message_split[0].lower()
                if message_split[1] == "just" and len(message_split) < 4:
                    points = 1000
                    db.add_user([subbed_user], channel)
                    db.modify_points(subbed_user, channel, points)
                    resp = "/me {0} just subscribed for the first time!\
 {1} cash for you!".format(subbed_user, points)
                    self.irc.send_message("#" + channel, resp)
                elif message_split[1] == "subscribed" and len(message_split) < 9:
                    months_subbed = message_split[3]
                    points = 250
                    db.add_user([subbed_user], channel)
                    db.modify_points(subbed_user, channel, points)
                    resp = "/me {0} has just resubscribed for {1} months \
straight and is getting {2} cash!".format(subbed_user, months_subbed, points)
                    self.irc.send_message("#" + channel, resp)
            except Exception as error:
                print error
Пример #3
0
def chance():
    db = Database()
    channel = globals.CURRENT_CHANNEL
    user = globals.CURRENT_USER
    g = Gamble(channel)
    points = abs(g.rob_yield(multiplier=1))
    db.add_user([user], channel)
    db.modify_points(user, channel, points)
    print user, points, channel
    if points == 0:
        resp = "Nothing this time! Try again in a half hour?"
    else:
        resp = "You got {0} cash!".format(points)
    return resp
Пример #4
0
def chance():
    db = Database()
    channel = globals.CURRENT_CHANNEL
    user = globals.CURRENT_USER
    g = Gamble(channel)
    points = abs(g.rob_yield(multiplier=1))
    db.add_user([user], channel)
    db.modify_points(user, channel, points)
    print user, points, channel
    if points ==  0:
        resp = "Nothing this time! Try again in a half hour?"
    else:
        resp = "You got {0} cash!".format(points)
    return resp
Пример #5
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"
Пример #6
0
def cron(channel):
    try:
        channel = channel.lstrip("#")
        from src.lib.twitch import get_stream_status, get_hosts
        from src.lib.channel_data import ChannelData
        from src.lib.queries import Database
        cd = ChannelData(channel)
        if get_stream_status():
            channel_id = cd.get_channel_id_from_db()[0]
            hosts = get_hosts(channel_id)
            unthanked_users = []
            for host in hosts:
                host_data = cd.get_channel_data_by_user(
                    host["host_login"], "host")
                if not host_data:
                    cd.insert_channel_data(host["host_login"], "host")
                    db = Database()
                    db.add_user([host["host_login"]], channel)
                    db.modify_points(host["host_login"], channel, 100)
                    unthanked_users.append(host["host_login"])
            if len(unthanked_users) == 1:
                user = unthanked_users[0]
                resp = "Thank you {0} for the host! Here's 100 cash!".format(
                    user)
                globals.irc.send_message("#" + channel, resp)
            elif len(unthanked_users) > 1:
                import globals
                resp = "The following users are receiving 100 cash for hosting: " + ", ".join(
                    unthanked_users) + "!"
                globals.irc.send_message("#" + channel, resp)
            elif len(unthanked_users) > 10:
                resp = "Thanks to the {0} people hosting! Each of you get 100 cash!".format(
                    len(unthanked_users))
                globals.irc.send_message("#" + channel, resp)
        else:
            cd.remove_channel_data("host")
    except Exception as error:
        print error
Пример #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
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
                }