Skip to content

Commit

Permalink
Upgrade packages and delete server settings when leaving a server.
Browse files Browse the repository at this point in the history
  • Loading branch information
retrixe committed Jan 7, 2019
1 parent f36c9a1 commit c47c1e6
Show file tree
Hide file tree
Showing 4 changed files with 555 additions and 369 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@material-ui/core": "^3.0.1",
"@material-ui/icons": "^3.0.1",
"apollo-boost": "^0.1.4",
"eris": "https://codeload.github.com/abalabahaha/eris/tar.gz/bd48702f8d472c010e9b2378467c1bfca9abd5ce",
"eris": "https://codeload.github.com/abalabahaha/eris/tar.gz/f919f961b16b5943a794e9052a7c7f27dbb5074f",
"graphql": "^14.0.2",
"graphql-yoga": "^1.16.7",
"isomorphic-unfetch": "^2.0.0",
Expand Down
6 changes: 6 additions & 0 deletions server/bot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ export const guildMemberRemove = (client: Client, db: Db) => async (
} catch (e) {}
}

// When the bot leaves a server, this function will be called.
export const guildDelete = (db: Db) => async (guild: Guild) => {
const settings = await db.collection('servers').findOne({ serverID: guild.id })
if (settings) await db.collection('servers').deleteOne({ serverID: guild.id })
}

// When client recieves a message, it will callback.
export default async (message: Message, client: Client, tempDB: DB, db: Db) => {
try {
Expand Down
4 changes: 3 additions & 1 deletion server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { MongoClient } from 'mongodb'
// Import fs.
import { readdir, statSync } from 'fs'
// Import the bot.
import { guildMemberAdd, guildMemberRemove } from './bot'
import { guildMemberAdd, guildMemberRemove, guildDelete } from './bot'
// Get the token needed.
import 'json5/lib/require'
import { token, mongoURL } from '../config.json5'
Expand Down Expand Up @@ -48,6 +48,8 @@ MongoClient.connect(mongoURL === 'dotenv' ? process.env.MONGO_URL : mongoURL, {
// When a server loses a member, it will callback.
client.on('guildMemberAdd', guildMemberAdd(client, db, tempDB))
client.on('guildMemberRemove', guildMemberRemove(client, db))
// When the bot leaves a server, it will callback.
client.on('guildDelete', guildDelete(db))
// Register the commandParser.
const commandParser = new CommandParser(client, tempDB, db)
client.on('messageCreate', commandParser.onMessage)
Expand Down
Loading

0 comments on commit c47c1e6

Please sign in to comment.