-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
202 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// import < | ||
const cron = require('node-cron'); | ||
const { | ||
|
||
Client, | ||
IntentsBitField | ||
|
||
} = require('discord.js'); | ||
|
||
// > | ||
|
||
|
||
class client { | ||
|
||
constructor({ | ||
|
||
pToken, | ||
pDatabase | ||
|
||
}) { | ||
|
||
// setup < | ||
// initialize < | ||
this.token = pToken; | ||
this.database = pDatabase; | ||
this.users = process.env.users; | ||
this.channelId = process.env.channelId; | ||
|
||
this.client = new Client({ | ||
|
||
rest : {version : '10'}, | ||
intents : [ | ||
|
||
IntentsBitField.Flags.Guilds, | ||
IntentsBitField.Flags.GuildMembers, | ||
IntentsBitField.Flags.GuildMessages, | ||
IntentsBitField.Flags.MessageContent | ||
|
||
] | ||
|
||
}); | ||
|
||
// > | ||
|
||
} | ||
|
||
|
||
async fetch() { | ||
|
||
var data = {}; | ||
await Promise.all(this.users.map(async u => { | ||
|
||
let result = this.database.getRepositories(u); | ||
data[u] = result; | ||
|
||
})); | ||
|
||
return data; | ||
|
||
} | ||
|
||
|
||
message(result) { | ||
|
||
client.channels.cache.get(this.channelId).send({ | ||
|
||
content : { | ||
|
||
// event (failure) < | ||
// event (success) < | ||
false : '`Failed to update.`', | ||
true : '`Update was successful.`' | ||
|
||
// > | ||
|
||
}[result] | ||
|
||
}); | ||
|
||
} | ||
|
||
|
||
schedule() { | ||
|
||
this.client.on('ready', async () => { | ||
|
||
cron.schedule('0 0 * * *', async () => { | ||
|
||
let data = await fetch(); | ||
let result = await this.database.updateFile(data); | ||
|
||
this.message(result); | ||
|
||
}); | ||
|
||
}); | ||
|
||
} | ||
|
||
|
||
async run() { | ||
|
||
this.client.run(this.token); | ||
this.schedule(); | ||
|
||
} | ||
|
||
} | ||
|
||
|
||
// export < | ||
module.exports = client; | ||
|
||
// > |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// import < | ||
const {githubUpdate} = require('lxrbckl'); | ||
const {Octokit} = require('@Octokit/rest'); | ||
|
||
// > | ||
|
||
|
||
class database { | ||
|
||
constructor(pToken) { | ||
|
||
// setup < | ||
// initialize < | ||
this.token = pToken; | ||
this.owner = process.env.owner; | ||
this.branch = process.env.branch; | ||
this.filepath = process.env.filepath; | ||
this.repository = process.env.repository; | ||
|
||
this.octokit = new Octokit({auth : this.token}); | ||
|
||
// > | ||
|
||
} | ||
|
||
|
||
async getRepositories(user) { | ||
|
||
var data = {}; | ||
let query = `GET /users/${user}/repos`; | ||
var repos = await this.octokit.paginate(query); | ||
for (const r of repos) { | ||
|
||
let result = (await octokit.repos.get({ | ||
|
||
owner : user, | ||
repo : r.name | ||
|
||
})).data; | ||
|
||
data[result.name] = { | ||
|
||
'url' : result.url, | ||
'topics' : result.topics, | ||
'language' : result.language, | ||
'description' : result.description | ||
|
||
}; | ||
|
||
} | ||
|
||
return data; | ||
|
||
} | ||
|
||
|
||
async updateFile(data) { | ||
|
||
let result = await githubUpdate({ | ||
|
||
pData : data, | ||
pOwner : this.owner, | ||
opShowError : false, | ||
pPath : this.filepath, | ||
pGithub : this.octokit, | ||
opBranch : this.branch, | ||
pRepository : this.repository | ||
|
||
}); | ||
|
||
return (result == undefined); | ||
|
||
} | ||
|
||
} | ||
|
||
|
||
// export < | ||
module.exports = database; | ||
|
||
// > |