This repository has been archived by the owner on Feb 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
class embed { | ||
constructor() { | ||
this.permissions = []; | ||
this.command = "embed"; | ||
this.description = "Creates and sends an embed based on parameters"; | ||
this.usage = "embed description=\"desc\" color=0x0061ff footer.text=\"Footer\" field.name1=\"value1\""; | ||
} | ||
|
||
execute(message, args) { | ||
// Remove content | ||
delete message["content"]; | ||
|
||
// Create default embed | ||
let embed = { | ||
title: "BotNeck Embed", | ||
type: "rich", | ||
description: "This message is from the BotNeck Bot!", | ||
color: 0x0061ff, | ||
url: "https://github.com/AtiLion/BotNeck-Bot", | ||
timestamp: "now", | ||
footer: { | ||
text: "Powered by BotNeck Bot", | ||
icon_url: "", | ||
}, | ||
author: { | ||
name: "AtiLion", | ||
url: "https://github.com/AtiLion", | ||
icon_url: "https://avatars3.githubusercontent.com/u/20825809?s=460&v=4", | ||
}, | ||
fields: [] | ||
} | ||
|
||
|
||
// Parse the args | ||
for(let key in args) { | ||
// Only look for keys | ||
if(!isNaN(key)) continue; | ||
|
||
// Split key | ||
let keySteps = key.split("."); | ||
|
||
// Blacklist | ||
if(keySteps[0] === "fields") continue; | ||
if(keySteps[0] === "type") continue; | ||
|
||
// Check for fields | ||
if(keySteps[0] !== "field") { | ||
// Build key step object | ||
let lastObj = embed; | ||
for(let i = 0; i < keySteps.length; i++) { | ||
// Get step | ||
let keyStep = keySteps[i]; | ||
|
||
// Last key step | ||
if(i + 1 >= keySteps.length) { | ||
if(args[key]) | ||
lastObj[keyStep] = args[key]; | ||
else | ||
delete lastObj[keyStep]; | ||
break; | ||
} | ||
|
||
// Move into | ||
let targetObj = lastObj[keyStep]; | ||
if(!targetObj) lastObj[keyStep] = targetObj = {}; | ||
lastObj = targetObj; | ||
} | ||
} else { | ||
let field = { | ||
name: keySteps[1], | ||
value: args[key], | ||
inline: true | ||
} | ||
|
||
embed.fields.push(field); | ||
} | ||
} | ||
|
||
// Fix timestamp | ||
if(embed.timestamp) { | ||
if(embed.timestamp == "now") | ||
embed.timestamp = new Date().toISOString(); | ||
else if(embed.timestamp != "") | ||
embed.timestamp = new Date(embed.timestamp).toISOString(); | ||
} | ||
|
||
// Print out | ||
message["embed"] = embed; | ||
} | ||
} |