Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Nurutomo committed Apr 18, 2023
1 parent 91c2ee9 commit af43635
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 46 deletions.
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
"@adiwajshing/baileys": "github:adiwajshing/baileys",
"@adiwajshing/keyed-db": "^0.2.4",
"@commonify/lowdb": "^3.0.0",
"awesome-phonenumber": "^3.4.0",
"awesome-phonenumber": "^5.4.0",
"chalk": "^4.1.2",
"link-preview-js": "^2.1.13",
"link-preview-js": "^3.0.4",
"mongoose": "^6.3.3",
"node-fetch": "^2.6.7",
"pino": "^7.11.0",
Expand All @@ -44,17 +44,17 @@
"steno": "^2.1.0",
"url-regex": "^5.0.0"
},
"devDependencies": {
"@types/node": "^16.4.2",
"@types/node-fetch": "^2.6.1",
"@types/ws": "^8.5.3",
"typedoc": "^0.22.15",
"typescript": "^4.6.4"
},
"files": [
"database/*",
"lib/*",
"lang/*",
"sessions/*"
]
],
"devDependencies": {
"@types/node": "^18.15.11",
"@types/node-fetch": "^2.6.3",
"@types/ws": "^8.5.4",
"typedoc": "^0.24.4",
"typescript": "^5.0.4"
}
}
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { onCommand, ParsedMessage } from './types'
import Connection from './util/Connection'
import db from './util/Database'
import { readFile } from 'fs/promises'
import Plugins, { PluginClass } from './util/PluginManager'

if (require.main === module) {
Connection.isModule = false
var bot = new Connection
bot.start()
readFile('./config.yml', 'utf-8').then(data => {
bot.developers = data.split('\n')
}).catch(console.error)
}

export default Connection
Expand Down
6 changes: 3 additions & 3 deletions src/listeners/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class Message {
let isBotAdmin = m.isGroup ? participants.find(({ id }) => id.split('@')[0].split(':')[0] == me.split('@')[0].split(':')[0]).admin?.includes('admin') : false

let isOwner = [me, ...conn.owners].map(id => id.split('@')[0].split(':')[0]).findIndex(id => id === m.sender.split('@')[0].split(':')[0]) > -1
let isHost = conn.hosts.map(id => id.split('@')[0].split(':')[0]).findIndex(id => id === m.sender.split('@')[0].split(':')[0]) > -1
let isDeveloper = conn.developers.map(id => id.split('@')[0].split(':')[0]).findIndex(id => id === m.sender.split('@')[0].split(':')[0]) > -1


let [command, ...args] = m.text.trim().split(' ').filter(v => v)
Expand All @@ -54,7 +54,7 @@ export default class Message {
false

if (!isCommand || m.sentSource.endsWith('baileys')) continue
if (!(await conn.permissionHandler(conn, { m, groupMetadata, isAdmin, isBotAdmin, isOwner, isHost }, plugin.permissions, name => m.reply({ text: `_Anda tidak memiliki izin untuk menggunakan fitur_ *${name.join()}*` })))) continue
if (!(await conn.permissionHandler(conn, { m, groupMetadata, isAdmin, isBotAdmin, isOwner, isDeveloper }, plugin.permissions, name => m.reply({ text: `_Anda tidak memiliki izin untuk menggunakan fitur_ *${name.join()}*` })))) continue

await plugin.onCommand({
m,
Expand All @@ -71,7 +71,7 @@ export default class Message {
isAdmin,
isBotAdmin,
isOwner,
isHost
isDeveloper
} as onCommand)
m.isCommand = true
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default class exec extends PluginClass {
constructor () {
super()
this.command = ['>', '=>'] as PluginClass['command']
this.permissions = ['host', 'owner'] as PluginClass['permissions']
this.permissions = ['developer'] as PluginClass['permissions']
}

async onCommand({
Expand Down
16 changes: 7 additions & 9 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { makeInMemoryStore, WAMessage, WAProto, getDevice, downloadMediaMessage, AnyMessageContent, MiscMessageGenerationOptions, GroupMetadata, GroupMetadataParticipants, GroupParticipant, MessageUpsertType } from '@adiwajshing/baileys'
import { makeInMemoryStore, WAMessage, WAProto, getDevice, downloadMediaMessage, AnyMessageContent, MiscMessageGenerationOptions, GroupMetadata, GroupParticipant, MessageUpsertType, WASocket } from '@adiwajshing/baileys'

import makeMDSocket from '@adiwajshing/baileys/lib/Socket'
import Connection from '../util/Connection'

export * from './TypedEventEmitter'
Expand All @@ -18,16 +17,15 @@ export type Tail<T extends any[]> = T extends [infer _I, ...infer L] ? L : never
type BAC<T extends any[]> = [First<Tail<T>>, First<T>, ...Tail<Tail<T>>]

export type MessageTypes = keyof WAProto.IMessage
export type AnyWASocket = ReturnType<typeof makeMDSocket>
export type Permissions = '' | 'host' | 'owner' | 'group' | 'private' | 'admin' | 'bot_admin'
export type Permissions = 'developer' | 'owner' | 'group' | 'private' | 'admin' | 'bot_admin'

export interface onCommand {
export declare interface onCommand {
m?: ParsedMessage
_m?: {
messages: WAMessage[],
type: MessageUpsertType
}
sock?: AnyWASocket
sock?: WASocket
text?: string
args?: string[]
_args?: string[]
Expand All @@ -39,7 +37,7 @@ export interface onCommand {
isAdmin: boolean
isBotAdmin: boolean
isOwner: boolean
isHost: boolean
isDeveloper: boolean
}

export interface ParsedMessage {
Expand Down Expand Up @@ -68,7 +66,7 @@ export interface ParsedQuotedMessage extends Omit<ParsedMessage, 'm' | 'quoted'
fakeObj?: WAMessage
}

export interface ParserOptions {
export declare interface ParserOptions {
loadMessage?: (jid: string, id: string) => Promise<WAProto.IWebMessageInfo> | null
sendMessage?: AnyWASocket['sendMessage']
sendMessage?: WASocket['sendMessage']
}
4 changes: 2 additions & 2 deletions src/util/Connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ export default class Connection {
storePath: PathLike
name: string
storeFolder: PathLike
hosts: string[] = []
developers: string[] = []
owners: string[] = []
print: typeof Print
permissionHandler = PermissionHandler(_jid => '')
permissionHandler = PermissionHandler()

constructor(name: string = 'creds', print = Print) {
this.name = name
Expand Down
11 changes: 5 additions & 6 deletions src/util/Helper.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { AnyMessageContent, Chat, Contact, generateWAMessageFromContent, MessageType, MiscMessageGenerationOptions, normalizeMessageContent, WAProto } from '@adiwajshing/baileys'
import { AnyMessageContent, Chat, Contact, generateWAMessageFromContent, MessageType, MiscMessageGenerationOptions, normalizeMessageContent, WAProto, WASocket } from '@adiwajshing/baileys'
import { parsePhoneNumber } from 'awesome-phonenumber'
import { AnyWASocket } from '../types'
import Connection from './Connection'

interface Helper extends AnyWASocket {
reply: (jid: string, msg: AnyMessageContent, quoted: WAProto.WebMessageInfo, options?: MiscMessageGenerationOptions) => ReturnType<AnyWASocket['sendMessage']>
interface Helper extends WASocket {
reply: (jid: string, msg: AnyMessageContent, quoted: WAProto.WebMessageInfo, options?: MiscMessageGenerationOptions) => ReturnType<WASocket['sendMessage']>
forwardCopy: (jid: string, message: WAProto.IWebMessageInfo, forceForward: Boolean, options: MiscMessageGenerationOptions) => Promise<WAProto.WebMessageInfo>
getName: (jid: string) => string
}

export default function Helper(sock: AnyWASocket, store: Connection['store'], _withoutContact = true): Helper {
export default function Helper(sock: WASocket, store: Connection['store'], _withoutContact = true): Helper {
return {
...sock,
reply(jid: string, msg: AnyMessageContent, quoted: WAProto.WebMessageInfo, options?: MiscMessageGenerationOptions) {
Expand Down Expand Up @@ -68,7 +67,7 @@ export default function Helper(sock: AnyWASocket, store: Connection['store'], _w
} : id === sock.authState.creds.me!.id ?
sock.authState.creds.me :
store.contacts[id] || {}
return (withoutContact && !id.endsWith('@g.us') ? '' : 'name' in v && v.name) || ('vname' in v && v.vname) || ('notify' in v && v.notify) || parsePhoneNumber('+' + id.replace(/(:.+)?@s\.whatsapp\.net/, '')).getNumber('international')
return (withoutContact && !id.endsWith('@g.us') ? '' : 'name' in v && v.name) || ('vname' in v && v.vname) || ('notify' in v && v.notify) || parsePhoneNumber('+' + id.replace(/(:.+)?@s\.whatsapp\.net/, '')).number.international
}
}
}
6 changes: 3 additions & 3 deletions src/util/MessageParser.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { downloadMediaMessage, extractMessageContent, getContentType, getDevice, WAMessage, WAProto, areJidsSameUser, isJidGroup } from '@adiwajshing/baileys'
import { ParsedMessage, ParserOptions, AnyWASocket } from '../types'
import { downloadMediaMessage, extractMessageContent, getContentType, getDevice, WAMessage, WAProto, areJidsSameUser, isJidGroup, WASocket } from '@adiwajshing/baileys'
import { ParsedMessage, ParserOptions } from '../types'
import Connection from './Connection'

function MessageParser(conn: AnyWASocket, m: WAMessage, options: ParserOptions = {}): ParsedMessage {
function MessageParser(conn: WASocket, m: WAMessage, options: ParserOptions = {}): ParsedMessage {
const {
loadMessage,
sendMessage
Expand Down
18 changes: 9 additions & 9 deletions src/util/PermissionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import { ParsedMessage, Permissions } from '../types'
import { PluginClass } from './PluginManager'
import { GroupMetadata } from '@adiwajshing/baileys'

const PermissionHandler = (getUserPermission: (userJid: string) => Permissions) => async (
{ sock, store, hosts, owners }: Connection,
const PermissionHandler = (getUserPermission?: (userJid: string) => Promise<Permissions> | Permissions | void) => async (
{ sock }: Connection,
{
m, groupMetadata, isAdmin, isBotAdmin, isOwner, isHost
m, groupMetadata, isAdmin, isBotAdmin, isOwner, isDeveloper
}: {
m: ParsedMessage,
groupMetadata: GroupMetadata,
isAdmin: boolean,
isBotAdmin: boolean,
isOwner: boolean,
isHost: boolean
isDeveloper: boolean
},
permissions: PluginClass['permissions'],
failCallback: (name: string[]) => any
Expand All @@ -24,10 +24,10 @@ const PermissionHandler = (getUserPermission: (userJid: string) => Permissions)
let isGroup = m.isGroup
let isPrivate = !m.isGroup

let cperm = getUserPermission(m.sender)
let isOther = Perm.includes(cperm)
let cperm = typeof getUserPermission === 'function' ? await getUserPermission(m.sender) : false
let isOther = cperm ? Perm.includes(cperm) : false

// console.log({ isAdmin, isBotAdmin, isGroup, isPrivate, isOwner, isHost, Perm, me })
// console.log({ isAdmin, isBotAdmin, isGroup, isPrivate, isOwner, isDeveloper, Perm, me })
let permFail = []
if (!isGroup && Perm.includes('group')) permFail.push('group')
if (!isPrivate && Perm.includes('private')) permFail.push('private')
Expand All @@ -36,10 +36,10 @@ const PermissionHandler = (getUserPermission: (userJid: string) => Permissions)
if (!isAdmin && Perm.includes('admin')) permFail.push('admin')

if (!isOwner && Perm.includes('owner')) permFail.push('owner')
if (!isHost && Perm.includes('host')) permFail.push('host')
if (!isDeveloper && Perm.includes('developer')) permFail.push('developer')

if (!isOther && cperm && !permFail) permFail.push(cperm)
if (permFail && Perm.length == permFail.length) return (failCallback(permFail), false)
if (permFail.length && Perm.length == permFail.length) return (failCallback(permFail), false)
return true
}
export default PermissionHandler
6 changes: 3 additions & 3 deletions src/util/Print.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { ParsedMessage } from '../types'
let url_regex = urlRegex({ strict: false })
export default async function Print(m: ParsedMessage, { sock, store }: Connection) {
let _name = sock.getName(m.sender)
let sender = formatJidNumber(m.sender) + (_name ? ' ~' + _name : '')
let sender = formatJidNumber(m.sender)
if (_name && _name !== sender) sender += ' ~' + _name
let chat = sock.getName(m.chat)
// let ansi = '\x1b['
let filesize = m.msg && typeof m.msg === 'object' ?
Expand All @@ -19,7 +20,6 @@ export default async function Print(m: ParsedMessage, { sock, store }: Connectio
m.text.length :
0
: m.text ? m.text.length : 0
let user = {}
let me = formatJidNumber(sock.authState.creds.me!.id)
console.log(`
${chalk.redBright('%s')} ${chalk.black(chalk.bgYellow('%s'))} ${chalk.black(chalk.bgGreen('%s'))} ${chalk.magenta('%s [%s %sB]')}
Expand Down Expand Up @@ -85,7 +85,7 @@ ${chalk.green('%s')} ${chalk.yellow('%s%s')} ${chalk.blueBright('to')} ${chalk.g
}

function formatJidNumber(jid: string) {
return parsePhoneNumber('+' + getNumber(jid)).getNumber('international')
return parsePhoneNumber('+' + getNumber(jid)).number.international
}

function getNumber(jid: string) {
Expand Down

0 comments on commit af43635

Please sign in to comment.