-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdice.py
158 lines (138 loc) · 4.73 KB
/
dice.py
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import requests
import json
import time
import random
from environs import Env
import argparse
parser = argparse.ArgumentParser(epilog="If you don't use -b and -d. The bet will be money divide by 50")
parser.add_argument("-t", "--times", type=int, default=200, help="How many times to play dice (default = 200)")
group = parser.add_mutually_exclusive_group()
group.add_argument("-b", "--bet", type=int, help="How much money do you want to bet")
group.add_argument("-d", "--divide", type=int, help="Your bet will be money divide by number")
args = parser.parse_args()
env = Env()
env.read_env()
chanel = env.list("GAMBLE")
authorization = env.str("AUTHORIZATION")
person_Id = env.str("PERSON_ID")
token = env.str("TOKEN")
name = env.str("NAME")
money = 0
header = {
"Authorization": authorization,
"Content-Type": "application/json",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36",
}
number = args.times
datas = [0] * 6 # [ times, win, lose, equal, winDouble, winTriple ]
def getMoney(chanel_id):
msg = {
"content": "!coins",
"nonce": "82329451214{}33232234".format(random.randrange(0, 1000)),
"tts": False,
}
discord_url = "https://discord.com/api/v9/channels/{}/messages?limit=100".format(chanel_id)
try:
res = requests.post(url=discord_url, headers=header, data=json.dumps(msg))
except:
pass
time.sleep(2)
res = requests.get(url=discord_url, headers=header)
result = json.loads(res.content)
moneyContent = ''
cmp = '<@!' + person_Id + '>,你有'
for context in result:
if len(context['embeds']) != 0:
if cmp in context['embeds'][0]['description']:
moneyContent += context['embeds'][0]['description']
break
moneyStartIndex = moneyContent.index('有') + 2
cmp = ' ' + token
moneyEndtIndex = moneyContent.index(cmp)
buf = ''
for i in range(moneyStartIndex, moneyEndtIndex):
if moneyContent[i] != ',':
buf += moneyContent[i]
global money
money = int(buf)
print('money: ', money)
def statistics(chanel_id):
global datas
discord_url = "https://discord.com/api/v9/channels/{}/messages?limit=100".format(chanel_id)
res = requests.get(url=discord_url, headers=header)
result = json.loads(res.content)
time.sleep(1)
for context in result:
if (':game_die: ' + name) in context['content']:
if '下注了兩次' in context['content']:
datas[4] += 1
break
elif '這是平局' in context['content']:
datas[3] += 1
break
elif '贏' in context['content']:
datas[1] += 1
break
elif '輸' in context['content']:
datas[2] += 1
break
elif (':game_die: :astonished: ' + name) in context['content']:
datas[5] += 1
break
def chat(chanel):
global datas
for chanel_id in chanel:
getMoney(chanel_id)
if (args.bet == None) and (args.divide == None):
bet = money // 50
elif args.bet == None:
bet = money // args.divide
elif args.divide == None:
bet = args.bet
print('bet: ', bet)
buf = '!dice '
buf += str(bet)
for i in range(number):
msg = {
"content": buf,
"nonce": "82329451214{}33232234".format(random.randrange(0, 1000)),
"tts": False,
}
discord_url = "https://discord.com/api/v9/channels/{}/messages".format(chanel_id)
try:
res = requests.post(url=discord_url, headers=header, data=json.dumps(msg))
datas[0] += 1
except:
pass
time.sleep(random.randrange(10, 15))
statistics(chanel_id)
def readData():
global datas
with open('result.txt', 'r') as f:
temp = f.readlines()
cmp = ' = '
for i in range(len(temp)):
buf = ''
start = temp[i].index(cmp) + 3
end = temp[i].index('\n')
for j in range(start, end):
buf += temp[i][j]
datas[i] = int(buf)
print(temp)
def writeData():
data = ['times = ', 'win = ', 'lose = ', 'eaual = ', 'winDouble = ', 'winTriple = ']
for i in range(len(data)):
data[i] += str(datas[i])
data[i] += '\n'
print(data)
with open('result.txt', 'w') as f:
f.writelines(data)
if __name__ == "__main__":
while True:
try:
readData()
chat(chanel)
writeData()
break
except:
break