Skip to content

Commit

Permalink
feat(robo): experimental support for user installs (#237)
Browse files Browse the repository at this point in the history
* Added support for user installs

I did not test it yet inside of robo.js but it worked outside using my own code pkmmte agreed on me trying to contribute it into this amazing framework!

* chore: minor cleanup

---------

Co-authored-by: Pkmmte Xeleon <[email protected]>
  • Loading branch information
bloomsirenix and Pkmmte authored May 10, 2024
1 parent dcd2da5 commit d6138ef
Show file tree
Hide file tree
Showing 13 changed files with 2,638 additions and 1,640 deletions.
5 changes: 5 additions & 0 deletions .changeset/twenty-pets-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'robo.js': patch
---

feat: experimental support for user installs
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
### Hacktoberfest Submission

#### Name

[The name of your plugin or bot]

#### Package/Repository

- For plugins: How it's installed.
- For bots: GitHub link to the bot.

#### Description

[A concise and clear description of what your submission does]

#### (Optional) Contact for Prize Distribution

[Discord username for DM, or you can email us at [[email protected]](mailto:[email protected])]

#### Checklist:

- [ ] I have added my details to the `HACKTOBERFEST.md` file.
- [ ] My submission adheres to the Robo.js and Hacktoberfest guidelines.
8 changes: 4 additions & 4 deletions .github/workflows/cla.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: "CLA Assistant"
name: 'CLA Assistant'
on:
issue_comment:
types: [created]
pull_request_target:
types: [opened,closed,synchronize]
types: [opened, closed, synchronize]

# explicitly configure permissions, in case your GITHUB_TOKEN workflow permissions are set to read-only in repository settings
permissions:
Expand All @@ -16,7 +16,7 @@ jobs:
CLAAssistant:
runs-on: ubuntu-latest
steps:
- name: "CLA Assistant"
- name: 'CLA Assistant'
if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the CLA Document and I hereby sign the CLA') || github.event_name == 'pull_request_target'
uses: contributor-assistant/[email protected]
env:
Expand All @@ -28,7 +28,7 @@ jobs:
branch: 'main'
allowlist: pkmmte,bot*,allcontributors,vercel

# the followings are the optional inputs - If the optional inputs are not given, then default values will be taken
# the followings are the optional inputs - If the optional inputs are not given, then default values will be taken
#remote-organization-name: enter the remote organization name where the signatures should be stored (Default is storing the signatures in the same repository)
#remote-repository-name: enter the remote repository name where the signatures should be stored (Default is storing the signatures in the same repository)
#create-file-commit-message: 'For example: Creating file for storing CLA Signatures'
Expand Down
4 changes: 2 additions & 2 deletions CLA.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ This Contributor License Agreement (this "**Agreement**" or "**CLA**") sets fort

2. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT WILL YOU OR WAVEPLAY BE LIABLE FOR ANY LOSS OF PROFITS, LOSS OF ANTICIPATED SAVINGS, LOSS OF DATA, INDIRECT, SPECIAL, INCIDENTAL, CONSEQUENTIAL AND EXEMPLARY DAMAGES ARISING OUT OF THIS AGREEMENT REGARDLESS OF THE LEGAL OR EQUITABLE THEORY (CONTRACT, TORT OR OTHERWISE) UPON WHICH THE CLAIM IS BASED.

## 5. Indemnification.
## 5. Indemnification.

You agree to indemnify, defend and hold harmless WavePlay and its officers, directors, employees, agents, affiliates, successors and assigns from and against any and all losses, damages, liabilities, deficiencies, claims, actions, judgments, settlements, interest, awards, penalties, fines, costs, or expenses of whatever kind, including reasonable attorneys' fees, arising from or relating to your breach of any representations and warranties in this Agreement.

Expand All @@ -56,4 +56,4 @@ You agree to indemnify, defend and hold harmless WavePlay and its officers, dire

4. No course of dealing on the part of WavePlay or WavePlay's officers, agents, or representatives, nor any failure or delay in the exercise of any right by WavePlay, shall operate as a waiver thereof, and any single or partial exercise of any such right shall not preclude any later exercise of any such right. Our failure at any time to require strict performance of any provision hereof shall not affect any right thereafter to demand strict compliance and performance. Any suspension or waiver of a right must be in writing and be signed by a duly authorized officer of WavePlay.

5. If any provision of this Agreement is found void and unenforceable, such provision will be replaced to the extent possible with a provision that comes closest to the meaning of the original provision and which is enforceable. The terms and conditions set forth in this Agreement shall apply notwithstanding any failure of essential purpose of this Agreement or any limited remedy to the maximum extent possible under law.
5. If any provision of this Agreement is found void and unenforceable, such provision will be replaced to the extent possible with a provision that comes closest to the meaning of the original provision and which is enforceable. The terms and conditions set forth in this Agreement shall apply notwithstanding any failure of essential purpose of this Agreement or any limited remedy to the maximum extent possible under law.
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ Hey there! First and foremost, a big **THANK YOU** for showing interest in our p

This document will guide you through the process of contributing to Robo.js.

**Not a coder but got a neat idea?** No worries!
**Not a coder but got a neat idea?** No worries!

**[📝 Suggest features by creating a GitHub Issue](https://github.com/your-repo-name/issues)**

**[🚀 Community: Join our Discord server](https://roboplay.dev/discord)**

Remember, contributing to the core is different from making your own Robo or plugin. If you're looking for a starter guide:
Remember, contributing to the core is different from making your own Robo or plugin. If you're looking for a starter guide:

**[📖 Tutorial: Making a "To-do" Robo](https://blog.waveplay.com/how-to-make-a-discord-robo)**

Expand Down Expand Up @@ -66,15 +66,15 @@ Got the right VS Code plugins? These tools will be a lot of help getting PRs app

## Running

Ready to run the project?
Ready to run the project?

1. **Fork the repo**: You'll need the entire monorepo to run the project.
2. **Install dependencies**: Run `pnpm install` to install all dependencies for the monorepo.
3. **Build binaries**: Run `pnpm build:robo` to build Robo.js. All other packages rely on it, even if you're not contributing to the core.
4. **Build packages**: Run `pnpm build` to build all packages. This will build all packages in the monorepo. You can also navigate to a specific package and run `pnpm build` there to build just that package.
5. **Test it out**: Whether you're working on the core or a plugin, you can test your changes by running `pnpm dev` in the package directory. You can then link your package to a Robo project using `pnpm add <dirToPkg>`.

If you'd like to auto rebuild, you can run `pnpm dev` instead of `pnpm build`. This will start a watcher that will rebuild your package whenever you make changes.
If you'd like to auto rebuild, you can run `pnpm dev` instead of `pnpm build`. This will start a watcher that will rebuild your package whenever you make changes.

Plus, if you ran your test Robo in `dev` mode after that, it will automatically reload when you make changes!

Expand All @@ -90,7 +90,7 @@ We highly encourage you to follow **[Conventional Commits](https://www.conventio

We follow **[Semantic Versioning](https://semver.org/)** (SemVer) for packages v1.0.0 and up. Under that? The second digit is for breaking changes and the third for everything else.

We also rely on **[Changesets](https://github.com/changesets/changesets)** for change management. Just run `pnpm changeset` and let the CLI guide you.
We also rely on **[Changesets](https://github.com/changesets/changesets)** for change management. Just run `pnpm changeset` and let the CLI guide you.

Starting a new package? Use `0.0.0` as your initial version and Changesets will handle the rest.

Expand Down
3 changes: 1 addition & 2 deletions HACKTOBERFEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ We encourage you to provide a contact method for prize distribution, but it's no

## Submissions

*Please note that the example below is not an actual submission; it's for illustration purposes. Replace it with your own details.*
_Please note that the example below is not an actual submission; it's for illustration purposes. Replace it with your own details._

### [Name (Plugin/Bot)]

Expand All @@ -37,4 +37,3 @@ We encourage you to provide a contact method for prize distribution, but it's no
- **Package**: [emoji-reaction-plugin](https://www.npmjs.com/package/emoji-reaction-plugin)
- **Description**: Make your conversations fun and interactive with various emoji based reactions.
- **Contact**: bekool.sh

7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

[![GitHub license](https://img.shields.io/github/license/Wave-Play/robo)](https://github.com/Wave-Play/robo/blob/main/LICENSE) [![npm](https://img.shields.io/npm/v/robo.js)](https://www.npmjs.com/package/robo.js) [![install size](https://packagephobia.com/badge?p=robo.js@latest)](https://packagephobia.com/result?p=robo.js@latest) [![Discord](https://img.shields.io/discord/1087134933908193330?color=7289da)](https://roboplay.dev/discord) [![All Contributors](https://img.shields.io/github/all-contributors/Wave-Play/robo.js?color=cf7cfc)](#contributors)


**Power up Discord with effortless activities, bots, web servers, and more!**

Upgrade your Discord projects with effortless integration, dynamic plugins, and advanced debugging—unlocking the full potential of Discord.js and beyond. 🚀✨
Expand Down Expand Up @@ -89,9 +88,9 @@ For events, say you want to listen to `messageCreate` events. Create a `messageC

```javascript
export default (message) => {
if (message.content.includes('hello')) {
message.channel.send('Hello there!');
}
if (message.content.includes('hello')) {
message.channel.send('Hello there!')
}
}
```

Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-ai/.robo/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,4 @@
"applications.commands",
"bot"
]
}
}
2 changes: 1 addition & 1 deletion packages/plugin-api/.robo/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
"scopes": [
"bot"
]
}
}
20 changes: 17 additions & 3 deletions packages/robo/src/cli/utils/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ export async function registerCommands(
const addedContextChanges = addedContextCommands.map((cmd) => color.green(`${color.bold(cmd)} (new)`))
const removedContextChanges = removedContextCommands.map((cmd) => color.red(`${color.bold(cmd)} (deleted)`))
const updatedContextChanges = changedContextCommands.map((cmd) => color.blue(`${color.bold(cmd)} (updated)`))

const allChanges = [...addedChanges, ...removedChanges, ...updatedChanges]
const allContextChanges = [...addedContextChanges, ...removedContextChanges, ...updatedContextChanges]
if (allChanges.length > 0) {
Expand All @@ -346,13 +345,23 @@ export async function registerCommands(
if (allContextChanges.length > 0) {
logger.info('Context menu changes: ' + allContextChanges.join(', '))
}

const commandData = [
...slashCommands.map((command) => command.toJSON()),
...contextMessageCommands.map((command) => command.toJSON()),
...contextUserCommands.map((command) => command.toJSON())
]

// Inject user install if enabled
if (config.experimental?.userInstall) {
commandData.forEach((command) => {
// @ts-expect-error - Types outdated
command.integration_types = [0, 1]
// @ts-expect-error - Types outdated
command.contexts = [0, 1, 2]
})
}

// Get existing commands
const existingCommands = (await rest.get(
guildId ? Routes.applicationGuildCommands(clientId, guildId) : Routes.applicationCommands(clientId)
)) as APIApplicationCommand[]
Expand Down Expand Up @@ -404,7 +413,12 @@ export async function registerCommands(
}

const endTime = Date.now() - startTime
const commandType = guildId ? 'guild' : 'global'
let commandType = guildId ? 'guild' : 'global'

if (config.experimental?.userInstall) {
commandType += ' and user install'
}

logger.info(`Successfully updated ${color.bold(commandType + ' commands')} in ${endTime}ms`)
logger.info(color.dim('It may take a while for the changes to reflect in Discord.'))
await Flashcore.delete(FLASHCORE_KEYS.commandRegisterError)
Expand Down
1 change: 1 addition & 0 deletions packages/robo/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface Config {
buildDirectory?: string
disableBot?: boolean
incrementalBuilds?: boolean
userInstall?: boolean
}
flashcore?: {
keyv?: unknown
Expand Down
Loading

0 comments on commit d6138ef

Please sign in to comment.