forked from woolysammoth/coinflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coinflow.py
168 lines (132 loc) · 4.99 KB
/
coinflow.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
159
160
161
162
163
164
165
166
167
168
import netvend.netvend as netvend
import commands as com
import util
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.clock import Clock
import os.path
import dbCreate
if not os.path.isfile('coinflow.db'):
dbCreate.genDB()
class CoinFlowApp(App):
"""
The base Application class needed for Kivy
chbsagent is for the alpha/beta phase to ensure new agents have funds
agent starts off as None to indicate a logged out state
"""
chbsagent = netvend.Agent('correct horse battery staple', seed=True)
agent = None
allNicks = []
tipAmount = 1
pollInterval = 60
def poll(self, value=False):
"""
This method polls the server to see if there's any new history to take action on
"""
if self.agent is None:
return
#set the timer to poll every inteval
#set the clock so that we poll netvend every minute or so to find out new details
Clock.schedule_interval(self.poll, self.pollInterval)
#check all posts to see if there has been activity
#if util.pollAllPosts(self):
#if there has check the new posts for updatable information
#util.checkAllPosts(self)
#check for new posts by our follows
if util.pollFollowsPosts(self):
#if there's new ones, display them
util.displayFollowsPosts(self)
def sendCommand(self, instance, value=False):
"""
This method is calle whenever the input box looses focus
It looses focus on a click out side itself or when Enter is pressed
We list the available commands here but the grunt work of the functions is done in commands.py
"""
if value:
return
#get the command and clear the input box
inText = self.input.text
if inText == '':
return
self.input.text = ''
#options
command = inText.split(None, 1)
#/add [seed] - set up a new agent using the supplied seed
#for the time being we add a simple balance to allow for testing
if command[0].lower() == '/add':
com.commandAdd(self, command)
return
#/login [nickname / address / seed] - login as an existing agent
elif command[0].lower() == '/login':
com.commandLogin(self, command)
return
#/tip [nickname / address] - send a tip to another user or post
elif command[0].lower() == '/tip':
com.commandTip(self, command)
return
#/balance - view the balance of your current agent
elif command[0].lower() == '/balance':
com.commandBalance(self, command)
return
#/post [message] - post a message to netvend
elif command[0].lower() == '/post':
com.commandPost(self, command)
return
#/history [address] - view the last ten posts for the specified user (defaults to self)
elif command[0].lower() == '/history':
com.commandHistory(self, command)
return
#/nick - set your nickname
elif command[0].lower() == '/nick':
com.commandNick(self, command)
return
#/listagents - list all users on the system
elif command[0].lower() == '/listagents':
com.commandListAgents(self, command)
return
#/follow [agent] - follow the specified agent
elif command[0].lower() == '/follow':
com.commandFollow(self, command)
return
#/listfollows [agent] - list everyone you follow
elif command[0].lower() == '/listfollows':
com.commandListFollows(self, command)
return
#/listprofiles [agent] - list all available profiles
elif command[0].lower() == '/listprofiles':
com.commandListProfiles(self, command)
return
#/gettipammount - get the current tip amount
elif command[0].lower() == '/gettipamount':
com.commandGetTipAmount(self, command)
#/settipammount - set the current tip amount
elif command[0].lower() == '/settipamount':
com.commandSetTipAmount(self, command)
#otherwise we don;t know what's goin on
else:
self.writeConsole(command[0] + ' is not a recognised command')
return
def writeConsole(self, text):
"""
Write the text to a new line on the Output console
"""
#get the current output text and store it
outText = self.output.text
#once we've figured out what to do, write to the console and return focus to the input box
self.output.text = str(outText) + str(text) + '\n'
self.input.focus = True
def build(self):
"""
Add the widgets and build the UI
"""
self.root = BoxLayout(orientation='vertical')
self.output = TextInput(size_hint=(1,.9), background_color=[0,0,0,0], foreground_color=[1,1,1,1], readonly=True, text='Welcome to CoinFlow\n===================\n\n/add [seed value] will create a new agent.\n/login [nickname/address/seed value] will login to an existing agent\n/nick [nickname] sets your agents nickname.\n/post [message] will post a message to netvend.\n/tip [nickname/address/post_id] will send a tip\n\nHave fun!\n\n')
self.input = TextInput(size_hint_y=None, height=30, multiline=False, focus=True)
self.input.bind(focus=self.sendCommand)
self.root.add_widget(self.output)
self.root.add_widget(self.input)
return self.root
if __name__ == '__main__':
CoinFlowApp().run()