Skip to content

Commit

Permalink
Merge pull request benawad#2752 from TheOtterlord/staging
Browse files Browse the repository at this point in the history
[KEBAB] add example to create bot
  • Loading branch information
TheOtterlord authored May 14, 2021
2 parents bff22c4 + 83cc8ec commit 9488a81
Show file tree
Hide file tree
Showing 11 changed files with 10,212 additions and 22,155 deletions.
2 changes: 1 addition & 1 deletion kebab/examples/bot/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# An example bot
1. Put your access- and refresh-token in `.env` (`DOGEHOUSE_TOKEN`, `DOGEHOUSE_REFRESH_TOKEN`)
1. Put your bot's api key in `.env` as `DOGEHOUSE_API_KEY`
2. Build the API package: `$ yarn` and `$ yarn build` in kebab's root directory
3. Build the example: `$ npm i` and `$ npm run build`
4. `$ npm start`
32 changes: 11 additions & 21 deletions kebab/examples/bot/package-lock.json

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

32 changes: 11 additions & 21 deletions kebab/examples/chat/package-lock.json

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

7 changes: 7 additions & 0 deletions kebab/examples/create-bot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# An script to create a bot account
1. Put your access and refresh-token in `.env` (`DOGEHOUSE_TOKEN`, `DOGEHOUSE_REFRESH_TOKEN`)
2. Choose your bot's username and place it in `.env` as `DOGEHOUSE_BOT_NAME`
3. Build the API package: `$ yarn` and `$ yarn build` in kebab's root directory
4. Build the example: `$ npm i` and `$ npm run build`
5. `$ npm start`
6. Save the api key printed to the screen in a safe place to later use with your bot.
102 changes: 102 additions & 0 deletions kebab/examples/create-bot/package-lock.json

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

16 changes: 16 additions & 0 deletions kebab/examples/create-bot/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "create-bot",
"private": true,
"scripts": {
"build": "tsc",
"start": "node build/index.js"
},
"dependencies": {
"@dogehouse/kebab": "file:../..",
"@types/node": "^14.14.35"
},
"devDependencies": {
"dotenv": "^8.2.0",
"typescript": "^4.2.3"
}
}
29 changes: 29 additions & 0 deletions kebab/examples/create-bot/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require("dotenv").config();

import { raw, wrap } from "@dogehouse/kebab";

const main = async () => {
try {
const wrapper = wrap(await raw.connect(
process.env.DOGEHOUSE_TOKEN!,
process.env.DOGEHOUSE_REFRESH_TOKEN!,
{
onConnectionTaken: () => {
console.error("\nAnother client has taken the connection");
process.exit();
}
}
));

wrapper.mutation.userCreateBot(process.env.DOGEHOUSE_BOT_NAME!).then(res => {
console.log(res)
}).catch(err => {
console.error(err)
})
} catch (e) {
if (e.code === 4001) console.error("invalid token!");
console.error(e)
}
};

main();
13 changes: 13 additions & 0 deletions kebab/examples/create-bot/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"outDir": "./build",
"strict": true,
"lib": ["DOM", "ES6"],
"esModuleInterop": true,
"skipLibCheck": true
},
"include": ["src"],
"exclude": ["node_modules"]
}
Loading

0 comments on commit 9488a81

Please sign in to comment.