Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@notenoughupdates/discord.js-minesweeper
Advanced tools
Readme
A Minesweeper generator library for Discord. See it in action here!
First, you need to add the library to your project (duh!):
npm install discord.js-minesweeper
# or
yarn add discord.js-minesweeper
Import it and use it as you wish!
const Minesweeper = require("discord.js-minesweeper");
// ...
const minesweeper = new Minesweeper();
minesweeper.start();
// Returns a Discord-interpretable string with a 9x9 matrix of spoilers and emojis, 10 of which are mines.
const minesweeper = new Minesweeper({
rows: 12,
columns: 16,
mines: 20,
emote: "tada",
returnType: "code"
});
minesweeper.start();
// Returns a Discord-interpretable code block with a 12x16 matrix of spoilers and emojis, 20 of which are mines that will appear as the :tada: emote.
revealFirstCell
is false. Defaults to true.Based on the specified returnType
, the returned data can vary.
'emoji'
- default value, returns a Discord message format with spoilers and emojis'code'
- same as 'emoji', but in a code block (i.e. for copying)'matrix'
- the matrix array itself.If a mine field is not possible with the provided data (i.e. too many mines), it will return null
.
start()
Generates a minesweeper mine field and returns it.
spoilerize(str)
Turns a text into a Discord spoiler.
str
- The string to spoilerize.getNumberOfMines(x, y)
Gets the number of mines in a particular (x, y) coordinate of the matrix.
x
- The x coordinate (row).y
- The y coordinate (column).getTextRepresentation()
Returns the Discord message equivalent of the mine field.
populate()
Populates the matrix with mine counts.
revealFirst()
Reveal a random cell.
Note: the methods generateEmptyMatrix()
and plantMines()
are for internal use and should not be used outside the module. Using any of these could alter the generated matrix in unexpected ways. Don't use them in your app unless you know what you're doing.
const Discord = require("discord.js");
const Minesweeper = require("discord.js-minesweeper");
const bot = new Discord.Client();
bot.on("message", function (message) {
const content = message.content.split(" ");
const args = content.slice(1);
if (content[0] === ".minesweeper") {
const rows = parseInt(args[0]);
const columns = parseInt(args[1]);
const mines = parseInt(args[2]);
if (!rows) {
return message.channel.send(":warning: Please provide the number of rows.");
}
if (!columns) {
return message.channel.send(":warning: Please provide the number of columns.");
}
if (!mines) {
return message.channel.send(":warning: Please provide the number of mines.");
}
const minesweeper = new Minesweeper({ rows, columns, mines });
const matrix = minesweeper.start();
return matrix ? message.channel.send(matrix) : message.channel.send(":warning: You have provided invalid data.");
}
});
bot.login(TOKEN);
const { Command } = require("discord.js-commando");
const Minesweeper = require("discord.js-minesweeper");
class MinesweeperCommand extends Command {
constructor(client) {
super(client, {
// ...
args: [
{
key: "rows",
prompt: "How many rows?",
type: "integer",
min: 4,
max: 20
},
{
key: "columns",
prompt: "How many columns?",
type: "integer",
min: 4,
max: 20
},
{
key: "mines",
prompt: "How many mines?",
type: "integer",
min: 1
}
]
});
}
async run(message, { rows, columns, mines }) {
const minesweeper = new Minesweeper({ rows, columns, mines });
const matrix = minesweeper.start();
return matrix ? message.say(matrix) : message.say(":warning: The provided data is invalid.");
}
}
module.exports = MinesweeperCommand;
Licensed under MIT. Check LICENSE for more information.
FAQs
Generate Minesweeper mine fields using Discord's spoiler tags.
The npm package @notenoughupdates/discord.js-minesweeper receives a total of 0 weekly downloads. As such, @notenoughupdates/discord.js-minesweeper popularity was classified as not popular.
We found that @notenoughupdates/discord.js-minesweeper demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.