feat(ClientUser): setSamsungActivity

This commit is contained in:
Elysia 2023-02-21 16:53:34 +07:00
parent db9bc318b3
commit e2076f7087
3 changed files with 40 additions and 57 deletions

16
Document/SamsungRPC.md Normal file
View File

@ -0,0 +1,16 @@
<img src='https://cdn.discordapp.com/attachments/820557032016969751/1077527909302018088/image.png'>
```js
const { Client } = require('discord.js-selfbot-v13');
const client = new Client();
client.on('ready', async () => {
client.user.setSamsungActivity('com.YostarJP.BlueArchive', 'START');
// client.user.setSamsungActivity('com.miHoYo.bh3oversea', 'UPDATE');
// client.user.setSamsungActivity('com.miHoYo.GenshinImpact', 'STOP');
});
client.login('token');
```

View File

@ -1,8 +1,6 @@
'use strict'; 'use strict';
const { setInterval } = require('timers');
const { Collection } = require('@discordjs/collection'); const { Collection } = require('@discordjs/collection');
const axios = require('axios');
const Invite = require('./Invite'); const Invite = require('./Invite');
const { Message } = require('./Message'); const { Message } = require('./Message');
const User = require('./User'); const User = require('./User');
@ -95,10 +93,6 @@ class ClientUser extends User {
* @private * @private
*/ */
if (!this.friendNicknames?.size) this.friendNicknames = new Collection(); if (!this.friendNicknames?.size) this.friendNicknames = new Collection();
this.package_name = null;
this.refreshInterval = null;
this.isSamsungActivityRunning = null;
} }
/** /**
@ -534,58 +528,30 @@ class ClientUser extends User {
/** /**
* Sets Discord Playing status to "Playing on Samsung Galaxy". Only selected gamss from discords database works * Sets Discord Playing status to "Playing on Samsung Galaxy". Only selected gamss from discords database works
* @param {string} [package_name] play store package name/application id of app * @param {string} packageName Android package name
* @param {?string} type Must be START, UPDATE, or STOP
* @returns {Promise<ClientUser>}
* @example
* // Set the client user's status
* client.user.setSamsungActivity('com.YostarJP.BlueArchive', 'START');
* // Update
* client.user.setSamsungActivity('com.miHoYo.bh3oversea', 'UPDATE');
* // Stop
* client.user.setSamsungActivity('com.miHoYo.GenshinImpact', 'STOP');
*/ */
async setSamsungActivity(package_name) { async setSamsungActivity(packageName, type = 'START') {
if (!this.client.token) { type = type.toUpperCase();
throw new Error('NO_TOKEN_PROVIDED'); if (!packageName || typeof packageName !== 'string') throw new Error('Package name is required.');
} if (!['START', 'UPDATE', 'STOP'].includes(type)) throw new Error('Invalid type (Must be START, UPDATE, or STOP)');
if (!package_name) { await this.client.api.presences.post({
console.error('No package name set'); data: {
return; package_name: packageName,
} update: type,
this.package_name = package_name;
await this.updateStatus('START');
console.log('Starting Presence');
this.isSamsungActivityRunning = true;
this.createRefreshInterval();
}
createRefreshInterval() {
if (this.refreshInterval) clearInterval(this.refreshInterval);
this.refreshInterval = setInterval(async () => {
if (!this.isSamsungActivityRunning) return;
console.log('Updating Status');
await this.updateStatus('UPDATE');
}, 5 * 60 * 1000);
}
/**
* Sends Presence Payload to Discord api
* @param {string} [update_code] value representing the state of activity. Possible values are "START","STOP","UPDATE"
*/
async updateStatus(update_code) {
if (!this.package_name) return;
try {
await axios.post(
`https://discord.com/api/v9/presences`,
{
package_name: this.package_name,
update: update_code,
}, },
{ });
headers: { if (type !== 'STOP') this._packageName = packageName;
Authorization: this.client.token, else this._packageName = null;
'User-Agent': return this;
'Mozilla/5.0 (Linux; Android 13) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/100.0.4896.127 Mobile OceanHero/6 Safari/537.36',
'Content-Type': 'application/json',
'Cache-Control': 'max-age=121',
},
},
);
} catch (err) {
console.error(err.message);
}
} }
} }

1
typings/index.d.ts vendored
View File

@ -1045,6 +1045,7 @@ export class ClientUser extends User {
public setDeaf(status: boolean): Promise<boolean>; public setDeaf(status: boolean): Promise<boolean>;
public setMute(status: boolean): Promise<boolean>; public setMute(status: boolean): Promise<boolean>;
public getInvite(options?: CreateInviteOptions): Promise<Invite>; public getInvite(options?: CreateInviteOptions): Promise<Invite>;
public setSamsungActivity(packageName: string, type?: 'START' | 'UPDATE' | 'STOP'): Promise<this>;
public getMentions( public getMentions(
limit?: number, limit?: number,
mentionRoles?: boolean, mentionRoles?: boolean,