From a4eb128fdd09a7d25f68b2b4451942b86c36c77a Mon Sep 17 00:00:00 2001 From: HoraK-FDF Date: Sat, 29 Jan 2022 01:17:27 +0100 Subject: shoplist tools --- config/create_shoplist.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ config/resort_shoplist.sh | 25 +++++++++++++++++++++++++ config/shoplist.txt.nfo | 3 +++ 3 files changed, 70 insertions(+) create mode 100755 config/create_shoplist.sh create mode 100755 config/resort_shoplist.sh create mode 100644 config/shoplist.txt.nfo diff --git a/config/create_shoplist.sh b/config/create_shoplist.sh new file mode 100755 index 0000000..caa934e --- /dev/null +++ b/config/create_shoplist.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +ITEM_DB_DIR="" +SHOP_LIST="shoplist.txt" + +SORT_MODE="2" +# 0 = no sort +# 1 = sort by id +# 2 = sort by item name + +if [ ! -e "$ITEM_DB_DIR" ]; then + echo "warning the directory \""$ITEM_DB_DIR"\" does not exist ..." + echo "... exiting!" + exit 1 +fi + +if [ -e "$SHOP_LIST" ]; then + echo "warning the file "$SHOP_LIST" allready exists ..." + echo "... enter y/Y to overwrite it : " + read KEY + if [ ! $KEY = "y" ] && [ ! $KEY = "Y" ]; then + echo "... exiting!" + exit 0 + fi +fi + +case $SORT_MODE in + 0) + cat "$ITEM_DB_DIR"/item_db* | grep -o -E "^[1-9][0-9]*[,][ ]+[a-zA-Z]*[,]" | sed -r -e 's/[,][ ]*/ /g' -e 's/[ ]*$//g' -e 's/ / 0 0 0 0 /g' > "$SHOP_LIST" + ;; + 1) + cat "$ITEM_DB_DIR"/item_db* | grep -o -E "^[1-9][0-9]*[,][ ]+[a-zA-Z]*[,]" | sed -r -e 's/[,][ ]*/ /g' -e 's/[ ]*$//g' -e 's/ / 0 0 0 0 /g' | sort -t " " -k 1 -g > "$SHOP_LIST" + ;; + 2) + cat "$ITEM_DB_DIR"/item_db* | grep -o -E "^[1-9][0-9]*[,][ ]+[a-zA-Z]*[,]" | sed -r -e 's/[,][ ]*/ /g' -e 's/[ ]*$//g' -e 's/ / 0 0 0 0 /g' | sort -t " " -k 2 > "$SHOP_LIST" + ;; + *) + echo "wrong value for variable SORT_MODE!" + exit 1 +esac + +exit 0 diff --git a/config/resort_shoplist.sh b/config/resort_shoplist.sh new file mode 100755 index 0000000..dbfd90c --- /dev/null +++ b/config/resort_shoplist.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +SHOP_LIST_FILE="shoplist.txt" +TMP_FILE="shoplist_tmp.txt" +# if in item db directory dont use "item_db" at start of filename + +SORT_MODE="0" +# 0 = sort by id +# 1 = sort by item name + +case $SORT_MODE in + 0) + cat "$SHOP_LIST_FILE" | sort -t " " -k 1 -g > "$TMP_FILE" + mv "$TMP_FILE" "$SHOP_LIST_FILE" + ;; + 1) + cat "$SHOP_LIST_FILE" | sort -t " " -k 2 > "$TMP_FILE" + mv "$TMP_FILE" "$SHOP_LIST_FILE" + ;; + *) + echo "wrong value for variable SORT_MODE!" + exit 1 +esac + +exit 0 diff --git a/config/shoplist.txt.nfo b/config/shoplist.txt.nfo new file mode 100644 index 0000000..ff251aa --- /dev/null +++ b/config/shoplist.txt.nfo @@ -0,0 +1,3 @@ +item_id buy_amount buy_price sell_amount sell_price comment/itemname(optional) +buy* = what player can sell to bot +sell* = what bot sells -- cgit v1.2.3-70-g09d2