How to use overridePermissions method in taiko

Best JavaScript code snippet using taiko

message.js

Source:message.js Github

copy

Full Screen

1const { prefixes, devs } = require('../config.json');2const Guild = require('../schemas/guild.js');3const Discord = require("discord.js");4const cooldowns = new Discord.Collection();5function prettyString(string) {6 return string.replace(/_/g, " ").replace(/guild/gi, "Server").replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();})7}8function combine(num) {9 if (num < 0) return -1;10 else if (num == 0) return 0;11 else return (num + combine(num - 1));12}13function lvl(num) {14 num = Math.floor(num / 560);15 for (level = 0; num >= combine(level +1); level++);16 return level;17}18module.exports = async (client, message) => {19 if (!client.ready || message.author.bot) return;20 message.options = await {21 overridePermissions: {22 denied: {23 users: new Map(),24 roles: new Map(),25 channels: new Map()26 },27 allowed: {28 users: new Map(),29 roles: new Map(),30 channels: new Map()31 },32 cooldown: new Map()33 },34 blacklist: {35 commands: [],36 channels: []37 }38 }39 if (message.channel.type == "text" || message.channel.type == "news") {40 if (message.guild.settings && !message.guild.settings.blacklist.channels.includes(message.channel.id) && !message.guild.blacklisted) {41 //Message options42 message.options.overridePermissions = message.guild.overridePermissions43 message.options.blacklist = {44 commands: message.guild.settings.blacklist.commands,45 channels: message.guild.settings.blacklist.channels46 }47 //Leveling48 let leveling = message.guild.settings.leveling49 if (leveling.options.filter.minLength < message.content.length && leveling.options.filter.maxLength > message.content.length && !message.guild.settings.blacklist.channels.includes(message.channel.id)) {50 await Guild.findOne({ guildID: message.guild.id }, (err, guild) => {51 if (err) return console.log("message: Leveling Database Fetch - An error occured: " + err);52 if (!guild) require("../utility/addguild.js")(message.guild);53 if (guild.members.get(message.author.id)) {54 let member = guild.members.get(message.author.id)55 if ((message.createdTimestamp - member.lastxpmessage) > leveling.options.delay * 1000) {56 //New57 let xp = Number(member.xp)58 let level = Number(lvl(xp, (leveling.options.cap || 560)))59 let lvlup = (level + 1) * (leveling.options.cap || 560)60 xp += Math.floor(Math.random() * (leveling.options.xp.max - leveling.options.xp.min) + leveling.options.xp.min)61 //Xp Rewards62 if (leveling.roles.xp.size > 0) {63 let xproles = []64 leveling.roles.xp.forEach((role, xp) => {65 xproles.push({role: role, xp: xp})66 })67 xproles.sort((a, b) => b.xp - a.xp)68 while (xproles.length != 0) {69 if (xproles[0].xp < xp) {70 const xprole = xproles.shift()71 if (!message.member.roles.cache.has(xprole.role)) {72 message.member.roles.add(xprole.role).then(() => {73 let replaceList = [74 {75 replace: "{{user}}",76 with: message.author77 }, {78 replace: "{{tag}}",79 with: message.author.tag80 }, {81 replace: "{{username}}",82 with: message.author.username83 }, {84 replace: "{{xp}}",85 with: xprole.xp86 }, {87 replace: "{{userxp}}",88 with: xp89 }, {90 replace: "{{role}}",91 with: `<@&${xprole.role}>`92 }93 ]94 let rewardmessage = leveling.reward.xp.message95 replaceList.forEach(s => {96 rewardmessage = rewardmessage.replace(s.replace, s.with)97 });98 if (leveling.reward.xp.embed) {99 let rewardEmbed = new Discord.MessageEmbed()100 .setDescription(rewardmessage)101 if (leveling.reward.xp.channel === "default") {102 message.channel.send(rewardEmbed)103 } else {104 client.channels.cache.get(leveling.reward.xp.channel).send(rewardEmbed)105 }106 } else {107 if (guild.settings.leveling.reward.xp.channel === "default") {108 message.channel.send(rewardmessage)109 } else {110 client.channels.cache.get(leveling.reward.xp.channel).send(rewardmessage)111 }112 }113 }).catch(err => {114 if (leveling.reward.xp.channel === "default") {115 message.channel.send({embed: {description: `${message.author} could not reward the user with role <@&${xprole.role}> because it's either deleted, I can't access the role or I can't manage roles. Here is the error: ${err}`}});116 } else {117 client.channels.cache.get(leveling.reward.xp.channel).send({embed: {description: `${message.author} could not reward the user with role <@&${xprole.role}> because it's either deleted, I can't access the role or I can't manage roles.Here is the error: ${err}`}});118 }119 });120 }121 break;122 } else {123 xproles.shift()124 }125 }126 }127 //Levelup128 if (level + 2 > member.level - 1 && xp - (combine(level) * 560) >= lvlup) {129 let replaceList = [130 {131 replace: "{{user}}",132 with: message.author133 }, {134 replace: "{{tag}}",135 with: message.author.tag136 }, {137 replace: "{{username}}",138 with: message.author.username139 }, {140 replace: "{{level}}",141 with: level + 1142 }, {143 replace: "{{xp}}",144 with: xp145 }146 ]147 let levelupmessage = leveling.levelup.message148 replaceList.forEach(s => {149 levelupmessage = levelupmessage.replace(s.replace, s.with)150 });151 //Message152 if (leveling.levelup.send) {153 if (leveling.levelup.embed) {154 let lvlupEmbed = new Discord.MessageEmbed()155 .setDescription(levelupmessage)156 if (leveling.levelup.channel === "default") {157 message.channel.send(lvlupEmbed)158 } else {159 client.channels.cache.get(leveling.levelup.channel).send(lvlupEmbed)160 }161 } else {162 if (leveling.levelup.channel === "default") {163 message.channel.send(levelupmessage)164 } else {165 client.channels.cache.get(leveling.levelup.channel).send(levelupmessage)166 }167 }168 }169 //Rewarding170 let levelroles = []171 leveling.roles.level.forEach((role, level) => {172 levelroles.push({role: role, lvl: level})173 })174 levelroles.sort((a, b) => b.lvl - a.lvl)175 while (levelroles.length != 0) {176 if (levelroles[0].lvl <= level + 1) {177 const lvlrole = levelroles.shift()178 if (!message.member.roles.cache.has(lvlrole.role)) {179 message.member.roles.add(lvlrole.role).then(() => {180 replaceList = [181 {182 replace: "{{user}}",183 with: message.author184 }, {185 replace: "{{tag}}",186 with: message.author.tag187 }, {188 replace: "{{username}}",189 with: message.author.username190 }, {191 replace: "{{level}}",192 with: level + 1193 }, {194 replace: "{{role}}",195 with: `<@&${lvlrole.role}>`196 }197 ]198 let rewardmessage = leveling.reward.level.message199 replaceList.forEach(s => {200 rewardmessage = rewardmessage.replace(s.replace, s.with)201 });202 if (leveling.reward.level.embed) {203 let rewardEmbed = new Discord.MessageEmbed()204 .setDescription(rewardmessage)205 if (leveling.reward.level.channel === "default") {206 message.channel.send(rewardEmbed)207 } else {208 client.channels.cache.get(leveling.reward.level.channel).send(rewardEmbed)209 }210 } else {211 if (leveling.reward.level.channel === "default") {212 message.channel.send(rewardmessage)213 } else {214 client.channels.cache.get(leveling.reward.level.channel).send(rewardmessage)215 }216 }217 }).catch(err => {218 if (leveling.reward.level.channel === "default") {219 message.channel.send({embed: {description: `${message.author} could not reward the user with role <@&${lvlrole.role}> because it's either deleted, I can't access the role or I can't manage roles. Here is the error: ${err}`}});220 } else {221 client.channels.cache.get(leveling.reward.level.channel).send({embed: {description: `${message.author} could not reward the user with role <@&${lvlrole.role}> because it's either deleted, I can't access the role or I can't manage roles. Here is the error: ${err}`}});222 }223 });224 }225 break;226 } else {227 levelroles.shift()228 }229 }230 }231 guild.members.set(message.author.id, {232 username: message.author.tag,233 id: message.author.id,234 xp: xp,235 level: level + 1,236 color: member.color,237 lastxpmessage: message.createdTimestamp238 })239 guild.save().catch(err => message.channel.send(`message: Saving User Profile - An error occured: ${err}`));240 }241 } else {242 guild.members.set(message.author.id, {243 username: message.author.tag,244 id: message.author.id,245 xp: "0",246 level: "0",247 color: "#add8e6",248 lastxpmessage: message.createdTimestamp249 })250 guild.save().catch(err => message.channel.send(`message: Saving User Profile - An error occured: ${err}`));251 }252 });253 }254 }255 }256 for (const thisPrefix of prefixes) {257 if (message.content.toLowerCase().startsWith(thisPrefix)) message.prefix = thisPrefix;258 }259 if (!message.prefix || message.author.bot || !message.content.toLowerCase().startsWith(message.prefix)) return;260 //Arguments261 const args = message.content.slice(message.prefix.length).split(/ +/);262 const commandName = args.shift().toLowerCase();263 //Commands definition264 const command = client.commands.get(commandName) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));265 if (!command) return;266 //Blacklist267 if (message.options.blacklist.commands.includes(command.name)) return message.channel.send("<:cross:724049024943915209> | This command has been blacklisted.")268 if (message.options.blacklist.channels.includes(message.channel.id)) return message.channel.send("<:cross:724049024943915209> | This channel has been blacklisted.")269 //Parameters270 if (command.dev && !devs.includes(message.author.id)) return message.channel.send("<:cross:724049024943915209> | Only Bot Developers can use this command!");271 if (command.guildOnly && message.channel.type == "dm") return message.channel.send("<:cross:724049024943915209> | This command can only be executed in a server!")272 if (command.dmOnly && message.channel.type != "dm") return message.channel.send("<:cross:724049024943915209> | This command can only be executed in DM's!");273 //Permissions274 if (command.reqPermissions && !devs.includes(message.author.id)) {275 if (message.options.overridePermissions) {276 if (message.options.overridePermissions.allowed.users.get(message.author.id)) {277 if (!message.options.overridePermissions.allowed.users.get(message.author.id).includes(command.name)) {278 let missing = [];279 command.reqPermissions.forEach(permission => {280 if (!message.guild.members.cache.get(message.author.id).permissions.has(permission)) missing.push(prettyString(permission))281 })282 if (missing.length > 0) return message.channel.send("<:cross:724049024943915209> | You don't have the required permission(s) to use this command! Missing permission(s): " + missing.join(', '));283 }284 } else {285 let missing = [];286 command.reqPermissions.forEach(permission => {287 if (!message.guild.members.cache.get(message.author.id).permissions.has(permission)) missing.push(prettyString(permission))288 })289 if (missing.length > 0) return message.channel.send("<:cross:724049024943915209> | You don't have the required permission(s) to use this command! Missing permission(s): " + missing.join(', '));290 }291 } else {292 let missing = [];293 command.reqPermissions.forEach(permission => {294 if (!message.guild.members.cache.get(message.author.id).permissions.has(permission)) missing.push(prettyString(permission))295 })296 if (missing.length > 0) return message.channel.send("<:cross:724049024943915209> | You don't have the required permission(s) to use this command! Missing permission(s): " + missing.join(', '));297 }298 }299 if (command.botPermissions) {300 let missing = [];301 command.botPermissions.forEach(perm => {302 if (!message.guild.me.permissions.has(perm)) missing.push(prettyString(perm))303 })304 if (missing.length > 0) return message.channel.send("<:cross:724049024943915209> | I don't have the required permission(s) to execute theis command! Missing permission(s): " + missing.join(', '));305 }306 //Override Permissions307 if (message.options.overridePermissions.denied.users.get(message.author.id)) {308 if (message.options.overridePermissions.denied.users.get(message.author.id).includes(command.name)) return message.channel.send(`<:cross:724049024943915209> | You are not permitted to use \`${command.name}\` command.`);309 }310 if (message.options.overridePermissions.denied.channels.get(message.channel.id)) {311 if (message.options.overridePermissions.denied.channels.get(message.channel.id).includes(command.name)) return message.channel.send(`<:cross:724049024943915209> | You cannot use the \`${command.name}\` command in this channel.`);312 }313 if (message.guild) {314 let roles = []315 message.member.roles.cache.forEach(role => {316 if (message.options.overridePermissions.denied.roles.get(role.id)) {317 if (message.options.overridePermissions.denied.roles.get(role.id).includes(command.name)) roles.push(role.name)318 }319 });320 if (roles.length > 0) return message.channel.send(`<:cross:724049024943915209> | You cannot use the \`${command.name}\` command with these role(s): ${roles.join(", ")}`);321 }322 //Override Cooldown323 if (message.options.overridePermissions.cooldown.get(command.name)) {324 command.cooldown = message.options.overridePermissions.cooldown.get(command.name)325 }326 //Cooldown327 if (!cooldowns.has(command.name)) {328 cooldowns.set(command.name, new Discord.Collection());329 }330 const now = Date.now();331 const timestamps = cooldowns.get(command.name);332 const cooldownAmount = (command.cooldown || 3) * 1000;333 if (!timestamps.has(message.author.id)) {334 timestamps.set(message.author.id, now);335 setTimeout(() => timestamps.delete(message.author.id), cooldownAmount);336 } else {337 const expirationTime = timestamps.get(message.author.id) + cooldownAmount;338 if (now < expirationTime && !devs.includes(message.author.id)) {339 const timeLeft = (expirationTime - now) / 1000;340 return message.reply(`Please wait ${timeLeft.toFixed(1)} more second(s) before reusing the \`${command.name}\` command.`);341 }342 timestamps.set(message.author.id, now);343 setTimeout(() => timestamps.delete(message.author.id), cooldownAmount);344 }345 try {346 message.error = function(error, embed, usage) {347 if (!error) throw new ReferenceError("Error context is not defined");348 if (embed) return this.channel.send({embed: {description: `<:cross:724049024943915209> | ${error}${usage ? `\n\nUsage:\n\`${this.prefix}${command.name} ${usage}\`` : ""}`}});349 else return this.channel.send(`<:cross:724049024943915209> | ${error}${usage ? `\n\nUsage:\n\`${this.prefix}${command.name} ${usage}\`` : ""}`)350 }351 message.success = function(success, embed) {352 if (!success) throw new ReferenceError("Success context is not defined");353 if (embed) return this.channel.send({embed: {description: `<:tick:724048990626381925> | ${success}`}});354 else return this.channel.send(`<:tick:724048990626381925> | ${success}`)355 }356 command.execute(client, message, args);357 } catch (err) {358 console.error(`message: Executing command error: ${command.name} - ${err}`);359 message.channel.send(`Executing command error: ${command.name} - ${err}`);360 }...

Full Screen

Full Screen

overridepermissions.js

Source:overridepermissions.js Github

copy

Full Screen

1const Discord = require("discord.js");2const Guild = require("../../schemas/guild.js");3module.exports = {4 name: "overridepermissions",5 category: "Settings",6 description: "Override command permissions for users, roles or channels",7 aliases: ["op"],8 usage: "<command> <deny - allow | cooldown> <user - role - channel>",9 examples: "g!op 8ball deny @Sax#6211\ng!op channelinfo allow #botcommands\ng!op help @BaddieRole",10 cooldown: 5,11 guildOnly: true,12 reqPermissions: ['MANAGE_GUILD'],13 execute(bot, message, args) {14 if (!args[0]) return message.error("You didn't provide a command to override permissions.", true, this.usage);15 if (!bot.commands.get(args[0].toLowerCase())) return message.channel.send("This command doesn't exist. Use `g!commands` command to list all commands")16 if (!args[1]) return message.channel.send("You didn't provide a option, `deny, allow, cooldown`", true ,"command <deny - allow - cooldown>")17 Guild.findOne({ guildID: message.guild.id }, async (err, guild) => {18 if (err) return message.channel.send(`An error occured: ${err}`);19 if (!guild) return message.channel.send("There was an error while fetching server database, please contact a bot dev! (https://discord.gg/tkR2nTf)");20 if (guild) {21 if (args[1].toLowerCase() == "deny") {22 if (!args[2]) return message.channel.send("You didn't mention a user, role or a channel to deny the permissions to.", true, "command deny <user - role - channel>");23 if (message.mentions.users.first()) {24 let array = [args[0].toLowerCase()]25 array = array.concat(guild.overridePermissions.denied.users.get(message.mentions.users.first().id))26 guild.overridePermissions.denied.users.set(message.mentions.users.first().id, array)27 message.guild.overridePermissions.denied.users.set(message.mentions.users.first().id, array)28 guild.save().then(() => message.success(`User has been denied from using the \`${args[0].toLowerCase()}\` command.`)).catch(err => message.channel.send(`An error occured: ${err}`))29 } else if (message.mentions.roles.first()) {30 guild.overridePermissions.denied.roles.set(message.mentions.roles.first().id, [args[0].toLowerCase()])31 message.guild.overridePermissions.denied.roles.set(message.mentions.roles.first().id, [args[0].toLowerCase()])32 guild.save().then(() => message.success(`The role has been denied from using the \`${args[0].toLowerCase()}\` command.`)).catch(err => message.channel.send(`An error occured: ${err}`))33 } else if (message.mentions.channels.first()) {34 guild.overridePermissions.denied.channels.set(message.mentions.channels.first().id, [args[0].toLowerCase()])35 message.guild.overridePermissions.denied.channels.set(message.mentions.channels.first().id, [args[0].toLowerCase()])36 guild.save().then(() => message.success(`The channel has been denied from using the \`${args[0].toLowerCase()}\` command.`)).catch(err => message.channel.send(`An error occured: ${err}`))37 } else {38 return message.error("You didn't mention a true user, role or a channel to deny the permissions to.", true, "command deny <user - role - channel>")39 }40 } else if (args[1].toLowerCase() == "allow") {41 if (!args[2]) return message.channel.send("You didn't mention a user, role or a channel to deny the permissions to.", true ,"command allow <user - role - channel>");42 if (message.mentions.users.first()) {43 let array = []44 if (guild.overridePermissions.denied.users.get(message.mentions.users.first().id)) {45 if (guild.overridePermissions.denied.users.get(message.mentions.users.first().id).includes(args[0].toLowerCase())) {46 array = array.concat(guild.overridePermissions.denied.users.get(message.mentions.users.first().id))47 for (var i = array.length - 1; i >= 0; i--) {48 if (array[i] === args[0].toLowerCase()) {49 array.splice(i, 1);50 }51 }52 guild.overridePermissions.denied.users.set(message.mentions.users.first().id, array)53 message.guild.overridePermissions.denied.users.set(message.mentions.users.first().id, array)54 guild.save().then(() => message.success(`User is now allowed to use the \`${args[0].toLowerCase()}\` command.`)).catch(err => message.channel.send(`An error occured: ${err}`))55 } else {56 return message.error("This user isnt denied for this command.");57 }58 } else {59 return message.error("This user isnt denied for this command.");60 }61 } else if (message.mentions.roles.first()) {62 if (guild.overridePermissions.denied.roles.get(message.mentions.roles.first().id)) {63 if (guild.overridePermissions.denied.roles.get(message.mentions.roles.first().id).includes(args[0].toLowerCase())) {64 let array = []65 array = array.concat(guild.overridePermissions.denied.roles.get(message.mentions.roles.first().id))66 for (var i = array.length - 1; i >= 0; i--) {67 if (array[i] === args[0].toLowerCase()) {68 array.splice(i, 1);69 }70 }71 guild.overridePermissions.denied.roles.set(message.mentions.roles.first().id, array)72 message.guild.overridePermissions.denied.roles.set(message.mentions.roles.first().id, array)73 guild.save().then(() => message.success(`Role is now allowed to use the \`${args[0].toLowerCase()}\` command.`)).catch(err => message.channel.send(`An error occured: ${err}`))74 } else {75 return message.error("This role isnt denied for this command.");76 }77 } else {78 return message.error("This role isnt denied for this command.");79 }80 } else if (message.mentions.channels.first()) {81 if (guild.overridePermissions.denied.channels.get(message.mentions.channels.first().id)) {82 if (guild.overridePermissions.denied.channels.get(message.mentions.channels.first().id).includes(args[0].toLowerCase())) {83 let array = []84 array = array.concat(guild.overridePermissions.denied.channels.get(message.mentions.channels.first().id))85 for (var i = array.length - 1; i >= 0; i--) {86 if (array[i] === args[0].toLowerCase()) {87 array.splice(i, 1);88 }89 }90 guild.overridePermissions.denied.channels.set(message.mentions.channels.first().id, array)91 message.guild.overridePermissions.denied.channels.set(message.mentions.channels.first().id, array)92 guild.save().then(() => message.success(`Role is now allowed to use the \`${args[0].toLowerCase()}\` command.`)).catch(err => message.channel.send(`An error occured: ${err}`))93 } else {94 return message.error("This role isnt denied for this command.");95 }96 } else {97 return message.error("This role isnt denied for this command.");98 }99 } else {100 return message.error("You didn't mention a true user, role or a channel to deny the permissions to.", true, "commmand allow <user - channel - role>")101 }102 } else if (args[1].toLowerCase() == "cooldown") {103 if (!args[2]) return message.error("You didn't provide the cooldown to set to command.", true, "command cooldown <amount>");104 if (args[2] < 0) return message.error("Cooldown cannot be negative.");105 guild.overridePermissions.cooldown.set(args[0].toLowerCase(), Number(args[2]))106 message.guild.overridePermissions.cooldown.set(args[0].toLowerCase(), Number(args[2]))107 guild.save().then(() => message.success(`Command cooldown for \`${args[0].toLowerCase()}\` command has been set to \`${args[2]}\` seconds.`)).catch(err => message.channel.send(`An error occured: ${err}`))108 }109 }110 })111 }...

Full Screen

Full Screen

addguild.js

Source:addguild.js Github

copy

Full Screen

1const Discord = require("discord.js");2const Guild = require("../../schemas/guild.js")3module.exports = {4 name: "addguild",5 category: "Dev",6 description: "Adds a guild to the database.",7 dev: true,8 async execute(bot, message, args) {9 if (!args[0]) {10 await Guild.findOne({ guildID: message.guild.id }, (err, guild) => {11 if (err) return message.error("An error occured while adding the guild to database: " + err);12 if (guild) message.error(`This database already exists!`);13 if (!guild) {14 let newGuild = new Guild({15 guildName: message.guild.name,16 guildID: message.guild.id,17 blacklisted: false,18 removed: false,19 members: {},20 cases: {},21 reactionroles: {},22 logging: {},23 overridePermissions: {24 denied: {25 users: {},26 roles: {},27 channels: {}28 },29 allowed: {30 users: {},31 roles: {},32 channels: {}33 },34 cooldown: {}35 },36 settings: {37 join: {38 autorole: {39 enabled: false,40 botroles: [],41 userroles: []42 },43 message: {44 text: {45 enabled: false,46 message: "{{user}} Welcome to my server!"47 },48 image: {49 enabled: false,50 text: "{{tag}} joined the server, we have {{count}} members now!"51 },52 channel: message.guild.systemChannel ? message.guild.systemChannel.id : null53 }54 },55 leveling: {56 roles: {57 level: {},58 xp: {}59 },60 levelup: {61 send: true,62 embed: false,63 message: ":tada: {{user}} has leveled up to {{level}}!",64 channel: "default"65 },66 reward: {67 xp: {68 send: true,69 embed: true,70 message: "{{user}} reached {{xp}} xp and been rewarded with {{role}}.",71 channel: "default"72 },73 level: {74 send: true,75 embed: true,76 message: "{{user}} reached {{level}} level and been rewarded with {{role}}.",77 channel: "default"78 }79 },80 options: {81 delay: 30,82 cap: 560,83 xp: {84 max: 100,85 min: 1086 },87 filter: {88 maxLength: 150,89 minLength: 15,90 repeative: false91 }92 }93 },94 blacklist: {95 commands: [],96 channels: []97 }98 }99 });100 message.guild.settings = newGuild.settings101 message.guild.blacklisted = newGuild.blacklisted102 message.guild.overridePermissions = newGuild.overridePermissions103 newGuild.save().then(() => message.success(`A new database guild has been added for ${message.guild.name}`)).catch(err => message.error(`An error occured while adding the database for Guild: ${message.guild.name} - err: ${err}`));104 }105 })106 } else if (args[0]) {107 if (!bot.guilds.cache.get(args[0])) return message.error("This guild does not exist.", false, this.usage)108 let guild = bot.guilds.cache.get(args[0])109 await Guild.findOne({ guildID: guild.id }, (err, dguild) => {110 if (err) return message.error("An error occured while adding the guild to database: " + err);111 if (dguild) message.error(`This database already exists!`);112 if (!guild) {113 let newGuild = new Guild({114 guildName: guild.name,115 guildID: guild.id,116 blacklisted: false,117 removed: false,118 members: {},119 cases: {},120 reactionroles: {},121 logging: {},122 overridePermissions: {123 denied: {124 users: {},125 roles: {},126 channels: {}127 },128 allowed: {129 users: {},130 roles: {},131 channels: {}132 },133 cooldown: {}134 },135 settings: {136 join: {137 autorole: {138 enabled: false,139 botroles: [],140 userroles: []141 },142 message: {143 text: {144 enabled: false,145 message: "{{user}} Welcome to my server!"146 },147 image: {148 enabled: false,149 text: "{{tag}} joined the server, we have {{count}} members now!"150 },151 channel: guild.systemChannel ? guild.systemChannel.id : null152 }153 },154 leveling: {155 roles: {156 level: {},157 xp: {}158 },159 levelup: {160 send: true,161 embed: false,162 message: ":tada: {{user}} has leveled up to {{level}}!",163 channel: "default"164 },165 reward: {166 xp: {167 send: true,168 embed: true,169 message: "{{user}} reached {{xp}} xp and been rewarded with {{role}}.",170 channel: "default"171 },172 level: {173 send: true,174 embed: true,175 message: "{{user}} reached {{level}} level and been rewarded with {{role}}.",176 channel: "default"177 }178 },179 options: {180 delay: 30,181 cap: 560,182 xp: {183 max: 100,184 min: 10185 },186 filter: {187 maxLength: 150,188 minLength: 15,189 repeative: false190 }191 }192 },193 blacklist: {194 commands: [],195 channels: []196 }197 }198 });199 message.guild.settings = newGuild.settings200 message.guild.blacklisted = newGuild.blacklisted201 message.guild.overridePermissions = newGuild.overridePermissions202 newGuild.save().then(() => message.success(`A new database guild has been added for ${guild.name}`)).catch(err => message.error(`An error occured while adding the database for Guild: ${guild.name} - err: ${err}`));203 }204 })205 }206 }...

Full Screen

Full Screen

main.js

Source:main.js Github

copy

Full Screen

...17 log(`- Starting up`);18 await Functions.writeDb(db);19 let browser = await Puppeteer.launch({headless});20 let context = browser.defaultBrowserContext();21 await context.overridePermissions(`https://yandex.ru/`, []);22 await context.overridePermissions(`https://music.yandex.ru/`, []);23 await context.overridePermissions(`https://passport.yandex.ru/`, []);24 let page = await browser.newPage();25 let s_counter = 0;26 const vp = {width: 1024, height: 500};27 await page.setViewport(vp);28 log('- Logging in Profile 1');29 await Functions.login(page, db.login1, db.password1);30 log('- Getting music list');31 const {nickname, link} = await Functions.getLink(page);32 await page.goto(link, {waitUntil: "load"});33 const pageTemp = await browser.newPage();34 const fetch = require(`node-fetch`);35 const response = await fetch("https://music.yandex.ru/handlers/library.jsx?owner=" + nickname + "&filter=tracks&likeFilter=favorite&sort=&dir=&lang=ru&external-domain=music.yandex.ru&overembed=false", {36 method: `GET`,37 mode: `cors`,38 headers: {39 "Referer": `https://music.yandex.ru/users/${nickname}/tracks`40 }41 });42 let audiosObj = await response.json();43 let audiosArr = audiosObj.contestTracksIds;44 await pageTemp.close();45 await browser.close();46 log('- Reloggging in');47 browser = await Puppeteer.launch({headless});48 context = browser.defaultBrowserContext();49 await context.overridePermissions(`https://yandex.ru/`, []);50 await context.overridePermissions(`https://music.yandex.ru/`, []);51 await context.overridePermissions(`https://passport.yandex.ru/`, []);52 page = await browser.newPage();53 await page.setViewport(vp);54 await Functions.login(page, db.login2, db.password2);55 log('- Last preparations');56 let linkPage = await browser.newPage();57 await linkPage.setViewport(vp);58 await linkPage.goto("https://music.yandex.ru/search?text=%D0%B4%D0%B5%D1%80%D0%B5%D0%B2%D0%BD%D1%8F%20%D0%B4%D1%83%D1%80%D0%B0%D0%BA%D0%BE%D0%B2", {waitUntil: "load"});59 let token = "", num = "", i = 0;60 await linkPage.setRequestInterception(true);61 linkPage.on("request", request => {62 if (request.method() === "POST" && token === "") {63 let s = request.postData();64 if (s.slice(0, 32) === "from=web-search-track-track-main") {65 log("> get token");...

Full Screen

Full Screen

BrowserSetup.js

Source:BrowserSetup.js Github

copy

Full Screen

...72 },73 newDesktopPage: async browser => {74 const context = browser.defaultBrowserContext();75 await context.clearPermissionOverrides();76 await context.overridePermissions(`https://${process.env.NODE_ENV}`, [77 "geolocation"78 ]);79 const page = await context.newPage();80 await page.setViewport({81 width: desktopResolution.width,82 height: desktopResolution.height83 });84 return page;85 },86 newMobilePage: async browser => {87 const context = browser.defaultBrowserContext();88 await context.clearPermissionOverrides();89 await context.overridePermissions(`https://${process.env.NODE_ENV}`, [90 "geolocation"91 ]);92 const page = await context.newPage();93 await page.setViewport({94 width: mobileResolution.width,95 height: mobileResolution.height,96 isMobile: true,97 hasTouch: true98 });99 return page;100 },101 newIphoneXPage: async browser => {102 const context = browser.defaultBrowserContext();103 await context.clearPermissionOverrides();104 await context.overridePermissions(`https://${process.env.NODE_ENV}`, [105 "geolocation"106 ]);107 const page = await context.newPage();108 await page.emulate(iPhoneX);109 return page;110 },111 newIpadPro: async browser => {112 const context = browser.defaultBrowserContext();113 await context.clearPermissionOverrides();114 await context.overridePermissions(`https://${process.env.NODE_ENV}`, [115 "geolocation"116 ]);117 const page = await context.newPage();118 await page.emulate(iPadPro);119 return page;120 }121};...

Full Screen

Full Screen

e2e.test.js

Source:e2e.test.js Github

copy

Full Screen

1describe("Front page", () => {2 beforeAll(async () => {3 await context.overridePermissions("http://localhost:3000", ["geolocation"]);4 await page.setGeolocation({ latitude: 60.1697802, longitude: 24.9472751 });5 await page.goto("http://localhost:3000");6 await page.screenshot({ path: "./screenshots/initialLoadSuccess.png" });7 });8 it('should be titled "Lunch Near Me"', async () => {9 await expect(page.title()).resolves.toMatch("Lunch Near Me");10 });11 it('should have a header "Lunch Near Me"', async () => {12 const header = await page.$eval("#page-header", (e) => e.innerHTML);13 expect(header).toBe("Lunch Near Me");14 });15 it("should show a map", async () => {16 const map = await page.$("#map");17 expect(map).toBeTruthy;18 });19 it("should show restaurant suggestions section", async () => {20 const restaurantSuggestions = await page.$("#restaurant-suggestions");21 expect(restaurantSuggestions).toBeTruthy;22 });23});24describe("Notification", () => {25 it("should be shown if there are no restaurants", async () => {26 await context.overridePermissions("http://localhost:3000", ["geolocation"]);27 // Location: London28 await page.setGeolocation({ latitude: 51.507351, longitude: -0.127758 });29 await page.goto("http://localhost:3000");30 await page.screenshot({ path: "./screenshots/no-restaurants.png" });31 const notificationText = await page.$eval(32 "#notificationContainer > div > div > div.MuiAlert-message",33 (e) => e.innerHTML34 );35 expect(notificationText).toBe("No restaurants found near your location.");36 });37 it("should be shown if location is inaccurate", async () => {38 await context.overridePermissions("http://localhost:3000", ["geolocation"]);39 await page.setGeolocation({40 latitude: 60.1697802,41 longitude: 24.9472751,42 accuracy: 5000,43 });44 await page.goto("http://localhost:3000");45 const notificationText = await page.$eval(46 "#notificationContainer > div > div > div.MuiAlert-message",47 (e) => e.innerHTML48 );49 expect(notificationText).toBe(50 "Couldn't get an accurate location. Maybe try with a different browser."51 );52 });...

Full Screen

Full Screen

browserHandler.test.js

Source:browserHandler.test.js Github

copy

Full Screen

...43 getTargets: () => {44 return { targetInfos: [] };45 },46 });47 browserHandler.overridePermissions('https://url.com', ['geolocation']);48 expect(isCalled).to.be.true;49 expect(calledWith).to.be.eql({50 origin: 'https://url.com',51 permissions: ['geolocation'],52 });53 });54 it('.overridePermissions should throw error if given permission is not valid', async () => {55 let isCalled = false;56 let mockBrInstance = {57 grantPermissions: async () => {58 isCalled = true;59 },60 };61 browserHandler.__set__('_browser', mockBrInstance);62 browserHandler.__set__('_target', {63 getTargets: () => {64 return { targetInfos: [] };65 },66 });67 try {68 await browserHandler.overridePermissions('https://url.com', ['foo-bar']);69 } catch (error) {70 expect(isCalled).to.be.false;71 expect(error.message).to.be.eql('Unknown permission: foo-bar');72 }73 });...

Full Screen

Full Screen

geolocation.test.js

Source:geolocation.test.js Github

copy

Full Screen

...16 await browser.setGeolocation({17 latitude: 80,18 longitude: -3019 });20 await browser.overridePermissions(configUrls.index, "geolocation");21 const correctLocation = await browser.evaluate(() => {22 return new Promise((resolve) => {23 navigator.geolocation.getCurrentPosition((res) => {24 resolve(res.coords.latitude === 80 && res.coords.longitude === -30);25 });26 });27 });28 assert.strictEqual(correctLocation, true);29 });30 it("Geolocation setting", async() => {31 await browser.open(configUrls.index, {32 geolocation: {33 latitude: 89,34 longitude: -6035 }36 });37 await browser.overridePermissions(configUrls.index, "geolocation");38 const correctLocation = await browser.evaluate(() => {39 return new Promise((resolve) => {40 navigator.geolocation.getCurrentPosition((res) => {41 resolve(res.coords.latitude === 89 && res.coords.longitude === -60);42 });43 });44 });45 assert.strictEqual(correctLocation, true);46 });47 it("Get Geolocation", async() => {48 await browser.open(configUrls.index, {49 geolocation: {50 latitude: 2,51 longitude: -652 }53 });54 await browser.overridePermissions(configUrls.index, "geolocation");55 const location = await browser.geolocation();56 assert.strictEqual(location.latitude, 2);57 assert.strictEqual(location.longitude, -6);58 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { openBrowser, goto, overridePermissions, closeBrowser } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await click("Where am I?");6 await click("Allow");7 await click("Where am I?");8 await click("Deny");9 await click("Where am I?");10 await click("Allow");11 await click("Where am I?");12 await click("Deny");13 } catch (e) {14 console.error(e);15 } finally {16 await closeBrowser();17 }18})();19### overridePermissions(origin, permissions)20### setGeolocation(options)

Full Screen

Using AI Code Generation

copy

Full Screen

1const { openBrowser, goto, overridePermissions, closeBrowser } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await closeBrowser();6 } catch (e) {7 console.error(e);8 } finally {9 }10})();11The following are 2 code examples for showing how to use taiko.overridePermissions(). These examples are extracted from open source projects. You can vote up the examples you like or vote down the ones you don't like. You c

Full Screen

Using AI Code Generation

copy

Full Screen

1const { overridePermissions } = require('taiko');2const { openBrowser, goto, closeBrowser } = require('taiko');3(async () => {4 try {5 await openBrowser({ headless: false });6 } catch (e) {7 console.error(e);8 } finally {9 await closeBrowser();10 }11})();12Taiko is licensed under [Apache License 2.0](

Full Screen

Using AI Code Generation

copy

Full Screen

1const { openBrowser, goto, overridePermissions } = require('taiko');2(async () => {3 try {4 await openBrowser();5 } catch (e) {6 console.error(e);7 } finally {8 closeBrowser();9 }10})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { openBrowser, goto, button, closeBrowser, overridePermissions } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await button("Click for JS Confirm").click();6 } catch (e) {7 console.error(e);8 } finally {9 await closeBrowser();10 }11})();12### openBrowser(options)13| options | Options to configure the browser instance. | `{}` |14| observe | Boolean to enable [Observability](#observability) | `false` |15### openBrowserTab(options)16| options | Options to configure the tab. | `{}` |

Full Screen

Using AI Code Generation

copy

Full Screen

1const { openBrowser, goto, closeBrowser, overridePermissions } = require('taiko');2(async () => {3 try {4 await openBrowser();5 } catch (e) {6 console.error(e);7 } finally {8 await closeBrowser();9 }10})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { openBrowser, goto, button, overridePermissions, closeBrowser } = require('taiko');2(async () => {3 try {4 await openBrowser({ headless: false });5 await button("I agree").exists();6 await button("I agree").click();7 } catch (e) {8 console.error(e);9 } finally {10 await closeBrowser();11 }12})();13[MIT](LICENSE)

Full Screen

Using AI Code Generation

copy

Full Screen

1const { overridePermissions } = require("taiko");2const { openBrowser, goto, closeBrowser } = require("taiko");3(async () => {4 try {5 await openBrowser();6 } catch (e) {7 console.error(e);8 } finally {9 await closeBrowser();10 }11})();12### overridePermissions(origin, permissions)13### clearPermissionOverrides()14### getPermissionOverrides()15### getPermissionOverrides(origin)16### getPermissionOverrides(origin, permission)

Full Screen

Using AI Code Generation

copy

Full Screen

1const { overridePermissions } = require('taiko');2const { clearPermissionOverrides } = require('taiko');3clearPermissionOverrides();4const { getPermissionOverrides } = require('taiko');5getPermissionOverrides();6async function overridePermissions(7| **See Also** | [clearPermissionOverrides](#clearPermissionOverrides) |8async function clearPermissionOverrides(): Promise<void>9| **Example** | clearPermissionOverrides(); |10| **See Also**| [overridePermissions](#overridePermissions) |11async function getPermissionOverrides(): Promise<PermissionOverride[]>12| **Example** | getPermissionOverrides(); |13| **See Also**| [overridePermissions](#overridePermissions) |14type PermissionOverride = {15 origin: string;16 permissions: string[];17};

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run taiko automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful