/[sudobot]/branches/4.x/src/services/AIChat.ts
ViewVC logotype

Annotation of /branches/4.x/src/services/AIChat.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (hide annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 3577 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 rakinar2 577 /**
2     * This file is part of SudoBot.
3     *
4     * Copyright (C) 2021-2022 OSN Inc.
5     *
6     * SudoBot is free software; you can redistribute it and/or modify it
7     * under the terms of the GNU Affero General Public License as published by
8     * the Free Software Foundation, either version 3 of the License, or
9     * (at your option) any later version.
10     *
11     * SudoBot is distributed in the hope that it will be useful, but
12     * WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU Affero General Public License for more details.
15     *
16     * You should have received a copy of the GNU Affero General Public License
17     * along with SudoBot. If not, see <https://www.gnu.org/licenses/>.
18     */
19    
20     import axios from "axios";
21     import { Message, Util } from "discord.js";
22     import { emoji } from "../utils/Emoji";
23     import Service from "../utils/structures/Service";
24     import { parseUser } from '../utils/parseInput';
25     import MessageEmbed from "../client/MessageEmbed";
26     import { generateInfractionDescription } from "../utils/util";
27    
28     export default class AIChat extends Service {
29     enabled = false;
30    
31     async generateReply(input: string, message: Message): Promise<string | null> {
32     if (!process.env.BRAIN_API_URL) {
33     return null;
34     }
35    
36     if (input.toLowerCase().startsWith('say ')) {
37     return input.substring('say '.length - 1);
38     }
39    
40     const matches = input.trim().toLowerCase().match(/^(f|fake)?ban( +)(<\@(\&)?\d+>)/gim);
41    
42     if (matches) {
43     if (!message.member?.roles.cache.has(this.client.config.props[message.guildId!].mod_role)) {
44     return "Are you kidding me? You don't have permission to do that.";
45     }
46    
47     const userMention = matches[0].split(/ +/)[1];
48     const user = await parseUser(this.client, userMention);
49    
50     if (user) {
51     user.send({
52     embeds: [
53     new MessageEmbed({
54     author: {
55     name: `You have been banned in ${message.guild!.name}`,
56     iconURL: message.guild!.iconURL() ?? undefined
57     },
58     color: 0xf14a60,
59     description: generateInfractionDescription(this.client, message.guildId!, 'ban_message') + "\n|| Of course this is fake :joy: ||",
60     fields: [
61     {
62     name: 'Reason',
63     value: "This is an Automatic ban"
64     },
65     {
66     name: 'Infraction ID',
67     value: '0000'
68     }
69     ]
70     })
71     ]
72     }).catch(console.error);
73     }
74    
75     return `${emoji('check')} Successfully banned ${userMention}${matches[0].trim().startsWith('f') ? ' || This is fake :joy: LMAO ||' : ''}`;
76     }
77    
78     try {
79     const response = await axios.get(`${process.env.BRAIN_API_URL}&${new URLSearchParams({
80     msg: input
81     }).toString()}`);
82    
83     console.log(response);
84    
85     if (!response.data.cnt) {
86     throw Error();
87     }
88    
89     return response.data.cnt.replace(/<(\/?)tips>/gi, '');
90     }
91     catch (e) {
92     console.log(e);
93     return null;
94     }
95     }
96     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26