Skip to content

Commit fa56db5

Browse files
authored
Add files via upload
1 parent e9ae0e3 commit fa56db5

File tree

3 files changed

+259
-0
lines changed

3 files changed

+259
-0
lines changed

index.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>BotWeb</title>
6+
<link rel="stylesheet" href="./style.css">
7+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css">
8+
</head>
9+
<body>
10+
<script src="https://code.jquery.com/jquery-3.2.1.min.js" charset="utf-8"></script>
11+
<script src="index.js" charset="utf-8"></script>
12+
<input type="text" class="BotWebInput">
13+
<script type="text/javascript">
14+
var Bot = BotWeb.init({
15+
name: "Paulon",
16+
input: $(".BotWebInput")
17+
});
18+
</script>
19+
</body>
20+
</html>

index.js

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
"use strict";
2+
3+
class BotWeb {
4+
5+
static init(config){
6+
7+
if (!BotWeb.instance) {
8+
var s = this;
9+
BotWeb.instance = new s(config);
10+
}
11+
return BotWeb.instance;
12+
13+
}
14+
15+
constructor(config) {
16+
this.Active = false;
17+
this.Database = {};
18+
this.Database["BotConfig"] = {};
19+
this.Database["BotConfig"]["input"] = config.input;
20+
this.Database["BotConfig"]["bot_name"] = config.name;
21+
this.Database["BotConfig"]["create_as"] = new Date();
22+
this.events();
23+
this.output();
24+
this.online();
25+
}
26+
27+
events(){
28+
29+
this.Database["EventsTrigger"] = {};
30+
this.Database["EventsTrigger"]["/search"] = function(msg){
31+
msg = encodeURI(msg).trim();
32+
var url = "https://pt.wikipedia.org/w/api.php?action=query&list=search&origin=*&srsearch="+msg+"&format=json";
33+
$.get(url, function(res){
34+
console.log(typeof res);
35+
if(!'query' in res){
36+
throw "Erro na funcao Search";
37+
}
38+
if(!'search' in res.query){
39+
throw "Erro na funcao Search";
40+
}
41+
var response = res.query.search[0];
42+
$(".BotWeb-Response").html(`<strong>${response.title}</strong><br/><p>${response.snippet}</p>`);
43+
$(".BotWeb-Response").css("display", "flex");
44+
$(".BotWeb-Modal").css("width", parseInt($(".BotWeb-Modal-Inputs").width()) + "px");
45+
$(".BotWeb-Response").css("width", "100%");
46+
$(".BotWeb-Response").addClass("animated bounceInDown");
47+
setTimeout(() => { $(".BotWeb-Response").removeClass("animated bounceInDown"); }, 4000);
48+
//var d = JSON.parse(Res);
49+
//console.log(d);
50+
});
51+
};
52+
this.Database["EventsTrigger"]["/temperature"] = function(msg){
53+
console.log("TEMPERATURE !!!");
54+
};
55+
this.Database["EventsTrigger"]["/andress"] = function(msg){
56+
console.log("ANDRESS !!!");
57+
};
58+
this.Database["EventsTrigger"]["/youtube"] = function(msg){
59+
console.log("SEARCH YOUTUBE !!!");
60+
};
61+
this.Database["EventsTrigger"]["/cotacao"] = function(msg){
62+
console.log("COTACAO !!!");
63+
};
64+
65+
}
66+
67+
output(){
68+
69+
function NewObj(n, c){
70+
var v = document.createElement(n);
71+
v.className = c;
72+
return v;
73+
}
74+
75+
var input = this.Database["BotConfig"]["input"],
76+
view = input.parentNode,
77+
clone = input,
78+
modal = NewObj("div", "BotWeb-Modal"),
79+
modalInputs = NewObj("div", "BotWeb-Modal-Inputs");
80+
81+
var height = $(clone).height();
82+
83+
input.remove();
84+
85+
this.Database["Template"] = {};
86+
this.Database["Template"]["BotWebBot"] = `<div class='BotWeb-Bot animated bounceIn' style='height:${height}px !important'>BotWeb</div>`;
87+
modalInputs.append(clone[0]);
88+
$(modal).html("<div class='BotWeb-Response'></div>");
89+
modal.append(modalInputs);
90+
$("body").append(modal);
91+
this.Database["BotConfig"]["input"] = clone[0];
92+
93+
}
94+
95+
OnMessage(msg){
96+
97+
var input = this.Database["BotConfig"]["input"],
98+
msgOrigin = msg,
99+
regexBot = /@botweb/ig,
100+
regexs = [
101+
/\/search/ig,
102+
/\/temperature/ig,
103+
/\/andress/ig,
104+
/\/youtube/ig,
105+
/\/cotacao/ig
106+
];
107+
108+
msg = msg.toLowerCase();
109+
if(this.Active){
110+
var t = regexs.filter((v) => {
111+
return v.test(msg) == true;
112+
});
113+
if(t.length > 0){
114+
var value = msg.replace(t[0], "").trim(),
115+
i = t[0].source.toString();
116+
var n = i.replace("/\//", "");
117+
n = "/" + n.substr(2);
118+
this.Database["EventsTrigger"][n](value);
119+
}
120+
}
121+
122+
if(regexBot.test(msg) && this.Active == false){
123+
$(Bot.Database.Template.BotWebBot).insertBefore($(".BotWebInput"));
124+
$(".BotWeb-Modal").css("box-shadow","0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23)");
125+
$(input).css("border-top-right-radius","3px");
126+
$(input).css("border-bottom-right-radius","3px");
127+
input.value = msg.replace(regexBot, "");
128+
this.Active = true;
129+
this.OnVerifyBotter(input);
130+
}
131+
132+
}
133+
134+
OnVerifyBotter(i){
135+
136+
function Botter(){
137+
138+
if($(i).val().length == 0 && $(".BotWeb-Response").css("display") == "flex"){
139+
140+
$(".BotWeb-Response").html("");
141+
$(".BotWeb-Response").css("display","none");
142+
143+
}
144+
145+
}
146+
147+
this.Database["OnBotter"] = setInterval(Botter, 4000);
148+
149+
}
150+
151+
online(){
152+
153+
var input = this.Database["BotConfig"]["input"],
154+
self = this;
155+
$(".BotWebInput").keyup(function(e){
156+
self.OnMessage(input.value);
157+
});
158+
//this.OnMessage(input.value)
159+
160+
}
161+
162+
toString() {
163+
164+
return JSON.stringify(this);
165+
166+
}
167+
168+
}

style.css

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
@import url('https://fonts.googleapis.com/css?family=Roboto');
2+
3+
* {
4+
margin: 0;
5+
padding: 0;
6+
}
7+
8+
body{
9+
height: 100vh;
10+
width: 100%;
11+
background-color: #2c3e50;
12+
display: flex;
13+
justify-content: center;
14+
align-items: center;
15+
font-family: 'Roboto', sans-serif;
16+
}
17+
18+
.BotWeb-Modal{
19+
width: 480px;
20+
display: flex;
21+
justify-content: center;
22+
align-items: center;
23+
flex-direction: column;
24+
}
25+
26+
.BotWeb-Response{
27+
height: 350px;
28+
margin-bottom: 10px;
29+
border: 3px;
30+
background: #16a085;
31+
width: 100%;
32+
display: none;
33+
justify-content: center;
34+
align-items: center;
35+
flex-direction: column;
36+
}
37+
38+
.BotWeb-Response>p{
39+
width: 80%;
40+
}
41+
42+
.BotWeb-Modal-Inputs{
43+
width: 100%;
44+
height: auto;
45+
display: flex;
46+
justify-content: center;
47+
align-items: center;
48+
}
49+
50+
.BotWeb-Bot{
51+
font-size: 17px;
52+
color: #ecf0f1;
53+
padding-left: 15px;
54+
padding-right: 15px;
55+
width: 85px;
56+
display: flex;
57+
justify-content: center;
58+
align-items: center;
59+
background: #16a085;
60+
border-top-left-radius: 3px;
61+
border-bottom-left-radius: 3px;
62+
animation: 2s all ease;
63+
}
64+
65+
.BotWebInput{
66+
width: 350px;
67+
height: 50px;
68+
font-size: 17px;
69+
padding-left: 15px;
70+
border: none;
71+
}

0 commit comments

Comments
 (0)