Skip to content

Commit

Permalink
Rename #0000 users to regular fries and shake
Browse files Browse the repository at this point in the history
Should help with issue #443
  • Loading branch information
EionRobb committed Jul 13, 2024
1 parent b47be1e commit c6efb80
Show file tree
Hide file tree
Showing 3 changed files with 274 additions and 27 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ WIN32_CC ?= $(WIN32_DEV_TOP)/mingw-4.7.2/bin/gcc

PROTOC_C ?= protoc-c
PKG_CONFIG ?= pkg-config
XGETTEXT ?= xgettext

DIR_PERM = 0755
LIB_PERM = 0755
Expand Down Expand Up @@ -129,7 +130,7 @@ libdiscord3.dll: $(PURPLE_C_FILES) $(PURPLE_COMPAT_FILES)
$(WIN32_CC) -O0 -g -ggdb -shared -o $@ $^ $(WIN32_PIDGIN3_CFLAGS) $(WIN32_PIDGIN3_LDFLAGS)

po/purple-discord.pot: libdiscord.c
xgettext $^ -k_ --no-location -o $@
$(XGETTEXT) $^ -k_ --no-location -o $@

po/%.po: po/purple-discord.pot
msgmerge $@ po/purple-discord.pot > tmp-$*
Expand Down
38 changes: 32 additions & 6 deletions libdiscord.c
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,9 @@ discord_create_fullname(DiscordUser *user)
{
g_return_val_if_fail(user != NULL, NULL);

if (user->discriminator == 0) {
return g_strdup(user->name);
}
return g_strdup_printf("%s#%04d", user->name, user->discriminator);
}

Expand Down Expand Up @@ -925,15 +928,23 @@ discord_alloc_nickname(DiscordUser *user, DiscordGuild *guild, const gchar *sugg
if (existing && existing->id != user->id) {
/* Ambiguous; try with the discriminator */

nick = g_strdup_printf("%s#%04d", base_nick, user->discriminator);
if (user->discriminator == 0) {
nick = g_strdup(base_nick);
} else {
nick = g_strdup_printf("%s#%04d", base_nick, user->discriminator);
}

existing = g_hash_table_lookup(guild->nicknames_rev, nick);

if (existing && existing->id != user->id) {
/* Ambiguous; use the full tag */

g_free(nick);
nick = g_strdup_printf("%s (%s#%04d)", base_nick, user->name, user->discriminator);
if (user->discriminator == 0) {
nick = g_strdup_printf("%s (%s)", base_nick, user->name);
} else {
nick = g_strdup_printf("%s (%s#%04d)", base_nick, user->name, user->discriminator);
}
}
}

Expand Down Expand Up @@ -1300,11 +1311,13 @@ discord_combine_username(const gchar *username, const gchar *discriminator)
{
g_return_val_if_fail(username != NULL, NULL);

if (discriminator == NULL) {
discriminator = "0000";
gint disc_int = to_int(discriminator);

if (disc_int == 0) {
return g_strdup(username);
}

return g_strconcat(username, "#", discriminator, NULL);
return g_strdup_printf("%s#%04d", username, disc_int);
}

static gchar *
Expand Down Expand Up @@ -5050,8 +5063,21 @@ discord_create_relationship(DiscordAccount *da, JsonObject *json)
PurpleBuddy *buddy = purple_blist_find_buddy(da->account, merged_username);

if (buddy == NULL) {
PurpleContact *buddy_contact = NULL;
PurpleGroup *buddy_group = discord_get_or_create_default_group();

// Special case: Check we're not migrating a friend from #0000 to just the username, so we can keep logs
if (user->discriminator == 0) {
gchar *old_username = g_strdup_printf("%s#0000", user->name);
PurpleBuddy *old_buddy = purple_blist_find_buddy(da->account, old_username);
if (old_buddy != NULL) {
buddy_contact = purple_buddy_get_contact(old_buddy);
buddy_group = purple_buddy_get_group(old_buddy);
}
g_free(old_username);
}
buddy = purple_buddy_new(da->account, merged_username, user->name);
purple_blist_add_buddy(buddy, NULL, discord_get_or_create_default_group(), NULL);
purple_blist_add_buddy(buddy, buddy_contact, buddy_group, NULL);
}

discord_get_avatar(da, user, TRUE);
Expand Down
Loading

0 comments on commit c6efb80

Please sign in to comment.