Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added repo command #16

Merged
merged 1 commit into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# June 2023
- feat: (06/16/2023): Add repo link command

# May 2023
- feat: (05/25/2023): Add new role handler, update gpt command, changelog
- fix: (05/26/2023): Fix permissions loophole in 'roles' command
Expand Down
16 changes: 9 additions & 7 deletions .github/command-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@

### General

| Command | Description |
|:--------|:----------------------|
| /chat | Interact with chatgpt |
| Command | Description |
| :------ | :---------------------------- |
| /chat | Interact with chatgpt |
| /repo | Fetch one of the OWDDM repos. |



### Memes

| Command | Description |
|:--------|:------------------------------------------|
| :------ | :---------------------------------------- |
| /cowsay | emulates the famous UNIX program 'cowsay' |

### Moderation

| Command | Description |
|:--------|:----------------------------------------------------------------------------------------------------|
| /roles | |
| Command | Description |
| :------ | :---------- |
| /roles | |
84 changes: 42 additions & 42 deletions src/commands/general/chatgpt.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Logger, {CommandDefinition, makeEmbed, InputCommandOptions, makeLines} from '../../lib';
import { CommandCategory, ResponseType } from '../../constants';
import { openai_api } from '../../index';
import { EmbedBuilder, Colors } from "discord.js";
import { EmbedBuilder, Colors } from 'discord.js';

const chatgptOptions: InputCommandOptions[] = [{
name: 'prompt',
description: 'what will you ask?'
name: 'prompt',
description: 'what will you ask?'
}];

export const chatgpt: CommandDefinition = {
Expand All @@ -17,46 +17,46 @@ export const chatgpt: CommandDefinition = {
interaction: async (interaction) => {

const input = interaction.options.getString(chatgptOptions[0].name)?.trim() ?? 'no text provided';
const maxChars = 300;
if(input.length > maxChars) {
const overMaxEmbed = new EmbedBuilder({
title: '🚫 Error: Character Limit Exceeded',
description: makeLines([
`Please provide a prompt less than ${maxChars} characters long.`,
`You provided ${input.length} characters.`,
'',
`For prompts longer than the maximum, please visit https://chat.openai.com`
]),
color: Colors.Red,
})
await interaction.reply({
embeds: [overMaxEmbed],
ephemeral: true,
});
return;
}
const maxChars = 300;
if(input.length > maxChars) {
const overMaxEmbed = new EmbedBuilder({
title: '🚫 Error: Character Limit Exceeded',
description: makeLines([
`Please provide a prompt less than ${maxChars} characters long.`,
`You provided ${input.length} characters.`,
'',
'For prompts longer than the maximum, please visit https://chat.openai.com'
]),
color: Colors.Red,
});
await interaction.reply({
embeds: [overMaxEmbed],
ephemeral: true,
});
return;
}

await interaction.deferReply();
try {
console.log(`${input.length}`)
const response = await openai_api.createChatCompletion({
model: 'gpt-3.5-turbo',
messages: [{role:'user', content: input}],
});
await interaction.deferReply();
try {
console.log(`${input.length}`);
const response = await openai_api.createChatCompletion({
model: 'gpt-3.5-turbo',
messages: [{role:'user', content: input}],
});

const responseEmbed = makeEmbed({
title: input,
description: response.data.choices[0].message?.content,
footer: {
text: 'Model provided by OpenAI',
}
})
const responseEmbed = makeEmbed({
title: input,
description: response.data.choices[0].message?.content,
footer: {
text: 'Model provided by OpenAI',
}
});

await interaction.followUp({embeds: [responseEmbed]});
await interaction.followUp({embeds: [responseEmbed]});

} catch (error) {
Logger.error(error)
await interaction.reply('error: ' + error)
}
}
}
} catch (error) {
Logger.error(error);
await interaction.reply('error: ' + error);
}
}
};
75 changes: 75 additions & 0 deletions src/commands/general/repo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import Logger, { CommandDefinition, makeEmbed, makeLines, InputCommandOptions } from '../../lib';
import { CommandCategory, ResponseType } from '../../constants';
import { throws } from 'assert';

const repos = new Map ([
['org', 'https://github.com/owddm/org'],
['site','https://github.com/owddm/owddm.com'],
['data', 'https://github.com/owddm/public'],
['bot', 'https://github.com/owddm/discord-bot'],
['accounting', 'https://github.com/owddm/accounting'],
['survey', 'https://github.com/owddm/survey'],
['presentations', 'https://github.com/owddm/presentations'],
['legacy_site', 'https://github.com/owddm/owddm.github.io']
]);

const repoOptions: InputCommandOptions[] = [{
name: 'repo',
description: 'enter a valid repo name to get it\'s url'
}];

function getRepoUrl(option: string): string {
const repo = repos.get(option);
if (repo === undefined) {
throw Object.assign(new Error(`Error: ${option} not found`), {code: 404});
}

return repo;
}

const errorEmbed = makeEmbed({
title: '🚫 Error: Repository not found',
description: makeLines([
'The indicated repository wasn\'t found, please enter one of the following repositories: ',
'',
'• org',
'',
'• site',
'',
'• data',
'',
'• bot',
'',
'• accounting',
'',
'• survey',
'',
'• presentations',
'',
'• legacy_site'
])
});


export const repo: CommandDefinition = {
name: 'repo',
options: repoOptions,
description: 'Fetch one of the OWDDM repos.',
category: CommandCategory.GENERAL,
response: ResponseType.EDIT,
interaction: async (interaction) => {
const input = interaction.options.getString(repoOptions[0].name)?.trim() ?? 'no text provided';

try {
const response = getRepoUrl(input);

interaction.reply({
content: response
});
} catch (error) {
interaction.reply({
embeds: [errorEmbed]
});
}
}
};
26 changes: 14 additions & 12 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import Logger, { CommandDefinition } from "../lib";
import Logger, { CommandDefinition } from '../lib';
import { cowsay } from './memes/cowsay';
import { chatgpt } from "./general/chatgpt";
import { chatgpt } from './general/chatgpt';
import { roleSelect } from './moderation/role_assignment';
import { repo } from './general/repo';

export const commands: CommandDefinition[] = [
cowsay,
chatgpt,
roleSelect,
]
cowsay,
chatgpt,
roleSelect,
repo,
];

const commandsObject: { [k: string]: CommandDefinition } = {};

for (const def of commands) {
for (const name of def.name) {
if (commandsObject[def.name]) {
Logger.warn(`Duplicate command/alias inserted: ${name}`);
}
}
commandsObject[def.name] = def;
for (const name of def.name) {
if (commandsObject[def.name]) {
Logger.warn(`Duplicate command/alias inserted: ${name}`);
}
}
commandsObject[def.name] = def;
}
58 changes: 29 additions & 29 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,34 @@ export const enum Roles {
}

export const regionRoles = [
'Osaka',
'Kyoto',
'Kobe',
'Tokyo',
'Aichi',
'Abroad'
]
'Osaka',
'Kyoto',
'Kobe',
'Tokyo',
'Aichi',
'Abroad'
];

export const techRoles = [
'typescript',
'javascript',
'csharp',
'java',
'kotlin',
'php',
'dart',
'html',
'css',
'ruby',
'rust',
'clang',
'cpp',
'python',
'react',
'angular',
'svelte',
'dotnet',
'flutter',
'vue',
'solidjs',
]
'typescript',
'javascript',
'csharp',
'java',
'kotlin',
'php',
'dart',
'html',
'css',
'ruby',
'rust',
'clang',
'cpp',
'python',
'react',
'angular',
'svelte',
'dotnet',
'flutter',
'vue',
'solidjs',
];
Loading