1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| bot.on('message', function (user, userID, channelID, message, evt) { if (message.substring(0, 1) == '!') { var args = message.substring(1).split(' '); var cmd = args[0]; args = args.splice(1); switch(cmd) { case 'addserver': if (args.length!=3) { bot.sendMessage({ to: channelID, message: '<@'+userID+'> 新增要监测的服务器: `!addserver <csgo/css> <备注名> <IP>`\n参数用空格隔开,参数中不得含空格,不要使用双引号' }); return; } AddServer(args[0], args[1], args[2], userID, channelID); break; } } }
function AddServer(Game, Name, IP, User, ChannelID) { if (Game != "css" && Game != "csgo") { bot.sendMessage({to: ChannelID, message: '<@'+User+'> 游戏类型只能为`css`或`csgo`' }); return; } var result = db.get('servers').find({ name: Name }).value(); if (result) { bot.sendMessage({ to: ChannelID, message: '<@'+User+'> 备注名重复' }); return; } result = db.get('servers').find({ ip: IP }).value(); if (result) { bot.sendMessage({ to: ChannelID, message: '<@'+User+'> IP重复' }); return; } db.get('servers') .push({ game: Game, name: Name, ip: IP}) .write() bot.sendMessage({ to: ChannelID, message: '<@'+User+'> 添加成功' }); }
|