SHARE
TWEET

Untitled

a guest Dec 14th, 2019 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. ```js
  3. async function processRetriveDataFromDB(rows){
  4.     let subscriptions = new Discord.Collection()
  5.     let ctr = 1, sql = '', description = ''
  6.     console.log('in processRetriveDataFromDB')
  7.  
  8.     for (row of rows){
  9.         let guildId = row.guild_id
  10.         serverData.guilds.set(guildId, {  
  11.             id: guildId,
  12.             name: row.name,
  13.             stats: {
  14.                 webhooksStats: JSON.parse(row.stats_webhooks),
  15.                 reactionsStats:  JSON.parse(row.stats_reactions)
  16.             },
  17.             welcomeMessage: row.welcome_messag,
  18.             welcomeMessageEnable: row.welcome_message_enabled,
  19.             defualtRoles: row.auto_roles,
  20.             autoRolesEnable: row.auto_roles_enabled,
  21.             botEnable: row.bot_enabled,
  22.             premiumEnable: row.premium_enabled,
  23.             partnersEnable: row.partners_enabled,
  24.             emojisEnable: row.emojis_enabled,
  25.             aemojisEnable: row.aemojis_enabled,
  26.             members: JSON.parse(row.members),
  27.             subscriptions: JSON.parse(row.subscriptions)
  28.         })
  29.         if (serverData.guilds.get(guildId).members === null || isEmpty(serverData.guilds.get(guildId).members)) {
  30.             sql = initMembers(guildId)
  31.         }
  32.        
  33.     }
  34.    
  35.     console.log('ready to send sql command...')
  36.     description  = 'populate DATABASE with MEMBERS data'
  37.  
  38.     sendSql(sql, description)
  39.  
  40.  
  41.     function initMembers(guildId) {
  42.         // console.log(`in initMembers`)   
  43.         serverData.guilds.get(guildId).members = new Discord.Collection()
  44.  
  45.         for (let member of client.guilds.get(guildId).members){
  46.             let memberId = member[0]
  47.             serverData.guilds.get(guildId).members.set(memberId, new Member(member[1]))
  48.             let serverMember = serverData.guilds.get(guildId).members.get(memberId)
  49.             console.log(serverMember.displayName)
  50.             buildSql(serverMember, memberId, guildId, ctr++)
  51.            
  52.             //for debuggin purposes to limit output
  53.             if (ctr === 2) return sql
  54.             if (ctr === 3) return sql
  55.             if (ctr === 4) return sql
  56.             if (ctr === 5) return sql
  57.         }
  58.         function buildSql(serverMember, memberId, guildId, ctr){
  59.             console.log(ctr)
  60.             sql += `INSERT INTO members VALUES (${ctr}, '${memberId}', '${guildId}', '${escape(serverMember.displayName)}', '${escape(serverMember.avatarURL)}', 0, '${escape(serverMember.firstJoinedAt)}', '${escape(serverMember.joinedAt)}', 0, '${escape(serverMember.roles.toString())}', NULL);\n\n`
  61.             function escape(value){
  62.                  if (typeof value === 'string') return value.replace(/'/g, "''")
  63.                  else return value
  64.             }
  65.         }
  66.         return sql
  67.     }
  68.  
  69. }
  70.  
  71. ```
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top