Giter Site home page Giter Site logo

Convert name to ID? about plugapi HOT 8 CLOSED

moongoesrawr avatar moongoesrawr commented on June 2, 2024
Convert name to ID?

from plugapi.

Comments (8)

WiBla avatar WiBla commented on June 2, 2024

Correct me if I'm wrong (It's been a really long time since I last worked with plugAPI) but I think a way to implement this feature would be by first creating a getUserByName function that returns an user object, then use that user's id in order to ban him.

https://github.com/plugCubed/plugAPI/wiki/%5Bactions%5D-getUsers

bot.getUserByName = function(name) {
    return bot.getUsers().filter(user => user.username === name);
}

Then you can do (in your command handler or anywhere else):

bot.moderateBanUser(bot.getUserByName('WiBla').id);

You can check the wiki for more info on banning people with
reasons and to set the duration as well : https://github.com/plugCubed/plugAPI/wiki/%5Bactions%5D-moderateBanUser

Keep in mind that I haven't tested any of this code but I'm fairly confident it should work!
Hope this helps 😄

from plugapi.

moongoesrawr avatar moongoesrawr commented on June 2, 2024

Thank you so much for providing this. I tried it, and it doesn't work for me. I'm assuming where you have 'WiBla' below is where I would use my input variable?

bot.moderateBanUser(bot.getUserByName('WiBla').id);

from plugapi.

WiBla avatar WiBla commented on June 2, 2024

My pleasure!
Indeed, you need to substitute my username with the actual one you need, you should hopefully have this inside a variable as you said :)

Also, I've just looked at the command event after being told by @thedark1337 that plugAPI already provide you a user ID!
https://github.com/plugCubed/plugAPI/wiki/%5Bevents%5D-command

And indeed it does, so you should be able to do:

bot.on('command:ban', function(cmd) {
    bot.moderateBanUser(cmd.mentions[0].id);
});

In this very crude example, I'm only getting the first mentioned user's id (mentions[0]), but since it is an array, you can loop through all of its content!
Also, it goes without saying that this example does not check for user permission, both on the user that triggered the command but also for the bot itself. You should always do this and even more so with a moderation command.

With all of that, I hope you will be able to make the feature you wanted!
Please let us know how it went and if you ever need more help!

from plugapi.

moongoesrawr avatar moongoesrawr commented on June 2, 2024

Thanks so much again for helping me. I wish I was more knowledgeable about this stuff. I'm trying though! :) I'm afraid I'm confused again. Should I still use your code, plus this new snippet? Do I just use this new snippet? When I started doing this I kind of latched onto an older bot and did my own thing from there. Should all commands be done the way you have provided with bot.on('command:ban', function(cmd) {}, or is this not to actually run a command? Again sorry for the questions, i'm trying to become familiar with it all. I'd like to do a complete re-write but I am not sure I'm knowledgeable enough yet. Here is the current command that i'm playing with. I'm testing with bot.moderateAddDJ(); first before I move onto my ban commands.

case ".test":
            if (bot.havePermission(data.from.id, roleHost)) {
                let username = qualifier;
                let usernameAdd = S(username).chompLeft('@').s;
                bot.moderateAddDJ(bot.getUserByName(usernameAdd).id);
            }
	   break;

from plugapi.

thedark1337 avatar thedark1337 commented on June 2, 2024

https://plugcubed.github.io/plugAPI/

Sorry its not very well documented, but, linked is the docs to the API

the way WiBla just showed is the official commands handler for plugAPI and 99% of the time it works, although i believe there's still a few bugs related to it.

That way would however require you needing to rewrite your bot so it uses the API's way of writing commands, or you can test out the get user by name way if you want to run your own command handler.

from plugapi.

moongoesrawr avatar moongoesrawr commented on June 2, 2024

Looks like I have a bot to re-write. :)

from plugapi.

moongoesrawr avatar moongoesrawr commented on June 2, 2024

Ok guys, I redid my commands using this new method and while it works for most everything, I'm having problems with waitlist bans/unbans and mute/unmute. Nothing happens. I'm hoping my code is just wrong, but shouldn't this work if I have the duration and reason assigned to the variables I'm using? I tried it without and it didn't work either.

.wlban @username
.wlunban @username

bot.on('command:wlban', function(data) {
    if (bot.havePermission(data.from.id, roleManager)) {
        bot.moderateWaitListBan(data.mentions[0].id, wlbanGenre, wlbanLong);
    }
});

My wait list unban as well.

bot.on('command:wlunban', function(data) {
    if (bot.havePermission(data.from.id, roleManager)) {
        bot.moderateWaitListUnban(data.mentions[0].id);
    }
});

from plugapi.

moongoesrawr avatar moongoesrawr commented on June 2, 2024

I figured it out. :) Thanks for all the help with this everyone.

from plugapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.