Skip to content

Commit 314e514

Browse files
committed
refactor command handling on 1country and llms bots
1 parent 1379b1b commit 314e514

File tree

4 files changed

+32
-46
lines changed

4 files changed

+32
-46
lines changed

src/config.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export default {
3838
model: 'chat-bison',
3939
minimumBalance: 0,
4040
isEnabled: Boolean(parseInt(process.env.LLMS_ENABLED ?? '1')),
41-
prefixes: { bardPrefix: ['b.', 'B.'] },
4241
pdfUrl: process.env.PDF_URL ?? '',
4342
processingTime: 300000
4443
},
@@ -96,10 +95,7 @@ export default {
9695
defaultRPC: 'https://api.harmony.one',
9796
restrictedPhrases: process.env.RESTRICTED_PHRASES
9897
? process.env.RESTRICTED_PHRASES.split(', ')
99-
: ['metamask', 'walletconnect'],
100-
registerPrefix: process.env.COUNTRY_PREFIX
101-
? process.env.COUNTRY_PREFIX.split(',')
102-
: ['+', '%']
98+
: ['metamask', 'walletconnect']
10399
},
104100
voiceMemo: {
105101
isEnabled: Boolean(parseInt(process.env.VOICE_MEMO_ENABLED ?? '1')),

src/modules/1country/index.ts

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,21 @@ import { type OnMessageContext, type OnCallBackQueryData, type PayableBot, Reque
1111
import { type BotPayments } from '../payment'
1212
import { getCommandNamePrompt, getUrl } from './utils/'
1313
import { isAdmin } from '../open-ai/utils/context'
14-
import config from '../../config'
1514
import { MAX_TRIES, sendMessage } from '../open-ai/helpers'
1615
import { sleep } from '../sd-images/utils'
1716
import { isValidUrl } from '../open-ai/utils/web-crawler'
1817
import { now } from '../../utils/perf'
1918

20-
export const SupportedCommands = {
21-
register: { name: 'rent' },
22-
visit: { name: 'visit' },
23-
check: { name: 'check' },
24-
cert: { name: 'cert' },
25-
nft: { name: 'nft' },
26-
set: { name: 'set' }
19+
export enum SupportedCommands {
20+
register = 'rent',
21+
visit = 'visit',
22+
check = 'check',
23+
cert = 'cert',
24+
nft = 'nft',
25+
set = 'set'
2726
}
2827

29-
// enum SupportedCommands {
30-
// CHECK = "check",
31-
// NFT = "nft",
32-
// VISIT = "visit",
33-
// CERT = "cert",
34-
// RENEW = "renew",
35-
// NOTION = "notion",
36-
// SUBDOMAIN = "subdomain",
37-
// }
28+
const COUNTRY_PREFIX_LIST = ['+', '%']
3829

3930
export class OneCountryBot implements PayableBot {
4031
public readonly module = 'OneCountryBot'
@@ -58,7 +49,7 @@ export class OneCountryBot implements PayableBot {
5849
ctx: OnMessageContext | OnCallBackQueryData
5950
): boolean {
6051
const hasCommand = ctx.hasCommand(
61-
Object.values(SupportedCommands).map((command) => command.name)
52+
Object.values(SupportedCommands).map((command) => command)
6253
)
6354
const hasPrefix = this.hasPrefix(ctx.message?.text ?? '')
6455
if (hasPrefix && ctx.session.oneCountry.lastDomain) {
@@ -68,7 +59,7 @@ export class OneCountryBot implements PayableBot {
6859
}
6960

7061
private hasPrefix (prompt: string): boolean {
71-
const prefixList = config.country.registerPrefix
62+
const prefixList = COUNTRY_PREFIX_LIST
7263
for (let i = 0; i < prefixList.length; i++) {
7364
if (prompt.toLocaleLowerCase().startsWith(prefixList[i])) {
7465
return true
@@ -88,17 +79,17 @@ export class OneCountryBot implements PayableBot {
8879
return
8980
}
9081

91-
if (ctx.hasCommand(SupportedCommands.visit.name)) {
82+
if (ctx.hasCommand(SupportedCommands.visit)) {
9283
await this.onVistitCmd(ctx)
9384
return
9485
}
9586

96-
if (ctx.hasCommand(SupportedCommands.check.name)) {
87+
if (ctx.hasCommand(SupportedCommands.check)) {
9788
await this.onCheckCmd(ctx)
9889
return
9990
}
10091

101-
if (ctx.hasCommand(SupportedCommands.register.name)) {
92+
if (ctx.hasCommand(SupportedCommands.register)) {
10293
await this.onRegister(ctx)
10394
return
10495
}
@@ -108,17 +99,17 @@ export class OneCountryBot implements PayableBot {
10899
return
109100
}
110101

111-
if (ctx.hasCommand(SupportedCommands.nft.name)) {
102+
if (ctx.hasCommand(SupportedCommands.nft)) {
112103
await this.onNftCmd(ctx)
113104
return
114105
}
115106

116-
if (ctx.hasCommand(SupportedCommands.cert.name)) {
107+
if (ctx.hasCommand(SupportedCommands.cert)) {
117108
await this.onCertCmd(ctx)
118109
return
119110
}
120111

121-
if (ctx.hasCommand(SupportedCommands.set.name)) {
112+
if (ctx.hasCommand(SupportedCommands.set)) {
122113
await this.onSet(ctx)
123114
return
124115
}

src/modules/llms/helpers.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import config from '../../config'
21
import {
32
type OnMessageContext,
43
type OnCallBackQueryData,
@@ -7,22 +6,22 @@ import {
76
type ChatPayload
87
} from '../types'
98
import { type ParseMode } from 'grammy/types'
10-
// import { getChatModel, getChatModelPrice, getTokenNumber } from "./api/openAi";
119
import { LlmsModelsEnum } from './types'
1210
import { type Message } from 'grammy/out/types'
1311
import { llmAddUrlDocument } from './api/llmApi'
1412

15-
export const SupportedCommands = {
16-
bardF: { name: 'bard' },
17-
bard: { name: 'b' },
18-
j2Ultra: { name: 'j2-ultra' },
19-
sum: { name: 'sum' },
20-
ctx: { name: 'ctx' },
21-
pdf: { name: 'pdf' }
13+
export enum SupportedCommands {
14+
bardF = 'bard',
15+
bard = 'b',
16+
j2Ultra = 'j2-ultra',
17+
sum = 'sum',
18+
ctx = 'ctx',
19+
pdf = 'pdf'
2220
}
2321

2422
export const MAX_TRIES = 3
2523
const LLAMA_PREFIX_LIST = ['*']
24+
const BARD_PREFIX_LIST = ['b.', 'B.']
2625

2726
export const isMentioned = (
2827
ctx: OnMessageContext | OnCallBackQueryData
@@ -51,7 +50,7 @@ export const hasLlamaPrefix = (prompt: string): string => {
5150
}
5251

5352
export const hasBardPrefix = (prompt: string): string => {
54-
const prefixList = config.llms.prefixes.bardPrefix
53+
const prefixList = BARD_PREFIX_LIST
5554
for (let i = 0; i < prefixList.length; i++) {
5655
if (prompt.toLocaleLowerCase().startsWith(prefixList[i])) {
5756
return prefixList[i]

src/modules/llms/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class LlmsBot implements PayableBot {
6363
ctx: OnMessageContext | OnCallBackQueryData
6464
): boolean {
6565
const hasCommand = ctx.hasCommand(
66-
Object.values(SupportedCommands).map((command) => command.name)
66+
Object.values(SupportedCommands).map((command) => command)
6767
)
6868
if (isMentioned(ctx)) {
6969
return true
@@ -117,12 +117,12 @@ export class LlmsBot implements PayableBot {
117117
return
118118
}
119119

120-
if (ctx.hasCommand(SupportedCommands.pdf.name)) {
120+
if (ctx.hasCommand(SupportedCommands.pdf)) {
121121
await this.onPdfCommand(ctx)
122122
return
123123
}
124124

125-
if (ctx.hasCommand(SupportedCommands.bard.name) || ctx.hasCommand(SupportedCommands.bardF.name)) {
125+
if (ctx.hasCommand(SupportedCommands.bard) || ctx.hasCommand(SupportedCommands.bardF)) {
126126
await this.onChat(ctx, LlmsModelsEnum.BISON)
127127
return
128128
}
@@ -142,17 +142,17 @@ export class LlmsBot implements PayableBot {
142142
return
143143
}
144144

145-
if (ctx.hasCommand(SupportedCommands.j2Ultra.name)) {
145+
if (ctx.hasCommand(SupportedCommands.j2Ultra)) {
146146
await this.onChat(ctx, LlmsModelsEnum.J2_ULTRA)
147147
return
148148
}
149149

150-
if (ctx.hasCommand(SupportedCommands.ctx.name)) {
150+
if (ctx.hasCommand(SupportedCommands.ctx)) {
151151
await this.onCurrentCollection(ctx)
152152
return
153153
}
154154

155-
if (ctx.hasCommand(SupportedCommands.sum.name) ||
155+
if (ctx.hasCommand(SupportedCommands.sum) ||
156156
(ctx.message?.text?.startsWith('sum ') && ctx.chat?.type === 'private')
157157
) {
158158
await this.onSum(ctx)

0 commit comments

Comments
 (0)