Bot.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { NCWebsocket } from 'node-napcat-ts'
  2. import {Botconfig as config, load, saveConfig} from './config.js'
  3. import { runplugins } from './Plugins.js';
  4. export class Bot extends NCWebsocket{
  5. constructor() {
  6. super({
  7. protocol: config.bot.protocol,
  8. host: config.bot.host,
  9. port: config.bot.port,
  10. accessToken: config.bot.accessToken,
  11. throwPromise: config.bot.throwPromise,
  12. reconnection: {
  13. enable: config.bot.reconnection.enable,
  14. attempts: config.bot.reconnection.attempts,
  15. delay: config.bot.reconnection.delay
  16. }
  17. });
  18. }
  19. async reload(){
  20. let isload = await load
  21. if(isload.isuplad){
  22. isload.isuplad=false;
  23. if (isload.isGroupMessage) {
  24. this.send_group_msg({
  25. group_id: Number(isload.id),
  26. message:[{
  27. type:"text",
  28. data:{
  29. text: `加载插件 ${isload.name} 成功`
  30. }
  31. }]
  32. })
  33. }else{
  34. this.send_private_msg({
  35. user_id:Number(isload.id),
  36. message:[{
  37. type:"text",
  38. data:{
  39. text:`加载插件 ${isload.name} 成功`
  40. }
  41. }]
  42. })
  43. }
  44. saveConfig("load", isload)
  45. }
  46. }
  47. async run(){
  48. try {
  49. await this.connect()
  50. await runplugins()
  51. await this.reload()
  52. console.log('启动成功!')
  53. } catch (error) {
  54. console.error(error)
  55. }
  56. }
  57. }