Skip to content

Commit

Permalink
Merge pull request #18 from wuttinanDEV/dev
Browse files Browse the repository at this point in the history
add send deploy status to channel when start app, add listening event
  • Loading branch information
Th3Fire authored Jul 20, 2018
2 parents 2582926 + 8e24366 commit c5c64a9
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 27 deletions.
82 changes: 60 additions & 22 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ const version = require('../package.json').version;
const config = require('./config')
const constants = require('./constants')
const func = require('./function')
console.log('version : ', version)

const { prefix, channelChatbotId, token } = config

let channel;
let testCH
const log = console.log;

var usersMuted = [];
Expand All @@ -33,28 +33,77 @@ const search = (key, array, remove) => {
}
}

client.on('ready', function (message) {
client.on('ready', message => {
log(chalk.green('Logged in as ' + chalk.blue.underline.bold(`${client.user.tag}!`)));
log(chalk.green('Bot has started, with ' + chalk.hex('#00ff04').bold(client.users.size) + ' users, in ' + chalk.hex('#ff1ef7').bold(client.channels.size) + ' channels of ' + chalk.hex('#56d2ff').bold(client.guilds.size) + ' guilds.'));
channel = client.channels.get(channelChatbotId);
channel.send({
embed: {
title: '📈 Deploy status',
title: '📈Deploy application status',
color: 11400258,
description: `สถานะ: สำเร็จ \nเวลา: ${new Date()} \nบอท: ${client.user.username} \nแชนแนล: ${channel.name} \nversion: ${version}`,
//description: `สถานะ: สำเร็จ \nเวลา: ${new Date()} \nบอท: ${client.user.username} \nแชนแนล: ${channel.name} \nversion: ${version}`,
footer: {
text: 'Build by : Wuttinan Chaoyos [WannCry]'
}
text: 'Developed by : Wuttinan Chaoyos [WannCry]'
},
fields: [
{
name: 'สถานะ:',
value: 'สำเร็จ'
},
{
name: 'ชื่อบอท:',
value: client.user.username
}
, {
name: 'แชนแนล:',
value: channel.name
},
{
name: 'ออนไลน์:',
value: `${client.guilds.size} แชนแนล`
},
{
name: 'เวลา:',
value: new Date()
},
{
name: 'เวอร์ชัน:',
value: version
}
],
timestamp: new Date(),

}
})
client.user.setActivity(`ดูดกัญชา`);
});

client.on('message', function (message) {
if (message.author.bot) return;
client.on("guildMemberAdd", (member) => {
log(`New User "${member.user.username}" has joined "${member.guild.name}"`);
channel.send(`🤝ยินดีต้อนรับ🤝 ${member.user.username} สู่ห้อง 🏠${member.guild.name}🏠`)
});

client.on("guildMemberRemove", (member) => {
log(`"${member.user.username}" has leave from "${member.guild.name}"`);
channel.send(`🤝ลาก่อน🤝 ${member.user.username} ได้ออกจากห้อง 🏠${member.guild.name}🏠`)
});

client.on("guildUpdate", (oldGuild, newGuild) => {
if (oldGuild.name !== newGuild.name) {
log(`ห้อง: ${oldGuild.name} เปลี่ยนชื่อห้องเป็น ${newGuild.name}`);
channel.send(`ห้อง: ${oldGuild.name} เปลี่ยนชื่อห้องเป็น ${newGuild.name}`)
}
});

let myRole = message.member.hasPermission([constants.MANAGE_CHANNELS], false, true)
client.on("userUpdate", (oldUser, newUser) => {
if (oldUser.username !== newUser.username) {
log(`member ${oldUser.username} เปลี่ยนชื่อผู้ใช้เป็น ${newUser.username}`);
channel.send(`member ${oldUser.username} เปลี่ยนชื่อผู้ใช้เป็น ${newUser.username}`)
}
});

client.on('message', async message => {
if (message.author.bot) return;
//private message to bot
if (message.channel.type === 'dm') {
if (message.content.indexOf('!msg') === 0) {
Expand All @@ -67,24 +116,18 @@ client.on('message', function (message) {
}
if (message.channel.id !== channelChatbotId) return;


//check message is command
if (message.content.startsWith(prefix)) {

const args = message.content.slice(prefix.length).trim().split(/ +/g)
const command = args.shift().toLowerCase();

console.log('args : ', args)
console.log('command : ', command)

try {
let commandFile = require(`./commands/${command}`)
commandFile.run(client, message, args)
} catch (err) {
console.error(err)
}


if (message.content === '!unmute') {
if (search(message.author.id, usersMuted, true)) {
message.reply('unmute เรียบร้อย คิดถึงเค้าละซิ้');
Expand All @@ -97,24 +140,19 @@ client.on('message', function (message) {
message.reply('ชิชิชิ บังบาจ mute เค้าไปกะได้ *หากต้องการ unmute พิมพ์ !unmute');
return;
}

return;
}

//check user mute bot? if true not response that user.
if (search(message.author.id, usersMuted, false)) return;

// Simsimi here
try {
func.simsimi(message)
} catch (err) {
console.log(chalk.hex('#ff0000')(`error: ${err}`))
log(chalk.hex('#ff0000')(`error: ${err}`))
}


});

client.on('disconnect', function (event) {
console.log('event : ', event)
})

client.login(token);
2 changes: 1 addition & 1 deletion app/commands/kick.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const constants = require('../constants')
exports.run = (client, message, [mention, ...reason]) => {
exports.run = async (client, message, [mention, ...reason]) => {
let hasPermission = message.member.hasPermission([constants.KICK_MEMBERS], false, true)
if (!hasPermission)
return message.reply("You haven't permission to use this command.")
Expand Down
2 changes: 1 addition & 1 deletion app/commands/ping.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
exports.run = (client, message, args) => {
exports.run = async (client, message, args) => {
message.channel.send('pong!').catch(console.error)
}
4 changes: 2 additions & 2 deletions app/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module.exports = {
token: process.env.BOT_TOKEN || "",
channelChatbotId: process.env.DISCORD_CHANNEL_ID || "",
simsimiOption: {
lc: process.env.SIM_LC || "",
ft: process.env.SIM_FT || "",
lc: process.env.SIM_LC || "th",
ft: process.env.SIM_FT || "0.0",
key: process.env.SIM_KEY || ""
},
prefix: process.env.PREFIX || "!",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simsimi-discord",
"version": "1.0.1",
"version": "1.0.2",
"description": "",
"main": "./app/app.js",
"scripts": {
Expand Down

0 comments on commit c5c64a9

Please sign in to comment.