Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Binux committed Jan 27, 2014
1 parent b2d96a5 commit 273cde4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 6 additions & 2 deletions bot.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<input type="checkbox" onchange="ws.send('set_bool GACHA_FRIEND '+this.checked)" />自动抽伴点
<button onclick="ws.send('item_use 1')">吃绿:AP</button>
<button onclick="ws.send('item_use 2')">吃红:BC</button>
<button onclick="ws.send('report 1')">状态</button>
<button onclick="log.innerHTML=''">清除日志</button>
<br />
舔怪卡组:<input onchange="ws.send('roundtable low_cost '+this.value)" value="" />
Expand Down Expand Up @@ -80,22 +81,25 @@
}
function login(form) {
if (window.ws) {
if (ws.timeout) window.clearTimeout(ws.timeout);
ws.close();
if (ws.timeout) window.clearTimeout(ws.timeout);
delete window.ws;
}
var login_id = form.id.value,
password = form.pwd.value,
area = form.area.value,
server = form.server.value,
offline = form.offline.checked && "1" || "";
ws = new WebSocket("ws://"+location.host+"/bot?id="+login_id+"&password="+password+"&area="+area+"&offline="+offline+"&server="+encodeURIComponent(server));
window.ws = new WebSocket("ws://"+location.host+"/bot?id="+login_id+"&password="+password+"&area="+area+"&offline="+offline+"&server="+encodeURIComponent(server));
ws.onopen = function() {
log.innerHTML += "<br />connected.";
document.querySelector("#setting").style.display = 'block';
};
ws.onclose = function() {
log.innerHTML += "<br /><span class=error>disconnected.</span>";
document.querySelector("#setting").style.display = 'none';
setTimeout(function() { login(form); }, 60*1000);
ws.timeout = setTimeout(function() { login(form); }, 60*1000);
};
ws.onmessage = function(event) {
log.innerHTML += "<br />"+event.data;
Expand Down
5 changes: 4 additions & 1 deletion web_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def login(self, login_id, password):
def run(self, login_id, password, area=None):
while not self._quit:
try:
self._print('running...')
super(WebSocketBot, self).run(login_id, password, int(area) if area else None)
except ma.HeaderError, e:
print e.code, e.message
Expand Down Expand Up @@ -95,6 +96,8 @@ def on_wsmessage(self, message):
if cmd == 'item_use':
self.ma.item_use(int(rest))
self.report()
if cmd == 'report':
self.report()
elif cmd == 'set':
attr, value = rest.split(' ', 1)
setattr(self, attr, int(value))
Expand Down Expand Up @@ -218,7 +221,7 @@ def websocket_app(environ, start_response):

elif request.path == '/':
start_response("200 OK", [("Content-Type", "text/html")])
return open(os.path.join(os.path.dirname(__file__), "bot.html")).readlines()
return [open(os.path.join(os.path.dirname(__file__), "bot.html")).read().replace("$CONN", str(WebSocketBot.connected)), ]
else:
start_response("404 NOT FOUND", [("Content-Type", "text/html")])
return ("404 NOT FOUND", )
Expand Down

0 comments on commit 273cde4

Please sign in to comment.