From 704828f405ad137a30f1356efcb17aba6488b457 Mon Sep 17 00:00:00 2001 From: Ave Ozkal Date: Sun, 26 May 2019 22:31:51 +0300 Subject: [PATCH] Slashcommands: add account switcher --- patches/slashcommands/903.patch | 203 ++++++++++++++++++++++++++++++-- patches/slashcommands/README.md | 4 +- 2 files changed, 194 insertions(+), 13 deletions(-) diff --git a/patches/slashcommands/903.patch b/patches/slashcommands/903.patch index 677a84c..2e88f7b 100644 --- a/patches/slashcommands/903.patch +++ b/patches/slashcommands/903.patch @@ -1,6 +1,6 @@ diff -crB com.discord-903-base/smali/com/discord/models/domain/ModelChannel.smali com.discord-903/smali/com/discord/models/domain/ModelChannel.smali *** com.discord-903-base/smali/com/discord/models/domain/ModelChannel.smali 2019-05-24 23:40:49.520802264 +0300 ---- com.discord-903/smali/com/discord/models/domain/ModelChannel.smali 2019-05-26 16:28:14.734931852 +0300 +--- com.discord-903/smali/com/discord/models/domain/ModelChannel.smali 2019-05-26 20:27:36.478778820 +0300 *************** *** 2082,2087 **** --- 2082,2097 ---- @@ -22,7 +22,7 @@ diff -crB com.discord-903-base/smali/com/discord/models/domain/ModelChannel.smal diff -crB com.discord-903-base/smali/com/discord/stores/StoreMessages.smali com.discord-903/smali/com/discord/stores/StoreMessages.smali *** com.discord-903-base/smali/com/discord/stores/StoreMessages.smali 2019-05-24 23:40:49.670802999 +0300 ---- com.discord-903/smali/com/discord/stores/StoreMessages.smali 2019-05-26 18:11:36.112395942 +0300 +--- com.discord-903/smali/com/discord/stores/StoreMessages.smali 2019-05-26 22:26:25.368827559 +0300 *************** *** 432,437 **** --- 432,441 ---- @@ -38,7 +38,7 @@ diff -crB com.discord-903-base/smali/com/discord/stores/StoreMessages.smali com. *************** *** 948,953 **** ---- 952,3606 ---- +--- 952,3720 ---- return-void .end method @@ -2218,7 +2218,7 @@ diff -crB com.discord-903-base/smali/com/discord/stores/StoreMessages.smali com. + .end method + + .method public static final slashCtc(Ljava/lang/String;)Ljava/lang/String; -+ .locals 2 ++ .locals 3 + + # called from smali/com/discord/widgets/chat/input/WidgetChatInputSend$configureSendListeners$1.smali + @@ -2338,7 +2338,7 @@ diff -crB com.discord-903-base/smali/com/discord/stores/StoreMessages.smali com. + + move-result v0 + -+ if-eqz v0, :cond_1 ++ if-eqz v0, :cond_5 + + # Get value + @@ -2352,8 +2352,122 @@ diff -crB com.discord-903-base/smali/com/discord/stores/StoreMessages.smali com. + + return-object p0 + ++ :cond_5 ++ const-string v0, "account " ++ ++ invoke-virtual {p0, v0}, Ljava/lang/String;->startsWith(Ljava/lang/String;)Z ++ ++ move-result v0 ++ ++ if-eqz v0, :cond_7 ++ ++ # Move to config value interpretation ++ ++ const/16 v0, 0x8 ++ ++ invoke-virtual {p0, v0}, Ljava/lang/String;->substring(I)Ljava/lang/String; ++ ++ move-result-object p0 ++ ++ invoke-virtual {p0}, Ljava/lang/String;->trim()Ljava/lang/String; ++ ++ move-result-object p0 ++ ++ # Set value ++ ++ invoke-static {}, Lcom/discord/stores/StoreStream;->getUserSettings()Lcom/discord/stores/StoreUserSettings; ++ ++ move-result-object v0 ++ ++ invoke-virtual {v0, p0}, Lcom/discord/stores/StoreUserSettings;->getAccountToken(Ljava/lang/String;)Ljava/lang/String; ++ ++ move-result-object p0 ++ ++ const-string v1, "none" ++ ++ invoke-virtual {p0, v1}, Ljava/lang/String;->startsWith(Ljava/lang/String;)Z ++ ++ move-result v1 ++ ++ if-nez v1, :cond_6 ++ ++ invoke-virtual {v0, p0}, Lcom/discord/stores/StoreUserSettings;->setStoredToken(Ljava/lang/String;)V ++ ++ const-string p0, "CTC: Successfully changed accounts. Please restart application." ++ ++ return-object p0 ++ ++ :cond_6 ++ ++ const-string p0, "CTC: No such account found." ++ ++ return-object p0 ++ ++ :cond_7 ++ const-string v0, "addaccount " ++ ++ invoke-virtual {p0, v0}, Ljava/lang/String;->startsWith(Ljava/lang/String;)Z ++ ++ move-result v0 ++ ++ if-eqz v0, :cond_1 ++ ++ # Get value ++ ++ const/16 v0, 0xb ++ ++ invoke-virtual {p0, v0}, Ljava/lang/String;->substring(I)Ljava/lang/String; ++ ++ move-result-object p0 ++ ++ # Get next space ++ ++ const-string v0, " " ++ ++ invoke-virtual {p0, v0}, Ljava/lang/String;->indexOf(Ljava/lang/String;)I ++ ++ move-result v0 ++ ++ # const/4 v1, 0x6 ++ ++ invoke-virtual {p0, v0}, Ljava/lang/String;->substring(I)Ljava/lang/String; ++ ++ move-result-object v1 ++ ++ # at this point: ++ # p0 = "$username $token" ++ # v1 = "$username" ++ ++ const-string v2, "" ++ ++ invoke-virtual {p0, v1, v2}, Ljava/lang/String;->replace(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)Ljava/lang/String; ++ ++ move-result-object p0 ++ ++ invoke-virtual {p0}, Ljava/lang/String;->trim()Ljava/lang/String; ++ ++ move-result-object p0 ++ ++ invoke-virtual {v1}, Ljava/lang/String;->trim()Ljava/lang/String; ++ ++ move-result-object v1 ++ ++ # at this point: ++ # p0 = "$token" ++ # v1 = "$username" ++ ++ invoke-static {}, Lcom/discord/stores/StoreStream;->getUserSettings()Lcom/discord/stores/StoreUserSettings; ++ ++ move-result-object v0 ++ ++ invoke-virtual {v0, p0, v1}, Lcom/discord/stores/StoreUserSettings;->setAccountToken(Ljava/lang/String;Ljava/lang/String;)V ++ ++ const-string p0, "CTC: Added account." ++ ++ return-object p0 ++ + :cond_1 -+ const-string p0, "CTC: No known command supplied. (available: token, showtyping or channelleak. everything except specified token needs to be lowercase)" ++ const-string p0, "CTC: No known command supplied. (available: token, showtyping, channelleak, addaccount, account. Everything except specified token needs to be lowercase)" + + return-object p0 + .end method @@ -2696,7 +2810,7 @@ diff -crB com.discord-903-base/smali/com/discord/stores/StoreMessages.smali com. .annotation system Ldalvik/annotation/Signature; *************** *** 977,982 **** ---- 3630,3639 ---- +--- 3744,3753 ---- invoke-static {p4, v0}, Lkotlin/jvm/internal/k;->h(Ljava/lang/Object;Ljava/lang/String;)V @@ -2709,10 +2823,10 @@ diff -crB com.discord-903-base/smali/com/discord/stores/StoreMessages.smali com. if-eqz p6, :cond_0 diff -crB com.discord-903-base/smali/com/discord/stores/StoreUserSettings.smali com.discord-903/smali/com/discord/stores/StoreUserSettings.smali *** com.discord-903-base/smali/com/discord/stores/StoreUserSettings.smali 2019-05-24 23:40:49.700803146 +0300 ---- com.discord-903/smali/com/discord/stores/StoreUserSettings.smali 2019-05-26 18:03:13.643331588 +0300 +--- com.discord-903/smali/com/discord/stores/StoreUserSettings.smali 2019-05-26 22:24:34.401539018 +0300 *************** *** 1272,1277 **** ---- 1272,1387 ---- +--- 1272,1452 ---- return v0 .end method @@ -2825,13 +2939,78 @@ diff -crB com.discord-903-base/smali/com/discord/stores/StoreUserSettings.smali + + return-void + .end method ++ ++ .method public getAccountToken(Ljava/lang/String;)Ljava/lang/String; ++ .locals 3 ++ ++ const-string v2, "STORE_AUTHED_TOKEN_CTC_USER_" ++ ++ invoke-virtual {p1}, Ljava/lang/String;->toUpperCase()Ljava/lang/String; ++ ++ move-result-object p1 ++ ++ new-instance v0, Ljava/lang/StringBuilder; ++ ++ invoke-direct {v0, v2}, Ljava/lang/StringBuilder;->(Ljava/lang/String;)V ++ ++ invoke-virtual {v0, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder; ++ ++ invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String; ++ ++ move-result-object v2 ++ ++ iget-object v0, p0, Lcom/discord/stores/StoreAuthentication;->prefs:Landroid/content/SharedPreferences; ++ ++ const-string v1, "none" ++ ++ invoke-interface {v0, v2, v1}, Landroid/content/SharedPreferences;->getString(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; ++ ++ move-result-object v0 ++ ++ return-object v0 ++ .end method ++ ++ ++ .method public setAccountToken(Ljava/lang/String;Ljava/lang/String;)V ++ .locals 2 ++ ++ const-string v1, "STORE_AUTHED_TOKEN_CTC_USER_" ++ ++ invoke-virtual {p1}, Ljava/lang/String;->toUpperCase()Ljava/lang/String; ++ ++ move-result-object p1 ++ ++ new-instance v0, Ljava/lang/StringBuilder; ++ ++ invoke-direct {v0, v1}, Ljava/lang/StringBuilder;->(Ljava/lang/String;)V ++ ++ invoke-virtual {v0, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder; ++ ++ invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String; ++ ++ move-result-object v1 ++ ++ iget-object v0, p0, Lcom/discord/stores/StoreAuthentication;->prefs:Landroid/content/SharedPreferences; ++ ++ invoke-interface {v0}, Landroid/content/SharedPreferences;->edit()Landroid/content/SharedPreferences$Editor; ++ ++ move-result-object v0 ++ ++ invoke-interface {v0, v1, p2}, Landroid/content/SharedPreferences$Editor;->putString(Ljava/lang/String;Ljava/lang/String;)Landroid/content/SharedPreferences$Editor; ++ ++ move-result-object p1 ++ ++ invoke-interface {p1}, Landroid/content/SharedPreferences$Editor;->apply()V ++ ++ return-void ++ .end method + .method handleConnectionOpen(Lcom/discord/models/domain/ModelPayload;)V .locals 0 diff -crB com.discord-903-base/smali/com/discord/widgets/chat/input/WidgetChatInputEditText$1.smali com.discord-903/smali/com/discord/widgets/chat/input/WidgetChatInputEditText$1.smali *** com.discord-903-base/smali/com/discord/widgets/chat/input/WidgetChatInputEditText$1.smali 2019-05-24 23:40:49.907470826 +0300 ---- com.discord-903/smali/com/discord/widgets/chat/input/WidgetChatInputEditText$1.smali 2019-05-26 16:32:19.513084840 +0300 +--- com.discord-903/smali/com/discord/widgets/chat/input/WidgetChatInputEditText$1.smali 2019-05-26 20:27:36.482112172 +0300 *************** *** 124,129 **** --- 124,139 ---- @@ -2853,7 +3032,7 @@ diff -crB com.discord-903-base/smali/com/discord/widgets/chat/input/WidgetChatIn diff -crB com.discord-903-base/smali/com/discord/widgets/chat/input/WidgetChatInputSend$configureSendListeners$1.smali com.discord-903/smali/com/discord/widgets/chat/input/WidgetChatInputSend$configureSendListeners$1.smali *** com.discord-903-base/smali/com/discord/widgets/chat/input/WidgetChatInputSend$configureSendListeners$1.smali 2019-05-24 23:40:49.907470826 +0300 ---- com.discord-903/smali/com/discord/widgets/chat/input/WidgetChatInputSend$configureSendListeners$1.smali 2019-05-26 17:40:46.959503995 +0300 +--- com.discord-903/smali/com/discord/widgets/chat/input/WidgetChatInputSend$configureSendListeners$1.smali 2019-05-26 20:27:36.482112172 +0300 *************** *** 355,360 **** --- 355,362 ---- @@ -2914,7 +3093,7 @@ diff -crB com.discord-903-base/smali/com/discord/widgets/chat/input/WidgetChatIn .line 79 diff -crB com.discord-903-base/smali/com/discord/widgets/chat/input/WidgetChatInputSend.smali com.discord-903/smali/com/discord/widgets/chat/input/WidgetChatInputSend.smali *** com.discord-903-base/smali/com/discord/widgets/chat/input/WidgetChatInputSend.smali 2019-05-24 23:40:49.907470826 +0300 ---- com.discord-903/smali/com/discord/widgets/chat/input/WidgetChatInputSend.smali 2019-05-26 17:40:34.489430375 +0300 +--- com.discord-903/smali/com/discord/widgets/chat/input/WidgetChatInputSend.smali 2019-05-26 20:27:36.485445524 +0300 *************** *** 50,55 **** --- 50,79 ---- diff --git a/patches/slashcommands/README.md b/patches/slashcommands/README.md index 45d95c3..fb68915 100644 --- a/patches/slashcommands/README.md +++ b/patches/slashcommands/README.md @@ -22,11 +22,13 @@ Following commands are supported, but create less accessible text (so you should - /flip -> Flips text (like "ʇɥıs") - /clap -> Please :clap: clap -CutTheCord has a couple features that can be enabled or disabled with slash commands as well: +CutTheCord has a couple features that can utilized with slash commands as well: - /ctc channelleak true/false -> Shows all channels, even those you don't have permissions to view (might mess with channel editing or editing while it's enabled) - /ctc notyping true/false -> Disables typing event so that it's not visible when you type (true = typing is shown, false = not shown) - /ctc token -> Gives your token - /ctc token $token -> Sets your token to the one specified, allowing switching between accounts +- /ctc addaccount $name $token -> Adds an account to the account switcher (name can be anything) +- /ctc account $name -> Switches to the account (requires you to restart the app) Commands like fw can be generated by `textreplacegen.py` or `textreplacegen-array.py` provided in this folder.