Skip to content

Commit

Permalink
add cfpurge command
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam- committed Aug 24, 2023
1 parent 1666104 commit 9c6b0ee
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,33 @@ client.on('messageCreate', async message => {
updateStream(message.member, value)
updateStreams(client.channels)
return message.channel.send(value ? `Successfully added stream \`${value}\`` : 'Successfully removed stream')
} else if (command === 'cfpurge') {
const arg = args.shift()
if (!arg) {
return
}

const zoneid = config.cfpurge.zoneId
const token = config.cfpurge.token
const body = {
files: [arg]
}
const response = await fetch(`https://api.cloudflare.com/client/v4/zones/${zoneid}/purge_cache`, {
method: 'POST',
body: JSON.stringify(body),
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`
}
})
const json = await response.json()
let msg
if (json.success) {
msg = 'Successfully purged ' + arg
} else {
msg = 'Error purging ' + arg + ': ' + JSON.stringify(json)
}
return message.channel.send(msg)
}
}

Expand Down
4 changes: 4 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,9 @@ export default {
autoLogs: {
logScriptUrlWindows: process.env.AUTOLOGS_SCRIPT_URL_WIN || 'https://static.runelite.net/autologs.ps1.txt',
logScriptUrlMacOS: process.env.AUTOLOGS_SCRIPT_URL_MAC || 'https://static.runelite.net/autologs.sh'
},
cfpurge: {
zoneId: 'zoneId', // runelite.net
token: process.env.CLOUDFLARE_TOKEN
}
}

0 comments on commit 9c6b0ee

Please sign in to comment.