/[sudobot]/trunk/src/App.js
ViewVC logotype

Diff of /trunk/src/App.js

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 5 by rakin, Mon Jul 29 17:28:11 2024 UTC revision 26 by rakin, Mon Jul 29 17:28:16 2024 UTC
# Line 7  const Config = require("./Config"); Line 7  const Config = require("./Config");
7  const Database = require("./Database");  const Database = require("./Database");
8  const Logger = require("./Logger");  const Logger = require("./Logger");
9  const SpamFilter = require("./SpamFilter");  const SpamFilter = require("./SpamFilter");
10    const server = require("./server");
11    const AntiRaid = require("./AntiRaid");
12    const MessageFilter = require("./MessageFilter");
13    const { random } = require("../commands/pixabay");
14    const AFKEngine = require("./AFKEngine");
15    
16  class App {  class App {
17      constructor(rootdir) {      constructor(rootdir) {
18          global.app = App.app = this;          global.app = App.app = this;
19          this.rootdir = rootdir;          this.rootdir = rootdir;
20          this.loadConfig();          this.loadConfig();
21            this.env = process.env;
22    
23          this.client = new Client({          this.client = new Client({
24              partials: ["CHANNEL"],              partials: ["CHANNEL"],
# Line 20  class App { Line 26  class App {
26                  Intents.FLAGS.GUILDS,                  Intents.FLAGS.GUILDS,
27                  Intents.FLAGS.GUILD_MESSAGES,                  Intents.FLAGS.GUILD_MESSAGES,
28                  Intents.FLAGS.DIRECT_MESSAGES,                  Intents.FLAGS.DIRECT_MESSAGES,
29                  Intents.FLAGS.DIRECT_MESSAGE_TYPING                  Intents.FLAGS.DIRECT_MESSAGE_TYPING,
30                    Intents.FLAGS.GUILD_PRESENCES,
31                    Intents.FLAGS.GUILD_MEMBERS,
32                    Intents.FLAGS.GUILD_BANS
33              ]              ]
34          });          });
35    
# Line 29  class App { Line 38  class App {
38          this.commandManager = new CommandManager(path.resolve(__dirname, rootdir, "commands"));          this.commandManager = new CommandManager(path.resolve(__dirname, rootdir, "commands"));
39          this.logger = new Logger();          this.logger = new Logger();
40          this.spamFilter = new SpamFilter();          this.spamFilter = new SpamFilter();
41            this.antiRaid = new AntiRaid();
42            this.messageFilter = new MessageFilter();
43            this.afkEngine = new AFKEngine();
44          this.boot();          this.boot();
45      }      }
46    
47      boot() {      boot() {
48          this.on('ready', () => {          this.on('ready', () => {
49              console.log("Logged in as " + this.client.user.tag);              console.log("Logged in as " + this.client.user.tag);
50    
51                this.client.user.setStatus(random(['dnd', 'idle']));
52                this.client.user.setActivity("over the server", { type: "WATCHING" });
53    
54                server();
55          });          });
56    
57          this.on('messageCreate', async (message) => {          this.on('messageCreate', async (message) => {
58              if (message.author.bot) {              if (message.author.bot || !message.guild || message.channel.type == 'dm') {
59                  return;                  return;
60              }              }
61    
62              await (this.msg = message);              await (this.msg = message);
63                            
64              //await this.spamFilter.start(message);              await this.spamFilter.start(message);
65                await this.messageFilter.start(message, this.commandManager);
66    
67              await this.commandManager.setMessage(message);              await this.commandManager.setMessage(message);
68    
69              const valid = await this.commandManager.valid();              const valid = await this.commandManager.valid();
70              const has = await this.commandManager.has();              const has = await this.commandManager.has();
71              const snippet = await this.commandManager.snippet();              const snippet = await this.commandManager.snippet();
72                const allowed = await this.commandManager.verify();
73                            
74              if (valid && has) {              if (valid && has && allowed) {
75                  await this.exec();                  await this.exec();
76              }              }
77              else if (valid && snippet !== undefined) {              else if (valid && snippet !== undefined) {
# Line 63  class App { Line 82  class App {
82              else if (valid && !has) {              else if (valid && !has) {
83                  await this.commandManager.notFound();                  await this.commandManager.notFound();
84              }              }
85                else if (valid && has && !allowed) {
86                    await this.commandManager.notAllowed();
87                }
88                else if(!valid) {
89                    await this.afkEngine.start(message);
90                }
91          });          });
92    
93          this.on("messageUpdate", async (oldMessage, newMessage) => {          this.on("messageUpdate", async (oldMessage, newMessage) => {
94              if (oldMessage.author.bot)              if (oldMessage.author.bot || oldMessage.content === newMessage.content)
95                  return;                  return;
96    
97              await this.logger.logEdit(oldMessage, newMessage);              await this.logger.logEdit(oldMessage, newMessage);
98          });          });
99    
100    
101            this.on('guildBanAdd', async (ban) => {
102                console.log('test');
103                await this.logger.logBanned(ban);
104            });
105    
106            this.on('guildBanRemove', async (ban) => {
107                console.log('test');
108                await this.logger.logUnbanned(ban);
109            });
110    
111          this.on("messageDelete", async (message) => {          this.on("messageDelete", async (message) => {
112              if (message.author.bot)              if (message.author.bot)
113                  return;                  return;
# Line 95  class App { Line 131  class App {
131              delete this.config.props[guild.id];              delete this.config.props[guild.id];
132              this.config.write();              this.config.write();
133          })          })
134    
135            this.on('guildMemberAdd', async (member) => {
136                console.log('Joined');
137                await this.antiRaid.start(member);
138                await this.logger.logJoined(member);
139            });
140    
141            this.on('guildMemberRemove', async (member) => {
142                await this.logger.logLeft(member);
143            });
144      }      }
145    
146      loadConfig() {      loadConfig() {
# Line 115  class App { Line 161  class App {
161      run() {      run() {
162          this.client.login(process.env.TOKEN);          this.client.login(process.env.TOKEN);
163      }      }
164    
165        tempFileCreate(name) {
166            const fullname = path.join(__dirname, '..', 'tmp', name);
167            const file = fs.createWriteStream(fullname);
168    
169            return {
170                name: fullname,
171                file
172            };
173        }
174  }  }
175    
176  module.exports = App;  module.exports = App;

Legend:
Removed from v.5  
changed lines
  Added in v.26

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26