Skip to content

Commit

Permalink
V1.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasB25 committed May 4, 2024
1 parent 923807d commit 91234f3
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 46 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/.git
/dist
/node_modules
.eslintcache
.eslintcache
yarn.lock
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
/node_modules
.eslintcache
.env
package-lock.json
package-lock.json
yarn.lock
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/.git
/dist
/node_modules
.eslintcache
.eslintcache
yarn.lock
56 changes: 29 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<center><img src="https://capsule-render.vercel.app/api?type=waving&color=gradient&height=200&section=header&text=Midjourney&fontSize=80&fontAlignY=35&animation=twinkling&fontColor=gradient" /></center>
<center><img src="https://capsule-render.vercel.app/api?type=waving&color=gradient&height=200&section=header&text=AikouBot&fontSize=80&fontAlignY=35&animation=twinkling&fontColor=gradient" /></center>

[![Version][version-shield]](version-url)
[![Contributors][contributors-shield]][contributors-url]
Expand All @@ -7,24 +7,24 @@
[![Issues][issues-shield]][issues-url]
[![Support Server][support-shield]][support-server]
[![MIT License][license-shield]][license-url]
[![Run on Repl.it](https://repl.it/badge/github/LucasB25/Midjourney)](https://repl.it/github/LucasB25/Midjourney)
[![Remix on Glitch](https://cdn.glitch.com/2703baf2-b643-4da7-ab91-7ee2a2d00b5b%2Fremix-button.svg)](https://glitch.com/edit/#!/import/github/LucasB25/Midjourney)
[![Run on Repl.it](https://repl.it/badge/github/LucasB25/AikouBot)](https://repl.it/github/LucasB25/AikouBot)
[![Remix on Glitch](https://cdn.glitch.com/2703baf2-b643-4da7-ab91-7ee2a2d00b5b%2Fremix-button.svg)](https://glitch.com/edit/#!/import/github/LucasB25/AikouBot)

<!-- PROJECT LOGO -->
<br />

<h1 align="center">Midjourney</h1>
<h1 align="center">AikouBot</h1>

<p align="center">Midjourney and TypeScript.
<p align="center">AikouBot and TypeScript.
<br />
<br />
<a href="https://discord.gg/AhUJa2kdAr">Serveur Support</a>
·
<a href="https://github.com/LucasB25/Midjourney/issues">Report Bug & Request Feature</a>
<a href="https://github.com/LucasB25/AikouBot/issues">Report Bug & Request Feature</a>
</p>
</p>

# Midjourney
# AikouBot

A Discord Bot that can generate text based on a given prompt using [Replicate](https://replicate.com/)

Expand All @@ -38,28 +38,30 @@ A Discord Bot that can generate text based on a given prompt using [Replicate](h

## 🚀 Installation from source

1. Clone the Midjourney repository:
1. Clone the AikouBot repository:

```bash
git clone https://github.com/LucasB25/Midjourney.git
git clone https://github.com/LucasB25/AikouBot.git
```

2. change the directory to Midjourney
2. change the directory to AikouBot

```bash
cd Midjourney
cd AikouBot
```

3. Install the required packages:

```bash
npm i
or
yarn i
```

4. Set up your environment variables:

Create a `.env` file in the root directory of your project with the following variables:
or you can use the [.env.example](https://raw.githubusercontent.com/LucasB25/Midjourney/main/.env.example) file
or you can use the [.env.example](https://raw.githubusercontent.com/LucasB25/AikouBot/main/.env.example) file

```bash
TOKEN= #Discord Bot Token
Expand All @@ -77,34 +79,34 @@ npm start

## 📜 Contributing

Thank you for your interest in contributing to Midjourney! Here are some guidelines to follow when contributing:
Thank you for your interest in contributing to AikouBot! Here are some guidelines to follow when contributing:

1. Fork the repository and create a new branch for your feature or bug fix.
2. Write clean and concise code that follows the established coding style.
3. Create detailed and thorough documentation for any new features or changes.
4. Write and run tests for your code.
5. Submit a pull request with your changes.

Your contribution will be reviewed by the project maintainers, and any necessary feedback or changes will be discussed with you. We appreciate your help in making Midjourney better!
Your contribution will be reviewed by the project maintainers, and any necessary feedback or changes will be discussed with you. We appreciate your help in making AikouBot better!

## 👥 Contributors

Thanks goes to these wonderful people :

<a href="https://github.com/LucasB25/Midjourney/graphs/contributors">
<img src="https://contrib.rocks/image?repo=LucasB25/Midjourney" alt="contributors" width="500" />
<a href="https://github.com/LucasB25/AikouBot/graphs/contributors">
<img src="https://contrib.rocks/image?repo=LucasB25/AikouBot" alt="contributors" width="500" />
</a>

[version-shield]: https://img.shields.io/github/package-json/v/LucasB25/Midjourney?style=for-the-badge
[contributors-shield]: https://img.shields.io/github/contributors/LucasB25/Midjourney.svg?style=for-the-badge
[contributors-url]: https://github.com/LucasB25/Midjourney/graphs/contributors
[forks-shield]: https://img.shields.io/github/forks/LucasB25/Midjourney.svg?style=for-the-badge
[forks-url]: https://github.com/LucasB25/Midjourney/network/members
[stars-shield]: https://img.shields.io/github/stars/LucasB25/Midjourney.svg?style=for-the-badge
[stars-url]: https://github.com/LucasB25/Midjourney/stargazers
[issues-shield]: https://img.shields.io/github/issues/LucasB25/Midjourney.svg?style=for-the-badge
[issues-url]: https://github.com/LucasB25/Midjourney/issues
[license-shield]: https://img.shields.io/github/license/LucasB25/Midjourney.svg?style=for-the-badge
[license-url]: https://github.com/LucasB25/Midjourney/blob/mains/LICENSE
[version-shield]: https://img.shields.io/github/package-json/v/LucasB25/AikouBot?style=for-the-badge
[contributors-shield]: https://img.shields.io/github/contributors/LucasB25/AikouBot.svg?style=for-the-badge
[contributors-url]: https://github.com/LucasB25/AikouBot/graphs/contributors
[forks-shield]: https://img.shields.io/github/forks/LucasB25/AikouBot.svg?style=for-the-badge
[forks-url]: https://github.com/LucasB25/AikouBot/network/members
[stars-shield]: https://img.shields.io/github/stars/LucasB25/AikouBot.svg?style=for-the-badge
[stars-url]: https://github.com/LucasB25/AikouBot/stargazers
[issues-shield]: https://img.shields.io/github/issues/LucasB25/AikouBot.svg?style=for-the-badge
[issues-url]: https://github.com/LucasB25/AikouBot/issues
[license-shield]: https://img.shields.io/github/license/LucasB25/AikouBot.svg?style=for-the-badge
[license-url]: https://github.com/LucasB25/AikouBot/blob/mains/LICENSE
[support-server]: https://discord.gg/AhUJa2kdAr
[support-shield]: https://img.shields.io/discord/942117923001098260.svg?style=for-the-badge&logo=discord&colorB=7289DA
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "midjourney",
"version": "1.2.5",
"description": "A simple midjourney bot for discord",
"name": "AikouBot",
"version": "1.3.2",
"description": "A simple AikouBot bot for discord",
"type": "module",
"main": "dist/index.js",
"scripts": {
Expand All @@ -16,14 +16,14 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/LucasB25/Midjourney.git"
"url": "git+https://github.com/LucasB25/AikouBot.git"
},
"bugs": {
"url": "https://github.com/LucasB25/Midjourney/issues"
"url": "https://github.com/LucasB25/AikouBot/issues"
},
"homepage": "https://github.com/LucasB25/Midjourney#readme",
"homepage": "https://github.com/LucasB25/AikouBot#readme",
"devDependencies": {
"@types/node": "^20.12.7",
"@types/node": "^20.12.8",
"@types/signale": "^1.4.7",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
Expand All @@ -46,10 +46,11 @@
"underlineLabel": true
},
"dependencies": {
"@google/generative-ai": "^0.10.0",
"@napi-rs/canvas": "^0.1.52",
"discord.js": "^14.14.1",
"dotenv": "^16.4.5",
"replicate": "^0.29.1",
"replicate": "^0.29.4",
"signale": "^1.4.0",
"undici": "^6.15.0"
}
Expand Down
8 changes: 3 additions & 5 deletions src/commands/imagine/About.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class About extends Command {
const row = new ActionRowBuilder<ButtonBuilder>()
.addComponents(
new ButtonBuilder()
.setLabel('Invite midjourney')
.setLabel('Invite AikouBot')
.setURL(
`https://discord.com/oauth2/authorize?client_id=${client.user?.id}&scope=bot%20applications.commands&permissions=8`
)
Expand All @@ -52,10 +52,8 @@ export default class About extends Command {

const embed = new EmbedBuilder()
.setAuthor({
name: 'Midjourney',
iconURL: 'https://c.clc2l.com/t/M/i/Midjourney-96BXbL.png',
name: 'AikouBot',
})
.setThumbnail('https://c.clc2l.com/t/M/i/Midjourney-96BXbL.png')
.addFields([
{
name: 'Creator',
Expand All @@ -64,7 +62,7 @@ export default class About extends Command {
},
{
name: 'Repository',
value: '[Here](https://github.com/lucasb25/Midjourney)',
value: '[Here](https://github.com/lucasb25/AikouBot)',
inline: true,
},
{
Expand Down
8 changes: 7 additions & 1 deletion src/commands/imagine/Imagine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,13 @@ export default class Imagine extends Command {
.setURL(prediction[i])
)
);
const row2 = new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder()
.setLabel(`Support`)
.setStyle(ButtonStyle.Link)
.setURL('https://discord.gg/JeaQTqzsJw')
);

await interaction.editReply({ files: [attachment], components: [row] });
await interaction.editReply({ files: [attachment], components: [row, row2] });
}
}
1 change: 0 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ export default {

googleKey: process.env.GOOGLE_KEY,
googleModel: process.env.GOOGLE_MODEL as any,
proxy: process.env.LOCAL_FETCH_PROXY as any,
};
67 changes: 67 additions & 0 deletions src/events/client/MessageCreate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { GoogleGenerativeAI } from '@google/generative-ai';
import { Message, TextChannel } from 'discord.js';

import { Bot, Event, EventsTypes } from '../../structures/index.js';

function truncateText(text: string, maxLength: number): string {
return text.length > maxLength ? text.substring(0, maxLength - 3) + '...' : text;
}

export default class MessageCreate extends Event {
constructor(client: Bot, file: string) {
super(client, file, {
name: EventsTypes.MessageCreate,
});
}

public async run(message: Message): Promise<void> {
if (message.channel instanceof TextChannel) {
if (message.content.endsWith('?')) {
try {
const threadName = truncateText(message.content, 100);
const thread = await message.startThread({
name: threadName,
autoArchiveDuration: 60,
});

const generationConfig = {
maxOutputTokens: 1900,
temperature: 0.9,
topK: 1,
topP: 1,
};

const genAI = new GoogleGenerativeAI(this.client.config.googleKey);
const model = genAI.getGenerativeModel({ model: this.client.config.googleModel, generationConfig } as any);

let chat = model.startChat({
history: [
{
role: 'user',
parts: [{ text: message.content }],
},
],
});

let result = await chat.sendMessage(message.content);
let response = result.response;

let generatedText = response.text();

while (generatedText.length > 1500) {
await thread.send(generatedText.substring(0, 1500));
generatedText = generatedText.substring(1500);

result = await chat.sendMessage(generatedText);
response = result.response;
generatedText = response.text();
}

await thread.send(generatedText);
} catch (error) {
console.error('An error occurred while generating the response:', error);
}
}
}
}
}
8 changes: 8 additions & 0 deletions src/structures/Client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { GoogleGenerativeAI } from '@google/generative-ai';
import {
ApplicationCommandType,
Client,
Expand Down Expand Up @@ -27,6 +28,7 @@ export default class Bot extends Client {
private data: RESTPostAPIChatInputApplicationCommandsJSONBody[] = [];
public replicate: Replicate | null = null;
public canvas = new Canvas();
public genAI: GoogleGenerativeAI | null = null;

constructor(options: ClientOptions) {
super(options);
Expand All @@ -40,6 +42,12 @@ export default class Bot extends Client {
this.replicate = new Replicate({ auth: config.replicateToken });
if (!this.replicate) throw new Error('Failed to initialize Replicate.');
this.logger.info('Replicate is initialized.');

// if (!config.googleKey) throw new Error('Google key is missing.');
// this.genAI = new GoogleGenerativeAI(config.googleKey);
// if (!this.genAI) throw new Error('Failed to initialize GoogleGenerativeAI.');
// this.logger.info('GoogleGenerativeAI is initialized.');

await this.loadCommands();
await this.loadEvents();
await this.login(token);
Expand Down
2 changes: 1 addition & 1 deletion src/structures/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const defaultOptions: LoggerOptions = {
disabled: false,
interactive: false,
logLevel: LogLevel.INFO,
scope: 'Midjourney',
scope: 'AikouBot',
types: {
[LogLevel.INFO]: { badge: 'ℹ', color: 'blue', label: 'info' },
[LogLevel.WARN]: { badge: '⚠', color: 'yellow', label: 'warn' },
Expand Down

0 comments on commit 91234f3

Please sign in to comment.