0.3.0 • Published 2 years ago

qq-guild-bot-es v0.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

qq-guild-bot-es

QQ频道机器人Node.js版本

@tencent-connect/bot-node-sdk进行了封装

config

{
    "appID" : "your appid",
    "token" : "your token"
}

QQGuildBot

var config = require('./config.json');
var QQGuildBot = require('qq-guild-bot-es')(config);

ws

'use strict';

var config = require('./config.json');
var QQGuildBot = require('qq-guild-bot-es')(config);

// ws
var ws = QQGuildBot.createWS();

// listen
ws.on('READY', data => {
    console.log('[READY] 事件接收 :', data);
});
ws.on('ERROR', data => {
    console.log('[ERROR] 事件接收 :', data);
});
ws.on('GUILDS', data => {
    console.log('[GUILDS] 事件接收 :', data);
});
ws.on('GUILGUILD_MEMBERSDS', data => {
    console.log('[GUILGUILD_MEMBERSDS] 事件接收 :', data);
});
ws.on('DIRECT_MESSAGE', data => {
    console.log('[DIRECT_MESSAGE] 事件接收 :', data);
});
ws.on('AUDIO_ACTION', data => {
    console.log('[AUDIO_ACTION] 事件接收 :', data);
});
ws.on('AT_MESSAGES', data => {
    console.log('[AT_MESSAGES] 事件接收 :', data);
});

api

userInfo

获取自己的用户信息

'use strict';

var config = require('./config.json');
var QQGuildBot = require('qq-guild-bot-es')(config);

var test = async function(){
    try{
        var userInfo = await QQGuildBot.userInfo();
        console.log(userInfo);
    }catch(e){
        console.log(e);
    }
};

test();

return

{
  id: 'xxx',
  username: 'xxx',
  avatar: 'xxx',
  union_openid: 'xxx',
  union_user_account: ''
}

guildList

获取频道列表

'use strict';

var config = require('./config.json');
var QQGuildBot = require('qq-guild-bot-es')(config);

var test = async function(){
    try{
        var guilds = await QQGuildBot.guildList();
        
        console.log(guilds);
    }catch(e){
        console.log(e);
    }
};

test();

return

[
  {
    id: 'xxx',
    name: 'xxx',
    icon: 'xxx',
    owner: false
  }
]

guildInfo

获取频道详情

'use strict';

var config = require('./config.json');
var QQGuildBot = require('qq-guild-bot-es')(config);

var test = async function(){
    try{
        // guildId
        var guildId = 'xxx';

        // guild
        var guild = await QQGuildBot.guildInfo(guildId);
        console.log(guild);
    }catch(e){
        console.log(e);
    }
};

test();

return

{
  id: 'xxx',
  name: 'xxx',
  owner_id: 'xxx',
  owner: false,
  member_count: 3,
  max_members: 300,
  description: ''
}

guildChannelList

获取子频道列表

'use strict';

var config = require('./config.json');
var QQGuildBot = require('qq-guild-bot-es')(config);

var test = async function(){
    try{
        // guild id
        var guildId = 'xxx';

        // guild channels
        var guildChannels = await QQGuildBot.guildChannelList(guildId);
        console.log(guildChannels);
    }catch(e){
        console.log(e);
    }
};

test();

return

[
  {
    id: 'xxx',
    guild_id: 'xxx',
    name: '很高兴遇见你',
    type: 4,
    position: 2,
    parent_id: '0',
    owner_id: '0',
    sub_type: 0
  },
]

guildChannelInfo

获取子频道详情

'use strict';

var config = require('./config.json');
var QQGuildBot = require('qq-guild-bot-es')(config);

var test = async function(){
    try{
        // guild channel id
        var guildChannelId = 'xxx';

        // guild channel
        var guildChannel = await QQGuildBot.guildChannelInfo(guildChannelId);
        console.log(guildChannel);
    }catch(e){
        console.log(e);
    }
};

test();

return

{
  id: 'xxx',
  guild_id: 'xxx',
  name: '很高兴遇见你',
  type: 4,
  position: 2,
  owner_id: '0',
  sub_type: 0
}

guildChannelAdd

创建子频道

'use strict';

var config = require('./config.json');
var QQGuildBot = require('qq-guild-bot-es')(config);

var test = async function(){
    try{
        // guild id
        var guildId = 'xxx';

        // guild channel info
        var guildChannelInfo        = {};
        guildChannelInfo.name       = 'test channel name';
        guildChannelInfo.type       = 0;
        guildChannelInfo.sub_type   = 0;
        // guildChannelInfo.position = 0;
        // guildChannelInfo.parent_id = 0;

        // guild channel add
        var guildChannel = await QQGuildBot.guildChannelAdd(guildId, guildChannelInfo);
        console.log(guildChannel);
    }catch(e){
        console.log(e);
    }
};

test();

return

{
  id: 'xxx',
  guild_id: 'xxx',
  name: 'test channel name',
  type: 1,
  position: 1640078491,
  owner_id: 'xxx',
  sub_type: 0
}

guildChannelUpdate

修改子频道

'use strict';

var config = require('./config.json');
var QQGuildBot = require('qq-guild-bot-es')(config);

var test = async function(){
    try{
        // guild channel id
        var guildChannelId = 'xxx';

        // guild channel info
        var guildChannelInfo = {};
        guildChannelInfo.name = 'test channel name1';
        guildChannelInfo.type = 0;

        // guild channel update
        var guildChannel = await QQGuildBot.guildChannelUpdate(guildChannelId, guildChannelInfo);
        console.log(guildChannel);
    }catch(e){
        console.log(e);
    }
};

test();

return

{
  id: 'xxx',
  guild_id: 'xxx',
  name: 'test channel name1',
  type: 0,
  position: 6,
  parent_id: 'xxx',
  owner_id: 'xxx',
  sub_type: 0,
  private_type: 0
}

guildChannelDel

删除子频道

'use strict';

var config = require('./config.json');
var QQGuildBot = require('qq-guild-bot-es')(config);

var test = async function(){
    try{
        // guild channel id
        var guildChannelId = 'xxx';

        // guild channel del
        var guildChannel = await QQGuildBot.guildChannelDel(guildChannelId);
        console.log(guildChannel);
    }catch(e){
        console.log(e);
    }
};

test();

return

{
  id: 'xxx',
  type: 0,
  name: 'test channel name1',
  guild_id: 'xxx'
}

guildChannelPermissions

获取子频道权限

'use strict';

var config = require('./config.json');
var QQGuildBot = require('qq-guild-bot-es')(config);

var test = async function(){
    try{
        // guild channel id
        var guildChannelId = 'xxx';

        // user id
        var userId = 'xxx';

        // guild channel permissions
        var guildChannelPermissions = await QQGuildBot.guildChannelPermissions(guildChannelId, userId);
        console.log(guildChannelPermissions);
    }catch(e){
        console.log(e);
    }
};

test();

return

{
  channel_id: 'xxx',
  user_id: 'xxx',
  permissions: '6'
}

guildChannelPermissionsUpdate

修改子频道权限

'use strict';

var config = require('./config.json');
var QQGuildBot = require('qq-guild-bot-es')(config);

var test = async function(){
    try{
        // guild channel id
        var guildChannelId = 'xxx';

        // user id
        var userId = 'xxx';

        // options
        var options = {
            remove : '2'
        };

        // guild channel permissions update
        var res = await QQGuildBot.guildChannelPermissionsUpdate(guildChannelId, userId, options);
        console.log(res);
    }catch(e){
        console.log(e);
    }
};

test();

return

{
  channel_id: 'xxx',
  user_id: 'xxx',
  permissions: '6'
}

guildMemberList

获取频道成员列表

'use strict';

var config = require('./config.json');
var QQGuildBot = require('qq-guild-bot-es')(config);

var test = async function(){
    try{
        // guild id
        var guildId = 'xxx';

        // queryParams
        var queryParams = {
            after: 0,
            limit: 10
        };

        // guild members
        var guildMembers = await QQGuildBot.guildMemberList(guildId, queryParams);
        console.log(guildMembers);
    }catch(e){
        console.log(e);
    }
};

test();

return

[
  {
    user: {
      id: 'xxx',
      username: 'xxx',
      avatar: 'xxx',
      bot: false,
      public_flags: 0,
      system: false
    },
    nick: '',
    roles: [ '4' ],
    joined_at: '2021-12-15T15:20:47+08:00',
    deaf: false,
    mute: false,
    pending: false
  }
]

guildMemberInfo

获取频道成员详情

'use strict';

var config = require('./config.json');
var QQGuildBot = require('qq-guild-bot-es')(config);

var test = async function(){
    try{
        // guildId
        var guildId = 'xxx';

        // userId
        var userId = 'xxx';

        var guildMember = await QQGuildBot.guildMemberInfo(guildId, userId);
        console.log(guildMember);
    }catch(e){
        console.log(e);
    }
};

test();

return

{
  user: {
    id: 'xxx',
    username: 'xxx',
    avatar: 'xxx',
    bot: true,
    public_flags: 0,
    system: false
  },
  nick: '',
  roles: [ '2' ],
  joined_at: '2021-12-22T16:36:00+08:00',
  deaf: false,
  mute: false,
  pending: false
}

guildMemberDel

#删除频道成员

'use strict';

var config = require('./config.json');
var QQGuildBot = require('qq-guild-bot-es')(config);

var test = async function(){
    try{
        // guildId
        var guildId = 'xxx';

        // userId
        var userId = 'xxx';

        // del
        await QQGuildBot.guildMemberDel(guildId, userId);
    }catch(e){
        console.log(e);
    }
};

test();

return

guildRoleList

获取频道身份组列表

'use strict';

var config = require('./config.json');
var QQGuildBot = require('qq-guild-bot-es')(config);

var test = async function(){
    try{
        // guild id
        var guildId = 'xxx';

        // guild roles
        var guildRoles = await QQGuildBot.guildRoleList(guildId);
        console.log(guildRoles);
    }catch(e){
        console.log(e);
    }
};

test();

return

{
  guild_id: 'xxx',
  roles: [
    {
      id: '4',
      name: '创建者',
      color: 4294927682,
      hoist: 1,
      number: 1,
      member_limit: 1
    },
  ],
  role_num_limit: '30'
}

guildRoleAdd

创建频道身份组

'use strict';

var config = require('./config.json');
var QQGuildBot = require('qq-guild-bot-es')(config);

var test = async function(){
    try{
        // guild id
        var guildId = 'xxx';

        // guild role info
        var guildRoleInfo = {};
        guildRoleInfo.name = 'test name';
        guildRoleInfo.color = 0;
        guildRoleInfo.hoist = 0;

        // guild role add
        var guildRole = await QQGuildBot.guildRoleAdd(guildId, guildRoleInfo);
        console.log(guildRole);
    }catch(e){
        console.log(e);
    }
};

test();

return

{
  role_id: '10070176',
  role: {
    id: '10070176',
    name: 'test name',
    color: 4278245297,
    hoist: 0,
    number: 0,
    member_limit: 2000
  }
}

guildRoleUpdate

修改频道身份组

'use strict';

var config = require('./config.json');
var QQGuildBot = require('qq-guild-bot-es')(config);

var test = async function(){
    try{
        // guild id
        var guildId = 'xxx';

        // guild role id
        var roleId = 'xxx';

        // guild role info
        var guildRoleInfo = {};
        guildRoleInfo.name = 'test name1';
        guildRoleInfo.color = 0;
        guildRoleInfo.hoist = 0;

        // guild role update
        var guildRole = await QQGuildBot.guildRoleUpdate(guildId, roleId, guildRoleInfo);
        console.log(guildRole);
    }catch(e){
        console.log(e);
    }
};

test();

return

{
  guild_id: '4270944985244709406',
  role_id: '10070115',
  role: {
    id: '10070115',
    name: 'test name',
    color: 4278245297,
    hoist: 0,
    number: 0,
    member_limit: 2000
  }
}

guildRoleDel

删除频道身份组

'use strict';

var config = require('./config.json');
var QQGuildBot = require('qq-guild-bot-es')(config);

var test = async function(){
    try{
        // guild id
        var guildId = 'xxx';

        // guild role id
        var guildRoleId = 'xxx';

        // guild role del
        await QQGuildBot.guildRoleDel(guildId, guildRoleId);
    }catch(e){
        console.log(e);
    }
};

test();

return

guildRoleMemberAdd

创建频道身份组成员

'use strict';

var config = require('./config.json');
var QQGuildBot = require('qq-guild-bot-es')(config)

var test = async function(){
    try{
        // guild id
        var guildId = 'xxx';

        // guild role id
        var guildRoleId = 'xxx';

        // user id
        var userId = 'xxx';
        
        // guild channel id
        var guildChannelId = '';

        // add
        await QQGuildBot.guildRoleMemberAdd(guildId, guildRoleId, userId, guildChannelId);
    }catch(e){
        console.log(e);
    }
};

test();

return

guildRoleMemberDel

guildRoleMemberDel

'use strict';

var config = require('./config.json');
var QQGuildBot = require('qq-guild-bot-es')(config)

var test = async function(){
    try{
        // guild id
        var guildId = 'xxx';

        // guild role id
        var guildRoleId = 'xxx';

        // user id
        var userId = 'xxx';
        
        // guild channel id
        var guildChannelId = '';

        // del
        await QQGuildBot.guildRoleMemberDel(guildId, guildRoleId, userId, guildChannelId);
    }catch(e){
        console.log(e);
    }
};

test();

return

version

0.1.0.20220105

  1. qq guild bot es

0.0.9.20211231

  1. create ws
  2. create ws md

0.0.8.20211230

  1. guild member list
  2. guild member info
  3. guild member del
  4. guild role member add
  5. guild role member del
  6. guild message list
  7. guild message send

0.0.7.20211229

  1. guild channel update
  2. guild channel del
  3. guild channel permissions
  4. guild channel permissions update

0.0.6.20211221

  1. guild channel add

0.0.5.20211217

  1. userinfo
  2. guild channel list
  3. guild channel info

0.0.4.20211216

  1. create guild role
  2. guild role add
  3. guild role update
  4. config
  5. config md
  6. guild role del
  7. guild.js
  8. guild-role.js
  9. fix md

0.0.3.20211215

  1. add node sdk example
  2. add util
  3. get client
  4. get my guilds
  5. get guild
  6. get guild info
  7. get guild list
  8. get guild roles
  9. qq-guild-bot-es
  10. get guild list ok
  11. get guild info ok
  12. get guild roles ok

0.0.2.20211213

  1. add jest
  2. add jsdoc
  3. add mit
  4. jsdoc and jest ok

0.0.1.20211210

  1. project init