Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discord rpc update #42

Merged
merged 8 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file modified Installers/TPDiscord-Mac.tpp
Binary file not shown.
Binary file modified Installers/TPDiscord-Win-DEVELOPMENT.tpp
Binary file not shown.
Binary file modified Installers/TPDiscord-Win-DiscordCanary.tpp
Binary file not shown.
Binary file modified Installers/TPDiscord-Win-PTB.tpp
Binary file not shown.
Binary file modified Installers/TPDiscord-Win.tpp
Binary file not shown.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ v4.0.4
v4.0.5
Package Update:
- Update find-process npm module to 1.4.7 - to pick up bug fix for #32
v4.1.0
Package Update:
- Update discord-rpc npm module to 4.0.1 - to pick up bug fix for #41 and ehancement #20
Updates:
- No More Re-Auhtorization prompt if you have already authorized your developer app, so restarts will be clean and connect without issue
- Refactored the event subscription process due to discord-rpc npm module update. Verified all events still fire as expected.

```

## Plugin Capabilities
Expand Down
4 changes: 2 additions & 2 deletions base/Mac/TPDiscord/entry.tp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"sdk": 3,
"version": 4005,
"TPDiscord_Version": "4.0.5",
"version": 4100,
"TPDiscord_Version": "4.1.0",
"name": "Touch Portal Discord Plugin",
"id": "TPDiscord",
"plugin_start_cmd": "sh %TP_PLUGIN_FOLDER%TPDiscord/start_tpdiscord.sh",
Expand Down
4 changes: 2 additions & 2 deletions base/Win/TPDiscord/entry.tp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"sdk": 3,
"version": 4005,
"TPDiscord_Version":"4.0.5",
"version": 4100,
"TPDiscord_Version":"4.1.0",
"name": "Touch Portal Discord Plugin",
"id": "TPDiscord",
"plugin_start_cmd": "\"%TP_PLUGIN_FOLDER%TPDiscord\\tpdiscord.exe\"",
Expand Down
83 changes: 73 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tpdiscord",
"version": "4.0.5",
"version": "4.1.0",
"description": "Touch Portal Plugin for Discord using RPC",
"bin": {
"tpdiscord": "src/index.js"
Expand All @@ -25,7 +25,7 @@
]
},
"dependencies": {
"discord-rpc": "^3.2.0",
"discord-rpc": "^4.0.1",
"find-process": "^1.4.7",
"out-url": "^1.1.1",
"touchportal-api": "^2.0.1"
Expand Down
48 changes: 36 additions & 12 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,23 +334,30 @@ const connectToDiscord = function () {
last_voice_channel_subs.forEach( sub => {
sub.unsubscribe();
})
last_voice_channel_subs = [];
}
if( data.channel_id == null ) {
discord_voice_channel_name = '<None>';
}
else if( data.guild_id == null ) {
discord_voice_channel_name = 'Personal';
let vsCreate = await DiscordClient.subscribe("VOICE_STATE_CREATE",{channel_id: data.channel_id}, voiceState);
let vsUpdate = await DiscordClient.subscribe("VOICE_STATE_UPDATE",{channel_id: data.channel_id}, voiceState);
let vsDelete = await DiscordClient.subscribe("VOICE_STATE_DELETE",{channel_id: data.channel_id}, voiceState);
let vsCreate = await DiscordClient.subscribe("VOICE_STATE_CREATE",{channel_id: data.channel_id});
let vsUpdate = await DiscordClient.subscribe("VOICE_STATE_UPDATE",{channel_id: data.channel_id});
let vsDelete = await DiscordClient.subscribe("VOICE_STATE_DELETE",{channel_id: data.channel_id});
DiscordClient.on("VOICE_STATE_CREATE", (data) => {voiceState(data);})
DiscordClient.on("VOICE_STATE_UPDATE", (data) => {voiceState(data);})
DiscordClient.on("VOICE_STATE_DELETE", (data) => {voiceState(data);})
last_voice_channel_subs = [ vsCreate, vsUpdate, vsDelete ];
}
else {
// Lookup Voice Channel Name
discord_voice_channel_name = channels[data.guild_id].voice.names[data.channel_id];
let vsCreate = await DiscordClient.subscribe("VOICE_STATE_CREATE",{channel_id: data.channel_id}, voiceState);
let vsUpdate = await DiscordClient.subscribe("VOICE_STATE_UPDATE",{channel_id: data.channel_id}, voiceState);
let vsDelete = await DiscordClient.subscribe("VOICE_STATE_DELETE",{channel_id: data.channel_id}, voiceState);
let vsCreate = await DiscordClient.subscribe("VOICE_STATE_CREATE",{channel_id: data.channel_id});
let vsUpdate = await DiscordClient.subscribe("VOICE_STATE_UPDATE",{channel_id: data.channel_id});
let vsDelete = await DiscordClient.subscribe("VOICE_STATE_DELETE",{channel_id: data.channel_id});
DiscordClient.on("VOICE_STATE_CREATE", (data) => {voiceState(data);})
DiscordClient.on("VOICE_STATE_UPDATE", (data) => {voiceState(data);})
DiscordClient.on("VOICE_STATE_DELETE", (data) => {voiceState(data);})
last_voice_channel_subs = [ vsCreate, vsUpdate, vsDelete ];
}

Expand Down Expand Up @@ -403,15 +410,30 @@ const connectToDiscord = function () {

TPClient.settingUpdate(PLUGIN_CONNECTED_SETTING,"Connected");

await DiscordClient.subscribe("VOICE_SETTINGS_UPDATE", voiceActivity);
await DiscordClient.subscribe("GUILD_CREATE", guildCreate);
await DiscordClient.subscribe("CHANNEL_CREATE", channelCreate);
await DiscordClient.subscribe("VOICE_CHANNEL_SELECT", voiceChannel);
await DiscordClient.subscribe("VOICE_CONNECTION_STATUS", voiceConnectionStatus);
await DiscordClient.subscribe("VOICE_SETTINGS_UPDATE");
await DiscordClient.subscribe("GUILD_CREATE");
await DiscordClient.subscribe("CHANNEL_CREATE");
await DiscordClient.subscribe("VOICE_CHANNEL_SELECT");
await DiscordClient.subscribe("VOICE_CONNECTION_STATUS");

getGuilds();

});
DiscordClient.on('VOICE_SETTINGS_UPDATE', (data) => {
voiceActivity(data);
})
DiscordClient.on('GUILD_CREATE', (data) => {
guildCreate(data);
})
DiscordClient.on('CHANNEL_CREATE', (data) => {
channelCreate(data);
})
DiscordClient.on('VOICE_CHANNEL_SELECT', (data) => {
voiceChannel(data);
})
DiscordClient.on('VOICE_CONNECTION_STATUS', (data) => {
voiceConnectionStatus(data);
})

DiscordClient.on("disconnected", () => {
logIt("WARN","discord connection closed, will attempt reconnect, once process detected");
Expand All @@ -422,12 +444,14 @@ const connectToDiscord = function () {
discordRunning = false;
});

const prompt = 'none';
DiscordClient.login({
clientId : pluginSettings["Discord Client Id"],
clientSecret: pluginSettings["Discord Client Secret"],
accessToken,
scopes,
redirectUri
redirectUri,
prompt
}).catch((error) => {
logIt("ERROG","login error",error);
if( error.code == 4009 ) {
Expand Down