Skip to content

Commit

Permalink
feat: allow basic overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
osiastedian committed Feb 29, 2024
1 parent 0378151 commit 3e83d4b
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 16 deletions.
9 changes: 9 additions & 0 deletions constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ const prefix = config.prefix;

const fs = require("fs");
const path = require("path");
const defaultMessages = require("./message.json");
let messages = defaultMessages;

if (process.env.MESSAGE_OVERRIDE) {
const overrideMessages = require(process.env.MESSAGE_OVERRIDE);
messages = { ...messages, ...overrideMessages };
}

const defaultHelpPaths = {
main: "./help/main.md",
Expand Down Expand Up @@ -128,4 +135,6 @@ function getHelpCommands(parm) {

module.exports = {
help: getHelpCommands,
messages,
applyContext,
};
5 changes: 5 additions & 0 deletions message-aida.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"register.error.registered": "You already registered for Rollux on your {botname} profile.",
"register.success": "You have successfully registered for Rollux on your {botname} profile.",
"send.error.noWallet": "You don't have a Rollux wallet yet. Use `!register` to create one."
}
5 changes: 5 additions & 0 deletions message.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"register.error.registered": "You already registered for NEVM and Rollux on your {botname} profile.",
"register.success": "You have successfully registered for NEVM on your {botname} profile.",
"send.error.noWallet": "You don't have a nevm wallet yet. Use `!register nevm` to create one."
}
2 changes: 1 addition & 1 deletion nevm/balance.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async function balance(client, message, args) {
});
}

const networkName = args[0].toLowerCase();
const networkName = (args[0] ?? process.env.DEFAULT_EVM_NETWORK).toLowerCase();
const networkConfig = config[networkName.toLowerCase()];

const jsonProvider = new ethers.providers.JsonRpcProvider(
Expand Down
12 changes: 7 additions & 5 deletions nevm/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const config = require("../config.json");
const utils = require("../utils");
const HDWallet = require("ethereum-hdwallet");

const { messages, applyContext } = require("../constants");

const tipbotWallet = HDWallet.fromMnemonic(config.ethMnemonic).derive(
HDWallet.DefaultHDPath
);
Expand Down Expand Up @@ -33,10 +35,10 @@ async function registerNevm(client, message, args) {
.send({
embed: {
color: constants.FAIL_COL,
description:
"You already registered for NEVM and Rollux on your " +
config.botname +
" profile.",
description: applyContext(
messages["register.error.registered"],
config
),
},
})
.then((msg) => {
Expand All @@ -56,7 +58,7 @@ async function registerNevm(client, message, args) {
user.send({
embed: {
color: constants.SUCCESS_COL,
description: `You have successfully registered for NEVM on your ${config.botname} profile.\n`,
description: applyContext(messages["register.success"], config),
},
});
}
Expand Down
7 changes: 6 additions & 1 deletion nevm/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ async function send(client, message, args, senderProfile, receiverProfile) {
return sendUsageExample(message);
}

const [argUser, argValue, argNetwork, argSymbol] = args;
const [
argUser,
argValue,
argNetwork = process.env.DEFAULT_EVM_NETWORK,
argSymbol = "SYS",
] = args;

const senderWallet = await db.nevm.getNevmWallet(senderProfile.userID);
const receiverWallet = await db.nevm.getNevmWallet(receiverProfile.userID);
Expand Down
7 changes: 6 additions & 1 deletion nevm/withdraw.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,12 @@ async function withdraw(client, message, args) {
if (args.length < 2) {
return sendUsageExample(message);
}
const [address, amount, networkName, tokenSymbol] = args;
const [
address,
amount,
networkName = process.env.DEFAULT_EVM_NETWORK,
tokenSymbol = "SYS",
] = args;
const isWithdrawAll = amount === "all";

if (!etherUtils.isAddress(address)) {
Expand Down
25 changes: 17 additions & 8 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,9 @@ client.on("message", async (message) => {
case "deposit":
try {
if (
args.length > 0 &&
config.evmNetworks.includes(args[0].toLowerCase())
(args.length > 0 &&
config.evmNetworks.includes(args[0].toLowerCase())) ||
config.evmOnly
) {
return nevm.deposit(message);
}
Expand Down Expand Up @@ -375,8 +376,9 @@ client.on("message", async (message) => {
) {
console.log("withdawal args", args);
if (
args.length >= 3 &&
config.evmNetworks.includes(args[2].toLocaleLowerCase())
(args.length >= 3 &&
config.evmNetworks.includes(args[2].toLocaleLowerCase())) ||
config.evmOnly
) {
return nevm.withdraw(client, message, args);
}
Expand All @@ -398,8 +400,9 @@ client.on("message", async (message) => {
message.channel.type == "dm"
) {
if (
args.length > 0 &&
config.evmNetworks.includes(args[0].toLowerCase())
(args.length > 0 &&
config.evmNetworks.includes(args[0].toLowerCase())) ||
config.evmOnly
) {
return nevm.balance(client, message, args);
}
Expand Down Expand Up @@ -1218,7 +1221,10 @@ client.on("message", async (message) => {
return;
}

if (config.evmNetworks.includes(args[2].toLocaleLowerCase())) {
if (
config.evmNetworks.includes(args[2].toLocaleLowerCase()) ||
config.evmOnly
) {
return await nevm.send(
client,
message,
Expand Down Expand Up @@ -1252,7 +1258,10 @@ client.on("message", async (message) => {
message.channel.id == config.giveawayChannel ||
message.channel.type === "dm"
) {
if (args.length > 0 && args[0].toLowerCase() === "nevm") {
if (
(args.length > 0 && args[0].toLowerCase() === "nevm") ||
config.evmOnly
) {
return nevm.register(client, message, args);
}

Expand Down

0 comments on commit 3e83d4b

Please sign in to comment.