Start work on tg bot

This commit is contained in:
Austen Adler 2017-01-07 22:27:12 +00:00
parent a362dcdae5
commit b01a0003a6
2 changed files with 49 additions and 24 deletions

View File

@ -1,31 +1,43 @@
local host, port = "127.0.0.1", 12345
local socket = require("socket")
local tcp = assert(socket.tcp())
tcp:connect(host, port)
function on_msg_receive (msg) function on_msg_receive (msg)
if msg.out then if msg.out then
return return
end end
if ((msg.text=='/purple') or (msg.text=='/p')) then --local file = io.open("/home/pi/git/lights/tglog.txt", "w")
local file = io.open("/home/pi/git/lights/tglog.txt", "w") --local timestr = os.date("%Y/%m/%d-%H:%M:%S")
local timestr = os.date("%Y/%m/%d-%H:%M:%S") local message = "Invaild color"
local message = ("purple|" .. timestr .. "|") if ((string.lower(msg.text)=='/purple') or (string.lower(msg.text)=='/p')) then
send_msg (msg.from.print_name, message, ok_cb, false) --message = ("purple|" .. timestr .. "|")
file:write("purple|", timestr, "\n")
file:close() tcp:send("p")
send_msg (msg.from.print_name, "Purple", ok_cb, false)
--file:write("purple|", timestr, "\n")
--file:write("p")
--file:close()
elseif ((string.lower(msg.text)=='/yellow') or (string.lower(msg.text)=='/y')) then
tcp:send("y")
send_msg (msg.from.print_name, "Uh, yella, I guess", ok_cb, false)
end end
end end
function on_our_id (id) function on_our_id (id)
end end
function on_secret_chat_created (peer) function on_secret_chat_created (peer)
end end
function on_user_update (user) function on_user_update (user)
end end
function on_chat_update (user) function on_chat_update (user)
end end
function on_get_difference_end () function on_get_difference_end ()
end end
function on_binlog_replay_end () function on_binlog_replay_end ()
end end

35
main.c
View File

@ -9,6 +9,9 @@
#define GREEN false, true, false #define GREEN false, true, false
#define BLUE false, false, true #define BLUE false, false, true
#define PURPLE true, false, true #define PURPLE true, false, true
#define YELLOW true, true, false
#define CYAN false, true, true
#define WHITE true, true, true
typedef enum { LEFT, RIGHT } Side_t; typedef enum { LEFT, RIGHT } Side_t;
bool colorField[] = { bool colorField[] = {
false, // Left red false, // Left red
@ -46,8 +49,6 @@ void changeColor(Side_t side, bool red, bool green, bool blue) {
colorField[shift] = red; colorField[shift] = red;
colorField[shift + 1] = green; colorField[shift + 1] = green;
colorField[shift + 2] = blue; colorField[shift + 2] = blue;
updateColors();
delay(1000);
} }
void changeAllColors(bool red, bool green, bool blue) { void changeAllColors(bool red, bool green, bool blue) {
changeColor(LEFT, red, green, blue); changeColor(LEFT, red, green, blue);
@ -61,14 +62,26 @@ int main(void) {
changeAllColors(OFF); changeAllColors(OFF);
updateColors(); updateColors();
delay(1000); delay(1000);
for(;;) { int ch;
changeColor(LEFT, RED); while((ch = getchar()) != EOF){
changeColor(LEFT, OFF); if(ch == 'p') {
changeColor(LEFT, GREEN); changeAllColors(PURPLE);
changeColor(LEFT, OFF); } else if (ch == 'y') {
changeColor(LEFT, BLUE); changeAllColors(YELLOW);
changeColor(LEFT, OFF); } else if (ch == 'r') {
changeColor(LEFT, PURPLE); changeAllColors(RED);
changeColor(LEFT, OFF); } else if (ch == 'g') {
changeAllColors(GREEN);
} else if (ch == 'b') {
changeAllColors(BLUE);
} else if (ch == 'o') {
changeAllColors(OFF);
} else if (ch == 'w') {
changeAllColors(WHITE);
} else {
printf("Invalid char");
continue;
}
delay(1000);
} }
} }