Skip to content

Commit 3825f72

Browse files
authored
feat: Allows optional playstyle during creation and updates (#10)
* Allows optional playstyle during creation and updates * Adds on push to github workflow * Updates instructions for testing * Adds config.ini during tests * Updates badge in Readme
1 parent f8babb7 commit 3825f72

File tree

9 files changed

+68
-35
lines changed

9 files changed

+68
-35
lines changed

.github/workflows/general.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: "GSBOT Build and Tests"
3+
4+
on: [push]
5+
6+
jobs:
7+
gsbot:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- uses: actions/cache@v1
12+
with:
13+
path: ~/.cache/pip
14+
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
15+
restore-keys: |
16+
${{ runner.os }}-pip-
17+
- name: Run Tests
18+
run: |
19+
cp config.ini.example config.ini
20+
docker-compose run gsbot sh -c "python -m pytest"

.travis.yml

-26
This file was deleted.

Readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Gear Score Bot for Black Desert Online
2-
[![Travis Build](https://travis-ci.org/pachev/gsbot.svg?branch=master)]()
2+
![GSBOT Build And Tests](https://github.com/pachev/gsbot/workflows/GSBOT%20Tests/badge.svg)
33
[![Discord Server](https://img.shields.io/discord/417173590757212162.svg)](https://discord.gg/STa7Ebz)
44

55
#### [A Discord Bot][2]

cogs/add.py

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ async def add(self,
7373
aap: int,
7474
dp: int,
7575
char_class,
76+
playstyle = None,
7677
user: discord.User = None):
7778
"""Adds your primary character to the guild. This character is linked with your
7879
discord id and can only be updated by either that member or an officer.
@@ -106,6 +107,7 @@ async def add(self,
106107
'ap': ap,
107108
'aap': aap,
108109
'dp': dp,
110+
'playstyle': playstyle.title() if is_playstyle_valid(playstyle) else None,
109111
'gear_score': math.trunc((ap + aap) / 2 + dp),
110112
'renown_score': math.trunc((ap + aap) / 2 + dp),
111113
'primary': is_primary,

cogs/update.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,9 @@ async def update_attribute(self, ctx, attribute, user: discord.User = None):
8181
})
8282
elif attribute['name'] == 'playstyle':
8383
val = attribute['value']
84-
if val.lower() == 'awakening':
84+
if is_playstyle_valid(val):
8585
character.update_attributes({
86-
attribute['name']: 'Awakening',
87-
})
88-
elif val.lower() == 'succession':
89-
character.update_attributes({
90-
attribute['name']: 'Succession',
86+
attribute['name']: val.title(),
9187
})
9288
else:
9389
await ctx.send(codify("Playstyle can only be Awakening or Succession"))
@@ -121,7 +117,15 @@ async def update(self, ctx):
121117
"for more info. ex. gsbot update ap 230 or gsbot update all 61 200 230 250 4.5"))
122118

123119
@update.command(pass_context=True)
124-
async def all(self, ctx, level: int, ap: int, aap: int, dp: int, level_percent: float, user: discord.User = None):
120+
async def all(self,
121+
ctx,
122+
level: int,
123+
ap: int,
124+
aap: int,
125+
dp: int,
126+
level_percent: float = None,
127+
playstyle: str = None,
128+
user: discord.User = None):
125129
"""Updates user's main character's information. **Officers can tag another user to update for them """
126130
date = datetime.now()
127131

@@ -137,14 +141,18 @@ async def all(self, ctx, level: int, ap: int, aap: int, dp: int, level_percent:
137141
historical_data = character.hist_data
138142
historical_data.append(update)
139143

144+
playstyle = playstyle if is_playstyle_valid(playstyle) else character.playstyle
145+
progress = character.progress if level_percent is None else level_percent
146+
140147
character.update_attributes({
141148
'ap': ap,
142149
'aap': aap,
143150
'dp': dp,
144151
'level': level,
145152
'gear_score': math.trunc((ap + aap) / 2 + dp),
146153
'renown_score': math.trunc((ap + aap) / 2 + dp),
147-
'progress': level_percent,
154+
'progress': progress,
155+
'playstyle': playstyle,
148156
'updated': date,
149157
'hist_data': historical_data
150158
})

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ discord.py
44
tabulate
55
aiohttp
66
websockets
7+
pytest

tests/test_utils.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
""" Main test module for all utils. TODO: Add more tests here"""
2+
from utils import is_playstyle_valid
3+
4+
5+
def test_is_playstyle_valid():
6+
""" Checks that the playstyle passed in is valid"""
7+
result = is_playstyle_valid("awakened")
8+
assert result is False
9+
10+
result = is_playstyle_valid("SUCcesSION")
11+
assert result is True
12+
13+
result = is_playstyle_valid("SUCcesSION")
14+
assert result is True
15+
16+
result = is_playstyle_valid("awakenING")
17+
assert result is True
18+
19+
result = is_playstyle_valid("aakenING")
20+
assert result is False
21+
22+
result = is_playstyle_valid(None)
23+
assert result is False

travis-secrets.tar.enc

-6.52 KB
Binary file not shown.

utils.py

+5
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,8 @@ async def send_or_display(server: int, author, ctx, content):
194194
return
195195

196196
await ctx.send(content)
197+
198+
199+
def is_playstyle_valid(playstyle: str) -> bool:
200+
val = playstyle if playstyle is not None else ""
201+
return val.lower() in ["awakening", "succession"]

0 commit comments

Comments
 (0)