Skip to content
This repository has been archived by the owner on May 6, 2019. It is now read-only.

Commit

Permalink
use discordie getter method for isPrivate
Browse files Browse the repository at this point in the history
  • Loading branch information
Dustin Blackman committed Aug 18, 2016
1 parent 1cb03cf commit a607ea0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 20 deletions.
10 changes: 4 additions & 6 deletions src/commands/info/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import Promise from 'bluebird';
import nconf from 'nconf';
import R from 'ramda';

import { evtMsgPrivate } from '../../helpers';


function avatar(client, evt, suffix) {
if (!suffix && !evt.message.mentions.length) {
Expand All @@ -17,7 +15,7 @@ function avatar(client, evt, suffix) {
});
}

if (evtMsgPrivate(evt)) return Promise.resolve(`Sorry, we can\'t get ${suffix} avatar from a direct message. Try in a channel instead!`);
if (evt.message.channel.isPrivate) return Promise.resolve(`Sorry, we can\'t get ${suffix} avatar from a direct message. Try in a channel instead!`);
const user = R.find(R.propEq('username', suffix))(evt.message.guild.members);
if (!user) return;
if (!user.avatarURL) return Promise.resolve(`${user.username} is naked.`);
Expand All @@ -26,7 +24,7 @@ function avatar(client, evt, suffix) {

function channelinfo(client, evt, suffix) {
const channelinfo = [];
if (evtMsgPrivate(evt)) {
if (evt.message.channel.isPrivate) {
channelinfo.push(`\`\`\`ID: ${evt.message.channel.id}
Type: Direct Message
New Messages: ${evt.message.channel.messages.length} (since the bot was restarted)
Expand Down Expand Up @@ -98,7 +96,7 @@ User Limit: ${channel.user_limit}

function serverinfo(client, evt, suffix) {
const serverinfo = [];
if (evtMsgPrivate(evt)) return Promise.resolve('Use this in an actual server.\nhttp://fat.gfycat.com/GranularWeeCorydorascatfish.gif');
if (evt.message.channel.isPrivate) return Promise.resolve('Use this in an actual server.\nhttp://fat.gfycat.com/GranularWeeCorydorascatfish.gif');
if (!suffix) {
const roles = R.join(', ', R.reject(name => name === '@everyone', R.pluck('name', evt.message.guild.roles)));
serverinfo.push(`\`\`\`Name: ${evt.message.guild.name}
Expand Down Expand Up @@ -138,7 +136,7 @@ Icon: ${guild.iconURL ? guild.iconURL : 'None'}

function userinfo(client, evt, suffix) {
const userinfo = [];
if (evtMsgPrivate(evt)) {
if (evt.message.channel.isPrivate) {
userinfo.push(`\`\`\`Name: ${evt.message.author.username}
ID: ${evt.message.author.id}
Discriminator: ${evt.message.author.discriminator}
Expand Down
7 changes: 0 additions & 7 deletions src/helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import R from 'ramda';

export function getOrdinal(n) {
const s = ['th', 'st', 'nd', 'rd'];
const v = n % 100;
Expand All @@ -19,8 +17,3 @@ export function numberWithCommas(x) {
export function secondDec(n) {
return Math.round(n * 100) / 100;
}

export function evtMsgPrivate(evt) {
const isPrivate = evt.message.channel.isPrivate;
return isPrivate && isPrivate === true || (R.is(Function, isPrivate) && isPrivate());
}
3 changes: 1 addition & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import sentry from './sentry';

import { startPortalIntervals, startPortalTimeouts } from './portals';
import { createDuplicateClient, getMessageTTL, setMessageTTL, getUserLang } from './redis';
import { evtMsgPrivate } from './helpers';


// Init
Expand Down Expand Up @@ -119,7 +118,7 @@ function onMessage(evt) {
}

// Check personal messages
if (evtMsgPrivate(evt)) {
if (evt.message.channel.isPrivate) {
// Handle invite links
if (evt.message.content.indexOf('https://discord.gg/') > -1 || evt.message.content.indexOf('https://discordapp.com/invite/') > -1) {
return commands.join(client, evt, evt.message.content);
Expand Down
10 changes: 5 additions & 5 deletions tests/info/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('info', () => {
name: 'server'
},
channel: {
isPrivate: () => false,
isPrivate: false,
name: 'test',
id: '1234',
type: 'text',
Expand All @@ -68,7 +68,7 @@ Topic: abc

it('should return a string containing mentioned channel information', () => {
const channel = {
isPrivate: () => false,
isPrivate: false,
name: 'test',
id: '9876543210',
type: 'text',
Expand Down Expand Up @@ -107,7 +107,7 @@ Topic: abc
const evt = {
message: {
channel: {
isPrivate: () => false
isPrivate: false
},
guild: {
name: 'test',
Expand Down Expand Up @@ -156,7 +156,7 @@ Icon: http://website.com/img.png
const evt = {
message: {
channel: {
isPrivate: () => false
isPrivate: false
},
mentions: {},
author: {
Expand Down Expand Up @@ -184,7 +184,7 @@ Avatar: http://website.com/img.png
const evt = {
message: {
channel: {
isPrivate: () => false
isPrivate: false
},
mentions: [{
username: 'user',
Expand Down

0 comments on commit a607ea0

Please sign in to comment.