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)
if msg.out then
return
end
if ((msg.text=='/purple') or (msg.text=='/p')) then
local file = io.open("/home/pi/git/lights/tglog.txt", "w")
local timestr = os.date("%Y/%m/%d-%H:%M:%S")
local message = ("purple|" .. timestr .. "|")
send_msg (msg.from.print_name, message, ok_cb, false)
file:write("purple|", timestr, "\n")
file:close()
--local file = io.open("/home/pi/git/lights/tglog.txt", "w")
--local timestr = os.date("%Y/%m/%d-%H:%M:%S")
local message = "Invaild color"
if ((string.lower(msg.text)=='/purple') or (string.lower(msg.text)=='/p')) then
--message = ("purple|" .. timestr .. "|")
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
function on_our_id (id)
end
function on_secret_chat_created (peer)
end
function on_user_update (user)
end
function on_chat_update (user)
end
function on_get_difference_end ()
end
function on_binlog_replay_end ()
end

35
main.c
View File

@ -9,6 +9,9 @@
#define GREEN false, true, false
#define BLUE false, 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;
bool colorField[] = {
false, // Left red
@ -46,8 +49,6 @@ void changeColor(Side_t side, bool red, bool green, bool blue) {
colorField[shift] = red;
colorField[shift + 1] = green;
colorField[shift + 2] = blue;
updateColors();
delay(1000);
}
void changeAllColors(bool red, bool green, bool blue) {
changeColor(LEFT, red, green, blue);
@ -61,14 +62,26 @@ int main(void) {
changeAllColors(OFF);
updateColors();
delay(1000);
for(;;) {
changeColor(LEFT, RED);
changeColor(LEFT, OFF);
changeColor(LEFT, GREEN);
changeColor(LEFT, OFF);
changeColor(LEFT, BLUE);
changeColor(LEFT, OFF);
changeColor(LEFT, PURPLE);
changeColor(LEFT, OFF);
int ch;
while((ch = getchar()) != EOF){
if(ch == 'p') {
changeAllColors(PURPLE);
} else if (ch == 'y') {
changeAllColors(YELLOW);
} else if (ch == 'r') {
changeAllColors(RED);
} 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);
}
}