generated from array-in-a-matrix/matrix-bot-template
init
This commit is contained in:
parent
84c4962fbb
commit
e918c5fa93
3 changed files with 1258 additions and 9 deletions
44
index.js
44
index.js
|
@ -7,17 +7,43 @@ const client = new MatrixClient(config.homeserver, config.token, storage);
|
|||
AutojoinRoomsMixin.setupOnClient(client);
|
||||
client.start().then(() => console.log(`Client has started!`));
|
||||
|
||||
// ? event listener
|
||||
client.on("room.message", (roomId, event) => {
|
||||
// ? check if the message's text is not empty and isn't sent by the bot itself
|
||||
client.on("room.message", (room, event) => {
|
||||
if (! event["content"] || event["sender"] === config.user) return;
|
||||
// ? if message starts with the bot's <prefix + command> then execute the command
|
||||
if (event["content"]["body"].toLowerCase().startsWith(config.prefix + "COMMAND")){
|
||||
|
||||
//
|
||||
// TODO: START CODE HERE
|
||||
//
|
||||
|
||||
const messageArray = event["content"]["body"].split(" ").map(word => word.toLowerCase());
|
||||
//console.log(messageArray)
|
||||
|
||||
if (messageArray[0].toLowerCase() == config.prefix){
|
||||
switch(messageArray[1]){
|
||||
case 's':
|
||||
case 'pkg':
|
||||
case 'search':
|
||||
search_pkg(room, messageArray[2]);
|
||||
break;
|
||||
case 'aur':
|
||||
break;
|
||||
default:
|
||||
console.warn('no matches');
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
async function search_pkg(room, pkg){
|
||||
|
||||
const response = await fetch("https://archlinux.org/packages/search/json/?q=" + pkg);
|
||||
const dataJSON = await response.json();
|
||||
|
||||
if (!dataJSON.results.length){
|
||||
const message = 'This package does not exist.';
|
||||
console.log(message)
|
||||
client.sendText(room, message);
|
||||
} else {
|
||||
const message =
|
||||
`Package Name: ${dataJSON.results[0].pkgname}
|
||||
Package Repo: ${dataJSON.results[0].repo}
|
||||
Package Architecture: ${dataJSON.results[0].arch};`
|
||||
|
||||
console.log(message)
|
||||
client.sendText(room, message);
|
||||
}
|
||||
}
|
||||
|
|
6
package.json
Normal file
6
package.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"matrix-bot-sdk": "^0.6.6"
|
||||
},
|
||||
"type": "module"
|
||||
}
|
1217
pnpm-lock.yaml
generated
Normal file
1217
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue