Skip to content

Commit 3b1d167

Browse files
committed
feat: add action to compute hashes
1 parent ed3bf34 commit 3b1d167

File tree

3 files changed

+268
-0
lines changed

3 files changed

+268
-0
lines changed

.github/workflow/hash-files.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Create Hashes
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
hash-files:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4.2.2
15+
16+
- name: Hash all eligible files
17+
shell: bash
18+
run: |
19+
shopt -s globstar
20+
for file in **/*; do
21+
# Skip directories
22+
[ -d "$file" ] && continue
23+
24+
# Skip unwanted files and folders
25+
[[ "$file" == .git/* || "$file" == .github/* || "$file" == tools/* ]] && continue
26+
[[ "$file" == "LICENSE" || "$file" == "README.md" ]] && continue
27+
[[ "$file" == *.hash ]] && continue
28+
29+
# Compute hash and save next to the file
30+
HASH=$(md5sum "$file" | awk '{ print $1 }')
31+
echo "$HASH" > "$file.hash"
32+
done
33+
34+
- name: Commit hash files
35+
run: |
36+
git config --global user.name "Wasp Bot"
37+
git config --global user.email "waspbot@waspcripts.com"
38+
39+
# Only commit if there are changes
40+
if [[ -n "$(git status --porcelain '*.hash')" ]]; then
41+
git add '*.hash'
42+
CURRENT_DATE=$(date +'%Y.%m.%d')
43+
COMMIT_HASH=$(git rev-parse --short HEAD)
44+
git commit -m "Automatic version bump to $CURRENT_DATE-$COMMIT_HASH"
45+
git push
46+
else
47+
echo "No hash changes to commit."

tools/update_gear.simba

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
{$I WaspLib/osrs.simba}
2+
3+
const
4+
ENDPOINT = 'https://oldschool.runescape.wiki/api.php?';
5+
SILENT: Boolean = False;
6+
TEST_ITEM: String = '';
7+
8+
function GetEndPoint(name: String): String;
9+
begin
10+
Result := ENDPOINT + 'action=parse&page=' +
11+
name.Replace(' ', '_').Replace('+', '%2B') +
12+
'&prop=wikitext&redirects=1&format=json';
13+
end;
14+
15+
type TSlotArray = array [0..12] of TStringArray;
16+
17+
var
18+
Slots: TSlotArray;
19+
20+
function TStringArray.GetStr(): String;
21+
var
22+
i: Integer;
23+
begin
24+
if Self = [] then Exit('[]');
25+
Result := '[';
26+
for i := 0 to High(Self)-1 do
27+
Result += '"' + Self[i] + '", ';
28+
Result += '"' + Self[High(Self)] + '"]';
29+
end;
30+
31+
function TSlotArray.GetStr(): String;
32+
var
33+
i: Integer;
34+
begin
35+
for i := 0 to 10 do
36+
Result += ' "' + ToStr(ERSEquipment(i)).After('ERSEquipment.').ToLower() + '": ' + Self[i].Unique().Sorted().GetStr() + ',' + LINE_SEP;
37+
38+
Result += ' "spec_weapons": ' + Self[11].Unique().Sorted().GetStr() + ',' + LINE_SEP;
39+
Result += ' "2h": ' + Self[12].Unique().Sorted().GetStr();
40+
end;
41+
42+
procedure FillSlot(item, txt: String);
43+
var
44+
str: String;
45+
begin
46+
if not txt.RegExprExists('equipable(?:[0-9])? = Yes') then
47+
Exit;
48+
49+
if txt.Contains('slot = weapon') then
50+
begin
51+
Slots[ERSEquipment.WEAPON] += item;
52+
if txt.Contains('Category:Weapons with Special attacks') then
53+
Slots[11] += item;
54+
Exit;
55+
end;
56+
57+
if txt.Contains('slot = 2h') then
58+
begin
59+
Slots[12] += item;
60+
if txt.Contains('Category:Weapons with Special attacks') then
61+
Slots[11] += item;
62+
Exit;
63+
end;
64+
65+
if txt.Contains('slot = head') then
66+
begin
67+
Slots[ERSEquipment.HEAD] += item;
68+
Exit;
69+
end;
70+
71+
if txt.Contains('slot = cape') then
72+
begin
73+
Slots[ERSEquipment.CAPE] += item;
74+
Exit;
75+
end;
76+
77+
if txt.Contains('slot = neck') then
78+
begin
79+
Slots[ERSEquipment.NECK] += item;
80+
Exit;
81+
end;
82+
83+
if txt.Contains('slot = ammo') then
84+
begin
85+
Slots[ERSEquipment.AMMO] += item;
86+
Exit;
87+
end;
88+
89+
if txt.Contains('slot = body') then
90+
begin
91+
Slots[ERSEquipment.BODY] += item;
92+
Exit;
93+
end;
94+
95+
if txt.Contains('slot = shield') then
96+
begin
97+
Slots[ERSEquipment.SHIELD] += item;
98+
Exit;
99+
end;
100+
101+
if txt.Contains('slot = legs') then
102+
begin
103+
Slots[ERSEquipment.LEGS] += item;
104+
Exit;
105+
end;
106+
107+
if txt.Contains('slot = hands') then
108+
begin
109+
Slots[ERSEquipment.HANDS] += item;
110+
Exit;
111+
end;
112+
113+
if txt.Contains('slot = feet') then
114+
begin
115+
Slots[ERSEquipment.FEET] += item;
116+
Exit;
117+
end;
118+
119+
if txt.Contains('slot = ring') then
120+
Slots[ERSEquipment.RING] += item;
121+
end;
122+
123+
procedure TStringArray.Filter();
124+
var
125+
i: Integer;
126+
tmp: String;
127+
begin
128+
for i := High(Self) downto 0 do
129+
begin
130+
if Self[i].StartsWith('noted ') or Self[i].EndsWith(' 100') or
131+
Self[i].EndsWith(' 75') or Self[i].EndsWith(' 50') or
132+
Self[i].EndsWith(' 25') or Self[i].EndsWith(' 0') then
133+
begin
134+
Delete(Self, i, 1);
135+
Continue;
136+
end;
137+
138+
//get rid of jewellery charges...
139+
if not Self[i].EndsWith(')') then Continue;
140+
141+
tmp := Self[i].Between('(', ')');
142+
if not tmp.IsInteger then Continue;
143+
144+
tmp := Self[i].Replace('(' + tmp + ')', '(' + ToStr(StrToInt(tmp) + 1) + ')');
145+
146+
if Self.Contains(tmp) then
147+
Delete(Self, i, 1);
148+
end;
149+
end;
150+
151+
152+
var
153+
items: TStringArray;
154+
i: Integer;
155+
url: String;
156+
json, tmp: TJSONItem;
157+
text: String;
158+
begin
159+
ClearSimbaOutput();
160+
161+
items := FileReadLines(ItemFinder.Database.DataDir + 'item').Unique();
162+
items.Filter();
163+
164+
for i := 0 to High(items) do
165+
begin
166+
if (TEST_ITEM <> '') and (i > 0) then Break;
167+
if i mod 300 = 0 then
168+
WriteLn('Reading information from the wiki ', i, '/', High(items), ' items done.');
169+
170+
if TEST_ITEM <> '' then
171+
url := GetEndPoint(TEST_ITEM)
172+
else
173+
url := GetEndPoint(items[i]);
174+
175+
if TEST_ITEM <> '' then
176+
WriteLn url;
177+
178+
try
179+
json := HTTPClient.GetJson(url);
180+
except
181+
WriteLn('Failed to fetch: ', items[i]);
182+
end;
183+
184+
if TEST_ITEM <> '' then
185+
WriteLn json.ToJSON();
186+
187+
if json = nil then
188+
begin
189+
WriteLn('Failed to fetch, json is nil: ', items[i]);
190+
Continue;
191+
end;
192+
193+
try
194+
tmp := json.Item['parse'];
195+
except
196+
WriteLn('Failed to find parse: ', items[i]);
197+
json.Free();
198+
Continue;
199+
end;
200+
201+
try
202+
text := tmp.Item['wikitext'].ToJSON();
203+
except
204+
if not SILENT then
205+
WriteLn('Failed to find wikitext: ', items[i]);
206+
json.Free();
207+
Continue;
208+
end;
209+
210+
if TEST_ITEM <> '' then
211+
FillSlot(TEST_ITEM, text)
212+
else
213+
FillSlot(items[i], text);
214+
json.Free();
215+
end;
216+
217+
text := '{' + LINE_SEP + Slots.GetStr() + LINE_SEP + '}';
218+
WriteLn text;
219+
if TEST_ITEM = '' then
220+
FileWrite(GearData.PATH, text);
221+
end;

0 commit comments

Comments
 (0)