-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathrun.py
108 lines (99 loc) · 4.05 KB
/
run.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
import requests
import time
from block_io import BlockIo
token = "" #Telegram bot token
url = "https://api.telegram.org/bot%s/" %(token)
n = 0
version = 2
block_io = BlockIo('Blockio api key', 'Blockio pin', version)
active_users = {}
def getCount(chatid):
n = []
t = time.time()
chat_users = active_users[chatid]
for i in chat_users:
if t - chat_users[i] <= 600:
n.append(i)
return n
def sendMsg(message,chatid):
requests.get(url + "sendMessage", data={"chat_id":chatid,"text":message})
def process(message,username,chatid):
message = message.split(" ")
for i in range(message.count(' ')):
message.remove(' ')
if "/register" in message[0]:
try:
block_io.get_new_address(label=username)
sendMsg("@"+username+" you are now registered.",chatid)
except:
sendMsg("@"+username+" you are already registered.",chatid)
elif "/balance" in message[0]:
try:
data = block_io.get_address_balance(labels=username)
balance = data['data']['balances'][0]['available_balance']
pending_balance = data['data']['balances'][0]['pending_received_balance']
sendMsg("@"+username+" Balance : "+balance+ "Doge ("+pending_balance+" Doge)",chatid)
except:
sendMsg("@"+username+" you are not regsitered yet. use /register to register.",chatid)
elif "/tip" in message[0]:
try:
person = message[1].replace('@','')
amount = abs(float(message[2]))
block_io.withdraw_from_labels(amounts=str(amount), from_labels=username, to_labels=person)
sendMsg("@"+username+" tipped "+ str(amount) + " doge to @"+person+"",chatid)
except ValueError:
sendMsg("@"+username+" invalid amount.",chatid)
except:
sendMsg("@"+username+" insufficient balance or @"+person+" is not registered yet.",chatid)
elif "/address" in message[0]:
try:
data = block_io.get_address_by_label(label=username)
sendMsg("@"+username+" your address is "+data['data']['address']+"",chatid)
except:
sendMsg("@"+username+" you are not registered yet. use /register to register.",chatid)
elif "/withdraw" in message[0]:
try:
amount = abs(float(message[1]))
address = message[2]
data = block_io.withdraw_from_labels(amounts=str(amount), from_labels=username, to_addresses=address)
except ValueError:
sendMsg("@"+username+" invalid amount.",chatid)
except:
sendMsg("@"+username+" insufficient balance or you are not registered yet.",chatid)
elif "/rain" in message[0]:
try:
users = getCount(chatid)
if username in users:
users.remove(username)
number = len(users)
amount = ("10," * (number - 1)) + '10'
name = username
username = ((username+',') * (number - 1)) + username
if number < 2:
sendMsg("@"+username+" less than 2 shibes are active.",chatid)
else:
print(amount)
print(username)
block_io.withdraw_from_labels(amounts=amount, from_labels=username, to_labels=','.join(users))
sendMsg("@"+name+" is raining on "+','.join(users)+"",chatid)
except:
pass
elif "/active" in message:
sendMsg("Current active : %d shibes" %(len(getCount(chatid))),chatid)
else:
global active_users
try:
active_users[chatid][username] = time.time()
except KeyError:
active_users[chatid] = {}
active_users[chatid][username] = time.time()
while True:
try:
data = requests.get(url+"getUpdates", data={"offset":n}).json()
n = data["result"][0]["update_id"] + 1
username = data["result"][0]["message"]["from"]['username']
chatid = data["result"][0]["message"]["chat"]["id"]
message = data["result"][0]["message"]["text"]
process(message,username,chatid)
except:
pass