Skip to content

Commit

Permalink
maintenance + other goodies
Browse files Browse the repository at this point in the history
- added new commands: system, debug
  - system: displays information about your os.
  - debug: displays information about outside dependencies.
- removed old commands
  - finance: its been gone, but now bear no longer requires the yahoo-finance package
  - shibe: the site is dead (azrogers/ShibeOnline#3). D:
- moved some commands around, added some small features
- handle outside dependency requirements """better\"""
  - there is now a function that checks for them; they're handled in a more unified way now.
  - in the future, there should be a property of the command block that defines and handles these.
- update package.json to use a specific version of whatwg-url that doesn't directly require punycode (gets around DEP0040). this is a jump from v5 to v14, but there have been no issues in testing, so hopefully things continue to just work...
  • Loading branch information
mechabubba committed Sep 21, 2024
1 parent 3b9cc78 commit 2f2c2ab
Show file tree
Hide file tree
Showing 19 changed files with 542 additions and 781 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ bear is a modified fork of [sandplate](https://github.com/06000208/sandplate) 0.
3. Install a bunch of shit;
```sh
# for debian/raspbian users;
$ sudo apt-get install fortune-mod cowsay latex
$ sudo apt-get install fortune-mod cowsay texlive

# you don't have to install these all at once! you can run the `debug` bot command to see what your setup supports and doesn't support. :)
```
4. Compile [`mathtex`](https://github.com/mechabubba/mathtex) (name the binary `mathtex`) and throw that in the bin folder.

Expand Down
22 changes: 0 additions & 22 deletions bot/commands/2b2t.js

This file was deleted.

11 changes: 0 additions & 11 deletions bot/commands/8ball.js

This file was deleted.

3 changes: 1 addition & 2 deletions bot/commands/about.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const CommandBlock = require("../../modules/CommandBlock");
const { randomColor, gitinfo, humanizeDuration } = require("../../modules/miscellaneous");
const package = require("../../package.json");
const { MessageEmbed, Permissions } = require("discord.js");
const djsver = require("discord.js").version;
const { MessageEmbed, Permissions, version } = require("discord.js");
const { DateTime } = require("luxon");

// The permissions to give to the invite.
Expand Down
53 changes: 53 additions & 0 deletions bot/commands/animals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const CommandBlock = require("../../modules/CommandBlock");
const fetch = require("node-fetch");
const { weightedRandom } = require("../../modules/miscellaneous");
const { MessageEmbed } = require("discord.js");

/**
* Polar bear weights. The keys correspond to the images in `assets/bears/`. Higher numbers correspond to more common bears.
* @todo I would like to credit whoever made these edits but I'm genuinely uncertain who did. I will look into it.
*/
const bears = {
"bear.gif": 1000,
"speedy.gif": 50,
"child.gif": 10,
"gay.gif": 10,
"corrupted.gif": 10,
"sugoi.gif": 1,
};

module.exports = [
new CommandBlock({
names: ["bear"],
description: "<a:_:588518103814504490>\n\n**Tip:** Try your luck to get a rare bear.",
clientChannelPermissions: ["ATTACH_FILES"],
}, function(client, message, content, args) {
if(!client.storage.has("local.bear")) {
client.storage.set("local.bear", { points: 0 });
}
let bearpoints = client.storage.get("local.bear.points");
bearpoints++;

const img = weightedRandom(Object.keys(bears), bears);
const embed = new MessageEmbed()
.setColor("#FEFEFE")
.setTitle("he's here...")
.setImage(`attachment://${img}`)
.setFooter({ text: `\uD83D\uDC3B ${bearpoints}` });
message.reply({ embeds: [embed], files: [`assets/bears/${img}`], allowedMentions: { repliedUser: false } });

client.storage.set("local.bear.points", bearpoints);
}),
new CommandBlock({
names: ["httpcat", "cattp", "http"],
description: "Gets an HTTP cat code. Images fetched from [http.cat](https://http.cat).",
usage: "(code)",
clientChannelPermissions: ["ATTACH_FILES"],
}, async function(client, message, content, [code]) {
try {
await message.reply({ files: [`https://http.cat/${code}.jpg`], allowedMentions: { repliedUser: false } });
} catch(e) { // just in case ;)
message.reply({ files: [{ attachment: "../../assets/service_unavailable.jpg", name: "service_unavailable.jpg" }], allowedMentions: { repliedUser: false } });
}
}),
];
38 changes: 0 additions & 38 deletions bot/commands/bear.js

This file was deleted.

92 changes: 92 additions & 0 deletions bot/commands/fun.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
const CommandBlock = require("../../modules/CommandBlock");
const { sleep } = require("../../modules/miscellaneous");
const fetch = require("node-fetch");

const ball_responses = ["As I see it, yes.", "Ask again later.", "Better not tell you now.", "Cannot predict now.", "Concentrate and ask again.", "Don't count on it.", "It is certain.", "It is decidedly so.", "Most likely.", "My reply is no.", "My sources say no.", "Outlook not so good.", "Outlook good.", "Reply hazy, try again.", "Signs point to yes.", "Very doubtful.", "Without a doubt.", "Yes.", "Yes - definitely.", "You may rely on it."];
const cooltext_font_endpoints = require("../../data/cooltext_font_endpoints.json"); /** A list of fonts and font endpoints from cooltext.com. */
const cooltext_settings = {
charlimit: 256, /** (Very arbitrary) character limit for each image. */
cooldown: 500, /** Cooldown in ms. */
};

module.exports = [
new CommandBlock({
names: ["2b2t"],
summary: "Gets the current queue length of 2b2t.",
description: "Gets the current queue length of 2b2t. Data fetched from [2b2t.io](https://2b2t.io/).",
}, async function(client, message, content, args) {
try {
const resp = await fetch("https://2b2t.io/api/queue?last=true");
if(!resp.ok) throw new Error(resp.statusText);

const json = await resp.json();
if(!json || !json[0] || !json[0][1]) throw new Error("Recieved malformed json.");

return message.reply({ content: `The 2b2t.org queue is **${json[0][1]}** users long.`, allowedMentions: { repliedUser: false } });
} catch(e) {
return message.reply({ content: `${client.reactions.negative.emote} An error occured;\`\`\`\n${e.message}\`\`\`` });
}
}),
new CommandBlock({
names: ["8ball", "8"],
description: "Shakes a magic 8 ball.",
usage: "[query]",
}, async function(client, message, content, args) {
if(!content) return message.reply(`${client.reactions.negative.emote} You need to ask it something!`);
return message.reply({ content: `\uD83C\uDFB1 ${ball_responses[Math.floor(Math.random() * ball_responses.length)]}`, allowedMentions: { repliedUser: false } }); // if you're reading this, im sorry for ruining the magic
}),
new CommandBlock({
names: ["cooltext"],
description: `Creates cool text. Images are generated from https://cooltext.com.\n\nSupported fonts;\`\`\`${Object.keys(cooltext_font_endpoints).join(", ")}\`\`\`\nNote there is a character limit of ${cooltext_settings.charlimit} per image.`,
usage: "[font] [...text]",
clientChannelPermissions: ["ATTACH_FILES"],
}, async function(client, message, content, [font, ...args]) {
if(!content) return message.reply(`${client.reactions.negative.emote} You must input a piece of text to render!`);

const text = args.join(" ");
if(text.length > cooltext_settings.charlimit) return message.reply(`${client.reactions.negative.emote} There is a character limit of ${cooltext_settings.charlimit} per image.`);

const _now = Date.now();
client.cookies["cooltext_cooldown"] = client.cookies["cooltext_cooldown"] ?? _now;
if(client.cookies["cooltext_cooldown"] > _now) {
await sleep(client.cookies["cooltext_cooldown"] - _now);
}
client.cookies["cooltext_cooldown"] = Date.now() + cooltext_settings.cooldown;

if(!(font in cooltext_font_endpoints)) return message.reply(`${client.reactions.negative.emote} The provided font does not exist.`);

const serialized_text = encodeURIComponent(text).replace(/%20/g, "+");
const data = cooltext_font_endpoints[font] + `&Text=${serialized_text}`;

// This API isn't public, so this will probably break eventually.
try {
const resp = await fetch("https://cooltext.com/PostChange", {
method: "post",
body: data,
headers: {
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"Content-Length": data.length,
},
});

if(!resp.ok) {
throw new Error(resp.statusText);
}

const json = await resp.json();
if(!json || !json.renderLocation) throw new Error("Recieved malformed json.");

return message.reply({ files: [json.renderLocation.replace("https", "http")], allowedMentions: { repliedUser: false } }); // They dont encrypt things correctly on their end, requiring us to use HTTP.
} catch(e) {
return message.reply(`${client.reactions.negative.emote} An error occured;\`\`\`\n${e.message}\`\`\``);
}
}),
new CommandBlock({
names: ["burning"],
description: "Makes really awesome burning text, generated from https://cooltext.com. \n\nThis command is an alias of `cooltext burning`.",
usage: "[text]",
clientChannelPermissions: ["ATTACH_FILES"]
}, async function(client, message, content, args) {
return client.commands.runByName("cooltext", message, "burning", ["burning", ...args]);
})
];
Loading

0 comments on commit 2f2c2ab

Please sign in to comment.