Skip to content

Commit

Permalink
V1.03.5
Browse files Browse the repository at this point in the history
  • Loading branch information
MujyKun committed Nov 7, 2020
1 parent 18fff9e commit 7786126
Show file tree
Hide file tree
Showing 22 changed files with 1,003 additions and 167 deletions.
9 changes: 9 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ WOLFRAM_APP_ID=
# Lyrics API KEY - https://github.com/KSoft-Si/ksoftapi.py
LYRICS_API_KEY =

# Idol Avatar Location (include / at the end)
IDOL_AVATAR_LOCATION="Photos/avatar/"

# Idol Banner Location (include / at the end)
IDOL_BANNER_LOCATION="Photos/banner/"

# Bias Game Folder Location (include / at the end)
BIAS_GAME_LOCATION="Photos/bias_game/"

# API
API_PORT=5454
PRIVATE_KEY=
Expand Down
70 changes: 55 additions & 15 deletions API/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ app.get('/', (req,res) => {
/translate --- Post -> Send in 'text' to translate, 'src_lang', 'target_lang' as a body. Also send in the private API key as 'p_key'.<br>
Groupmembers:<br>
/photos/:idolID --- Get redirected to an image of the Idol. Send in private API key as 'p_key' (body). <br>
/photos/:idolID --- Get redirected to an image of the Idol. Send in private API key as 'p_key' and send you DO NOT want group photos(0 or 1) as 'no_group_photos' (body). <br>
</h2>
`);
});
Expand All @@ -90,13 +90,12 @@ app.post('/photos/:id', async (req, res) =>{
// sleep for 1.5 seconds
await sleep(1.5);
}
var fileLink = `${await getrandomimage(req.params.id)}`;
var fileLink = `${await getrandomimage(req.params.id, req.body.no_group_photo)}`;
if (fileLink == 'undefined'){
res.sendStatus(404);
return;
}
currentlyWorking++;

var fileId = fileLink.replace("https://drive.google.com/uc?export=view&id=", "");
var x = await drive_js.drive.files.get(
{
Expand All @@ -105,7 +104,7 @@ app.post('/photos/:id', async (req, res) =>{
})
try{
var allFiles = fs.readdirSync(folderLocation);
if (Object.keys(allFiles).length > 20000){
if (Object.keys(allFiles).length > 50000){
allFiles.forEach(deletedFile => {
fs.unlink(folderLocation + deletedFile, (err) =>{
if (err) {
Expand Down Expand Up @@ -144,7 +143,7 @@ app.post('/photos/:id', async (req, res) =>{
function(err, { data }) {
data
.on("end", () => {
if (file_name.includes('.mp4')){
if (file_name.includes('.mp4') || file_name.includes('.webm')){
res.send({"final_image_link": final_image_link, "location": folderLocation + file_name, "file_name": file_name, "original_link": fileLink}, 415)
}
else{
Expand Down Expand Up @@ -235,10 +234,18 @@ app.post('/translate', async (req, res) => {
res.send(responsex);
});

app.get('/login', async (req, res) => {
let request = (await send_discord_request(req.query.code));
console.log(request);
res.send(request);

});


async function getmembers(){
try{
return await sql`
SELECT * FROM groupmembers.member ORDER BY id
SELECT id, fullname, stagename FROM groupmembers.member ORDER BY id
`}
catch(err) {
return none;
Expand All @@ -248,7 +255,7 @@ async function getmembers(){
async function getgroups(){
try{
return await sql`
SELECT * FROM groupmembers.groups
SELECT groupid, groupname FROM groupmembers.groups
`}
catch(err) {
return none;
Expand All @@ -265,18 +272,21 @@ async function getimages(){
}
}

async function getidolimages(id){
async function getidolimages(id, no_group_photos=0){
try{
return await sql`
SELECT * FROM groupmembers.imagelinks WHERE memberid = ${id}
`}
if (no_group_photos == 0){
return await sql`SELECT * FROM groupmembers.imagelinks WHERE memberid = ${id}`;
}
else{
return await sql`SELECT * FROM groupmembers.imagelinks WHERE memberid = ${id} AND groupphoto = ${0}`;
}}
catch(err) {
return none;
}
}

async function getrandomimage(id){
const idolLinks = await getidolimages(id);
async function getrandomimage(id, no_group_photos){
const idolLinks = await getidolimages(id, no_group_photos);
var links = idolLinks[Math.floor(Math.random() * idolLinks.length)];
try{
return links.link;
Expand All @@ -289,7 +299,7 @@ async function getrandomimage(id){
async function getspecificgroup(id){
try{
return await sql`
SELECT * FROM groupmembers.groups WHERE groupid = ${id}
SELECT groupid, groupname FROM groupmembers.groups WHERE groupid = ${id}
`}
catch(err) {
return none;
Expand All @@ -300,7 +310,7 @@ async function getspecificgroup(id){
async function getspecificidol(id){
try{
return await sql`
SELECT * FROM groupmembers.member WHERE id = ${id}
SELECT id, fullname, stagename FROM groupmembers.member WHERE id = ${id}
`}
catch(err) {
return none;
Expand Down Expand Up @@ -381,6 +391,36 @@ async function translate_text(text, source, target){
return (Translator.translate(text, source, target)).text;
}

async function send_discord_request(code){
options = {
method: "POST",
uri : endpointtoken,
json : true,
form : {
'client_id': clientid,
'client_secret': clientsecret,
'grant_type': 'authorization_code',
'code': code,
'redirect_uri': redirectlogin,
'scope': scopes
},
headers : {
'Content-Type': 'application/x-www-form-urlencoded'
}
};
rp(options)
.then(function (parsedBody) {
console.log(parsedBody);
return (parsedBody);
// POST succeeded...
})
.catch(function (err) {
console.log(err);
return (err);
// POST failed...
});
}

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
Expand Down
25 changes: 21 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [IreneBot V1.03.4](https://discordapp.com/oauth2/authorize?client_id=520369375325454371&scope=bot&permissions=1609956823)
# [IreneBot V1.03.5](https://discordapp.com/oauth2/authorize?client_id=520369375325454371&scope=bot&permissions=1609956823)

## [Support Irene by becoming a Patron!](https://www.patreon.com/bePatron?u=38971435)
**[Become a Patron!](https://www.patreon.com/bePatron?u=38971435)**
Expand Down Expand Up @@ -64,16 +64,24 @@ To find out more, look at the `GroupMembers` category.
| deleteidol | Deletes an idol. | %deleteidol (idol id) | removeidol |
| deleteidolfromgroup | Deletes idol from group | %deleteidolfromgroup (idol id) (group id) | removeidolfromgroup |
| deleteinteraction | Delete a url from an interaction | %deleteinteraction (url,url) | |
| deletelink | Removes a link from an idol. | %deletelink (link) | |
| getstatuses | Get all statuses of Irene. | %getstatuses | |
| kill | Kills the bot | %kill | |
| killapi | Restarts the API | %killapi | |
| maintenance | Enable/Disable Maintenance Mode. | %maintenance | |
| maintenance | Enable/Disable Maintenance Mode. | %maintenance (reason) | |
| mergeidol | Merges a duplicate Idol with it's original | %mergeidol (original idol id) (duplicate idol id) | |
| mergegroup | Merges a duplicate Group with it's original | %mergegroup (original group id) (duplicate group id) | |
| moveto | Moves a link to another idol. (Cannot be used for adding new links) | %moveto (idol id) (link) | |
| removestatus | Remove a status based on it's index. The index can be found using %getstatuses | %removestatus (status index) | |
| repost | Reposts a certain post from the DC APP to all channels. | %repost (post_number) | |


#### BiasGame:
| Command | Description | Format | Aliases |
|-------------|--------------------------------------|------------------------|-------------------|
| biasgame | Start a bias game in the current channel. The host of the game can use `stopbg` to stop playing. | %biasgame (male/female/all) (bracket size (4,8,16,32)) | bg |
| stopbg | Force-end a bias game if you are a moderator or host of the game. This command is meant for any issues or if a game happens to be stuck. | %stopbg | ★/Host |
| listbg | List a user's bias game leaderboards. | %listbg (user) | |


#### Cogs: ♥♥♥
| Command | Description | Format |
|-------------------|---------------------------------------------------------------------------|------------------------------|
Expand All @@ -95,6 +103,13 @@ To find out more, look at the `GroupMembers` category.
| rps | Play Rock Paper Scissors for Money | %rps (r/p/s)(amount) | rockpaperscissors |
| upgrade | Upgrade a command to the next level with your money. | %upgrade rob/daily/beg | levelup |

#### CustomCommands:
| Command | Description | Format | Aliases |
|------------------|--------------------------------------------------------------------------------------------------------------------------------------|---------------------------------|----------------|
| createcommand | Create a custom command. | %createcommand (command name) (message) | addcommand, ★ |
| deletecommand | Delete a custom command. | %deletecommand (command name) | removecommand, ★ |
| listcommands | List all the custom commands for the current server. | %listcommands | |


#### DreamCatcher:
| Command | Description | Format | Aliases |
Expand All @@ -110,6 +125,7 @@ To find out more, look at the `GroupMembers` category.
| Command | Description | Format | Aliases |
|------------------|------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------|------------------------|
| aliases | Lists the aliases of idols or groups that have one. Underscores are spaces and commas are to split idol or group names | %aliases (name of idol or group) [page number] ex: %aliases irene,seulgi,red_velvet | |
| card | Displays an Idol/Group's profile card. | %card (Idol/Group Name) | |
| count | Shows howmany times an idol has been called. | %count (name) | |
| countleaderboard | Shows leaderboards for how many times an idol has been called. | %clb | highestcount, cb, clb |
| countgroup | Shows how many images of a certain group there are. | %countgroup (group) | |
Expand All @@ -126,6 +142,7 @@ To find out more, look at the `GroupMembers` category.
| Command | Description | Format | Aliases |
|------------------|--------------------------------------------------------------------------------------------------------------------------------------|---------------------------------|----------------|
| guessinggame | Start an idol guessing game in the current channel. The host of the game can use `stop` to end the game or `skip` to skip the current round without affecting the round number. | %guessinggame (Male/Female/All) (# of rounds - default 20) (timeout for each round - default 20s) | gg |
| stopgg | Force-end a guessing game if you are a moderator or host of the game. This command is meant for any issues or if a game happens to be stuck. Must be game host or access to manage messages. | %stopgg | ★/Host|

#### Interactions:
| Command | Description | Format | Aliases |
Expand Down
Binary file added Reference Photos/bracket8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes.
File renamed without changes
Binary file added Reference Photos/versus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 7786126

Please sign in to comment.