Skip to content
This repository has been archived by the owner on Jun 15, 2018. It is now read-only.

Commit

Permalink
fixed config warning for status
Browse files Browse the repository at this point in the history
added embed command
added emote command
fixed clear command numbers
added version number to help
  • Loading branch information
jagrosh committed Dec 27, 2016
1 parent a965713 commit 23bc20a
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/jselfbot/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public Bot(Config config)
commands = new Command[]{
new ClearCmd(),
new DeleteCmd(emojis),
new EmbedCmd(),
new EmoteCmd(),
new EvalCmd(),
new GameCmd(),
new GoogleCmd(),
Expand Down Expand Up @@ -94,6 +96,7 @@ public void onMessageReceived(MessageReceivedEvent event) {
sbuilder.append("` ").append(command.description);
}
builder.setDescription(sbuilder.toString());
builder.setFooter("JSelfbot v"+Constants.VERSION, null);
event.getChannel().sendMessage(new MessageBuilder().setEmbed(builder.build()).build()).queue();
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/jselfbot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
* @author John Grosh (jagrosh)
*/
public class Constants {
public static final String VERSION = "0.3";
public static final String VERSION = "0.4";
public static final String FAILURE = "\u274C";
}
5 changes: 0 additions & 5 deletions src/jselfbot/JSelfBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,10 @@
*/
package jselfbot;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import javax.security.auth.login.LoginException;
import jselfbot.entities.Config;
import net.dv8tion.jda.core.AccountType;
import net.dv8tion.jda.core.JDABuilder;
import net.dv8tion.jda.core.OnlineStatus;
import net.dv8tion.jda.core.exceptions.RateLimitedException;
import net.dv8tion.jda.core.utils.SimpleLog;

Expand Down
4 changes: 2 additions & 2 deletions src/jselfbot/commands/ClearCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ protected void execute(String args, MessageReceivedEvent event) {
return;
}
try {
event.getChannel().getHistory().retrievePast(num).queue(success -> {
List<Message> list = success.stream().filter(m -> event.getJDA().getSelfUser().equals(m.getAuthor())).collect(Collectors.toList());
event.getChannel().getHistory().retrievePast(num==100 ? 100 : num+1).queue(success -> {
List<Message> list = success.stream().filter(m -> event.getJDA().getSelfUser().equals(m.getAuthor()) && !event.getMessage().equals(m)).collect(Collectors.toList());
list.forEach(m -> m.deleteMessage().queue());
tempReply("Deleting "+list.size()+" messages.", event);
}, failure -> {
Expand Down
44 changes: 44 additions & 0 deletions src/jselfbot/commands/EmbedCmd.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2016 John Grosh (jagrosh).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package jselfbot.commands;

import jselfbot.Command;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;

/**
*
* @author John Grosh (jagrosh)
*/
public class EmbedCmd extends Command {

public EmbedCmd()
{
this.name = "embed";
this.description = "puts text in an embed";
this.arguments = "<stuff>";
}

@Override
protected void execute(String args, MessageReceivedEvent event) {
EmbedBuilder builder = new EmbedBuilder();
if(event.getGuild()!=null)
builder.setColor(event.getGuild().getSelfMember().getColor());
builder.setDescription(args);
reply(builder.build(), event);
}

}
53 changes: 53 additions & 0 deletions src/jselfbot/commands/EmoteCmd.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2016 John Grosh (jagrosh).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package jselfbot.commands;

import jselfbot.Command;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.entities.Emote;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;

/**
*
* @author John Grosh (jagrosh)
*/
public class EmoteCmd extends Command {

public EmoteCmd()
{
this.name = "emote";
this.description = "checks info about an emote";
this.arguments = "<:emote:>";
}

@Override
protected void execute(String args, MessageReceivedEvent event) {
String id = args.replaceAll("<:.+:(\\d+)>", "$1");
Emote emote = event.getJDA().getEmoteById(id);
if(emote==null)
tempReply("Invalid emote or emote ID", event);
else
{
EmbedBuilder builder = new EmbedBuilder();
if(event.getGuild()!=null)
builder.setColor(event.getGuild().getSelfMember().getColor());
builder.setImage(emote.getImageUrl());
builder.setDescription(emote.getAsMention()+" **:"+emote.getName()+":**\nID: **"+emote.getId()+"**\nGuild: **"+emote.getGuild().getName()+"**");
reply(builder.build(), event);
}
}

}
2 changes: 1 addition & 1 deletion src/jselfbot/entities/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public Config() throws Exception
if(status == OnlineStatus.UNKNOWN)
{
status = OnlineStatus.IDLE;
LOG.warn("\""+value+"\" is not a valid status; using the default IDLE! Valid statuses are ONLINE, IDLE, DO_NOT_DISTURB, and INVISIBLE.");
LOG.warn("\""+value+"\" is not a valid status; using the default IDLE! Valid statuses are ONLINE, IDLE, DND, and INVISIBLE.");
}
}
}
Expand Down

0 comments on commit 23bc20a

Please sign in to comment.