Skip to content

Add Discord webhook for test completion #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions OpenBench/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,4 +513,69 @@ def updateTest(request, user):
# Force a refresh of the updated field when finished
if finished: Test.objects.get(id=testid).save()

# Send update to webhook, if it exists
if finished and os.path.exists('webhook'):
with open('webhook') as webhook_file:
webhook = webhook_file.readlines()[0]

lower, elo, upper = OpenBench.stats.ELO(swins, slosses, sdraws)
error = max(upper - elo, elo - lower)
elo = OpenBench.templatetags.mytags.twoDigitPrecision(elo)
error = OpenBench.templatetags.mytags.twoDigitPrecision(error)
h0 = OpenBench.templatetags.mytags.twoDigitPrecision(test.elolower)
h1 = OpenBench.templatetags.mytags.twoDigitPrecision(test.eloupper)
tokens = test.devoptions.split(' ')
threads = tokens[0].split('=')[1]
hash = tokens[1].split('=')[1]
outcome = 'passed' if passed else 'failed'
if test.test_mode == 'GAMES':
mode_string = f'{test.max_games} games'
else:
mode_string = f'SPRT [{h0}, {h1}]'
if passed:
color = 0x37F769
elif swins < slosses:
color = 0xFA4E4E
else:
color = 0xFEFF58

requests.post(webhook, json={
'username': test.engine,
'embeds': [{
'title': f'Test `{test.dev.name}` vs `{test.base.name}` {outcome}',
'url': request.build_absolute_uri(f'/test/{testid}'),
'color': color,
'author': { "name": test.author },
'fields': [
{
'name': 'Configuration',
'value': f'{test.timecontrol}s Threads={threads} Hash={hash}MB',
},
{
'name': 'Mode',
'value': mode_string,
},
{
'name': 'Wins',
'value': f'{swins}',
'inline': True,
},
{
'name': 'Losses',
'value': f'{slosses}',
'inline': True,
},
{
'name': 'Draws',
'value': f'{sdraws}',
'inline': True,
},
{
'name': 'Elo',
'value': f'{elo} ± {error} (95%)',
},
]
}]
})

return ['None', 'Stop'][finished]