Formatting and ERR utility

This commit is contained in:
Emil 2023-08-02 07:22:22 -06:00
parent 39fbceed7e
commit f62c8d4f75

View File

@ -13,6 +13,8 @@
#define CHANNEL "#/g/chad"
#define USERNAME "probotic"
#define ERR(msg,ret) do { fputs(msg); return ret; } while (0)
irc_session_t * session;
irc_callbacks_t callbacks;
@ -21,10 +23,8 @@ char * get_username(const char * origin)
const char USERNAME_TERMINATOR = '!';
int i = 0;
char * r;
while (origin[i] !=USERNAME_TERMINATOR)
{
i++;
}
while (origin[i] != USERNAME_TERMINATOR)
{ i++; }
r = (char *) malloc(i + 1);
strncpy(r, origin, i);
r[i] = '\00';
@ -50,26 +50,26 @@ msg_wrapper(const char* fmt,
}
void
event_connect(irc_session_t *session,
const char *event,
const char *origin,
const char **params,
event_connect(irc_session_t * session,
const char * event,
const char * origin,
const char ** params,
unsigned int count)
{
irc_cmd_join(session, CHANNEL, 0);
}
void
event_channel(irc_session_t *session,
const char *event,
const char *origin,
const char **params,
event_channel(irc_session_t * session,
const char * event,
const char * origin,
const char ** params,
unsigned int count)
{
const char *channel = params[0];
const char *message = params[1];
const char * channel = params[0];
const char * message = params[1];
char* swp = get_username(origin);
char * swp = get_username(origin);
msg_wrapper("%s, you are a faggot for this opinion.", swp);
free(swp);
}
@ -82,15 +82,11 @@ init(void)
callbacks.event_channel = event_channel;
session = irc_create_session(&callbacks);
if (!session) {
fprintf(stderr, "Error creating IRC session\n");
return 1;
}
if (!session)
{ ERR("Error creating IRC session\n", 1); }
irc_connect(session, SERVER, PORT, 0, USERNAME, USERNAME, USERNAME);
if (irc_run(session) != 0) {
fprintf(stderr, "Error running IRC session\nNo net?");
return 1;
}
if (irc_run(session) != 0)
{ ERR("Error running IRC session\nNo net?", 1); }
return 0;
}