Skip to content

Commit

Permalink
Modifying based on PR comments. moving back to a single connect function
Browse files Browse the repository at this point in the history
  • Loading branch information
witnessmenow committed Aug 7, 2018
1 parent b4af4f6 commit 4b05da4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
4 changes: 3 additions & 1 deletion examples/ESP8266/TwtichSendReceive/TwtichSendReceive.ino
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ void loop() {
if (!client.connected()) {
Serial.println("Attempting to connect to " + ircChannel );
// Attempt to connect
if (client.connectTwitch(TWITCH_BOT_NAME, ircChannel, TWITCH_OAUTH_TOKEN)) {
// Second param is not needed by Twtich
if (client.connect(TWITCH_BOT_NAME, "", TWITCH_OAUTH_TOKEN)) {
client.sendRaw("JOIN " + ircChannel);
Serial.println("connected and ready to rock");
sendTwitchMessage("Ready to go Boss!");
} else {
Expand Down
22 changes: 5 additions & 17 deletions src/IRCClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ IRCClient& IRCClient::setSentCallback(IRC_SENTCALLBACK_SIGNATURE) {
return *this;
}

boolean IRCClient::connect(String nickname, String user) {
boolean IRCClient::connect(String nickname, String user, String password) {
if (!connected()) {
int result = client->connect(this->host, this->port);
if (result == 1) {
this->nickname = nickname;
sendIRC("HELLO");
if(password != "")
{
sendIRC("PASS " + password);
}
sendIRC("NICK " + nickname);
sendIRC("USER " + user + " 8 * :Arduino IRC Client");
this->isConnected = true;
Expand All @@ -45,22 +49,6 @@ boolean IRCClient::connect(String nickname, String user) {
return true;
}

boolean IRCClient::connectTwitch(String nickname, String user, String password) {
if (!connected()) {
int result = client->connect(this->host, this->port);
if (result == 1) {
this->nickname = nickname;
sendIRC("PASS " + password);
sendIRC("NICK " + nickname);
sendIRC("JOIN " + user);
this->isConnected = true;
return true;
}
return false;
}
return true;
}

boolean IRCClient::loop() {
if (connected() && client->available()) {
String message = "";
Expand Down
3 changes: 1 addition & 2 deletions src/IRCClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ class IRCClient
IRCClient(const char*, uint16_t, Client& client);
IRCClient& setCallback(IRC_CALLBACK_SIGNATURE);
IRCClient& setSentCallback(IRC_SENTCALLBACK_SIGNATURE);
boolean connect(String nickname, String user);
boolean connectTwitch(String nickname, String user, String password);
boolean connect(String nickname, String user, String password = "");
boolean loop();
boolean connected();
void sendRaw(String data);
Expand Down

0 comments on commit 4b05da4

Please sign in to comment.