mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-01-10 18:06:22 +00:00
Added actual patches
This commit is contained in:
parent
435d273da0
commit
09c42e3c51
2 changed files with 25 additions and 7 deletions
|
@ -32,7 +32,7 @@ export function ReplaceTutorial() {
|
|||
}
|
||||
<Forms.FormTitle tag="h3" className={Margins.top8}>Available variables</Forms.FormTitle>
|
||||
<Forms.FormText>
|
||||
In all fields, you can put in variables that'll automatically be replaced by their content:
|
||||
In all fields (except stream URL), you can put in variables that'll automatically be replaced by their original content:
|
||||
<pre style={{ fontFamily: "monospace" }}>
|
||||
:name:, :details:, :state:
|
||||
<br />
|
||||
|
@ -44,6 +44,8 @@ export function ReplaceTutorial() {
|
|||
Leave a field empty to leave it as is.
|
||||
<br />
|
||||
Set a field to "null" to hide it on the presence.
|
||||
<br />
|
||||
You may need to reload Discord for changes to apply.
|
||||
</Forms.FormText>
|
||||
</>
|
||||
);
|
||||
|
|
|
@ -12,6 +12,7 @@ import definePlugin, { OptionType } from "@utils/types";
|
|||
import { React } from "@webpack/common";
|
||||
|
||||
import { ReplaceSettings, ReplaceTutorial } from "./ReplaceSettings";
|
||||
import { parse } from "path";
|
||||
|
||||
const APP_IDS_KEY = "ReplaceActivityType_appids";
|
||||
export type AppIdSetting = {
|
||||
|
@ -118,17 +119,32 @@ export default definePlugin({
|
|||
async start() {
|
||||
appIds = await DataStore.get(APP_IDS_KEY) ?? [makeEmptyAppId()];
|
||||
},
|
||||
|
||||
parseField(text: string, originalActivity: Activity): string {
|
||||
if (text === "null") return "";
|
||||
return text
|
||||
.replaceAll(":name:", originalActivity.name)
|
||||
.replaceAll(":details:", originalActivity.details)
|
||||
.replaceAll(":state:", originalActivity.state)
|
||||
.replaceAll(":large_image:", originalActivity.assets.large_image)
|
||||
.replaceAll(":large_text:", originalActivity.assets.large_text)
|
||||
.replaceAll(":small_image:", originalActivity.assets.small_image)
|
||||
.replaceAll(":small_text:", originalActivity.assets.small_text);
|
||||
},
|
||||
patchActivity(activity: Activity) {
|
||||
if (!activity) return;
|
||||
appIds.forEach(app => {
|
||||
if (app.enabled && app.appId === activity.application_id) {
|
||||
const oldActivity = { ...activity };
|
||||
activity.type = app.newActivityType;
|
||||
|
||||
if (app.newActivityType === ActivityType.STREAMING && app.newStreamUrl) {
|
||||
activity.url = app.newStreamUrl;
|
||||
}
|
||||
|
||||
if (app.newName) activity.name = this.parseField(app.newName, oldActivity);
|
||||
if (app.newActivityType === ActivityType.STREAMING && app.newStreamUrl) activity.url = app.newStreamUrl;
|
||||
if (app.newDetails) activity.details = this.parseField(app.newDetails, oldActivity);
|
||||
if (app.newState) activity.state = this.parseField(app.newState, oldActivity);
|
||||
if (app.newLargeImageText) activity.assets.large_text = this.parseField(app.newLargeImageText, oldActivity);
|
||||
if (app.newLargeImageUrl) activity.assets.large_image = this.parseField(app.newLargeImageUrl, oldActivity);
|
||||
if (app.newSmallImageText) activity.assets.small_text = this.parseField(app.newSmallImageText, oldActivity);
|
||||
if (app.newSmallImageUrl) activity.assets.small_image = this.parseField(app.newSmallImageUrl, oldActivity);
|
||||
if (app.disableTimestamps) activity.timestamps = {};
|
||||
}
|
||||
});
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue