-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuction_StreamlabsSystem.py
More file actions
114 lines (103 loc) · 4.96 KB
/
Auction_StreamlabsSystem.py
File metadata and controls
114 lines (103 loc) · 4.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import os
import sys
import json
import codecs
import time
import threading
from threading import Timer,Thread,Event
ScriptName = "Auction"
Website = "https://github.com/aseroff/auction/"
Description = "Hold auctions with bidding in your Streamlabs currency"
Creator = "rvaen17"
Version = "1.0.0"
configFile = "config.json"
settings = {}
currency_name = ""
auction = ""
bid = 0
user = 0
username = ""
time_elapsed = -1
def ScriptToggled(state):
return
def Init():
global configFile, settings, currency_name
currency_name = Parent.GetCurrencyName()
path = os.path.dirname(__file__)
try:
with codecs.open(os.path.join(path, configFile), encoding='utf-8-sig', mode='r') as file:
settings = json.load(file, encoding='utf-8-sig')
except:
settings = {
"liveOnly": False,
"secondsToWin": 30,
"minIncrement": 1,
"openingBid": 0,
"firstWarning": 10,
"secondWarning": 5,
"openingMessage": "/me Bidding for $auction has opened at $bid $currency. You can bid on this auction by using !bid and then the amount you want to bid. Bids must be $increment higher than the previous bid.",
"auctionInProgressMessage": "There is an auction for $auction already in progress!",
"newBidMessage": "/me @$user has the high bid at $bid $currency. Do I hear $min?",
"insufficientFundsMessage": "Sorry @$user, you can't afford that bid. NotLikeThis",
"invalidBidMessage": "Invalid bid! Minimum bid is $min $currency.",
"firstWarningMessage": "/me Going once to @$user for $bid $currency!",
"secondWarningMessage": "/me Going twice to @$user for $bid $currency!",
"winningMessage": "/me $auction has sold to @$user for $bid $currency!",
"noBidsMessage": "/me The auction for $auction has ended with no bids!"
}
def Execute(data):
global time_elapsed, user, username, bid, auction, currency_name
if ((settings["liveOnly"] and Parent.IsLive()) or (not settings["liveOnly"])) and data.IsChatMessage():
if (data.Message.strip().split(" ")[0] == "!auction" and Parent.HasPermission(data.User,"mod",data.UserName)):
if (time_elapsed == -1):
auction = data.Message.strip().replace("!auction ", "")
time_elapsed = 0
Parent.SendStreamMessage(settings["openingMessage"].replace("$auction", auction).replace("$currency", currency_name).replace("$bid", str(settings["openingBid"])).replace("$increment", str(settings["minIncrement"])))
timer = threading.Timer(1.0, timing)
if not timer.is_alive():
timer.start()
else:
Parent.SendStreamMessage((settings["auctionInProgressMessage"].replace("$auction", auction)))
elif (data.Message.strip().split(" ")[0] == "!bid" and data.Message.strip().split(" ")[1].isdigit() and time_elapsed != -1):
newbid = int(data.Message.strip().split(" ")[1])
min = bid + int(settings["minIncrement"])
if ((newbid == bid and username == "") or (newbid >= min)):
if ((Parent.GetPoints(data.UserName)) >= newbid):
user = data.User
username = data.UserName
bid = int(newbid)
time_elapsed = 0
Parent.SendStreamMessage(settings["newBidMessage"].replace("$currency", currency_name).replace("$user", username).replace("$bid", str(bid)).replace("$min", str(bid + int(settings["minIncrement"]))))
else:
Parent.SendStreamMessage(settings["insufficientFundsMessage"].replace("$user", data.UserName))
else:
Parent.SendStreamMessage(settings["invalidBidMessage"].replace("$currency", currency_name).replace("$min", str(min)))
return
def timing():
global time_elapsed, user, username, bid, auction, currency_name
while ((time_elapsed != -1) and (time_elapsed < int(settings["secondsToWin"]))):
time_elapsed += 1
if (time_elapsed == (int(settings["secondsToWin"]) - int(settings["firstWarning"])) and int(bid) != settings["openingBid"]):
Parent.SendStreamMessage(settings["firstWarningMessage"].replace("$user", username).replace("$bid", str(bid)).replace("$currency", currency_name))
elif (time_elapsed == (int(settings["secondsToWin"]) - int(settings["secondWarning"])) and int(bid) != settings["openingBid"]):
Parent.SendStreamMessage(settings["secondWarningMessage"].replace("$user", username).replace("$bid", str(bid)).replace("$currency", currency_name))
elif (time_elapsed == int(settings["secondsToWin"])):
if (username != ""):
Parent.SendStreamMessage(settings["winningMessage"].replace("$user", username).replace("$auction", auction).replace("$bid", str(bid)).replace("$currency", currency_name))
Parent.RemovePoints(user,username,bid)
else:
Parent.SendStreamMessage(settings["noBidsMessage"].replace("$auction", auction))
time_elapsed = -1
user = 0
username = ""
bid = 0
time.sleep(1)
def ReloadSettings(jsonData):
Init()
return
def OpenReadMe():
location = os.path.join(os.path.dirname(__file__), "README.txt")
os.startfile(location)
return
def Tick():
return