mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-08 06:03:04 -04:00
wip
This commit is contained in:
parent
7195d43c74
commit
6173b085a3
26 changed files with 1112 additions and 91 deletions
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
node_modules
|
||||||
|
package-lock.json
|
||||||
|
|
||||||
|
# Local Development Environment Setup
|
||||||
|
.env
|
||||||
|
local.js
|
93
README.md
93
README.md
|
@ -1,92 +1,3 @@
|
||||||
# Labscore V2
|
# labscore-v2
|
||||||
|
|
||||||
new bot new bot new bot
|
v2 of the worlds greatest discord bot (source: me)
|
||||||
|
|
||||||
## Getting started
|
|
||||||
|
|
||||||
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
|
||||||
|
|
||||||
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
|
||||||
|
|
||||||
## Add your files
|
|
||||||
|
|
||||||
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
|
||||||
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
|
|
||||||
|
|
||||||
```
|
|
||||||
cd existing_repo
|
|
||||||
git remote add origin https://gitlab.com/derpystuff/labscore-v2.git
|
|
||||||
git branch -M main
|
|
||||||
git push -uf origin main
|
|
||||||
```
|
|
||||||
|
|
||||||
## Integrate with your tools
|
|
||||||
|
|
||||||
- [ ] [Set up project integrations](https://gitlab.com/derpystuff/labscore-v2/-/settings/integrations)
|
|
||||||
|
|
||||||
## Collaborate with your team
|
|
||||||
|
|
||||||
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
|
||||||
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
|
||||||
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
|
||||||
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
|
||||||
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
|
|
||||||
|
|
||||||
## Test and Deploy
|
|
||||||
|
|
||||||
Use the built-in continuous integration in GitLab.
|
|
||||||
|
|
||||||
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
|
|
||||||
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
|
||||||
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
|
||||||
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
|
||||||
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
|
||||||
|
|
||||||
***
|
|
||||||
|
|
||||||
# Editing this README
|
|
||||||
|
|
||||||
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
|
||||||
|
|
||||||
## Suggestions for a good README
|
|
||||||
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
|
||||||
|
|
||||||
## Name
|
|
||||||
Choose a self-explaining name for your project.
|
|
||||||
|
|
||||||
## Description
|
|
||||||
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
|
||||||
|
|
||||||
## Badges
|
|
||||||
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
|
||||||
|
|
||||||
## Visuals
|
|
||||||
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
|
||||||
|
|
||||||
## Support
|
|
||||||
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
|
||||||
|
|
||||||
## Roadmap
|
|
||||||
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
|
||||||
|
|
||||||
## Contributing
|
|
||||||
State if you are open to contributions and what your requirements are for accepting them.
|
|
||||||
|
|
||||||
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
|
||||||
|
|
||||||
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
|
||||||
|
|
||||||
## Authors and acknowledgment
|
|
||||||
Show your appreciation to those who have contributed to the project.
|
|
||||||
|
|
||||||
## License
|
|
||||||
For open source projects, say how it is licensed.
|
|
||||||
|
|
||||||
## Project status
|
|
||||||
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
|
68
commands/message/core/help.js
Normal file
68
commands/message/core/help.js
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
const { codeblock, highlight, icon } = require('../../../labscore/utils/markdown')
|
||||||
|
const { createEmbed, formatPaginationEmbeds } = require('../../../labscore/utils/embed')
|
||||||
|
|
||||||
|
const { paginator } = require('../../../labscore/client');
|
||||||
|
|
||||||
|
function createHelpPage(context, title, contents){
|
||||||
|
return {
|
||||||
|
"embeds": [
|
||||||
|
createEmbed("default", context, {
|
||||||
|
description: `${title}\n` +
|
||||||
|
codeblock("ansi", contents) +
|
||||||
|
`\n${icon("question")} Use ${highlight(`${context.commandClient.prefixes.custom.first()}help <command>`)} to view more information about a command.`
|
||||||
|
})
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// These categories will be displayed to users, add them in the correct order
|
||||||
|
const categories = {
|
||||||
|
"core": `${icon("house")} Core Commands`,
|
||||||
|
"search": `${icon("search")} Search Commands`,
|
||||||
|
"dev": `${icon("analytics")} Development`
|
||||||
|
}
|
||||||
|
|
||||||
|
const reactions = {
|
||||||
|
previousPage: "⬅️",
|
||||||
|
nextPage: "➡️"
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'help',
|
||||||
|
label: 'command',
|
||||||
|
metadata: {
|
||||||
|
description: 'Command List',
|
||||||
|
examples: ['help ping'],
|
||||||
|
category: 'core',
|
||||||
|
usage: 'help [<command>]'
|
||||||
|
},
|
||||||
|
run: async (context, args) => {
|
||||||
|
context.triggerTyping();
|
||||||
|
if(args.label){
|
||||||
|
// Detailed command view
|
||||||
|
} else {
|
||||||
|
// Full command list
|
||||||
|
let commands = {
|
||||||
|
}
|
||||||
|
let prefix = context.commandClient.prefixes.custom.first()
|
||||||
|
for(const c of context.commandClient.commands){
|
||||||
|
if(!categories[c.metadata.category]) continue;
|
||||||
|
if(!commands[c.metadata.category]) commands[c.metadata.category] = []
|
||||||
|
commands[c.metadata.category].push(`${prefix}${c.name}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
let pages = []
|
||||||
|
for(const cat of Object.keys(categories)){
|
||||||
|
pages.push(createHelpPage(context, categories[cat], commands[cat]))
|
||||||
|
}
|
||||||
|
|
||||||
|
pages = formatPaginationEmbeds(pages)
|
||||||
|
const message = context.message
|
||||||
|
const paging = await paginator.createReactionPaginator({
|
||||||
|
message,
|
||||||
|
pages,
|
||||||
|
reactions
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
25
commands/message/core/ping.js
Normal file
25
commands/message/core/ping.js
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
const { format } = require('../../../labscore/utils/ansi')
|
||||||
|
const { codeblock, icon } = require('../../../labscore/utils/markdown')
|
||||||
|
const { createEmbed } = require('../../../labscore/utils/embed')
|
||||||
|
const { editOrReply } = require('../../../labscore/utils/message')
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
description: 'ping!',
|
||||||
|
name: 'ping',
|
||||||
|
metadata: {
|
||||||
|
description: 'bot latency',
|
||||||
|
examples: ['ping'],
|
||||||
|
category: 'core',
|
||||||
|
usage: 'ping'
|
||||||
|
},
|
||||||
|
run: async (context) => {
|
||||||
|
context.triggerTyping();
|
||||||
|
ping = await context.client.ping()
|
||||||
|
editOrReply(context, {
|
||||||
|
content: "",
|
||||||
|
embeds: [createEmbed("default", context, {
|
||||||
|
description: `${icon("connection")} **Bot Latency**\n` + codeblock("ansi", [`rest ${format(`${ping.rest}ms`, "m")}`, `gateway ${format(`${ping.gateway}ms`, "m")}`])
|
||||||
|
})]
|
||||||
|
})
|
||||||
|
},
|
||||||
|
};
|
37
commands/message/dev/debug/page.js
Normal file
37
commands/message/dev/debug/page.js
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
const { Constants } = require('detritus-client');
|
||||||
|
const { paginator } = require('../../../../labscore/client');
|
||||||
|
|
||||||
|
const reactions = {
|
||||||
|
previousPage: "⬅️",
|
||||||
|
nextPage: "➡️"
|
||||||
|
};
|
||||||
|
|
||||||
|
const createEmbedMessage = (title, description) => ({
|
||||||
|
embeds: [{ title, description }]
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'page',
|
||||||
|
metadata: {
|
||||||
|
description: 'pagination test',
|
||||||
|
examples: ['page'],
|
||||||
|
category: 'dev',
|
||||||
|
usage: 'page'
|
||||||
|
},
|
||||||
|
run: async (context) => {
|
||||||
|
const message = context.message
|
||||||
|
const pages = [
|
||||||
|
createEmbedMessage("Page", "ddd"),
|
||||||
|
createEmbedMessage("Page2", "eee"),
|
||||||
|
createEmbedMessage("Page 3", "h")
|
||||||
|
]
|
||||||
|
const paging = await paginator.createReactionPaginator({
|
||||||
|
// message is the message the user has sent
|
||||||
|
message,
|
||||||
|
// pages is an array of pages (will be passed as parameter in Message#edit)
|
||||||
|
pages,
|
||||||
|
// reactions is an object that includes `previousPage` and `nextPage` emojis (defined above)
|
||||||
|
reactions
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
14
commands/message/dev/debug/test.js
Normal file
14
commands/message/dev/debug/test.js
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'test',
|
||||||
|
metadata: {
|
||||||
|
description: 'test',
|
||||||
|
examples: ['test'],
|
||||||
|
category: 'dev',
|
||||||
|
usage: 'test'
|
||||||
|
},
|
||||||
|
run: async (context) => {
|
||||||
|
return context.editOrReply('test successful.')
|
||||||
|
},
|
||||||
|
};
|
64
commands/message/dev/eval.js
Normal file
64
commands/message/dev/eval.js
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
const { Constants, Utils } = require("detritus-client");
|
||||||
|
const Permissions = Constants.Permissions;
|
||||||
|
|
||||||
|
const AsyncFunction = Object.getPrototypeOf(async function(){}).constructor;
|
||||||
|
|
||||||
|
// TODO: remake this eventually, copy pasted it from v1 cause lazy
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
label: "code",
|
||||||
|
name: "dev",
|
||||||
|
metadata: {
|
||||||
|
description: 'Evaluate code.',
|
||||||
|
examples: ['eval console.log(\'ping\'); -async false'],
|
||||||
|
category: 'dev',
|
||||||
|
usage: 'eval <code> [-async <true|false>] [-noreply <true|false>] [-jsonspacing <integer>]'
|
||||||
|
},
|
||||||
|
args: [
|
||||||
|
{ default: false, name: "noreply", type: "bool" },
|
||||||
|
{ default: 2, name: "jsonspacing", type: "number" },
|
||||||
|
{ default: true, name: "async", type: "bool" }
|
||||||
|
],
|
||||||
|
onBefore: context => context.user.isClientOwner,
|
||||||
|
onCancel: context =>
|
||||||
|
context.reply(
|
||||||
|
`${context.user.mention}, you are lacking the permission \`BOT_OWNER\`.`
|
||||||
|
),
|
||||||
|
run: async (context, args) => {
|
||||||
|
await context.triggerTyping();
|
||||||
|
const { matches } = Utils.regex(
|
||||||
|
Constants.DiscordRegexNames.TEXT_CODEBLOCK,
|
||||||
|
args.code
|
||||||
|
);
|
||||||
|
if (matches.length) {
|
||||||
|
args.code = matches[0].text;
|
||||||
|
}
|
||||||
|
|
||||||
|
let language = "js";
|
||||||
|
let message;
|
||||||
|
try {
|
||||||
|
if(args.async == false){
|
||||||
|
message = await Promise.resolve(eval(args.code));
|
||||||
|
} else {
|
||||||
|
const func = new AsyncFunction('context', args.code);
|
||||||
|
message = await func(context);
|
||||||
|
}
|
||||||
|
if (typeof message === "object") {
|
||||||
|
message = JSON.stringify(message, null, args.jsonspacing);
|
||||||
|
language = "json";
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
message = error ? error.stack || error.message : error;
|
||||||
|
}
|
||||||
|
const max = 1990 - language.length;
|
||||||
|
if (!args.noreply) {
|
||||||
|
const reply = ["```" + language, String(message).slice(0, max), "```"].join("\n")
|
||||||
|
return context.editOrReply(
|
||||||
|
reply
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onError: (context, args, error) => {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
};
|
43
commands/message/dev/reload.js
Normal file
43
commands/message/dev/reload.js
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
const { Constants, Utils } = require("detritus-client");
|
||||||
|
const Permissions = Constants.Permissions;
|
||||||
|
|
||||||
|
// TODO: remake this eventually, copy pasted it from v1 cause lazy
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: "reload",
|
||||||
|
aliases: ["rl"],
|
||||||
|
metadata: {
|
||||||
|
description: 'Reloads commands on all shards.',
|
||||||
|
examples: ['reload'],
|
||||||
|
category: 'dev',
|
||||||
|
usage: 'reload'
|
||||||
|
},
|
||||||
|
onBefore: context => context.user.isClientOwner,
|
||||||
|
onCancel: context =>
|
||||||
|
context.reply(
|
||||||
|
`${context.user.mention}, you are lacking the permission \`BOT_OWNER\`.`
|
||||||
|
),
|
||||||
|
run: async (context, args) => {
|
||||||
|
await context.triggerTyping();
|
||||||
|
const time = Date.now();
|
||||||
|
console.log(`v2 | command refresh requested @ ${Date.now()} by ${context.user.username}${context.user.discriminator} (${context.user.id})`)
|
||||||
|
const data = await context.manager.broadcastEval(async (cluster) => {
|
||||||
|
let shards = 0
|
||||||
|
if (cluster.commandClient) {
|
||||||
|
const commandClient = cluster.commandClient;
|
||||||
|
commandClient.clear();
|
||||||
|
await commandClient.addMultipleIn('../commands/message/', {subdirectories: true});
|
||||||
|
shards = cluster.shards.length
|
||||||
|
}
|
||||||
|
return shards;
|
||||||
|
});
|
||||||
|
let refreshed = data.map((e)=>{return parseInt(e)}).reduce((a, b) => {return a + b}, 0)
|
||||||
|
let diff = Date.now();
|
||||||
|
if (diff < time) diff.setDate(diff.getDate() + 1);
|
||||||
|
diff = diff - time;
|
||||||
|
if(`${refreshed}` == "NaN"){
|
||||||
|
return context.editOrReply(`Failed to reload all commands after \`${diff}ms\`.`)
|
||||||
|
}
|
||||||
|
return context.editOrReply(` Reloaded commands on \`${refreshed}/${context.manager.cluster.shardCount}\` shards in \`${diff}ms\`.`)
|
||||||
|
}
|
||||||
|
};
|
38
commands/message/image/photofunia/yacht.js
Normal file
38
commands/message/image/photofunia/yacht.js
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
const { createEmbed } = require('../../../../labscore/utils/embed')
|
||||||
|
const { editOrReply } = require('../../../../labscore/utils/message')
|
||||||
|
const { STATICS } = require('../../../../labscore/utils/statics')
|
||||||
|
|
||||||
|
const { yacht } = require('../../../../labscore/api')
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'yacht',
|
||||||
|
label: 'text',
|
||||||
|
metadata: {
|
||||||
|
description: 'crazy yacht',
|
||||||
|
examples: ['yacht Im on a boat.'],
|
||||||
|
category: 'image',
|
||||||
|
usage: 'yacht <text>'
|
||||||
|
},
|
||||||
|
run: async (context, args) => {
|
||||||
|
context.triggerTyping();
|
||||||
|
if(!args.text) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (text).`)]})
|
||||||
|
if(args.text.length >= 26) return editOrReply(context, {embeds:[createEmbed("warning", context, `Parameter text too long (>25).`)]})
|
||||||
|
try{
|
||||||
|
let res = await yacht(context, args.text)
|
||||||
|
image = res.response.body.data.images[res.response.body.data.best_quality]
|
||||||
|
return editOrReply(context, {embeds:[createEmbed("default", context, {
|
||||||
|
description: `⛵`,
|
||||||
|
image: {
|
||||||
|
url: image
|
||||||
|
},
|
||||||
|
footer: {
|
||||||
|
iconUrl: STATICS.photofunia,
|
||||||
|
text: `PhotoFunia • ${context.application.name} • Took ${res.timings}s`
|
||||||
|
}
|
||||||
|
})]})
|
||||||
|
}catch(e){
|
||||||
|
console.log(e)
|
||||||
|
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to generate image.`)]})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
67
commands/message/search/bing-images.js
Normal file
67
commands/message/search/bing-images.js
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
const { createEmbed, formatPaginationEmbeds } = require('../../../labscore/utils/embed')
|
||||||
|
const { link } = require('../../../labscore/utils/markdown')
|
||||||
|
const { editOrReply } = require('../../../labscore/utils/message')
|
||||||
|
const { STATICS } = require('../../../labscore/utils/statics')
|
||||||
|
|
||||||
|
const { paginator } = require('../../../labscore/client');
|
||||||
|
const { bingImages } = require('../../../labscore/api');
|
||||||
|
|
||||||
|
function createImageResultPage(context, result){
|
||||||
|
let res = {
|
||||||
|
"embeds": [
|
||||||
|
createEmbed("default", context, {
|
||||||
|
description: `**${link(result.url, result.title)}**`,
|
||||||
|
image: {
|
||||||
|
url: result.image
|
||||||
|
},
|
||||||
|
footer: {
|
||||||
|
iconUrl: STATICS.bing,
|
||||||
|
text: `Microsoft Bing • ${context.application.name}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
]
|
||||||
|
}
|
||||||
|
if(result.thumbnail) res.embeds[0].thumbnail = { url: result.thumbnail };
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
const reactions = {
|
||||||
|
previousPage: "⬅️",
|
||||||
|
nextPage: "➡️"
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'bingimage',
|
||||||
|
label: 'query',
|
||||||
|
aliases: ['bi', 'img2'],
|
||||||
|
metadata: {
|
||||||
|
description: 'bing image search',
|
||||||
|
examples: ['bing Large Magenta Sphere'],
|
||||||
|
category: 'search',
|
||||||
|
usage: 'bing <query>'
|
||||||
|
},
|
||||||
|
run: async (context, args) => {
|
||||||
|
context.triggerTyping();
|
||||||
|
if(!args.query) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (query).`)]})
|
||||||
|
try{
|
||||||
|
let search = await bingImages(context, args.query)
|
||||||
|
search = search.response
|
||||||
|
|
||||||
|
let pages = []
|
||||||
|
for(const res of search.body.results){
|
||||||
|
pages.push(createImageResultPage(context, res))
|
||||||
|
}
|
||||||
|
|
||||||
|
pages = formatPaginationEmbeds(pages)
|
||||||
|
const message = context.message
|
||||||
|
const paging = await paginator.createReactionPaginator({
|
||||||
|
message,
|
||||||
|
pages,
|
||||||
|
reactions
|
||||||
|
});
|
||||||
|
}catch(e){
|
||||||
|
console.log(e)
|
||||||
|
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform google search.`)]})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
63
commands/message/search/bing.js
Normal file
63
commands/message/search/bing.js
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
const { createEmbed, formatPaginationEmbeds } = require('../../../labscore/utils/embed')
|
||||||
|
const { link } = require('../../../labscore/utils/markdown')
|
||||||
|
const { editOrReply } = require('../../../labscore/utils/message')
|
||||||
|
const { STATICS } = require('../../../labscore/utils/statics')
|
||||||
|
|
||||||
|
const { paginator } = require('../../../labscore/client');
|
||||||
|
const { bing } = require('../../../labscore/api');
|
||||||
|
|
||||||
|
function createSearchResultPage(context, result){
|
||||||
|
let res = {
|
||||||
|
"embeds": [
|
||||||
|
createEmbed("default", context, {
|
||||||
|
description: `**${link(result.url, result.title)}**\n${result.snippet}`,
|
||||||
|
footer: {
|
||||||
|
iconUrl: STATICS.bing,
|
||||||
|
text: `Microsoft Bing • ${context.application.name}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
]
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
const reactions = {
|
||||||
|
previousPage: "⬅️",
|
||||||
|
nextPage: "➡️"
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'bing',
|
||||||
|
label: 'query',
|
||||||
|
aliases: ['b', 'search2'],
|
||||||
|
metadata: {
|
||||||
|
description: 'bing search',
|
||||||
|
examples: ['bing Flask'],
|
||||||
|
category: 'search',
|
||||||
|
usage: 'bing <query>'
|
||||||
|
},
|
||||||
|
run: async (context, args) => {
|
||||||
|
context.triggerTyping();
|
||||||
|
if(!args.query) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (query).`)]})
|
||||||
|
try{
|
||||||
|
let search = await bing(context, args.query)
|
||||||
|
search = search.response
|
||||||
|
|
||||||
|
let pages = []
|
||||||
|
for(const res of search.body.results){
|
||||||
|
pages.push(createSearchResultPage(context, res))
|
||||||
|
}
|
||||||
|
|
||||||
|
pages = formatPaginationEmbeds(pages)
|
||||||
|
const message = context.message
|
||||||
|
const paging = await paginator.createReactionPaginator({
|
||||||
|
message,
|
||||||
|
pages,
|
||||||
|
reactions
|
||||||
|
});
|
||||||
|
}catch(e){
|
||||||
|
console.log(e)
|
||||||
|
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform google search.`)]})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
67
commands/message/search/google-images.js
Normal file
67
commands/message/search/google-images.js
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
const { createEmbed, formatPaginationEmbeds } = require('../../../labscore/utils/embed')
|
||||||
|
const { link } = require('../../../labscore/utils/markdown')
|
||||||
|
const { editOrReply } = require('../../../labscore/utils/message')
|
||||||
|
const { STATICS } = require('../../../labscore/utils/statics')
|
||||||
|
|
||||||
|
const { paginator } = require('../../../labscore/client');
|
||||||
|
const { googleImages } = require('../../../labscore/api');
|
||||||
|
|
||||||
|
function createImageResultPage(context, result){
|
||||||
|
let res = {
|
||||||
|
"embeds": [
|
||||||
|
createEmbed("default", context, {
|
||||||
|
description: `**${link(result.url, result.title)}**`,
|
||||||
|
image: {
|
||||||
|
url: result.image
|
||||||
|
},
|
||||||
|
footer: {
|
||||||
|
iconUrl: STATICS.google,
|
||||||
|
text: `Google Images • ${context.application.name}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
]
|
||||||
|
}
|
||||||
|
if(result.thumbnail) res.embeds[0].thumbnail = { url: result.thumbnail };
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
const reactions = {
|
||||||
|
previousPage: "⬅️",
|
||||||
|
nextPage: "➡️"
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'image',
|
||||||
|
label: 'query',
|
||||||
|
aliases: ['i', 'img'],
|
||||||
|
metadata: {
|
||||||
|
description: 'google image search',
|
||||||
|
examples: ['image Large Magenta Sphere'],
|
||||||
|
category: 'search',
|
||||||
|
usage: 'image <query>'
|
||||||
|
},
|
||||||
|
run: async (context, args) => {
|
||||||
|
context.triggerTyping();
|
||||||
|
if(!args.query) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (query).`)]})
|
||||||
|
try{
|
||||||
|
let search = await googleImages(context, args.query)
|
||||||
|
search = search.response
|
||||||
|
|
||||||
|
let pages = []
|
||||||
|
for(const res of search.body.results){
|
||||||
|
pages.push(createImageResultPage(context, res))
|
||||||
|
}
|
||||||
|
|
||||||
|
pages = formatPaginationEmbeds(pages)
|
||||||
|
const message = context.message
|
||||||
|
const paging = await paginator.createReactionPaginator({
|
||||||
|
message,
|
||||||
|
pages,
|
||||||
|
reactions
|
||||||
|
});
|
||||||
|
}catch(e){
|
||||||
|
console.log(e)
|
||||||
|
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform google search.`)]})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
64
commands/message/search/google.js
Normal file
64
commands/message/search/google.js
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
const { createEmbed, formatPaginationEmbeds } = require('../../../labscore/utils/embed')
|
||||||
|
const { link } = require('../../../labscore/utils/markdown')
|
||||||
|
const { editOrReply } = require('../../../labscore/utils/message')
|
||||||
|
const { STATICS } = require('../../../labscore/utils/statics')
|
||||||
|
|
||||||
|
const { paginator } = require('../../../labscore/client');
|
||||||
|
const { google } = require('../../../labscore/api');
|
||||||
|
|
||||||
|
function createSearchResultPage(context, result){
|
||||||
|
let res = {
|
||||||
|
"embeds": [
|
||||||
|
createEmbed("default", context, {
|
||||||
|
description: `**${link(result.url, result.title)}**\n${result.content}`,
|
||||||
|
footer: {
|
||||||
|
iconUrl: STATICS.google,
|
||||||
|
text: `Google • ${context.application.name}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
]
|
||||||
|
}
|
||||||
|
if(result.thumbnail) res.embeds[0].thumbnail = { url: result.thumbnail };
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
const reactions = {
|
||||||
|
previousPage: "⬅️",
|
||||||
|
nextPage: "➡️"
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'google',
|
||||||
|
label: 'query',
|
||||||
|
aliases: ['g', 'search'],
|
||||||
|
metadata: {
|
||||||
|
description: 'google search',
|
||||||
|
examples: ['google Flask'],
|
||||||
|
category: 'search',
|
||||||
|
usage: 'google <query>'
|
||||||
|
},
|
||||||
|
run: async (context, args) => {
|
||||||
|
context.triggerTyping();
|
||||||
|
if(!args.query) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (query).`)]})
|
||||||
|
try{
|
||||||
|
let search = await google(context, args.query)
|
||||||
|
search = search.response
|
||||||
|
|
||||||
|
let pages = []
|
||||||
|
for(const res of search.body.results){
|
||||||
|
pages.push(createSearchResultPage(context, res))
|
||||||
|
}
|
||||||
|
|
||||||
|
pages = formatPaginationEmbeds(pages)
|
||||||
|
const message = context.message
|
||||||
|
const paging = await paginator.createReactionPaginator({
|
||||||
|
message,
|
||||||
|
pages,
|
||||||
|
reactions
|
||||||
|
});
|
||||||
|
}catch(e){
|
||||||
|
console.log(e)
|
||||||
|
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform google search.`)]})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
93
commands/message/search/lyrics.js
Normal file
93
commands/message/search/lyrics.js
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
const { createEmbed, formatPaginationEmbeds } = require('../../../labscore/utils/embed')
|
||||||
|
const { editOrReply } = require('../../../labscore/utils/message')
|
||||||
|
const { STATICS } = require('../../../labscore/utils/statics')
|
||||||
|
|
||||||
|
const { lyrics } = require('../../../labscore/api');
|
||||||
|
const { paginator } = require('../../../labscore/client');
|
||||||
|
|
||||||
|
const reactions = {
|
||||||
|
previousPage: "⬅️",
|
||||||
|
nextPage: "➡️"
|
||||||
|
};
|
||||||
|
|
||||||
|
function createLyricsPage(context, search, fields){
|
||||||
|
let em= createEmbed("default", context, {
|
||||||
|
description: `**${search.body.song.title}**\n*Released ${search.body.song.release}*\n\n`,
|
||||||
|
fields: fields,
|
||||||
|
footer: {
|
||||||
|
iconUrl: STATICS.genius,
|
||||||
|
text: `Genius • ${context.application.name}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if(search.body.song.image) em.thumbnail = { url: search.body.song.image }
|
||||||
|
return em;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'lyrics',
|
||||||
|
label: 'query',
|
||||||
|
metadata: {
|
||||||
|
description: 'Searches for song lyrics on Genius.',
|
||||||
|
examples: ['lyrics desert bloom man'],
|
||||||
|
category: 'search',
|
||||||
|
usage: 'lyrics <query>'
|
||||||
|
},
|
||||||
|
run: async (context, args) => {
|
||||||
|
context.triggerTyping();
|
||||||
|
if(!args.query) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (query).`)]})
|
||||||
|
try{
|
||||||
|
let search = await lyrics(context, args.query)
|
||||||
|
search = search.response
|
||||||
|
|
||||||
|
// Split lyrics into field-sizes chunks
|
||||||
|
let chunks = search.body.lyrics.split(/\[(.*?)\]/) // should give us every chunk
|
||||||
|
let fields = [];
|
||||||
|
let cur = {
|
||||||
|
inline: false
|
||||||
|
};
|
||||||
|
let i = 0;
|
||||||
|
let l = 0;
|
||||||
|
for(const c of chunks){
|
||||||
|
if(c.length == 0) continue;
|
||||||
|
if(i == 0){
|
||||||
|
cur.name = `[${c}]`
|
||||||
|
i += 1
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
cur.value = c.substr(0,1024) + ``
|
||||||
|
i = 0
|
||||||
|
fields.push(cur)
|
||||||
|
cur = {
|
||||||
|
inline: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(fields.length > 3){
|
||||||
|
let pages = []
|
||||||
|
while(fields.length) {
|
||||||
|
pages.push({embeds:[createLyricsPage(context, search, fields.splice(0,3))]})
|
||||||
|
}
|
||||||
|
const message = context.message
|
||||||
|
|
||||||
|
pages = formatPaginationEmbeds(pages)
|
||||||
|
const paging = await paginator.createReactionPaginator({
|
||||||
|
message,
|
||||||
|
pages,
|
||||||
|
reactions
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return editOrReply(context, {embeds: [createLyricsPage(context, search, fields)]})
|
||||||
|
|
||||||
|
}catch(e){
|
||||||
|
if(e.response?.body?.status){
|
||||||
|
if(e.response.body.status == 2){
|
||||||
|
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform lyrics search.`)]})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(e)
|
||||||
|
return editOrReply(context, {embeds:[createEmbed("error", context, `Something went wrong.`)]})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
27
index.js
Normal file
27
index.js
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
const { ClusterManager } = require('detritus-client');
|
||||||
|
const express = require('express');
|
||||||
|
const app = express();
|
||||||
|
const time = Date.now();
|
||||||
|
|
||||||
|
const token = process.env.token;
|
||||||
|
|
||||||
|
let client = `../${__dirname}/labscore/client.js`
|
||||||
|
if(process.env.environment == "local") client = `./labscore/client.js`
|
||||||
|
const manager = new ClusterManager(client, token, {
|
||||||
|
shardCount: 2,
|
||||||
|
shardsPerCluster: 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
const runner = (async () => {
|
||||||
|
console.log(`v2 | starting v2.`)
|
||||||
|
await manager.run();
|
||||||
|
console.log(`v2 | ready. took ${(Date.now() - time) / 1000}.`)
|
||||||
|
})();
|
||||||
|
|
||||||
|
const getter = app.get("*", function (request, response) {
|
||||||
|
response.send(`🧪 v2 @ ${Date.now()}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
var listener = app.listen(process.env.PORT, function () {
|
||||||
|
console.log(`v2 | web server live on port ${listener.address().port}.`);
|
||||||
|
});
|
33
labscore/api/endpoints.js
Normal file
33
labscore/api/endpoints.js
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
const Hosts = Object.freeze({
|
||||||
|
prod: "https://vercel-router-test.vercel.app",
|
||||||
|
local: "http://localhost:3000",
|
||||||
|
emoji: "https://derpystuff.gitlab.io/webstorage3/container/",
|
||||||
|
statics: "https://derpystuff.gitlab.io/webstorage4/v2/"
|
||||||
|
})
|
||||||
|
|
||||||
|
const Api = Object.freeze({
|
||||||
|
HOST: Hosts.prod,
|
||||||
|
|
||||||
|
SEARCH_LYRICS: '/search/lyrics',
|
||||||
|
|
||||||
|
SEARCH_GOOGLE: '/search/google',
|
||||||
|
SEARCH_GOOGLE_IMAGES: '/search/google-images',
|
||||||
|
SEARCH_BING: '/search/bing',
|
||||||
|
SEARCH_BING_IMAGES: '/search/bing-images',
|
||||||
|
|
||||||
|
PHOTOFUNIA_YACHT: '/photofunia/yacht'
|
||||||
|
})
|
||||||
|
|
||||||
|
const Static = Object.freeze({
|
||||||
|
HOST: Hosts.emoji,
|
||||||
|
|
||||||
|
TWITTER: (codepoint) => {
|
||||||
|
return `twemoji-JedKxRr7RNYrgV9Sauy8EGAu/${codepoint}.png`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
Api,
|
||||||
|
Static,
|
||||||
|
Hosts
|
||||||
|
}
|
81
labscore/api/index.js
Normal file
81
labscore/api/index.js
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
const superagent = require('superagent')
|
||||||
|
const { Api, Static, Hosts } = require('./endpoints')
|
||||||
|
|
||||||
|
|
||||||
|
async function request(path, type, headers, args, host) {
|
||||||
|
let timing = Date.now();
|
||||||
|
url = Api.HOST + path
|
||||||
|
if(host) url = host + path
|
||||||
|
|
||||||
|
// apply default headers
|
||||||
|
if(!headers["Authorization"]) headers["Authorization"] = process.env.api_prod
|
||||||
|
if(!headers["user-agent"]) headers["user-agent"] = "labscore/2.0"
|
||||||
|
|
||||||
|
if (type === "GET") {
|
||||||
|
if(!args){
|
||||||
|
const response = await superagent.get(url);
|
||||||
|
return {
|
||||||
|
timings: ((Date.now() - timing) / 1000).toFixed(2),
|
||||||
|
response: response
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const response = await superagent.get(url)
|
||||||
|
.query(args)
|
||||||
|
.set(headers);
|
||||||
|
return {
|
||||||
|
timings: ((Date.now() - timing) / 1000).toFixed(2),
|
||||||
|
response: response
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (type === "POST") {
|
||||||
|
const response = await superagent
|
||||||
|
.post(url)
|
||||||
|
.set(headers)
|
||||||
|
.send(args);
|
||||||
|
return {
|
||||||
|
timings: ((Date.now() - timing) / 1000).toFixed(2),
|
||||||
|
response: response
|
||||||
|
};
|
||||||
|
}
|
||||||
|
throw new Error("unsupported, must either use GET or POST");
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.lyrics = async function(context, query){
|
||||||
|
return await request(Api.SEARCH_LYRICS, "GET", {}, {
|
||||||
|
q: query
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.google = async function(context, query){
|
||||||
|
return await request(Api.SEARCH_GOOGLE, "GET", {}, {
|
||||||
|
q: query
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.googleImages = async function(context, query){
|
||||||
|
return await request(Api.SEARCH_GOOGLE_IMAGES, "GET", {}, {
|
||||||
|
q: query
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.bing = async function(context, query){
|
||||||
|
return await request(Api.SEARCH_BING, "GET", {}, {
|
||||||
|
q: query
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.bingImages = async function(context, query){
|
||||||
|
return await request(Api.SEARCH_BING_IMAGES, "GET", {}, {
|
||||||
|
q: query
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.yacht = async function(context, text){
|
||||||
|
return await request(Api.PHOTOFUNIA_YACHT, "GET", {}, {
|
||||||
|
text: text
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.emojiTwitter = async function(codepoint){
|
||||||
|
return Static.HOST + Static.TWITTER(codepoint)
|
||||||
|
}
|
54
labscore/client.js
Normal file
54
labscore/client.js
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
const { Constants, ClusterClient, CommandClient } = require('detritus-client');
|
||||||
|
const { createPaginator } = require('./paginator')
|
||||||
|
const Paginator = require('detritus-pagination').PaginatorCluster
|
||||||
|
|
||||||
|
// Create client
|
||||||
|
const cluster = new ClusterClient("", {
|
||||||
|
cache: {messages: {expire: 60 * 60 * 1000}},
|
||||||
|
gateway: {
|
||||||
|
identifyProperties: {
|
||||||
|
$browser: 'Discord Android',
|
||||||
|
},
|
||||||
|
presence: {
|
||||||
|
activity: {
|
||||||
|
name: 'v2',
|
||||||
|
type: Constants.ActivityTypes.WATCHING,
|
||||||
|
},
|
||||||
|
status: Constants.PresenceStatuses.ONLINE,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create this clusters paginator
|
||||||
|
const paginator = new Paginator(cluster, {
|
||||||
|
maxTime: 120000,
|
||||||
|
pageLoop: true,
|
||||||
|
pageNumber: true
|
||||||
|
});
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
// Run cluster
|
||||||
|
await cluster.run();
|
||||||
|
const commandClient = new CommandClient(cluster, {
|
||||||
|
activateOnEdits: true,
|
||||||
|
mentionsEnabled: true,
|
||||||
|
prefix: '.',
|
||||||
|
ratelimits: [
|
||||||
|
{duration: 60000, limit: 50, type: 'guild'},
|
||||||
|
{duration: 5000, limit: 5, type: 'channel'},
|
||||||
|
]
|
||||||
|
});
|
||||||
|
await commandClient.addMultipleIn('../commands/message/');
|
||||||
|
await commandClient.run()
|
||||||
|
|
||||||
|
commandClient.on('commandDelete', async ({reply}) => {
|
||||||
|
if (reply){
|
||||||
|
reply.delete();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
})();
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
paginator
|
||||||
|
}
|
67
labscore/constants.js
Normal file
67
labscore/constants.js
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
const COLORS = Object.freeze({
|
||||||
|
"error": 15548997,
|
||||||
|
"success": 6411359,
|
||||||
|
"warning": 16426522,
|
||||||
|
"embed": 3092790,
|
||||||
|
"brand": 6085465
|
||||||
|
})
|
||||||
|
|
||||||
|
const ICONS = Object.freeze({
|
||||||
|
"error": "<:ico_error:925832574239121429>",
|
||||||
|
"warning": "<:ico_warning:925832574931189830>",
|
||||||
|
"success": "<:ico_check:925813919929491516>",
|
||||||
|
"success_simple": "<:lc_success:699608002910617670>",
|
||||||
|
"failiure": "<:ico_cross:925813919577153639>",
|
||||||
|
"failiure_simple": "<:lc_denied:688071041787887647>",
|
||||||
|
"activity": "<:ico_activity:903266937247780906>",
|
||||||
|
"analytics": "<:ico_analytics:914630522326642761>",
|
||||||
|
"audio": "<:ico_audio:903260568037769286>",
|
||||||
|
"boost": "<:ico_boost:903266056154513428>",
|
||||||
|
"calendar": "<:ico_calendar:903263528557887528>",
|
||||||
|
"channel": "<:ico_channel:903265030647210044>",
|
||||||
|
"check": "<:ico_check:925813919929491516>",
|
||||||
|
"command": "<:ico_command:903266599694372875>",
|
||||||
|
"connection": "<:ico_connection:903282945551388702>",
|
||||||
|
"cross": "<:ico_cross:925813919577153639>",
|
||||||
|
"downloading": "<:ico_downloading:903301897027452998>",
|
||||||
|
"emoji": "<:ico_emoji:903265030823374928>",
|
||||||
|
"fun": "<:ico_fun:903260112657981510>",
|
||||||
|
"house": "<:ico_house:903263528591429702>",
|
||||||
|
"image": "<:ico_image:903259583475240961>",
|
||||||
|
"info": "<:ico_info:903258571335147592>",
|
||||||
|
"list": "<:ico_list:903263528662757426>",
|
||||||
|
"list_large": "<:ico_list_large:903265635155443772>",
|
||||||
|
"microphone": "<:ico_microphone:903273971993169920>",
|
||||||
|
"moderation": "<:ico_moderation:903273971523387404>",
|
||||||
|
"nitro": "<:ico_nitro:903263528696283168>",
|
||||||
|
"note": "<:ico_note:914630523828179034>",
|
||||||
|
"nsfw": "<:ico_nsfw:925817891260072026>",
|
||||||
|
"pencil": "<:ico_pencil:903273971636662313>",
|
||||||
|
"people": "<:ico_people:915666775700561990>",
|
||||||
|
"person": "<:ico_person:903275266485420082>",
|
||||||
|
"qr": "<:ico_qr:915278046293000253>",
|
||||||
|
"rocket": "<:ico_rocket:914631573238865980>",
|
||||||
|
"role": "<:ico_role:903273016455209040>",
|
||||||
|
"rules": "<:ico_rules:915269410699243560>",
|
||||||
|
"search": "<:ico_search:903258998432731146>",
|
||||||
|
"snowsgiving": "<:ico_snowsgiving:915666777646694440>",
|
||||||
|
"stats": "<:ico_stats:903265030752047144>",
|
||||||
|
"timer": "<:ico_timer:915271575274680350>",
|
||||||
|
"util": "<:ico_util:903259395381690379>",
|
||||||
|
"locale": "<:ico_locale:925891616986791936>",
|
||||||
|
"question": "<:ico_question:949420315677691934>"
|
||||||
|
})
|
||||||
|
|
||||||
|
const WEB_ASSETS = Object.freeze({
|
||||||
|
"brands": {
|
||||||
|
"genius": "357a0d4aaf1cedfa41dfb38bf3acb961",
|
||||||
|
"labscore": "042e4a437e14580ee2fda8be217991d6"
|
||||||
|
},
|
||||||
|
"weather": "aab92e69374e4c7b8c6741fe02e574b9"
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
COLORS,
|
||||||
|
ICONS,
|
||||||
|
WEB_ASSETS
|
||||||
|
}
|
22
labscore/paginator.js
Normal file
22
labscore/paginator.js
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
const Paginator = require('detritus-pagination').PaginatorCluster
|
||||||
|
|
||||||
|
const paginators = {}
|
||||||
|
|
||||||
|
function createPaginator(client){
|
||||||
|
return new Paginator(client, {
|
||||||
|
// Maximum number of milliseconds for the bot to paginate
|
||||||
|
// It is recommended not to set this too high
|
||||||
|
// Defaults to 300000ms (5 minutes)
|
||||||
|
maxTime: 300000,
|
||||||
|
// Whether it should jump back to page 1 if the user tried to go past the last page
|
||||||
|
// Defaults to false
|
||||||
|
pageLoop: true,
|
||||||
|
// Whether a page number should be shown in embed footers
|
||||||
|
// If a string is passed as page, it will append the page number to the string
|
||||||
|
pageNumber: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
createPaginator
|
||||||
|
}
|
33
labscore/utils/ansi.js
Normal file
33
labscore/utils/ansi.js
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
const ANSI_COLORS = {
|
||||||
|
"reset": "[0m",
|
||||||
|
"black": "[30m",
|
||||||
|
"red": "[31m",
|
||||||
|
"green": "[32m",
|
||||||
|
"yellow": "[33m",
|
||||||
|
"blue": "[34m",
|
||||||
|
"magenta": "[35m",
|
||||||
|
"cyan": "[36m",
|
||||||
|
"white": "[37m"
|
||||||
|
}
|
||||||
|
|
||||||
|
const ALIASES = {
|
||||||
|
"b": "black",
|
||||||
|
"r": "red",
|
||||||
|
"g": "green",
|
||||||
|
"y": "yellow",
|
||||||
|
"bl": "blue",
|
||||||
|
"m": "magenta",
|
||||||
|
"c": "cyan",
|
||||||
|
"w": "white",
|
||||||
|
"rs": "reset"
|
||||||
|
}
|
||||||
|
|
||||||
|
function format(text, color){
|
||||||
|
if(!ANSI_COLORS[color] && !ALIASES[color]) throw "Invalid ANSI Color"
|
||||||
|
if(!ANSI_COLORS[color]) color = ALIASES[color]
|
||||||
|
return `${ANSI_COLORS[color]}${text}${ANSI_COLORS.reset}`
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
format
|
||||||
|
}
|
69
labscore/utils/embed.js
Normal file
69
labscore/utils/embed.js
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
const { COLORS } = require('../constants')
|
||||||
|
|
||||||
|
const embedTypes = Object.freeze({
|
||||||
|
"default": (context) => {
|
||||||
|
return {
|
||||||
|
color: COLORS.embed,
|
||||||
|
footer: {
|
||||||
|
iconUrl: `https://cdn.discordapp.com/avatars/${context.application.id}/${context.application.icon}.png?size=256`,
|
||||||
|
text: context.application.name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"warning": (context) => {
|
||||||
|
return {
|
||||||
|
author: {
|
||||||
|
iconUrl: `https://derpystuff.gitlab.io/webstorage4/v2/assets/icons/ico_warning_small.png`,
|
||||||
|
name: `Warning`
|
||||||
|
},
|
||||||
|
color: COLORS.warning
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"error": (context) => {
|
||||||
|
return {
|
||||||
|
author: {
|
||||||
|
iconUrl: `https://derpystuff.gitlab.io/webstorage4/v2/assets/icons/ico_error_small.png`,
|
||||||
|
name: `Error`
|
||||||
|
},
|
||||||
|
color: COLORS.error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Returns a formatted embed
|
||||||
|
module.exports.createEmbed = function(type, context, content){
|
||||||
|
if(!embedTypes[type]) throw "Invalid Embed Type"
|
||||||
|
if(!content) embedTypes[type](context)
|
||||||
|
let emb = embedTypes[type](context)
|
||||||
|
if(["warning","error"].includes(type)){
|
||||||
|
emb.author.name = content
|
||||||
|
return emb
|
||||||
|
}
|
||||||
|
return Object.assign(emb, content)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adds formatted page numbers to the embed footer
|
||||||
|
module.exports.formatPaginationEmbeds = function(embeds){
|
||||||
|
let i = 0;
|
||||||
|
let l = embeds.length;
|
||||||
|
let formatted = [];
|
||||||
|
for(const e of embeds){
|
||||||
|
i += 1;
|
||||||
|
let ne = e;
|
||||||
|
if(e.embed){
|
||||||
|
ne.embed.footer.text = e.embed.footer.text + ` • Page ${i}/${l}`
|
||||||
|
formatted.push(ne)
|
||||||
|
} else if (e.embeds){
|
||||||
|
let fse = []
|
||||||
|
for(const se of e.embeds){
|
||||||
|
se.footer.text = se.footer.text + ` • Page ${i}/${l}`
|
||||||
|
fse.push(se)
|
||||||
|
}
|
||||||
|
ne.embeds = fse
|
||||||
|
formatted.push(ne)
|
||||||
|
} else {
|
||||||
|
formatted.push(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return formatted;
|
||||||
|
}
|
19
labscore/utils/markdown.js
Normal file
19
labscore/utils/markdown.js
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
const { ICONS } = require('../constants')
|
||||||
|
|
||||||
|
module.exports.icon = function(icon){
|
||||||
|
if(!ICONS[icon]) return ICONS.question
|
||||||
|
return ICONS[icon]
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.highlight = function(content){
|
||||||
|
return "`" + content + "`"
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.codeblock = function(type, content){
|
||||||
|
return "```" + type + "\n" + content.join('\n') + "\n```"
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.link = function(url, masked){
|
||||||
|
if(masked) return `[${masked}](${url})`
|
||||||
|
return url
|
||||||
|
}
|
6
labscore/utils/message.js
Normal file
6
labscore/utils/message.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
module.exports.editOrReply = function(context, message, disableReference = false){
|
||||||
|
// Apply message_reference
|
||||||
|
if(!message.message_reference && !disableReference) message.reference = true
|
||||||
|
if(!message.allowedMentions) message.allowedMentions = {parse: [], repliedUser: false}
|
||||||
|
return context.editOrReply(message)
|
||||||
|
}
|
33
labscore/utils/statics.js
Normal file
33
labscore/utils/statics.js
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
const { Hosts } = require('../api/endpoints')
|
||||||
|
|
||||||
|
const Statics = Object.freeze({
|
||||||
|
brands: {
|
||||||
|
photofunia: {
|
||||||
|
file: "brands/photofunia.png",
|
||||||
|
revision: 1
|
||||||
|
},
|
||||||
|
genius: {
|
||||||
|
file: "brands/genius.png",
|
||||||
|
revision: 0
|
||||||
|
},
|
||||||
|
bing: {
|
||||||
|
file: "brands/bing.png",
|
||||||
|
revision: 0
|
||||||
|
},
|
||||||
|
google: {
|
||||||
|
file: "brands/google.png",
|
||||||
|
revision: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
function staticAsset(static){
|
||||||
|
return Hosts.statics + `assets/` + static.file + "?r=" + static.revision
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.STATICS = Object.freeze({
|
||||||
|
photofunia: staticAsset(Statics.brands.photofunia),
|
||||||
|
genius: staticAsset(Statics.brands.genius),
|
||||||
|
bing: staticAsset(Statics.brands.bing),
|
||||||
|
google: staticAsset(Statics.brands.google)
|
||||||
|
})
|
17
package.json
Normal file
17
package.json
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
{
|
||||||
|
"name": "v2",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"detritus-client": "^0.17.0-beta.12",
|
||||||
|
"detritus-pagination": "^1.4.0",
|
||||||
|
"dotenv": "^16.0.1",
|
||||||
|
"express": "^4.17.1",
|
||||||
|
"superagent": "^7.1.1"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue