How to use send_string method in redwood

Best JavaScript code snippet using redwood

TwTrk_cmds.js

Source:TwTrk_cmds.js Github

copy

Full Screen

1TwTrkCmd_Login = function(args) {2 this.delegate = null;3 this.want_input = false;4 this.run = function() {5 this.delegate.send_string("[PROMPT_BOT]");6 this.delegate.send_string("正在送您到 Twitter 認證...");7 setTimeout(function() {8 location.href = '/twitter_auth';9 }, 260);10 }11};12TwTrkCmd_Logout = function(args) {13 this.delegate = null;14 this.want_input = false;15 this.run = function() {16 this.delegate.send_string("[PROMPT_BOT]");17 this.delegate.send_string("感謝您的使用,再見!");18 setTimeout(function() {19 location.href = '/logout';20 }, 260);21 }22};23TwTrkCmd_SSL = function(args) {24 this.delegate = null;25 this.want_input = false;26 this.run = function() {27 this.delegate.send_string("[PROMPT_BOT]");28 this.delegate.send_string("正在啟動加密連線...");29 setTimeout(function() {30 location.href = 'https://twtrk.heroku.com/';31 }, 260);32 } 33}34TwTrkCmd_Help = function(args) {35 this.delegate = null;36 this.run = function() {37 this.delegate.send_string("[PROMPT_BOT]");38 this.delegate.send_string(" 可用指令列表:\r\n");39 this.delegate.send_string(" plurk - 登入噗浪帳號\r\n");40 this.delegate.send_string(" sync (on|off) - 切換是否同步\r\n");41 this.delegate.send_string(" rt (on|off) - 切換是否包含 rT\r\n");42 this.delegate.send_string(" info - 顯示使用者資訊\r\n");43 this.delegate.send_string(" help - 可用指令列表\r\n");44 this.delegate.send_string(" logout - 登出系統\r\n");45 this.delegate.send_string("\r\n");46 this.delegate.send_string("\033[1;37mTwTrk\033[m, \033[1;32mtwitter\033[m->\033[1;31mplurk\033[m syncing bot\r\n");47 this.delegate.send_string("Written by \033[1;31mZero\033[m 2011\r\n");48 this.delegate._cmd_finished();49 }50}51TwTrkCmd_Info = function(args) {52 this.delegate = null;53 this.args = args;54 this.run = function() {55 this.delegate.send_string("[PROMPT_BOT]");56 this.delegate.send_string("請稍後,查詢中...");57 var obj = this;58 $.ajax({59 type: 'get',60 url:'/info',61 dataType: 'json',62 success: function(data) {63 obj.delegate.send_string("\033[17D");64 obj.delegate.send_string("\033[K");65 obj.delegate.send_string("親愛的會員您好,您的資訊如下:\r\n");66 obj.delegate.send_string(" \033[1;32mTwitter\033[m 帳號: " + data.twitter_username + "\r\n");67 obj.delegate.send_string(" \033[1;31mPlurk\033[m 帳號: " + data.plurk_username + "\r\n");68 obj.delegate.send_string(" 同步功能: [" + (data.should_sync ? "\033[1;32m開啟\033[m" : "\033[1;31m關閉\033[m") + "] " + (data.include_rts ? "\033[1;32m包含 rT\033[m" : "\033[1;31m不包含 rT\033[m") + "\r\n");69 obj.delegate.send_string(" 註冊日期: " + data.joined_at + "\r\n");70 obj.delegate.send_string("\r\n");71 obj.delegate.send_string("最後五筆同步記錄:\r\n");72 obj.delegate.send_string("結果 | 同步筆數 | 同步時間\r\n");73 obj.delegate.send_string("=====================================\r\n");74 for(var i=0;i<data.logs.length;i++)75 {76 obj.delegate.send_string((data.logs[i].result ? "\033[1;32m成功\033[m" : "\033[1;31m失敗\033[m") + " |");77 obj.delegate.send_string(" " + data.logs[i].synced_twits + " |");78 obj.delegate.send_string(" " + data.logs[i].synced_at + "\r\n");79 }80 if (data.logs.length == 0)81 obj.delegate.send_string(" 沒有同步記錄\r\n");82 obj.delegate._cmd_finished();83 },84 error: function(xhr, ts, err) {85 obj.delegate.send_string("\033[17D");86 obj.delegate.send_string("\033[K");87 obj.delegate.send_string("連線\033[1;31m失敗\033[m,請稍後再試...\r\n");88 obj.delegate._cmd_finished();89 }90 });91 }92}93TwTrkCmd_Sync = function(args) {94 this.delegate = null;95 this.args = args;96 this.run = function() {97 if (this.args.size == 1)98 {99 this.delegate.send_string("[PROMPT_BOT]");100 this.delegate.send_string("說明:使用 sync on 開啟同步或是 sync off 關閉同步。")101 }102 else 103 {104 this.delegate.send_string("[PROMPT_BOT]");105 this.delegate.send_string("請稍後,設定中...");106 var obj = this;107 if (this.args[1] == "off")108 {109 $.ajax({110 type: 'get',111 url:'/set_sync?val=off',112 dataType: 'json',113 success: function(data) {114 obj.delegate.send_string("\033[17D");115 obj.delegate.send_string("\033[K");116 obj.delegate.send_string("同步功能已經 \033[1;31m關閉\033[m\r\n");117 obj.delegate._cmd_finished();118 },119 error: function(xhr, ts, err) {120 obj.delegate.send_string("\033[17D");121 obj.delegate.send_string("\033[K");122 obj.delegate.send_string("連線\033[1;31m失敗\033[m,請稍後再試...\r\n");123 obj.delegate._cmd_finished();124 }125 });126 }127 else128 {129 $.ajax({130 type: 'get',131 url:'/set_sync?val=on',132 dataType: 'json',133 success: function(data) {134 obj.delegate.send_string("\033[17D");135 obj.delegate.send_string("\033[K");136 if (data.status == 'ok')137 obj.delegate.send_string("同步功能已經 \033[1;32m啟動\033[m\r\n");138 else if (data.status == 'err')139 {140 if (data.msg == 'NEED_PLURK_CREDENTIALS')141 obj.delegate.send_string("無法啟動同步,請先使用 \033[1;31mplurk\033[m\r\n指令登入\033[1;31m噗浪\033[m。\r\n");142 else143 obj.delegate.send_string("不明錯誤,請稍後再試...\r\n");144 }145 obj.delegate._cmd_finished();146 },147 error: function(xhr, ts, err) {148 obj.delegate.send_string("\033[17D");149 obj.delegate.send_string("\033[K");150 obj.delegate.send_string("連線\033[1;31m失敗\033[m,請稍後再試...\r\n");151 obj.delegate._cmd_finished();152 }153 });154 }155 }156 }157}158TwTrkCmd_RT = function(args) {159 this.delegate = null;160 this.args = args;161 this.run = function() {162 if (this.args.size == 1)163 {164 this.delegate.send_string("[PROMPT_BOT]");165 this.delegate.send_string("說明:使用 rt on/off 設定是否包含rT。")166 }167 else 168 {169 this.delegate.send_string("[PROMPT_BOT]");170 this.delegate.send_string("請稍後,設定中...");171 var obj = this;172 if (this.args[1] == "off")173 {174 $.ajax({175 type: 'get',176 url:'/set_rts?val=off',177 dataType: 'json',178 success: function(data) {179 obj.delegate.send_string("\033[17D");180 obj.delegate.send_string("\033[K");181 obj.delegate.send_string("rT 已經 \033[1;31m關閉\033[m\r\n");182 obj.delegate._cmd_finished();183 },184 error: function(xhr, ts, err) {185 obj.delegate.send_string("\033[17D");186 obj.delegate.send_string("\033[K");187 obj.delegate.send_string("連線\033[1;31m失敗\033[m,請稍後再試...\r\n");188 obj.delegate._cmd_finished();189 }190 });191 }192 else193 {194 $.ajax({195 type: 'get',196 url:'/set_rts?val=on',197 dataType: 'json',198 success: function(data) {199 obj.delegate.send_string("\033[17D");200 obj.delegate.send_string("\033[K");201 obj.delegate.send_string("rT 已經 \033[1;32m啟動\033[m\r\n");202 obj.delegate._cmd_finished();203 },204 error: function(xhr, ts, err) {205 obj.delegate.send_string("\033[17D");206 obj.delegate.send_string("\033[K");207 obj.delegate.send_string("連線\033[1;31m失敗\033[m,請稍後再試...\r\n");208 obj.delegate._cmd_finished();209 }210 });211 }212 }213 }214}215TwTrkCmd_Plurk = function(args) {216 this.delegate = null;217 var obj = this;218 this.states = {219 WAIT_USERNAME: 'WAIT_USERNAME',220 WAIT_PASSWORD: 'WAIT_PASSWORD',221 WAIT_AUTH: 'WAIT_AUTH'222 };223 this.state = this.states.WAIT_USERNAME;224 this.run = function() {225 this.delegate.send_string("[PROMPT_BOT]");226 this.delegate.send_string("請輸入噗浪使用者名稱:\r\n > ")227 }228 this.want_input = true;229 this.receiving_password = false;230 this.username = "";231 this.password = "";232 this.recv_line = function(str) {233 switch(this.state) {234 case this.states.WAIT_USERNAME:235 this.username = str;236 this.state = this.states.WAIT_PASSWORD;237 this.receiving_password = true;238 this.delegate.send_string("[PROMPT_BOT]");239 this.delegate.send_string("請輸入噗浪密碼:\r\n 請注意您的噗浪密碼\r\n 將以\033[1;31m明碼\033[m儲存在伺服器上。\r\n > ")240 break;241 case this.states.WAIT_PASSWORD:242 this.password = str;243 this.state = this.states.WAIT_AUTH;244 this.want_input = false;245 this.delegate.send_string("[PROMPT_BOT]");246 this.delegate.send_string("請稍後驗證中...\r\n");247 var obj = this;248 $.ajax({249 type: 'post',250 url:'/plurk_auth',251 data: {username: this.username, password: this.password},252 dataType: 'json',253 success: function(data) {254 obj.delegate.send_string("[PROMPT_BOT]");255 obj.delegate.send_string("登入\033[1;32m成功\033[m,噗浪將開始同步!\r\n");256 obj.delegate._cmd_finished();257 },258 error: function(xhr, ts, err) {259 obj.delegate.send_string("[PROMPT_BOT]");260 obj.delegate.send_string("登入\033[1;31m失敗\033[m,請重新登入噗浪。\r\n");261 obj.delegate._cmd_finished();262 }263 });264 break;265 }266 }...

Full Screen

Full Screen

TwTrk.js

Source:TwTrk.js Github

copy

Full Screen

...33 return;34 35 if (data.data == "\r")36 {37 this.send_string("\r\n");38 if (this._running_cmd != null && this._running_cmd.recv_line)39 this._running_cmd.recv_line(this._cmdbuf);40 else41 {42 this._cmdbuf = str_trim(this._cmdbuf);43 var args = this._cmdbuf.split(" ");44 var cmd = args[0];45 if (this._cmdset[cmd] != null)46 {47 var running_cmd = new this._cmdset[cmd](args);48 running_cmd.delegate = this;49 this._running_cmd = running_cmd;50 setTimeout(function() {51 running_cmd.run();52 }, 1);53 }54 else55 {56 this.send_string("[PROMPT_BOT]");57 this.send_string("呃... 我聽不懂你在說什麼耶,可以再告訴我一次嘛?\r\n");58 this.send_string("[PROMPT_USER]");59 }60 }61 this._cmdbuf = "";62 }63 else if (data.data == "\b")64 {65 if (this._cmdbuf.length > 0)66 {67 this.send_string("\033[1D");68 this.send_string("\033[K");69 this._cmdbuf = this._cmdbuf.substr(0, this._cmdbuf.length - 1);70 }71 }72 else73 {74 if (this._running_cmd && this._running_cmd.receiving_password)75 this.send_string("*");76 else77 this.send_string(data.data);78 this._cmdbuf += data.data;79 }80 81 this._term.flushBuffer();82 }83 84 this._cmd_finished = function() {85 this._running_cmd = null;86 this.send_string("[PROMPT_USER]");87 }88 this.send_guest_greeting = function()89 {90 this.send_string("[PROMPT_BOT]");91 this.send_string("歡迎使用\033[1;31m噗浪\033[m\033[1;32m推特\033[m同步機器人。\r\n");92 this.send_string("[PROMPT_BOT]");93 this.send_string("請輸入 \033[1;31mlogin\033[m 使用 Twitter 帳號驗證身分。\r\n");94 if (window.location.protocol != 'https:')95 {96 this.send_string('[PROMPT_BOT]');97 this.send_string('想使用 SSL 安全連線保護你\r\n的隱私? 請輸入 \033[1;31mSSL\033[m 指令!\r\n');98 }99 this.send_string("[PROMPT_USER]");100 }101 this.send_user_greeting = function()102 {103 this.send_string("[PROMPT_BOT]");104 this.send_string("歡迎使用\033[1;31m噗浪\033[m\033[1;32m推特\033[m同步機器人。\r\n");105 this.send_string("[PROMPT_BOT]");106 this.send_string("Twitter 帳號確認完成,使用\r\n\033[1;31mplurk\033[m 指令登入噗浪後即可開始同步。\r\n");107 this.send_string("[PROMPT_BOT]");108 this.send_string("若有任何問題,請用 \033[1;31mhelp\033[m 指令。\r\n");109 this.send_string("[PROMPT_USER]");110 }111 112 this.send_msg_greeting = function(msgid)113 {114 if (msgid == "TWITTER_AUTH_FAILED")115 {116 this.send_string("[PROMPT_BOT]");117 this.send_string("認證失敗!");118 this.send_string("[PROMPT_BOT]");119 this.send_string("請輸入 \033[1;37mlogin\033[m 使用 Twitter 帳號驗證身分。\r\n");120 this.send_string("[PROMPT_USER]");121 }122 }123 124 /* private functions */125 this.send_string = function(str)126 {127 this._send_buf.push(str);128 }129 130 this.text_sending_task = function()131 {132 var obj = this;133 if (this._send_buf.length > 0)134 {135 if (!this._sending_lock)136 this.random_delay_send_text(this._send_buf.shift());137 }138 setTimeout(function() { obj.text_sending_task.apply(obj); }, 100);139 }140 this.text_sending_task();141 142 this.random_delay_send_text = function(str)143 {144 if (str.length == 0)145 {146 this._sending_lock = false;147 return;148 }149 150 this._sending_lock = true;151 var obj = this;152 var nextstr = str.substr(1, str.length);153 if (str == "[PROMPT_BOT]")154 {155 this._term.incomingData("\033[1;34mTwTrk\033[m> ");156 nextstr = "";157 }158 else if (str == "[PROMPT_USER]")159 {160 this._term.incomingData("\033[1;37m" + (this._username == "" ? "Guest> " : this._username + "\033[m> "));161 nextstr = "";162 }163 else164 {165 this._term.incomingData(str[0]);166 }167 this._term.flushBuffer();168 setTimeout(function() { obj.random_delay_send_text.apply(obj, [nextstr]); }, Math.random() * 5);169 }170 /* system init */171 var obj = this;172 this.send_string("請稍後,正在載入機器人程式中...");173 $.get('/get_status', {}, function(data) {174 if (data.user_state == 'guest')175 obj._user_state = USER_GUEST;176 else177 {178 obj._user_state = USER_AUTHED;179 obj._username = data.username;180 }181 182 obj._cmdset = obj._cmdsets[obj._user_state];183 184 obj.send_string('\033[1J');185 if (data.send_msg)186 obj.send_msg_greeting.apply(obj, [data.send_msg]);187 else if (obj._user_state == USER_GUEST)188 obj.send_guest_greeting.apply(obj);189 else190 obj.send_user_greeting.apply(obj);191 }, 'json');192}193// Author: Ariel Flesler194// http://flesler.blogspot.com/2008/11/fast-trim-function-for-javascript.html195// Licensed under BSD196function str_trim(str) {197 var start = -1,198 end = str.length;...

Full Screen

Full Screen

casinoService.js

Source:casinoService.js Github

copy

Full Screen

1// Local requires2const Casino = require('../casino/casino');3let casino_balance = 1000000000;4class CasinoService {5 constructor (client_balance, BET) {6 7 this.client_balance = client_balance;8 this.BET = BET;9 }10 SPIN = async() => {11 let matrix = await Casino.creatMatrix();12 let win_sum = await Casino.check(matrix, this.BET);13 if(this.client_balance < this.BET) {14 throw new Error(`you dont have enough money!`);15 }16 casino_balance += this.BET;17 this.client_balance += win_sum - this.BET;18 casino_balance -= win_sum;19 let send_string = '';20 send_string += 'your balance = ' + this.client_balance + '\n\n' ;21 send_string += matrix[0] + '\n' + matrix[1] + '\n' + matrix[2] + '\n\n\n';22 send_string += `your Win = ${win_sum}`;23 24 return send_string;25 }26}...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run redwood automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful