-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from chrisbruford/chris
Chris
- Loading branch information
Showing
20 changed files
with
282 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const User = require('../../../../models/user'); | ||
const logger = require('../../../logger'); | ||
|
||
module.exports = (guildID, userID) => { | ||
return new Promise((resolve, reject) => { | ||
User.then(User=>User.findOneAndUpdate({ discordID: userID }, { $addToSet: { broadcastGuilds: guildID } })) | ||
.then(user => { | ||
if (!user) { | ||
reject('No user found'); | ||
logger.log(new Error('No user found')); | ||
} else { | ||
resolve(true); | ||
} | ||
}) | ||
.catch(err=>logger.log(err)); | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports.add = require('./add'); | ||
module.exports.remove = require('./remove'); | ||
module.exports.list = require('./list'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const User = require('../../../../models/user'); | ||
const client = require('../common/client'); | ||
const logger = require('../../../logger'); | ||
|
||
module.exports = userID => { | ||
return new Promise((resolve, reject) => { | ||
User.then(User=>User.findOne({ discordID: userID })) | ||
.then(user => { | ||
if (!user) { | ||
reject('No user found'); | ||
logger.log(new Error('No user found')); | ||
} else { | ||
if (user.broadcastGuilds) { | ||
if (user.broadcastGuilds.length > 0) { | ||
let message = "```You are currently broadcasting to:\n"; | ||
user.broadcastGuilds.forEach(guildID => { | ||
let guild = client.guilds.get(guildID); | ||
let newLine = guild ? `${guild.name}\n`:`A guild I no longer exist in :(\n`; | ||
message += newLine; | ||
}) | ||
message += "```"; | ||
resolve(message); | ||
} else { | ||
resolve('You are not broadcasting to any guilds'); | ||
} | ||
} else { | ||
resolve('You are not broadcasting to any guilds'); | ||
} | ||
} | ||
}) | ||
.catch(err=>logger.log(err)) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const User = require('../../../../models/user'); | ||
const logger = require('../../../logger'); | ||
|
||
module.exports = (guildID, userID) => { | ||
return new Promise((resolve, reject) => { | ||
|
||
User.then(User=>User.findOneAndUpdate({discordID: userID}, { $pull: { broadcastGuilds: guildID } })) | ||
.then(user => { | ||
//see if guild was in original set anyway | ||
let exists = user.broadcastGuilds.find(el => el === guildID) | ||
|
||
if (exists) { | ||
return resolve(true); | ||
} else { | ||
reject(false); | ||
} | ||
}) | ||
.catch(err => { | ||
logger.log(err); | ||
reject(err); | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
"use strict"; | ||
const logger = require('../../../../logger'); | ||
const reqAccess = require('../reqAccess'); | ||
const responseDict = require('../responseDict'); | ||
const help = require("./help"); | ||
let broadcast = require('../../broadcasts'); | ||
|
||
class Broadcasts { | ||
|
||
exec(msg, commandArguments) { | ||
let argsArray = []; | ||
if (commandArguments.length !== 0) { | ||
argsArray = commandArguments.split(" "); | ||
} | ||
if (argsArray.length > 0) { | ||
let command = argsArray[0].toLowerCase(); | ||
|
||
if (this[command]) { | ||
this[command](msg, argsArray) | ||
} else { | ||
msg.channel.sendMessage("Unknown command"); | ||
} | ||
} else { | ||
msg.channel.sendMessage(responseDict.noParams()); | ||
} | ||
} | ||
|
||
add(msg, argsArray) { | ||
reqAccess(msg.guild, msg.member, 1) | ||
.then(() => { | ||
let thisGuild = msg.guild; | ||
return broadcast.add(thisGuild.id, msg.member.id); | ||
}) | ||
.then(wing => msg.channel.sendMessage(responseDict.success())) | ||
.catch(err => { | ||
logger.log(err); | ||
msg.channel.sendMessage(responseDict.fail()); | ||
}) | ||
} | ||
|
||
remove(msg, argsArray) { | ||
reqAccess(msg.guild, msg.member, 1) | ||
.then(() => { | ||
return broadcast.remove(msg.guild.id, msg.member.id); | ||
}) | ||
.then(wing => msg.channel.sendMessage(responseDict.success())) | ||
.catch(err => { | ||
logger.log(err); | ||
msg.channel.sendMessage(responseDict.fail()); | ||
}) | ||
} | ||
|
||
list(msg, argsArray) { | ||
reqAccess(msg.guild, msg.member, 0) | ||
.then(() => { | ||
let thisGuild = msg.guild; | ||
return broadcast.list(msg.member.id); | ||
}) | ||
.then(res => msg.member.sendMessage(res)) | ||
.catch(err => { | ||
logger.log(err); | ||
msg.channel.sendMessage(responseDict.fail()); | ||
}) | ||
} | ||
} | ||
|
||
let helpMessage = "Adds,Removes the current guild to your list of broadcast targets or lists all your broadcast targets"; | ||
let template = "broadcast <add|remove|list>"; | ||
let example = [ | ||
"`-broadcasts add`", | ||
"`-broadcasts remove`", | ||
"`-broadcasts list`" | ||
]; | ||
|
||
help.AddHelp("wings", helpMessage, template, example); | ||
|
||
module.exports = new Broadcasts(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
let interdicted = require('./interdicted'); | ||
let missionCompleted = require('./mission-completed'); | ||
|
||
module.exports = { | ||
interdicted | ||
interdicted, | ||
missionCompleted | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const discordGuildModel = require('../../../../models/discord-guild'); | ||
const client = require('../common/client'); | ||
const logger = require('../../../logger'); | ||
|
||
function alert(guildID, missionCompleted, cmdrName) { | ||
|
||
let defaults = { | ||
cmdrName: "Unknown CMDR", | ||
Name: "Unknown Mission", | ||
originator: "Unknown Faction" | ||
} | ||
missionCompleted = Object.assign(defaults, missionCompleted); | ||
|
||
return discordGuildModel.findOne({guildID}) | ||
.then(guild=>{ | ||
if (guild) { | ||
let targetChannelID = guild.logChannelID; | ||
let targetChannel = client.channels.get(targetChannelID); | ||
console.log(`mission completed to ${targetChannelID} ${targetChannel}`); | ||
targetChannel.sendMessage(`MISSION COMPLETED: ${cmdrName.toUpperCase()} completed ${missionCompleted.Name.toUpperCase()} for ${missionCompleted.originator.toUpperCase()}`); | ||
} else { | ||
logger.log(`No such guild found`); | ||
throw new Error('no such guild'); | ||
} | ||
}) | ||
.catch(err=>{ | ||
logger.log(err); | ||
}) | ||
} | ||
|
||
module.exports = { | ||
alert | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
let router = require('express').Router(); | ||
let {missionCompleted} = require('../../modules/kok-bot/modules/companion'); | ||
let logger = require('../../modules/logger'); | ||
|
||
router.post('/completed/:cmdr',(req,res)=>{ | ||
let cmdrName = decodeURIComponent(req.params.cmdr); | ||
|
||
if (!cmdrName) { | ||
res.sendStatus(400) ; | ||
logger.log(new Error("No cmdrName provided to route")); | ||
return | ||
} | ||
|
||
if (!req.user) { | ||
res.sendStatus(403) | ||
logger.log(new Error("non-logged in user attempted to do a mission completed alert")); | ||
return | ||
} | ||
|
||
require('../../models/user') | ||
.then(User=>{ | ||
if (!User) { throw new Error("Fatal model error: no user model found"); } | ||
return User.findOne(req.user) | ||
}) | ||
.then(user=>{ | ||
if (!user) { throw new Error(`No such user found: ${req.user.username}`) } | ||
if (user.username !== cmdrName) { throw new Error("commander name mismatch"); } | ||
let missionCompletedEvent = req.body.missionCompleted; | ||
//TODO: Refactor so that guildID is pulled from the logged in user and sent to THEIR guild(s) | ||
return missionCompleted.alert("141575893691793408",missionCompletedEvent,cmdrName) | ||
.then(response=>{ | ||
res.sendStatus(200).json(response); | ||
}) | ||
}) | ||
.catch(err=>{ | ||
logger.log(err); | ||
res.sendStatus(500); | ||
}) | ||
}) | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters