GeekyDeaks / discord-destinybot

Discord Destiny Bot
MIT License
8 stars 3 forks source link

Authorization missing? #19

Closed IrealiTY closed 7 years ago

IrealiTY commented 7 years ago

On certain commands the bot sends me a direct message with: You are not authorised to run foo

  1. is it intended for him to send DMs? (d!stats and d!summary are now DMs too instead of posted in the channel)
  2. How do I set the proper user permissions for commands?
unisys12 commented 7 years ago

I think would be done at the server level wouldn't it.

On Tue, Aug 30, 2016, 8:18 AM Aleks notifications@github.com wrote:

On certain commands the bot sends me a direct message with: You are not authorised to run foo

  1. is it intended for him to send DMs? (d!stats and d!summary are now DMs too instead of posted in the channel) 2.How do I set the proper user permissions for commands?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/GeekyDeaks/discord-destinybot/issues/19, or mute the thread https://github.com/notifications/unsubscribe-auth/AB_vg_sHgRMMpk1dlzmhSF9aOeLXZ5Ahks5qlC22gaJpZM4Jwg_k .

GeekyDeaks commented 7 years ago

Hi @IrealiTY - yeah, sorry, things have rapidly changed with the bot and the documentations is not keeping pace.

all commands should now by default respond with a PM, unless you end the command with public i.e. d!summary public. Errors responses are also deleted after 10s in a public channel (they cannot be deleted in a PM). I am considering making this a configureable option if there is interest.

Regarding the You are not authorised - some of the commands are considered admin only, so you need to setup a role on the server for those you wish to run them and then edit config.js to add the role to the bot as follows:

discord: {
    token: "...",
    adminRole: "Modteam",
    defaultServer: "geekydev"
},

While you are at it, I'd recommend also setting the defaultServer, so that you can correctly use commands in a PM.

IrealiTY commented 7 years ago

Interesting! That sounds good - I suggest that you could maybe set an option for ´privateorpublic` in the option. i.e. I use the bot on a small discord server and having it public all the time is not an issue

GeekyDeaks commented 7 years ago

Hi @IrealiTY - I have made the change you suggested in pull #24 - which is now merged into master. There is an additional config option in the discord object called pm:

discord: {
    token: "DISCORD_TOKEN",
    adminRole: "Modteam",
    defaultServer: "",
    pm: false
},

If it's set to false (or does not exist), then the bot will respond on the same channel the command was issued. If it's set to true, then the bot will attempt to respond on a PM

IrealiTY commented 7 years ago

Amazing thanks! Works as intended.

IrealiTY commented 7 years ago

Sorry for closing prematurely.

The auth error is still there. I've set the adminRole: "Admin", (the name of the group on discord is spelled exactly the same way)

but on execution of: d!my psn ireas I get:

MongoError: not authorized on des to execute command {
    update: "gamers", updates: [
        {
            q: {discord.id: "42166560596430848"},
            u: { $set: {
                psn: "ireas",
                discord.name: "Saeris",
                modified: true }
            },
            upsert: true,
            multi: false }
        ],
    ordered: true 
}

(formatted manually)

Here my config

'use strict';

module.exports = {

    discord: {
        token: "xxxxxxxxxx",
        adminRole: "Admin",
        defaultServer: "Hype of Iron",
        pm: false
    },
    modules: {
        db : {
            // Update url with actual mongo connection string. 
            url: "mongodb://localhost:27017/des"
            // all options are optional
            /*options: { 
                uri_decode_auth: ""
                db: "",
                server: "",
                replSet: "",
                promiseLibrary: ""
            }*/
        },
        role : {
            collection: "roles"
        },
        destiny: {
            apikey: "xxxxxx",
            url: "https://www.bungie.net/Platform/Destiny",
            defaultType: 2,
            collection: "destiny.manifest"
        },
        voc: {
            psnChannel: "psn",
            mvote : {
                adminRole : "Admin",
                voteRole : "Members",
                collection: "voc.mvote",
                port: 8000,
                host: '127.0.0.1'
            }
        },
        welcome: {},
        util : {},
        gamer: {
            collection: "gamers"
        }
    },
    commandPrefix: "d!",
    appDir: "",
    language: "en"
};

and a screencap of my discord roles image`

GeekyDeaks commented 7 years ago

Hi @IrealiTY - thanks for the detailed diags! Your config looks fine, but that looks like a mongoDB permissions error, not a discord error. Are you able to insert records into the gamer collection manually from the mongo client when you connect with no credentials?

i.e. can you do

$ mongo
MongoDB shell version: 3.2.9
connecting to: test
> use des
> db.gamers.insert({ test : true })
WriteResult({ "nInserted" : 1 })
> db.gamers.remove({ test : true })
WriteResult({ "nRemoved" : 1 })

You made me realise I had left something in that had I not meant to though. I made the my command admin only to restrict it's usage as it's not quite finished (no TZ and games logic yet), but it should at least work for you with the config you have.

IrealiTY commented 7 years ago
connecting to: test
> use des
switched to db des
> db.gamers.insert({ test : true })
WriteResult({
        "writeError" : {
                "code" : 13,
                "errmsg" : "not authorized on des to execute command { insert: \"gamers\", documents: [ { _id: ObjectId('57cd71029085836494b51c43'), test: true } ], ordered: true }"
        }
})
>
GeekyDeaks commented 7 years ago

Ok, so that would suggest that the connection does not have write permission. I have to confess I was lazy and setup my mongodb as a local instance with no authorisation.

Can you provide the output from the following mongoDB commands:

> use des
> db.runCommand({connectionStatus : 1})
> db.getRoles({ rolesInfo: 1, showBuiltinRoles : true})

I think we need to work out which users you have and their permissions for your instance and then configure your connection string to use the correct one

IrealiTY commented 7 years ago
> use des
switched to db des
> db.runCommand({connectionStatus : 1})
{
        "authInfo" : {
                "authenticatedUsers" : [ ],
                "authenticatedUserRoles" : [ ]
        },
        "ok" : 1
}
> db.getRoles({ rolesInfo: 1, showBuiltinRoles : true})
2016-09-05T17:40:54.763+0200 E QUERY    [thread1] Error: not authorized on des to execute command { rolesInfo: 1.0, showBuiltinRoles: true } :
_getErrorWithCode@src/mongo/shell/utils.js:23:13
DB.prototype.getRoles@src/mongo/shell/db.js:1591:1
@(shell):1:1
GeekyDeaks commented 7 years ago

ah - ok - that definitely looks like you have permission issues with the account you are connecting with. Problem is I am a complete n00b with mongoDB. I'll have a dig around to see if I can help, but this might be a case of the blind leading the blind I am afraid :)

IrealiTY commented 7 years ago

I'll check myself dw - had a GUI for mongo earlier gonna try with that, guess you can close the issue since its on my side :)

unisys12 commented 7 years ago

@IrealiTY Not sure which GUI you are using for Mongo, but I really like RoboMongo. Just sharing. Somewhat new to Mongo myself

GeekyDeaks commented 7 years ago

let's keep it open until you solve it - I'd be interested to know as it could be something useful for others that we should add to the README

IrealiTY commented 7 years ago

Yeah I used robomongo last time but i get errors..

Error details

Cannot connect to the MongoDB at 127.0.0.1:54848.

Error: Failed to execute "listdatabases" command.

so silly... one day it was ok, now its not

IrealiTY commented 7 years ago

fixed, reinstalled mongodb :D