static enum v7_err jsBotSay(struct v7 *v7, v7_val_t *res) { long argc = v7_argc(v7); if (argc == 0) { return V7_OK; } v7_val_t v = v7_arg(v7, 0); if (!v7_is_string(v)) { return V7_OK; } TString str = (const char*)v7_to_cstring(v7, &v); TString font; if (argc >= 2) { v7_val_t fontt = v7_arg(v7, 1); if (!v7_is_null(fontt) && !v7_is_undefined(fontt)) font = (const char*)v7_to_cstring(v7, &fontt); } int size = 0; if (argc >= 3) { v7_val_t sizee = v7_arg(v7, 2); if (v7_is_number(sizee)) size = floor(v7_to_number(sizee)); if (size < 10) size = 10; } TString col; if (argc >= 4) { v7_val_t coll = v7_arg(v7, 3); if (v7_is_string(coll)) col = (const char*)v7_to_cstring(v7, &coll); if (col.GetAt(0) != L'#' || col.GetLength() != 7) col = L""; } _activeBot->say(str, font, size, col); return V7_OK; }
static enum v7_err jsBotFontStyle(struct v7* v7, v7_val_t* res) { v7_val_t fontName = v7_arg(v7, 0); v7_val_t fontSize = v7_arg(v7, 1); v7_val_t fontColor = v7_arg(v7, 2); if (!v7_is_string(fontName) || !v7_is_number(fontSize) || !v7_is_string(fontColor)) { return V7_OK; } TString fontColor2 = v7_to_cstring(v7, &fontColor); TString strFontName = (v7_is_null(fontName)) ? "" : (const char*)v7_to_cstring(v7, &fontName); int nFontSize = (!v7_is_number(fontSize)) ? NULL : (int)v7_to_number(fontSize); COLORREF nFontColor = (!v7_is_string(fontColor)) ? NULL : GetCol(fontColor2.GetAsWChar()); _activeBot->setFontStyle(strFontName, nFontSize, nFontColor); return V7_OK; }
SJ_PRIVATE enum v7_err Wifi_changed(struct v7 *v7, v7_val_t *res) { enum v7_err rcode = V7_OK; v7_val_t cb = v7_arg(v7, 0); if (!v7_is_callable(v7, cb) && !v7_is_null(cb)) { *res = v7_mk_boolean(v7, 0); goto clean; } v7_disown(s_wifi_changed_cb.v7, &s_wifi_changed_cb.v); s_wifi_changed_cb.v7 = v7; s_wifi_changed_cb.v = cb; v7_own(s_wifi_changed_cb.v7, &s_wifi_changed_cb.v); *res = v7_mk_boolean(v7, 1); goto clean; clean: return rcode; }
static val_t Regex_test(struct v7 *v7, val_t this_obj, val_t args) { return v7_create_boolean(!v7_is_null(Regex_exec(v7, this_obj, args))); }
void sj_wifi_on_change_callback(enum sj_wifi_status event) { struct v7 *v7 = s_v7; v7_val_t cb = v7_get(v7, s_wifi, "_ccb", ~0); if (v7_is_undefined(cb) || v7_is_null(cb)) return; sj_invoke_cb1(s_v7, cb, v7_create_number(event)); }