Skip to content

Commit

Permalink
v0.3.64: fix some bugs, update MessateBuilder, and create menu.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ZTRdiamond committed May 7, 2024
1 parent 79d84e1 commit 5f45b1a
Show file tree
Hide file tree
Showing 22 changed files with 504 additions and 81 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Amira Bot
Sebuah bot asisten pada platform whatsapp yang digunakan untuk berbagai kebutuhan.
![Amira Bot Base](https://telegra.ph/file/54cbfb6c7f6b2d69f85cd.jpg)

# Amira Bot Base
Amira bot base is a chatbot base that has many features in it to make development easier and faster, Amira bot has a base with clean, neat and structured code. We offer features that can make it easier for developers to create their whatsapp bots easily using a good command handling system as well as other additional handlers such as event handlers, plugins handlers and much more.

[![License: CC BY-NC 4.0](https://img.shields.io/badge/License-CC_BY--NC_4.0-lightgrey.svg?style=for-the-badge)](https://creativecommons.org/licenses/by-nc/4.0/) ![GitHub commit activity (branch)](https://img.shields.io/github/commit-activity/t/zanixongroup/amira-bot-base?logo=github&cacheSeconds=12000&style=for-the-badge) ![GitHub last commit (by committer)](https://img.shields.io/github/last-commit/zanixongroup/amira-bot-base?style=for-the-badge) ![GitHub repo size](https://img.shields.io/github/repo-size/zanixongroup/amira-bot-base?logo=github&style=for-the-badge&link=https%3A%2F%2Fgithub.com%2Fzanixongroup%2Famira-bot-base) ![GitHub package.json version (branch)](https://img.shields.io/github/package-json/v/zanixongroup/amira-bot-base/master?style=for-the-badge&logo=github)
Binary file added assets/amira-md-base.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/amira-md-no-text.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/amira-md.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 64 additions & 1 deletion docs/Commands.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,65 @@
![Amira Bot Base](https://telegra.ph/file/54cbfb6c7f6b2d69f85cd.jpg)

# Command Documentation
This documentation will discuss the options of the command file, how to create commands and how to use commands.

The command structure is a good option for creating or developing a whatsapp bot to prioritize code neatness, the advantage is that it makes maintenance easier when one of the commands is broken, it will be easier to fix because each command will have its own space scope.

## Table of contents

1. [Create a command](#create-a-command)
1. [Command properties](#command-properties)
2. [Command options properties](#command-options-properties)
3. [Command code options properties](#command-code-options-properties)


<br>

## Create a command

Create your command easily with simple documentation and simple command syntax.


### Command properties
| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `tag` | `String` | `true` | Tag option is used for sorting command data for help or menu command. |
| `name` | `String` | `true` | The name option is used to identify commands about what tasks it can perform. |
| `command` | `Array` | `true` | The command option is a trigger function to call the command |
| `options` | `Object` | `false` | Options is used to place some permission options for the command. |
| `disable` | `object` | `false` | The disable option is used to disable the command with two properties: `status: Boolean` and `message: String`. |
| `cooldown` | `Object` | `false` | Used for making cooldown for command with two properties inside: `status: Boolean`, `duration: Integer (ms)`, and `message: String` (with {time} property). |
| `code` | `[Async function]` | `true` | Used for place your code and executing your code. |


### Command options properties
| Name | Type | Description |
| --- | --- | --- |
| `isAdmin` | `Boolean` | Identify the command is for admin group only. |
| `isBotAdmin` | `Boolean` | Check the command if the bot is admin before executing the code. |
| `isPremium` | `Boolean` | Check the user is premium or not before executing the code. |
| `isOwner` | `Boolean` | Identify the command is for owner bot only. |
| `isGroup` | `Boolean` | Identify the command is for group only. |
| `isPrivate` | `Boolean` | Identify the command is for private chat only. |
| `nonPrefix` | `Boolean` | Make the command executed without prefix. |

### Command code options properties
I'll not make the code options properties documentation here, because code options is a changeable properties that will updated in the future, you can check all default code options properties [HERE](https://github.com/ZanixonGroup/amira-bot-base/blob/master/src%2Fevents%2FMessage.js) or you can check localy on `/src/events/Message.js`

### Example command setup
```js
export default [{
tag: "main",
name: "help",
command: ["help"],
limit: {
status: Boolean,
amount: Integer // limit usage do you want for command
},
options: {
// your command options here!
},
code: async({ client, m }) => {
// put your code here.
}
}]
```
51 changes: 48 additions & 3 deletions docs/introduction.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
![Amira Bot Base](https://telegra.ph/file/54cbfb6c7f6b2d69f85cd.jpg)

# Introduction
Hello there, Welcome to the **Amira-MD** bot base documentation. Amira is a simple whatsapp bot with various supporting features that can make it easier for developers to develop better and structured bots.

Creating a whatsapp bot becomes easier with the **Amira-MD** base with its supporting features such as structured commands, plugins support, local database support and various other features.
Creating a whatsapp bot becomes easier with the **Amira Bot** base with its supporting features such as structured commands, plugins support, local database support and various other features.


## Table of contents

1. [Commands](#commands)
2. [Events](#events)
3. [Plugins](#plugins)


## Commands
Make your whatsapp bot command more structured with a good command handler, the command handler feature in this base can recursively read command files in nested folders. Not only how to read recursive command files, but you can also create many commands with just 1 file because we have personalized it so that the handler can read many commands in 1 file with its array system.

#### Example
#### Example: first_command.js
```js
export default [{
name: "your command name",
Expand All @@ -21,4 +30,40 @@ export default [{
```

**Note:**
> Read more command documentation on Commands.md file!
> Read more command documentation on Commands.md file!
## Events
We have also created event handlers to make it easier to create events and also make events more structured and searchable.

Create your event system easily using the syntax below!
#### Example: RejectCall.js
```js
export default {
name: "call", // baileys event name
code: async(json) => {
// your code here...
}
}
```

## Plugins
Plugins is a function system but with automatic handling, with this system you do not need to export or import manually. you only need to call the `plugins.yourFunction()` option property to start using functions from plugins.

You can create your own plugin with the method and syntax as below.
#### Example: say_and_greet.js
```js
export default [{
name: "say", // function name
code: (
query // function parameters
) => {
return "You say: " + query;
}
},{
name: "greet",
code: async(name) => {
if(!name) return `There's no one for me to greet!`;
return `Hello ${name}!`;
}
}]
```
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "amira-bot",
"version": "0.3.25",
"description": "Whatsapp bot assitant",
"name": "amira-bot-base",
"version": "0.3.64",
"description": "Simple whatsapp bot using baileys with a ton of features",
"type": "module",
"main": "bot.js",
"scripts": {
Expand All @@ -12,7 +12,7 @@
"author": "ZanixonGroup",
"license": "ISC",
"dependencies": {
"@whiskeysockets/baileys": "^6.7.0",
"@whiskeysockets/baileys": "^6.7.2",
"axios": "^1.6.8",
"baileys": "^6.7.0",
"cheerio": "^1.0.0-rc.12",
Expand Down
54 changes: 36 additions & 18 deletions src/commands/menu.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,46 @@
import fs from "fs";

export default [{
name: "menu",
command: ["menu"],
code: async({ client, m, remote, dirname, path, MessageBuilder }) => {
code: async({ client, m, remote, sender, Commands, MessageBuilder, prefix, upperFirst }) => {
try {
const __dirname = dirname(import.meta.url);
const media = fs.readFileSync(path.join(__dirname, "ztrdiamond-icon-low.png"));
const mentions = ["[email protected]"];

let listCommand = "";
let commandCategory = {}
Array.from(Commands.values()).map(d => {
commandCategory[d.tag] = Array.from(Commands.values()).filter(cmd => cmd.tag === d.tag);
});
for(let tag in commandCategory) {
if(tag === "hidden") return;
let commands = commandCategory[tag];
if(commands) {
let filteredCommand = commands.filter(d => !d.disable.status).map(cmd => {
let isPremium = cmd.options.isPremium ? "🄿" : "";
return `│・${prefix + cmd.command[0]} ${isPremium}`;
})
let list = filteredCommand.sort();
listCommand += `╭─❨ *${upperFirst(tag)}* ❩\n`;
listCommand += list.join("\n") + "\n";
listCommand += `╰──────────────────・\n\n`;
console.log(listCommand)
}
}
const message = new MessageBuilder()
.setCaption("Testing thumbnail")
.setMentions(mentions)
.setImage(media)
.setMimetype("image/png")
.setThumbnailTitle("Title nya")
.setThumbnailBody("Body nya")
.setText(`Halo @${sender.split("@")[0]}, Amira disini!
${listCommand}`)
.setMentions([sender])
.setThumbnailMediaUrl("https://github.com/ZanixonGroup")
.setThumbnailTitle("Amira Bot Base | WhatsApp Bot")
.setThumbnailBody("Copyright © ZanixonGroup 2024 - All Right Reserved")
.setThumbnailLarge()
.setThumbnailImage("https://telegra.ph/file/d7109be0db36e7cbd56a8.jpg")
.setThumbnailUrl("https://contoh.com")
.setThumbnailImage("https://telegra.ph/file/54cbfb6c7f6b2d69f85cd.jpg")
.setThumbnailUrl("https://github.com/ZanixonGroup")
.setForwardingScore(9999)
.setForwarded(true)
.setNewsletterJid("120363183632297680@newsletter")
.setNewsletterName("Developed by Zanixon Group™")
.setNewsletterServerMessageId(125)
.build()

console.log(message)
client.sendMessage(remote, message);
client.sendMessage(remote, message, { quoted: m });
} catch (e) {
console.log(e)
}
Expand Down
30 changes: 30 additions & 0 deletions src/commands/newsMessage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export default [{
tag: "example",
name: "News Letter Message",
command: ["news","nl","saluran","channel","newsletter"],
code: async({ client, m, quoted, remote, dirname, path, fs, MessageBuilder }) => {
const __dirname = dirname(import.meta.url);
try {
const temp = new MessageBuilder()
.setText("Hello world!")
.setThumbnailMediaUrl("https://github.com/ZanixonGroup")
.setThumbnailTitle("Amira Bot Base | WhatsApp Bot")
.setThumbnailBody("Copyright © ZanixonGroup 2024 - All Right Reserved")
.setThumbnailLarge()
.setThumbnailImage("https://telegra.ph/file/54cbfb6c7f6b2d69f85cd.jpg")
.setThumbnailUrl("https://github.com/ZanixonGroup")
.setForwardingScore(9999)
.setForwarded(true)
.setNewsletterJid("120363183632297680@newsletter")
.setNewsletterName("Zanixon Group™")
.setNewsletterServerMessageId(125)
.build()
let data = await client.generateMessage(remote, temp, m.key);
console.log(JSON.stringify(data, null, 2))
client.relayMessage(remote, data.message, { messageId: data.key.id });
client.relayMessage(remote, data.message, { messageId: data.key.id });
} catch (e) {
throw new Error(e)
}
}
}]
11 changes: 9 additions & 2 deletions src/commands/owner/eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { format } from "util";

export default [{
name: "eval",
command: [">>", ">"],
command: [">>", ">","eval"],
options: {
nonPrefix: true
},
Expand Down Expand Up @@ -50,6 +50,7 @@ export default [{
commandOptions,
isCommand,
plugins,
alertMessage,

// additional properties
Func,
Expand All @@ -58,9 +59,15 @@ export default [{

// additional modules
MessageCollector,
path
MessageBuilder,
path,
fs
}) => {
let __filename = filename(import.meta.url)
let __dirname = dirname(import.meta.url)

let evalCmd
if(!text) return m.reply("Mana kode yang mau di eval?");
try {
evalCmd = /await/i.test(text) ? eval("(async() => { " + text + " })()") : eval(m.text)
} catch (e) {
Expand Down
1 change: 0 additions & 1 deletion src/commands/sticker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export default [{
code: async({ client, m, quoted, mimetype, text }) => {
try {
if(!/image|video|webp/i.test(mimetype)) return m.reply("Balas gambar atau video yang ingin dijadikan sticker");
m.reply("Tunggu sebentar...")
const buffer = await quoted.download();
let exif;
if(text) {
Expand Down
28 changes: 18 additions & 10 deletions src/commands/test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
export default [{
tag: "example",
name: "test",
command: ["test","tes"],
cooldown: {
status: true,
duration: 86400000
},
code: async({ client, m }) => {
try {
m.reply("work coy!")
} catch (e) {
console.log(e)
}
code: async({ client, m, MessageCollector }) => {
m.reply("Balas dengan pesan apapun!");

// init MessageCollector
const col = new MessageCollector(m, {
timeout: 60000
});

// call MessageCollector
col.on("collect", async(data) => {
m.reply(`${JSON.stringify(data, null, 2)}`);
col.exit();
})

col.on("end", () => {
m.reply("Message collector diakhiri!")
})
}
}]
Binary file removed src/commands/ztrdiamond-icon-low.png
Binary file not shown.
12 changes: 6 additions & 6 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ global.exif = {

// alert messages
global.alertMessage = {
owner: "Features can only be accessed owner!",
owner: "Features can only be accessed by owner!",
group: "Features only accessible in group!",
private: "Features only accessible private chat!",
private: "Features only accessible in private chat!",
admin: "Features can only be accessed by group admin!",
botAdmin: "Bot is not admin, can't use the features!",
bot: "Features only accessible by me",
botAdmin: "Bot is not admin, you can't use the features!",
bot: "Features only accessible by bot",
media: "Reply media...",
query: "No Query?",
error: "Seems to have encountered an unexpected error, please repeat your command for a while again",
error: "Seems to have encountered an unexpected error.",
quoted: "Reply message...",
wait: "Wait a minute...",
urlInvalid: "Url Invalid",
urlInvalid: "Url Invalid!",
premium: "Premium Only Features!"
}
Loading

0 comments on commit 5f45b1a

Please sign in to comment.