Browse Source

Small update.

New blacklist-related features;
+ Added 2 more ways for (un)blacklisting.
~ Altered the function of blacklisting to support multi arguments at once (including ChatLinkAction).
+ Added 3 new sub-commands for blacklist (list/reset/clear).
Corrected some typos.
Added some missing coloring for some texts.
Now supports Pinkie Pie's proxy as well.
Risenio 6 years ago
parent
commit
a82cb388c4
4 changed files with 108 additions and 40 deletions
  1. 29 15
      README.md
  2. 75 21
      index.js
  3. 3 3
      manifest.json
  4. 1 1
      package.json

+ 29 - 15
README.md

@@ -1,29 +1,43 @@
 # Auto-Bank
 # Auto-Bank
   A script that auto merges inventory items to bank if same item exists in bank/special storage/wardrobe/guild bank/etc.'s tab.
   A script that auto merges inventory items to bank if same item exists in bank/special storage/wardrobe/guild bank/etc.'s tab.
 
 
-# Usage
+## Usage
   1. Use command `autobank`/`ab` to toggle banking.
   1. Use command `autobank`/`ab` to toggle banking.
   2. Open bank or click on bank tab to begin.
   2. Open bank or click on bank tab to begin.
   3. That's it. It will automatically check all pages in the bank you've open, and once it ends, it will close the bank for you.
   3. That's it. It will automatically check all pages in the bank you've open, and once it ends, it will close the bank for you.
 
 
 ## Commands
 ## Commands
-  All commands starts with `autobank` or `ab` as alternative.
+  All commands start with `autobank` or `ab` as alternative.
 
 
-  - `autobank` or `ab` to start.
+  - `autobank` or `ab` + open storage space (bank/extra storage or wardrobe, etc) ~ Starts the auto-banking process.
   ---
   ---
-  - `autobank <blacklist/bl>` toggles adding to blacklist.
-    * Open bank, and then try add that item to bank to blacklist. 
-      * Note: Item will not be banked while adding to blacklist.
-  ---
-  - `ab <rmvblacklist/rmbl>` toggles removing from blacklist.
-    * Open bank, and then try add that item to bank to remove it from blacklist.
-      * Note: Item will not be banked while removing from blacklist.
+  - `ab bl <add/rem/reset/clear>` ~ Manages blacklist.
+    * `ab bl <add/+/-/remove>`:
+      - There are 3 different ways to blacklist or unblacklist an item:
+        1. Followed by writing the id of item(s), if more than one, use space as separation between each, e.g.
+          > `ab bl add 1 2 3 4 5`
+          > `ab bl rem 1 2 3 4 5`
+        2. Followed by linked items (ctrl+left click), any amount of items, if more than one, spacing doesn't matter here (you may add space or not).
+          > `ab bl add <item1> <item2> <item3>...`
+          > `ab bl rem <item1> <item2> <item3>...`
+        3. If no arguments, it will enable (un)blacklisting;
+          > `ab bl add` ~ Toggles blacklisting.
+          > `ab bl rem` ~ Toggles unblacklisting.
+            - Open bank, then try add that item to bank to (un)blacklist it. 
+              * Note: Item will not be banked while this enabled.
+    * `ab bl <reset/default>`:
+      - This command resets the blacklist to the [default blacklist](##Blacklist).
+    * `ab bl <clear/empty>`:
+      - This will empty up the entire blacklist, to have 0 blacklisted items.
+    * `ab bl list`:
+      - Lists all the items that are currently blacklisted.
   ---
   ---
   - `autobank <guild/g>` toggles banking to guild bank. **Default Off**. 
   - `autobank <guild/g>` toggles banking to guild bank. **Default Off**. 
 
 
 ## Blacklist
 ## Blacklist
-  If no blacklist.json file was found, it will be using default blacklist.
-    - Editing/modifying the blacklist using blacklisting commands will saved into `blacklist.json` file.
+  If no blacklist.json file is found, it will be using the default blacklist.
+  - Editing/modifying the blacklist using blacklisting commands will be saved into the `blacklist.json` file.
+  - You can get the id of any item from [this site](https://teralore.com/en/).
   <details>
   <details>
     <summary><b>Default blacklist</b></summary>
     <summary><b>Default blacklist</b></summary>
   
   
@@ -67,12 +81,12 @@
   - ID: 206051  - [Popori Figurine](https://teralore.com/en/item/206051)
   - ID: 206051  - [Popori Figurine](https://teralore.com/en/item/206051)
   </details>
   </details>
 
 
-## Capability.
-  * Should work on any proxy. (Currently awaiting update def for Pinkie's).
+## Capability
+  * Should work on any proxy.
   * 1 dependency;
   * 1 dependency;
     - tera-game-state
     - tera-game-state
       - If you're using Caali's proxy(toolbox), you don't have to do anything, as this comes along-with by default.
       - If you're using Caali's proxy(toolbox), you don't have to do anything, as this comes along-with by default.
-      - If you're using Pinkie's proxy, you will have to get it, via [this LINK](https://github.com/tera-mods-forks/tera-game-state) & place it in your mods folder (`proxy dir/mods`).
+      - If you're using Pinkie's proxy, you will have to get it, via [this LINK](https://github.com/tera-mods-forks/tera-game-state) & place it in your mods folder (`[proxy dir]/mods`).
 
 
 
 
 ## Proof of concept
 ## Proof of concept

+ 75 - 21
index.js

@@ -14,12 +14,17 @@ if (fs.existsSync(fn)) fs.watch(fn, event => { if (event === 'change') ReadFile(
 module.exports = function AutoBank(mod) {
 module.exports = function AutoBank(mod) {
 
 
 	const NotCP = typeof mod.compileProto !== 'undefined'
 	const NotCP = typeof mod.compileProto !== 'undefined'
-	if (NotCP) return //Lets see if pinkie will update defs anytime soon.
+	const defs = { cPutWareItem: 3, sViewWareEx: 2 }
 
 
-	// ** Initialize dependency ** \\	
+	if (NotCP) {
+		defs.cPutWareItem = mod.compileProto('uint64 gameId\nint32 container\nint32 offset\nint64 money\nint32 fromPocket\nint32 fromSlot\nint32 id\nuint64 dbid\nint32 amount\nint32 toSlot')
+		defs.sViewWareEx = mod.compileProto('array items\n- array<int32> crystals\n- int32 id\n- uint64 dbid\n- uint64 ownerId\n- int32 container\n- int32 pocket\n- uint32 slot\n- int32 amountTotal\n- int32 amount\n- int32 enchant\n- int32 durability\n- bool soulbound\n- uint32 unk\n- bool masterwork\n- int32 enigma\n- int32 enchantAdvantage\n- int32 enchantBonus\n- int32 enchantBonusMaxPlus\n- bool awakened\n- int32 liberationStatus\nuint64 gameId\nint32 container\nint32 action\nint32 offset\nint32 maxUsedSlot\nint32 numUsedSlots\nint64 money\nint16 numUnlockedSlots')
+	}
+
+	// ** Initialize dependency ** \\
 	mod.game.initialize('inventory')
 	mod.game.initialize('inventory')
 
 
-	// ** Variables ** \\	
+	// ** Variables ** \\
 
 
 	let enabled = false,
 	let enabled = false,
 		GuildBanking = false,
 		GuildBanking = false,
@@ -36,7 +41,7 @@ module.exports = function AutoBank(mod) {
 	function sViewWareEx(event) {
 	function sViewWareEx(event) {
 		if (!enabled) return
 		if (!enabled) return
 		if (lastBankedPageOffset >= event.offset) return false
 		if (lastBankedPageOffset >= event.offset) return false
-		if (!GuildBanking && event.container === 3) return Msg('Banking to guild bank is disabled.')
+		if (!GuildBanking && event.container === 3) return Msg('Banking to guild bank is <font color="#FE6F5E">disabled</font>.')
 		let toBankItems = []
 		let toBankItems = []
 		if (event.items.length > 0 && mod.game.inventory.items.length > 0) {
 		if (event.items.length > 0 && mod.game.inventory.items.length > 0) {
 			lastBankedPageOffset = event.offset
 			lastBankedPageOffset = event.offset
@@ -61,7 +66,7 @@ module.exports = function AutoBank(mod) {
 			toBankItems = toUniqueDbidArr(toBankItems)
 			toBankItems = toUniqueDbidArr(toBankItems)
 			toBankItems = remvBlacklisted(toBankItems)
 			toBankItems = remvBlacklisted(toBankItems)
 			for (const toBank of toBankItems)
 			for (const toBank of toBankItems)
-				mod.toServer('C_PUT_WARE_ITEM', 3, { gameId: mod.game.me.gameId, container: event.container, offset: event.offset, fromPocket: toBank.pocket, fromSlot: toBank.slot, id: toBank.id, dbid: toBank.dbid, amount: toBank.amount, toSlot: event.offset })
+				mod.toServer('C_PUT_WARE_ITEM', defs.cPutWareItem, { gameId: mod.game.me.gameId, container: event.container, offset: event.offset, fromPocket: toBank.pocket, fromSlot: toBank.slot, id: toBank.id, dbid: toBank.dbid, amount: toBank.amount, toSlot: event.offset })
 		}
 		}
 		mod.setTimeout(() => {
 		mod.setTimeout(() => {
 			if (!enabled) return
 			if (!enabled) return
@@ -71,20 +76,11 @@ module.exports = function AutoBank(mod) {
 	}
 	}
 	function cPutWareItem({ id }) {
 	function cPutWareItem({ id }) {
 		if (AddToBl) {
 		if (AddToBl) {
-			if (blacklist.indexOf(id) === -1) {
-				blacklist.push(id)
-				Msg(`The item '${convToCLA(id)}' was <font color="#4DE19C">Added</font> to blacklist.`)
-			}
-			else Msg(`The item '${convToCLA(id)}' is Already blacklisted.`)
+			addToBl(id)
 			return false
 			return false
 		}
 		}
 		if (RmvFromBl) {
 		if (RmvFromBl) {
-			const blItemIndex = blacklist.indexOf(id)
-			if (blItemIndex !== -1) {
-				blacklist.splice(blItemIndex, 1)
-				Msg(`The item '${convToCLA(id)}' was <font color="#FE6F5E">Removed</font> from blacklist.`)
-			}
-			else Msg(`The item '${convToCLA(id)}' is Not blacklisted.`)
+			rmvFromBl(id)
 			return false
 			return false
 		}
 		}
 	}
 	}
@@ -99,8 +95,8 @@ module.exports = function AutoBank(mod) {
 
 
 	// ** Hooks ** \\
 	// ** Hooks ** \\
 
 
-	mod.hook('S_VIEW_WARE_EX', 2, sViewWareEx)
-	mod.hook('C_PUT_WARE_ITEM', 3, cPutWareItem)
+	mod.hook('S_VIEW_WARE_EX', defs.sViewWareEx, sViewWareEx)
+	mod.hook('C_PUT_WARE_ITEM', defs.cPutWareItem, cPutWareItem)
 	mod.hook('S_REQUEST_CONTRACT', 1, sRequestContract)
 	mod.hook('S_REQUEST_CONTRACT', 1, sRequestContract)
 	mod.hook('S_CANCEL_CONTRACT', 1, sCancelContract)
 	mod.hook('S_CANCEL_CONTRACT', 1, sCancelContract)
 	//mod.hook('S_SYSTEM_MESSAGE', 1, sSytemMessage)
 	//mod.hook('S_SYSTEM_MESSAGE', 1, sSytemMessage)
@@ -129,6 +125,12 @@ module.exports = function AutoBank(mod) {
 	function convToCLA(id) {
 	function convToCLA(id) {
 		return `<font color="#7289DA"><ChatLinkAction param="1#####${id}">&lt;ID=${id}&gt;</ChatLinkAction></font>`
 		return `<font color="#7289DA"><ChatLinkAction param="1#####${id}">&lt;ID=${id}&gt;</ChatLinkAction></font>`
 	}
 	}
+	function validIdOrCLA(str) {
+		const [...match] = str.matchAll(/<ChatLinkAction.+?1#####([0-9]+).*?<\/ChatLinkAction>|(^[0-9]+|\s[0-9]+|[0-9]+\s)/gm)
+		let res = []
+		for (const m of match) res.push(Number.parseInt(m[1] || m[2]))
+		return res
+	}
 
 
 	const Msg = msg => mod.command.message(`${NotCP ? '[Auto-Bank]' : ''} ${msg}`),
 	const Msg = msg => mod.command.message(`${NotCP ? '[Auto-Bank]' : ''} ${msg}`),
 		resetValues = () => {
 		resetValues = () => {
@@ -157,11 +159,35 @@ module.exports = function AutoBank(mod) {
 			if (RmvFromBl && AddToBl) toggleAddToBl()
 			if (RmvFromBl && AddToBl) toggleAddToBl()
 			Msg(`Removing from Blacklist <font color="#${RmvFromBl ? `4DE19C">En` : `FE6F5E">Dis`}abled</font>.`)
 			Msg(`Removing from Blacklist <font color="#${RmvFromBl ? `4DE19C">En` : `FE6F5E">Dis`}abled</font>.`)
 			if (!RmvFromBl) saveBlacklistFile()
 			if (!RmvFromBl) saveBlacklistFile()
+		},
+		addToBl = (...ids) => {
+			const str = ids.join(' '), res = validIdOrCLA(str)
+			if (!res.length) return Msg(`The argument(s) <font color="#FE6F5E">doesn't contain</font> valid id/itemLink to be blacklisted.\nGiven: '${str}'`)
+			for (const id of res)
+				if (blacklist.indexOf(id) === -1) {
+					blacklist.push(id)
+					Msg(`The item ${convToCLA(id)} was <font color="#4DE19C">Added</font> to blacklist.`)
+				}
+				else Msg(`The item ${convToCLA(id)} is <font color="#AB58F4">Already</font> blacklisted.`)
+			saveBlacklistFile()
+		},
+		rmvFromBl = (...ids) => {
+			const str = ids.join(' '), res = validIdOrCLA(str)
+			if (!res.length) return Msg(`The argument(s) <font color="#FE6F5E">doesn't contain</font> valid id/itemLink to be unblacklisted.\nGiven: '${str}'`)
+			for (const id of res) {
+				const blItemIndex = blacklist.indexOf(id)
+				if (blItemIndex !== -1) {
+					blacklist.splice(blItemIndex, 1)
+					Msg(`The item ${convToCLA(id)} was <font color="#FE6F5E">Removed</font> from blacklist.`)
+				}
+				else Msg(`The item ${convToCLA(id)} is <font color="#AB58F4">Not</font> blacklisted.`)
+			}
+			saveBlacklistFile()
 		}
 		}
 
 
 	// ** Command ** \\
 	// ** Command ** \\
 
 
-	mod.command.add(['autobank', 'ab'], (key) => {
+	mod.command.add(['autobank', 'ab'], (key, arg, ...args) => {
 		if (key) key = key.toLowerCase()
 		if (key) key = key.toLowerCase()
 		switch (key) {
 		switch (key) {
 			case 'guild': case 'g':
 			case 'guild': case 'g':
@@ -169,10 +195,38 @@ module.exports = function AutoBank(mod) {
 				Msg(`Banking to Guild Bank is <font color="#${GuildBanking ? `4DE19C">En` : `FE6F5E">Dis`}abled</font>.`)
 				Msg(`Banking to Guild Bank is <font color="#${GuildBanking ? `4DE19C">En` : `FE6F5E">Dis`}abled</font>.`)
 				break
 				break
 			case 'blacklist': case 'bl':
 			case 'blacklist': case 'bl':
-				toggleAddToBl()
+				switch (arg) {
+					case 'add': case '+':
+						if (!args.length) toggleAddToBl()
+						else addToBl(...args)
+						break
+					case 'remove': case 'rem': case 'rm': case '-':
+						if (!args.length) toggleRmvFromBl()
+						else rmvFromBl(...args)
+						break
+					case 'reset': case 'default':
+						blacklist = defaultBl
+						saveBlacklistFile()
+						Msg(`Blacklist has been reset to default.`)
+						break
+					case 'clear': case 'empty':
+						blacklist = []
+						saveBlacklistFile()
+						Msg(`Blacklist has been cleared.`)
+						break
+					case 'list':
+						let bll = blacklist.length
+						Msg(`Blacklist has ${bll} items.`)
+						while (bll--)
+							Msg(`\t- ${convToCLA(blacklist[bll])}`)
+						break
+					default:
+						Msg('Invalid blacklist command, please refer to the readme.')
+						break
+				}
 				break
 				break
 			case 'rmblacklist': case 'rmvblacklist': case 'rmbl': case 'rmvbl':
 			case 'rmblacklist': case 'rmvblacklist': case 'rmbl': case 'rmvbl':
-				toggleRmvFromBl()
+				Msg('<font color="#FE6F5E">Deprecated command</font>, please use `<font color="#AB58F4">ab bl rem \<items?...\></font>` instead!')
 				break
 				break
 			default:
 			default:
 				if (!enabled) {
 				if (!enabled) {

+ 3 - 3
manifest.json

@@ -1,9 +1,9 @@
 {
 {
     "files": {
     "files": {
-        "README.md": "ce042f8d3b055081a07dd9fd5f4aaef137c3f097f2cd6a030a4e7f9d950613aa",
-        "index.js": "840c50cfda007f1ad33a1d7302fb363b2715cdd40118d7491151ecb8092b2fb3",
+        "README.md": "a643250975ecea4bca4d776bf268dadda194dcea35b0307524b01a8b504823dc",
+        "index.js": "db6504d31741530407e1c81760c41e3da58edd89a0ccbb8cf02213717ed95d94",
         "module.json": "df54235a322877d003fa9a33d00cc19aaa8fb0808782399179e34d4e191fba8a",
         "module.json": "df54235a322877d003fa9a33d00cc19aaa8fb0808782399179e34d4e191fba8a",
-        "package.json": "e8886ae26005161df8365d0a94b2e76e29ecc04a5d7b7b804b647d21c0ae0300"
+        "package.json": "b9e2b74cb3dfef6d72d3829b2df3ca9d516c84e40daf22c8d141151c33769396"
     },
     },
     "defs": {
     "defs": {
         "C_CANCEL_CONTRACT": 1,
         "C_CANCEL_CONTRACT": 1,

+ 1 - 1
package.json

@@ -5,6 +5,6 @@
 	"description": "A script that auto merges inventory items to bank if same item exists in bank/special storage/wardrobe/etc's tab.",
 	"description": "A script that auto merges inventory items to bank if same item exists in bank/special storage/wardrobe/etc's tab.",
 	"version": "*",
 	"version": "*",
 	"homepage": "https://github.com/Risenio/Auto-Bank/blob/master/README.md",
 	"homepage": "https://github.com/Risenio/Auto-Bank/blob/master/README.md",
-	"keywords": ["tera", "tera-proxy", "tera-online", "fps-utils", "automatic"],
+	"keywords": ["tera", "tera-proxy", "tera-online", "automatic"],
 	"repository": { "type":	"git", "url": "git+https://github.com/Risenio/Auto-Bank.git" }
 	"repository": { "type":	"git", "url": "git+https://github.com/Risenio/Auto-Bank.git" }
 }
 }