forked from vivek0/WhatBot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
layer.py
111 lines (104 loc) · 7.21 KB
/
layer.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
from yowsup.layers.interface import YowInterfaceLayer, ProtocolEntityCallback
from yowsup.layers.protocol_messages.protocolentities import TextMessageProtocolEntity
from yowsup.layers.protocol_acks.protocolentities import OutgoingAckProtocolEntity
from yowsup.layers.protocol_receipts.protocolentities import OutgoingReceiptProtocolEntity
import tipbot
import crypto
class EchoLayer(YowInterfaceLayer):
def cleanList(self,text):
while "" in text:
text.remove("")
return text
@ProtocolEntityCallback("message")
def onMessage(self, messageProtocolEntity):
global disable
if True:
if messageProtocolEntity.getType() == 'text':
print messageProtocolEntity
receipt = OutgoingReceiptProtocolEntity(messageProtocolEntity.getId(), messageProtocolEntity.getFrom(), 'read', messageProtocolEntity.getParticipant())
self.toLower(receipt)
gotMessage = self.cleanList(messageProtocolEntity.getBody().split(" "))
if (messageProtocolEntity.getParticipant()):
if(gotMessage[0] == "!register" and len(gotMessage) == 1):
reply = tipbot.register(messageProtocolEntity.getParticipant())
messageEntity = TextMessageProtocolEntity(reply,to = messageProtocolEntity.getParticipant())
self.toLower(messageEntity)
elif(gotMessage[0] == "!balance" and len(gotMessage) == 1):
reply = tipbot.balance(messageProtocolEntity.getParticipant(),"")
messageEntity = TextMessageProtocolEntity(reply,to = messageProtocolEntity.getFrom())
self.toLower(messageEntity)
elif(gotMessage[0] == "!tip" and len(gotMessage) == 3):
reply = tipbot.tip(gotMessage,messageProtocolEntity.getParticipant())
messageEntity = TextMessageProtocolEntity(reply,to = messageProtocolEntity.getFrom())
self.toLower(messageEntity)
elif(gotMessage[0] == "!tag" and len(gotMessage) == 1):
reply = tipbot.getUserTag(messageProtocolEntity.getParticipant())
messageEntity = TextMessageProtocolEntity(reply,to = messageProtocolEntity.getParticipant())
self.toLower(messageEntity)
elif(gotMessage[0] == "!withdraw" and len(gotMessage) == 3):
reply = tipbot.withdraw(gotMessage,messageProtocolEntity.getParticipant())
messageEntity = TextMessageProtocolEntity(reply,to = messageProtocolEntity.getParticipant())
self.toLower(messageEntity)
elif(gotMessage[0] == "!address" and len(gotMessage) == 1):
reply = tipbot.getUserAdd(messageProtocolEntity.getParticipant())
messageEntity = TextMessageProtocolEntity(reply,to = messageProtocolEntity.getParticipant())
self.toLower(messageEntity)
elif(gotMessage[0] == "!change" and len(gotMessage) == 2):
reply = tipbot.changeTag(gotMessage,messageProtocolEntity.getParticipant())
messageEntity = TextMessageProtocolEntity(reply,to = messageProtocolEntity.getParticipant())
self.toLower(messageEntity)
elif(gotMessage[0] == "!help" and len(gotMessage) == 1):
reply = tipbot.commands()
messageEntity = TextMessageProtocolEntity(reply,to = messageProtocolEntity.getParticipant())
self.toLower(messageEntity)
elif(gotMessage[0] == "!market" and len(gotMessage) == 2):
reply = crypto.market(gotMessage)
messageEntity = TextMessageProtocolEntity(reply,to = messageProtocolEntity.getFrom())
self.toLower(messageEntity)
elif(gotMessage[0] == "!convert" and len(gotMessage) == 4):
reply = crypto.convert(gotMessage)
messageEntity = TextMessageProtocolEntity(reply,to = messageProtocolEntity.getFrom())
self.toLower(messageEntity)
elif(gotMessage[0] == "!info" and len(gotMessage) == 1):
reply = crypto.info()
messageEntity = TextMessageProtocolEntity(reply,to = messageProtocolEntity.getFrom())
self.toLower(messageEntity)
elif(gotMessage[0] == "!cbid" or gotMessage[0] == "!cask" and len(gotMessage) == 3):
if gotMessage[0] == "!cbid":
createType = "createbid"
else:
createType = "createask"
reply = tipbot.placeBidAsk(gotMessage,messageProtocolEntity.getParticipant(),createType)
messageEntity = TextMessageProtocolEntity(reply,to = messageProtocolEntity.getFrom())
self.toLower(messageEntity)
elif(gotMessage[0] == "!dbid" or gotMessage[0] == "!dask" and len(gotMessage) == 2):
if gotMessage[0] == "!dbid":
cancelType = "cancelbid"
else:
cancelType = "cancelask"
reply = tipbot.cancelBidAsk(gotMessage,messageProtocolEntity.getParticipant(),cancelType)
messageEntity = TextMessageProtocolEntity(reply,to = messageProtocolEntity.getFrom())
self.toLower(messageEntity)
elif(gotMessage[0] == "!fbal" or gotMessage[0] == "!cbal" and len(gotMessage) == 1):
if gotMessage[0] == "!fbal":
baltype = "fiatbalance"
else:
baltype = "coinbalance"
reply = tipbot.coinbal(messageProtocolEntity.getParticipant(),baltype)
messageEntity = TextMessageProtocolEntity(reply,to = messageProtocolEntity.getFrom())
self.toLower(messageEntity)
else:
if(gotMessage[0] == "!coinapi" and len(gotMessage) == 2):
reply = tipbot.coinAdd(gotMessage,messageProtocolEntity.getFrom())
messageEntity = TextMessageProtocolEntity(reply,to = messageProtocolEntity.getFrom())
self.toLower(messageEntity)
elif(gotMessage[0] == "!addr" and len(gotMessage) == 1):
reply = tipbot.getCoinsecAddr(messageProtocolEntity.getFrom())
messageEntity = TextMessageProtocolEntity(reply,to = messageProtocolEntity.getFrom())
self.toLower(messageEntity)
self.toLower(messageProtocolEntity.ack())
self.toLower(messageProtocolEntity.ack(True))
@ProtocolEntityCallback("receipt")
def onReceipt(self, entity):
ack = OutgoingAckProtocolEntity(entity.getId(), "receipt", entity.getType(), entity.getFrom())
self.toLower(ack)