Example usage for twitter4j Twitter createBlock

List of usage examples for twitter4j Twitter createBlock

Introduction

In this page you can find the example usage for twitter4j Twitter createBlock.

Prototype

User createBlock(long userId) throws TwitterException;

Source Link

Document

Blocks the user specified in the ID parameter as the authenticating user.

Usage

From source file:br.shura.team.mpsbot.venusext.BlockUserById.java

License:Open Source License

@Override
public void callVoid(Context context, FunctionCallDescriptor descriptor) throws ScriptRuntimeException {
    ConnectedBot bot = context.getApplicationContext().getUserData("bot", ConnectedBot.class);
    Twitter twitter = bot.getHandler();
    IntegerValue value = (IntegerValue) descriptor.get(0);

    Helper.execute(context, () -> twitter.createBlock(value.value()));
}

From source file:br.shura.team.mpsbot.venusext.BlockUserByName.java

License:Open Source License

@Override
public void callVoid(Context context, FunctionCallDescriptor descriptor) throws ScriptRuntimeException {
    ConnectedBot bot = context.getApplicationContext().getUserData("bot", ConnectedBot.class);
    Twitter twitter = bot.getHandler();
    StringValue value = (StringValue) descriptor.get(0);

    Helper.execute(context, () -> twitter.createBlock(value.value()));
}

From source file:com.github.moko256.twitlatte.ShowUserActivity.java

License:Apache License

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    ThrowableFunc throwableFunc = null;//from  w  ww .  java  2s  .c o m
    @StringRes
    int didAction = -1;
    Twitter twitter = GlobalApplication.twitter;

    switch (item.getItemId()) {
    case R.id.action_share:
        startActivity(Intent.createChooser(new Intent().setAction(Intent.ACTION_SEND).setType("text/plain")
                .putExtra(Intent.EXTRA_TEXT, getShareUrl()), getString(R.string.share)));
        break;
    case R.id.action_open_in_browser:
        AppCustomTabsKt.launchChromeCustomTabs(this, getShareUrl());
        break;
    case R.id.action_create_follow:
        throwableFunc = () -> twitter.createFriendship(user.getId());
        didAction = R.string.did_follow;
        break;
    case R.id.action_destroy_follow:
        throwableFunc = () -> twitter.destroyFriendship(user.getId());
        didAction = R.string.did_unfollow;
        break;
    case R.id.action_create_mute:
        throwableFunc = () -> twitter.createMute(user.getId());
        didAction = R.string.did_mute;
        break;
    case R.id.action_destroy_mute:
        throwableFunc = () -> twitter.destroyMute(user.getId());
        didAction = R.string.did_unmute;
        break;
    case R.id.action_create_block:
        throwableFunc = () -> twitter.createBlock(user.getId());
        didAction = R.string.did_block;
        break;
    case R.id.action_destroy_block:
        throwableFunc = () -> twitter.destroyBlock(user.getId());
        didAction = R.string.did_unblock;
        break;
    case R.id.action_destroy_follow_follower:
        throwableFunc = () -> {
            twitter.createBlock(user.getId());
            twitter.destroyBlock(user.getId());
        };
        didAction = R.string.did_destroy_ff;
        break;
    case R.id.action_spam_report:
        throwableFunc = () -> GlobalApplication.twitter.reportSpam(user.getId());
        break;
    }

    if (throwableFunc != null && didAction != -1) {
        ThrowableFunc finalThrowableFunc = throwableFunc;
        int finalDidAction = didAction;
        confirmDialog(item.getTitle(), getString(R.string.confirm_message),
                () -> runAsWorkerThread(finalThrowableFunc, finalDidAction));
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.javielinux.utils.UserActions.java

License:Apache License

public static void goToCreateBlock(Context context, InfoUsers infoUsers) {
    ConnectionManager.getInstance().open(context);
    Twitter twitter = ConnectionManager.getInstance()
            .getTwitter(DBUtils.getIdFromUserName(infoUsers.getName()));
    try {/*  w ww .jav a 2s  . c  om*/
        boolean isBlock = false;
        for (long id : twitter.getBlocksIDs().getIDs()) {
            if (id == infoUsers.getId()) {
                isBlock = true;
                break;
            }
        }
        if (true) {
            twitter.destroyBlock(infoUsers.getName());
            Utils.showMessage(context, context.getString(R.string.user_unlock));
        } else {
            twitter.createBlock(infoUsers.getName());
            Utils.showMessage(context, context.getString(R.string.user_block));
        }
    } catch (TwitterException e) {
        e.printStackTrace();
    }
}

From source file:twitter4j.examples.block.CreateBlock.java

License:Apache License

/**
 * Usage: java twitter4j.examples.block.CreateBlock [screen name]
 *
 * @param args message//www .  j  a  v  a2  s .c o m
 */
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("Usage: java twitter4j.examples.block.CreateBlock [screen name]");
        System.exit(-1);
    }
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        twitter.createBlock(args[0]);
        System.out.println("Successfully blocked user [" + args[0] + "].");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to block user: " + te.getMessage());
        System.exit(-1);
    }
}