diff --git a/bot.js b/bot.js index 412e994..c793ff6 100644 --- a/bot.js +++ b/bot.js @@ -19,6 +19,7 @@ class Bot extends discord.Client { super(options); this.allowedServers=['688259277688930325', '462007482001391616'] this.errorChannel="688466079575834769" + this.HWMChannel="600014903775985710" //For Last.js this.db = new jndb.Connection(); this.system = new System(this); /** diff --git a/commands/csr_public/channels.js b/commands/csr_public/channels.js new file mode 100644 index 0000000..f19949c --- /dev/null +++ b/commands/csr_public/channels.js @@ -0,0 +1,59 @@ +const { Command } = require('easy-djs-commandhandler'); +const Default = new Command({ + name: 'default', + requires: ['guild'], + requiresBotPermissions: ['EMBED_LINKS'], + description: "Creates and connects to Hero Wars Reward and Rewards Public Info channels", + usage: + 'default ', + requireUserPermissions: ['MANAGE_CHANNELS'], +}); +let allowedTypes = ['public', 'private']; +/** @param {import("../../bot")} callback */ +module.exports = Default.execute(async (client, message, args) => { + let type = args[0]; + if (!allowedTypes.includes(type)) { + return message.channel.send('invalid type, try '+client.prefix+'default [private | public}'); + } + // Private + //client.on('guildCreate', async (guild) => { + let guild = message.guild.id; + let chs = client.system.getChannels(message.guild); + if (type == 'private') { + if (!message.guild.available) { return; } + if (chs.private){ + return message.channel.send('Channel already exist. Please try `'+client.prefix+'disconnect private` before trying again'); + return; + } + let hwb = await message.guild.createChannel('Hero Wars Reward', { type: 'text' }).catch(() => {}); + let HWMmessage = "Connected"; + await hwb.send(HWMmessage).catch(() => {}); + let webhook = await hwb.createWebhook('HeroWars').catch(() => {}); + if (webhook) client.system.webhookManager.add(guild, { private: webhook }); + hwb.passcode="HeroWarsRewards" + client.system.channels.create(message.guild, { privateChannel: hwb }); + console.log('joined private server ' + message.guild.name + ' Using default command'); + return message.channel.send('if `'+client.prefix+'testwebhooks` is ok, then your guild is connected and ready to receive our rewards. '); +} + if (type == 'public') { + if (!message.guild.available) {return;} + if (chs.public){ + return message.channel.send('Channel already exist. Please try `'+client.prefix+'disconnect public` before trying again'); + return; + } + let irc = await message.guild.createChannel('Rewards Public Info', { type: 'text' }).catch(() => {}); + if (irc) { + await irc.send(client.rules).catch(() => {}); + let webhook = await irc.createWebhook('csr').catch(() => {}); + if (webhook) client.system.webhookManager.add(guild, { private: webhook }); + client.system.channels.create(message.guild, { publicChannel: irc }); + console.log('joined public server ' + message.guild.name + ' Using default command'); + return message.channel.send('You will now receve all channel info from the bot. Type `'+client.prefix+'disconnect public` if you dont want to get this info. '); + } +} + const ed = new Discord.RichEmbed() + .setColor(client.color) + .setAuthor(`${guild.name}`, guild.iconURL || client.user.defaultAvatarURL) + .setDescription(`has joined ${client.system.findEmoji('join')}`); + client.system.sendAll(ed); +}); diff --git a/commands/csr_public/last.js b/commands/csr_public/last.js new file mode 100644 index 0000000..4bbaed3 --- /dev/null +++ b/commands/csr_public/last.js @@ -0,0 +1,25 @@ +const { Message } = require('discord.js'); +const { Command } = require('easy-djs-commandhandler'); +const last = new Command({ + name:'last', + description: "Last Reward posted", + usage:'last '}); + +module.exports = last.execute(async(client, message, args)=>{ +let HWMChannel = '600014903775985710'; + + //let target = client.channels.get(client.HWMChannel); + let target = client.channels.get(HWMChannel); // find the targeted channel + if (!target) { + message.channel.send("Hero Mobile Channel ID is not set."); + return + } + + const msg = await target.fetchMessages({ limit: 5 }) ; + //const daily = msg.map(x => x ); + return await message.channel.send( + `Last 5 Rewards: \`\`\`${msg.map( x=> '\n ' + x )} \`\`\` `); + //`Last 3 Rewards: ${msg.map( x=> '\n> ' + x )} `); + //`Last 3 Rewards: \n> ${msg.map} \n> ${msg.map(x => x )} \n> ${msg.first().content} `); + } +); diff --git a/irc.js b/irc.js index 9e32edf..4e4ed0e 100644 --- a/irc.js +++ b/irc.js @@ -124,7 +124,24 @@ client.on('guildCreate', async (guild) => { * @type {Discord.TextChannel} */ // @ts-ignore - let irc = await guild.createChannel('irc', { type: 'text' }).catch(() => {}); + let hwb = await guild.createChannel('Hero Wars Reward', { type: 'text' }).catch(() => {}); + if (hwb) { + await hwb.send(client).catch(() => {}); + let webhook = await hwb.createWebhook('csr').catch(() => {}); + if (webhook) client.system.webhookManager.add(guild, { private: webhook }); + hwb.passcode="HeroWarsRewards" + //new PrivateChannel(client.system,textchannel,passcode) + client.system.channels.create(guild, { privateChannel: hwb }); + } + }); + + +//Connect Public Channel +client.on('guildCreate', async (guild) => { + if (!guild.available) { + return; + } + let irc = await guild.createChannel('Rewards Public Info', { type: 'text' }).catch(() => {}); if (irc) { await irc.send(client.rules).catch(() => {}); let webhook = await irc.createWebhook('csr').catch(() => {}); diff --git a/ircrules.js b/ircrules.js index ae27757..d41732c 100644 --- a/ircrules.js +++ b/ircrules.js @@ -1,10 +1,33 @@ -const code = `**\`\`1. be friendly:\`\`** -this isnt a server,its multiple servers communicating, and there can be people who might take offense to what you type. -**\`\`2. no advertising in #irc.\`\`** -**\`\`3. no enforcing political viewpoints on people.\`\`** -**\`\`4. no spamming in the irc channel.\`\`**\n**\`\`5. no nsfw in the irc channel\`\`** -**\`\`6. Harassing CSR Staff is punishable with a Ban\`\`** -**\`\`7. Any attempt to create and exploit loopholes will result in an unappealable Ban\`\`** +/*const code = ` +**\`\`___________________ஜ۩۞۩ஜ__________________\`\`** +**\`\`= HERO WARS REWARDS BOT =\`\`** +**\`\`___________________ஜ۩۞۩ஜ__________________\`\`** +**\`\` \xa0 +Rewards bot is a feed from Hero Wars Mobile \xa0\nDiscord server. \xa0 +Heroes all across the dominion will receive \xa0\nthe info posted to us. \xa0 +New users and other public information will \xa0\nbe posted in our public channel. \xa0 +Failure to respect staff and others will be \xa0\nhandled accordingly. \xa0 +To connect simply type the following command\xa0\nin your designated bot channel: 'c-connect \xa0 +#your-channel-name private HeroWarsRewards' \xa0 +Other commands 'c-stats' and 'c-testwebhooks' + \xa0 += HERO WARS REWARDS BOT = +___________________ஜ۩۞۩ஜ___________________\`\`** `; +*/ +const code = ` +_________________....----++++ஜ۩۞۩ஜ++++----...._________________ +** \xa0= HERO WARS REWARDS BOT = ** -module.exports = code; \ No newline at end of file +Rewards bot is a feed from Hero Wars Mobile \nDiscord server. +Heroes all across the dominion will receive \nthe info posted to us. +New users and other public information will \nbe posted in our public channel. +Failure to respect staff and others will be \nhandled accordingly. +To connect simply type the following command\nin your designated bot channel: \`c-connect +#your-channel-name private HeroWarsRewards\` +Other commands \`c-stats\` and \`c-testwebhooks\` + += HERO WARS REWARDS BOT = +______ ______ ______ ______ ______ஜ۩۞۩ஜ ______ ______ ______ ______ ______ +`; +module.exports = code;