Pull/Switch Model Commands Fix (#137)
* Update: Channel checker and channel name gone * Add: note of where problem can be * Update: Check if model already exists for Pull Command * Add: User/Admin Command Constants * Update: version increment
This commit is contained in:
@@ -7,7 +7,7 @@ services:
|
|||||||
build: ./ # find docker file in designated path
|
build: ./ # find docker file in designated path
|
||||||
container_name: discord
|
container_name: discord
|
||||||
restart: always # rebuild container always
|
restart: always # rebuild container always
|
||||||
image: kevinthedang/discord-ollama:0.7.1
|
image: kevinthedang/discord-ollama:0.7.2
|
||||||
environment:
|
environment:
|
||||||
CLIENT_TOKEN: ${CLIENT_TOKEN}
|
CLIENT_TOKEN: ${CLIENT_TOKEN}
|
||||||
OLLAMA_IP: ${OLLAMA_IP}
|
OLLAMA_IP: ${OLLAMA_IP}
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "discord-ollama",
|
"name": "discord-ollama",
|
||||||
"version": "0.7.1",
|
"version": "0.7.2",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "discord-ollama",
|
"name": "discord-ollama",
|
||||||
"version": "0.7.1",
|
"version": "0.7.2",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"discord.js": "^14.16.3",
|
"discord.js": "^14.16.3",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "discord-ollama",
|
"name": "discord-ollama",
|
||||||
"version": "0.7.1",
|
"version": "0.7.2",
|
||||||
"description": "Ollama Integration into discord",
|
"description": "Ollama Integration into discord",
|
||||||
"main": "build/index.js",
|
"main": "build/index.js",
|
||||||
"exports": "./build/index.js",
|
"exports": "./build/index.js",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { ChannelType, Client, CommandInteraction, ApplicationCommandOptionType } from 'discord.js'
|
import { Client, CommandInteraction, ApplicationCommandOptionType } from 'discord.js'
|
||||||
import { openConfig, SlashCommand } from '../utils/index.js'
|
import { openConfig, SlashCommand, UserCommand } from '../utils/index.js'
|
||||||
|
|
||||||
export const Capacity: SlashCommand = {
|
export const Capacity: SlashCommand = {
|
||||||
name: 'modify-capacity',
|
name: 'modify-capacity',
|
||||||
@@ -19,7 +19,7 @@ export const Capacity: SlashCommand = {
|
|||||||
run: async (client: Client, interaction: CommandInteraction) => {
|
run: async (client: Client, interaction: CommandInteraction) => {
|
||||||
// fetch channel and message
|
// fetch channel and message
|
||||||
const channel = await client.channels.fetch(interaction.channelId)
|
const channel = await client.channels.fetch(interaction.channelId)
|
||||||
if (!channel || channel.type !== (ChannelType.PrivateThread && ChannelType.PublicThread && ChannelType.GuildText)) return
|
if (!channel || !UserCommand.includes(channel.type)) return
|
||||||
|
|
||||||
// set state of bot chat features
|
// set state of bot chat features
|
||||||
openConfig(`${interaction.user.username}-config.json`, interaction.commandName, interaction.options.get('context-capacity')?.value)
|
openConfig(`${interaction.user.username}-config.json`, interaction.commandName, interaction.options.get('context-capacity')?.value)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { ChannelType, Client, CommandInteraction, TextChannel } from 'discord.js'
|
import { Channel, Client, CommandInteraction, TextChannel } from 'discord.js'
|
||||||
import { clearChannelInfo, SlashCommand } from '../utils/index.js'
|
import { clearChannelInfo, SlashCommand, UserCommand } from '../utils/index.js'
|
||||||
|
|
||||||
export const ClearUserChannelHistory: SlashCommand = {
|
export const ClearUserChannelHistory: SlashCommand = {
|
||||||
name: 'clear-user-channel-history',
|
name: 'clear-user-channel-history',
|
||||||
@@ -8,10 +8,10 @@ export const ClearUserChannelHistory: SlashCommand = {
|
|||||||
// Clear channel history for intended user
|
// Clear channel history for intended user
|
||||||
run: async (client: Client, interaction: CommandInteraction) => {
|
run: async (client: Client, interaction: CommandInteraction) => {
|
||||||
// fetch current channel
|
// fetch current channel
|
||||||
const channel = await client.channels.fetch(interaction.channelId)
|
const channel: Channel | null = await client.channels.fetch(interaction.channelId)
|
||||||
|
|
||||||
// if not an existing channel or a GuildText, fail command
|
// if not an existing channel or a GuildText, fail command
|
||||||
if (!channel || channel.type !== ChannelType.GuildText) return
|
if (!channel || !UserCommand.includes(channel.type)) return
|
||||||
|
|
||||||
// clear channel info for user
|
// clear channel info for user
|
||||||
const successfulWipe = await clearChannelInfo(interaction.channelId,
|
const successfulWipe = await clearChannelInfo(interaction.channelId,
|
||||||
@@ -21,12 +21,12 @@ export const ClearUserChannelHistory: SlashCommand = {
|
|||||||
// check result of clearing history
|
// check result of clearing history
|
||||||
if (successfulWipe)
|
if (successfulWipe)
|
||||||
interaction.reply({
|
interaction.reply({
|
||||||
content: `Channel history in **${channel.name}** cleared for **${interaction.user.username}**.`,
|
content: `Channel history in **this channel** successfully cleared for **${interaction.user.username}**.`,
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
})
|
})
|
||||||
else
|
else
|
||||||
interaction.reply({
|
interaction.reply({
|
||||||
content: `Channel history could not be found for **${interaction.user.username}** in **${channel.name}**.\n\nPlease chat with **${client.user?.username}** to start a chat history.`,
|
content: `Channel history could not be found for **${interaction.user.username}** in **this channel**.\n\nPlease chat with **${client.user?.username}** to start a chat history.`,
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { ChannelType, Client, CommandInteraction, ApplicationCommandOptionType } from 'discord.js'
|
import { ChannelType, Client, CommandInteraction, ApplicationCommandOptionType } from 'discord.js'
|
||||||
import { openConfig, SlashCommand } from '../utils/index.js'
|
import { AdminCommand, openConfig, SlashCommand } from '../utils/index.js'
|
||||||
|
|
||||||
export const Disable: SlashCommand = {
|
export const Disable: SlashCommand = {
|
||||||
name: 'toggle-chat',
|
name: 'toggle-chat',
|
||||||
@@ -19,7 +19,7 @@ export const Disable: SlashCommand = {
|
|||||||
run: async (client: Client, interaction: CommandInteraction) => {
|
run: async (client: Client, interaction: CommandInteraction) => {
|
||||||
// fetch channel and message
|
// fetch channel and message
|
||||||
const channel = await client.channels.fetch(interaction.channelId)
|
const channel = await client.channels.fetch(interaction.channelId)
|
||||||
if (!channel || channel.type !== ChannelType.GuildText) return
|
if (!channel || !AdminCommand.includes(channel.type)) return
|
||||||
|
|
||||||
// check if runner is an admin
|
// check if runner is an admin
|
||||||
if (!interaction.memberPermissions?.has('Administrator')) {
|
if (!interaction.memberPermissions?.has('Administrator')) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { ApplicationCommandOptionType, ChannelType, Client, CommandInteraction } from 'discord.js'
|
import { ApplicationCommandOptionType, Client, CommandInteraction } from 'discord.js'
|
||||||
import { openConfig, SlashCommand } from '../utils/index.js'
|
import { openConfig, SlashCommand, UserCommand } from '../utils/index.js'
|
||||||
|
|
||||||
export const MessageStream: SlashCommand = {
|
export const MessageStream: SlashCommand = {
|
||||||
name: 'message-stream',
|
name: 'message-stream',
|
||||||
@@ -19,7 +19,7 @@ export const MessageStream: SlashCommand = {
|
|||||||
run: async (client: Client, interaction: CommandInteraction) => {
|
run: async (client: Client, interaction: CommandInteraction) => {
|
||||||
// verify channel
|
// verify channel
|
||||||
const channel = await client.channels.fetch(interaction.channelId)
|
const channel = await client.channels.fetch(interaction.channelId)
|
||||||
if (!channel || channel.type !== (ChannelType.PrivateThread && ChannelType.PublicThread && ChannelType.GuildText)) return
|
if (!channel || !UserCommand.includes(channel.type)) return
|
||||||
|
|
||||||
// save value to json and write to it
|
// save value to json and write to it
|
||||||
openConfig(`${interaction.user.username}-config.json`, interaction.commandName, interaction.options.get('stream')?.value)
|
openConfig(`${interaction.user.username}-config.json`, interaction.commandName, interaction.options.get('stream')?.value)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { ChannelType, Client, CommandInteraction, ApplicationCommandOptionType } from 'discord.js'
|
import { Client, CommandInteraction, ApplicationCommandOptionType } from 'discord.js'
|
||||||
import { openConfig, SlashCommand } from '../utils/index.js'
|
import { openConfig, SlashCommand, UserCommand } from '../utils/index.js'
|
||||||
|
|
||||||
export const MessageStyle: SlashCommand = {
|
export const MessageStyle: SlashCommand = {
|
||||||
name: 'message-style',
|
name: 'message-style',
|
||||||
@@ -19,7 +19,7 @@ export const MessageStyle: SlashCommand = {
|
|||||||
run: async (client: Client, interaction: CommandInteraction) => {
|
run: async (client: Client, interaction: CommandInteraction) => {
|
||||||
// fetch channel and message
|
// fetch channel and message
|
||||||
const channel = await client.channels.fetch(interaction.channelId)
|
const channel = await client.channels.fetch(interaction.channelId)
|
||||||
if (!channel || channel.type !== (ChannelType.PrivateThread && ChannelType.PublicThread && ChannelType.GuildText)) return
|
if (!channel || !UserCommand.includes(channel.type)) return
|
||||||
|
|
||||||
// set the message style
|
// set the message style
|
||||||
openConfig(`${interaction.user.username}-config.json`, interaction.commandName, interaction.options.get('embed')?.value)
|
openConfig(`${interaction.user.username}-config.json`, interaction.commandName, interaction.options.get('embed')?.value)
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { ApplicationCommandOptionType, ChannelType, Client, CommandInteraction } from "discord.js";
|
import { ApplicationCommandOptionType, Client, CommandInteraction } from "discord.js";
|
||||||
import { SlashCommand } from "../utils/commands.js";
|
import { SlashCommand } from "../utils/commands.js";
|
||||||
import { ollama } from "../client.js";
|
import { ollama } from "../client.js";
|
||||||
|
import { ModelResponse } from "ollama";
|
||||||
|
import { UserCommand } from "../utils/index.js";
|
||||||
|
|
||||||
export const PullModel: SlashCommand = {
|
export const PullModel: SlashCommand = {
|
||||||
name: 'pull-model',
|
name: 'pull-model',
|
||||||
@@ -24,13 +26,16 @@ export const PullModel: SlashCommand = {
|
|||||||
|
|
||||||
// fetch channel and message
|
// fetch channel and message
|
||||||
const channel = await client.channels.fetch(interaction.channelId)
|
const channel = await client.channels.fetch(interaction.channelId)
|
||||||
if (!channel || channel.type !== (ChannelType.PrivateThread && ChannelType.PublicThread && ChannelType.GuildText)) return
|
if (!channel || !UserCommand.includes(channel.type)) return
|
||||||
|
|
||||||
|
// check if model was already pulled
|
||||||
|
const modelExists: boolean = await ollama.list()
|
||||||
|
.then(response => response.models.some((model: ModelResponse) => model.name.startsWith(modelInput)))
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// call ollama to pull desired model
|
// call ollama to pull desired model
|
||||||
await ollama.pull({
|
if (!modelExists)
|
||||||
model: modelInput
|
await ollama.pull({ model: modelInput })
|
||||||
})
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// could not resolve pull or model unfound
|
// could not resolve pull or model unfound
|
||||||
interaction.editReply({
|
interaction.editReply({
|
||||||
@@ -39,9 +44,14 @@ export const PullModel: SlashCommand = {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// successful pull
|
// successful interaction
|
||||||
interaction.editReply({
|
if (modelExists)
|
||||||
content: `Successfully added **${modelInput}** into your local model library.`
|
interaction.editReply({
|
||||||
})
|
content: `**${modelInput}** is already in your local model library.`
|
||||||
|
})
|
||||||
|
else
|
||||||
|
interaction.editReply({
|
||||||
|
content: `Successfully added **${modelInput}** into your local model library.`
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { ChannelType, Client, CommandInteraction, ApplicationCommandOptionType } from 'discord.js'
|
import { Client, CommandInteraction, ApplicationCommandOptionType } from 'discord.js'
|
||||||
import { SlashCommand } from '../utils/commands.js'
|
import { SlashCommand } from '../utils/commands.js'
|
||||||
|
import { AdminCommand } from '../utils/index.js'
|
||||||
|
|
||||||
export const Shutoff: SlashCommand = {
|
export const Shutoff: SlashCommand = {
|
||||||
name: 'shutoff',
|
name: 'shutoff',
|
||||||
@@ -19,7 +20,7 @@ export const Shutoff: SlashCommand = {
|
|||||||
run: async (client: Client, interaction: CommandInteraction) => {
|
run: async (client: Client, interaction: CommandInteraction) => {
|
||||||
// fetch channel and message
|
// fetch channel and message
|
||||||
const channel = await client.channels.fetch(interaction.channelId)
|
const channel = await client.channels.fetch(interaction.channelId)
|
||||||
if (!channel || channel.type !== ChannelType.GuildText) return
|
if (!channel || !AdminCommand.includes(channel.type)) return
|
||||||
|
|
||||||
// log this, this will probably be improtant for logging who did this
|
// log this, this will probably be improtant for logging who did this
|
||||||
console.log(`User -> ${interaction.user.tag} attempting to shutdown ${client.user!!.tag}`)
|
console.log(`User -> ${interaction.user.tag} attempting to shutdown ${client.user!!.tag}`)
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { ApplicationCommandOptionType, ChannelType, Client, CommandInteraction } from "discord.js";
|
import { ApplicationCommandOptionType, Client, CommandInteraction } from "discord.js";
|
||||||
import { SlashCommand } from "../utils/commands.js";
|
import { SlashCommand } from "../utils/commands.js";
|
||||||
import { ollama } from "../client.js";
|
import { ollama } from "../client.js";
|
||||||
import { ModelResponse } from "ollama";
|
import { ModelResponse } from "ollama";
|
||||||
import { openConfig } from "../utils/index.js";
|
import { openConfig, UserCommand } from "../utils/index.js";
|
||||||
|
|
||||||
export const SwitchModel: SlashCommand = {
|
export const SwitchModel: SlashCommand = {
|
||||||
name: 'switch-model',
|
name: 'switch-model',
|
||||||
@@ -26,7 +26,7 @@ export const SwitchModel: SlashCommand = {
|
|||||||
|
|
||||||
// fetch channel and message
|
// fetch channel and message
|
||||||
const channel = await client.channels.fetch(interaction.channelId)
|
const channel = await client.channels.fetch(interaction.channelId)
|
||||||
if (!channel || channel.type !== (ChannelType.PrivateThread && ChannelType.PublicThread && ChannelType.GuildText)) return
|
if (!channel || !UserCommand.includes(channel.type)) return
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Phase 1: Set the model
|
// Phase 1: Set the model
|
||||||
@@ -46,6 +46,7 @@ export const SwitchModel: SlashCommand = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
// todo: problem can be here if async messes up
|
||||||
if (switchSuccess) return
|
if (switchSuccess) return
|
||||||
|
|
||||||
// Phase 2: Try to get it regardless
|
// Phase 2: Try to get it regardless
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { ChannelType, Client, CommandInteraction, TextChannel, ThreadChannel } from 'discord.js'
|
import { ChannelType, Client, CommandInteraction, TextChannel, ThreadChannel } from 'discord.js'
|
||||||
import { openChannelInfo, SlashCommand } from '../utils/index.js'
|
import { AdminCommand, openChannelInfo, SlashCommand } from '../utils/index.js'
|
||||||
|
|
||||||
export const ThreadCreate: SlashCommand = {
|
export const ThreadCreate: SlashCommand = {
|
||||||
name: 'thread',
|
name: 'thread',
|
||||||
@@ -9,7 +9,7 @@ export const ThreadCreate: SlashCommand = {
|
|||||||
run: async (client: Client, interaction: CommandInteraction) => {
|
run: async (client: Client, interaction: CommandInteraction) => {
|
||||||
// fetch the channel
|
// fetch the channel
|
||||||
const channel = await client.channels.fetch(interaction.channelId)
|
const channel = await client.channels.fetch(interaction.channelId)
|
||||||
if (!channel || channel.type !== ChannelType.GuildText) return
|
if (!channel || !AdminCommand.includes(channel.type)) return
|
||||||
|
|
||||||
const thread = await (channel as TextChannel).threads.create({
|
const thread = await (channel as TextChannel).threads.create({
|
||||||
name: `${client.user?.username}-support-${Date.now()}`,
|
name: `${client.user?.username}-support-${Date.now()}`,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { ChannelType, Client, CommandInteraction, TextChannel, ThreadChannel } from 'discord.js'
|
import { ChannelType, Client, CommandInteraction, TextChannel, ThreadChannel } from 'discord.js'
|
||||||
import { openChannelInfo, SlashCommand } from '../utils/index.js'
|
import { AdminCommand, openChannelInfo, SlashCommand } from '../utils/index.js'
|
||||||
|
|
||||||
export const PrivateThreadCreate: SlashCommand = {
|
export const PrivateThreadCreate: SlashCommand = {
|
||||||
name: 'private-thread',
|
name: 'private-thread',
|
||||||
@@ -9,7 +9,7 @@ export const PrivateThreadCreate: SlashCommand = {
|
|||||||
run: async (client: Client, interaction: CommandInteraction) => {
|
run: async (client: Client, interaction: CommandInteraction) => {
|
||||||
// fetch the channel
|
// fetch the channel
|
||||||
const channel = await client.channels.fetch(interaction.channelId)
|
const channel = await client.channels.fetch(interaction.channelId)
|
||||||
if (!channel || channel.type !== ChannelType.GuildText) return
|
if (!channel || !AdminCommand.includes(channel.type)) return
|
||||||
|
|
||||||
const thread = await (channel as TextChannel).threads.create({
|
const thread = await (channel as TextChannel).threads.create({
|
||||||
name: `${client.user?.username}-private-support-${Date.now()}`,
|
name: `${client.user?.username}-private-support-${Date.now()}`,
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { ChannelType } from 'discord.js'
|
||||||
import { UserMessage } from './index.js'
|
import { UserMessage } from './index.js'
|
||||||
|
|
||||||
export interface UserConfiguration {
|
export interface UserConfiguration {
|
||||||
@@ -42,6 +43,21 @@ export interface Channel {
|
|||||||
messages: UserMessage[]
|
messages: UserMessage[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The following 2 types is allow for better readability in commands
|
||||||
|
* Admin Command -> Don't run in Threads
|
||||||
|
* User Command -> Used anywhere
|
||||||
|
*/
|
||||||
|
export const AdminCommand = [
|
||||||
|
ChannelType.GuildText
|
||||||
|
]
|
||||||
|
|
||||||
|
export const UserCommand = [
|
||||||
|
ChannelType.GuildText,
|
||||||
|
ChannelType.PublicThread,
|
||||||
|
ChannelType.PrivateThread
|
||||||
|
]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the configuration we are editing/taking from is a Server Config
|
* Check if the configuration we are editing/taking from is a Server Config
|
||||||
* @param key name of command we ran
|
* @param key name of command we ran
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ export async function clearChannelInfo(filename: string, channel: TextChannel, u
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
console.log(cleanedHistory)
|
|
||||||
return cleanedHistory
|
return cleanedHistory
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user