introduce a /join command for guild text channels
This commit is contained in:
@@ -16,6 +16,7 @@ dc_guild_t dc_guild_from_json(json_t *j);
|
||||
|
||||
size_t dc_guild_channels(dc_guild_t d);
|
||||
dc_channel_t dc_guild_nth_channel(dc_guild_t d, size_t idx);
|
||||
dc_channel_t dc_guild_channel_by_name(dc_guild_t g, char const *name);
|
||||
|
||||
char const *dc_guild_name(dc_guild_t d);
|
||||
void dc_guild_set_name(dc_guild_t d, char const *val);
|
||||
|
||||
@@ -98,6 +98,7 @@ dc_channel_t dc_session_channel_recipients(dc_session_t s,
|
||||
*/
|
||||
void dc_session_add_guild(dc_session_t s, dc_guild_t g);
|
||||
GHashTable *dc_session_guilds(dc_session_t s);
|
||||
dc_guild_t dc_session_guild_by_name(dc_session_t s, char const *name);
|
||||
|
||||
/**
|
||||
* comparision functions for sorting, and finding
|
||||
|
||||
@@ -58,7 +58,7 @@ dc_guild_t dc_guild_from_json(json_t *j)
|
||||
g->id = strdup(json_string_value(val));
|
||||
|
||||
/* there is a ton of more information here, that we should look
|
||||
* add, including "member_count", "owner_id", but for channels
|
||||
* to add, including "member_count", "owner_id", but for now "channels"
|
||||
* will do nicely
|
||||
*/
|
||||
val = json_object_get(j, "channels");
|
||||
@@ -91,6 +91,21 @@ dc_channel_t dc_guild_nth_channel(dc_guild_t d, size_t idx)
|
||||
return g_ptr_array_index(d->channels, idx);
|
||||
}
|
||||
|
||||
dc_channel_t dc_guild_channel_by_name(dc_guild_t g, char const *name)
|
||||
{
|
||||
return_if_true(g == NULL || name == NULL, NULL);
|
||||
size_t i = 0;
|
||||
|
||||
for (i = 0; i < g->channels->len; i++) {
|
||||
dc_channel_t c = g_ptr_array_index(g->channels, i);
|
||||
if (strcmp(dc_channel_name(c), name) == 0) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char const *dc_guild_name(dc_guild_t d)
|
||||
{
|
||||
return_if_true(d == NULL, NULL);
|
||||
|
||||
@@ -450,3 +450,21 @@ void dc_session_add_guild(dc_session_t s, dc_guild_t g)
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
dc_guild_t dc_session_guild_by_name(dc_session_t s, char const *name)
|
||||
{
|
||||
return_if_true(s == NULL || s->guilds == NULL || name == NULL, NULL);
|
||||
|
||||
GHashTableIter iter;
|
||||
gpointer key, value;
|
||||
|
||||
g_hash_table_iter_init(&iter, s->guilds);
|
||||
while (g_hash_table_iter_next(&iter, &key, &value)) {
|
||||
dc_guild_t g = (dc_guild_t)value;
|
||||
if (strcmp(dc_guild_name(g), name) == 0) {
|
||||
return g;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user