diff --git a/lib/app.js b/lib/app.js index 6432fab5c..0778c8b4e 100644 --- a/lib/app.js +++ b/lib/app.js @@ -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) } } diff --git a/lib/config.js b/lib/config.js index 3b5f91c15..34a0847e0 100644 --- a/lib/config.js +++ b/lib/config.js @@ -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 } }