made tengwar command rate-limited
This commit is contained in:
parent
3ef3f38fb0
commit
7a4b3e8c36
|
@ -6,9 +6,8 @@ import handiebot.utils.MessageUtils;
|
|||
import net.agspace.TengwarImageGenerator;
|
||||
import net.agspace.Translator;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
import static handiebot.HandieBot.resourceBundle;
|
||||
import static handiebot.utils.MessageUtils.sendFile;
|
||||
import static handiebot.utils.MessageUtils.sendMessage;
|
||||
|
||||
/**
|
||||
|
@ -31,17 +30,14 @@ public class TengwarCommand extends ContextCommand {
|
|||
String input = MessageUtils.getTextFromArgs(context.getArgs(), 1);
|
||||
if (context.getArgs()[0].equalsIgnoreCase("to")){
|
||||
String result = Translator.translateToTengwar(input);
|
||||
try {
|
||||
//TODO: replace with rate-limited send method.
|
||||
context.getChannel().sendFile("Raw text: `" +result+'`', TengwarImageGenerator.generateImage(result,
|
||||
sendFile(TengwarImageGenerator.generateImage(result,
|
||||
600,
|
||||
24f,
|
||||
false,
|
||||
false,
|
||||
System.getProperty("user.home")+"/.handiebot/tengwarTemp.png"));
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.getProperty("user.home")+"/.handiebot/tengwarTemp.png"),
|
||||
"Raw text: `" +result+'`',
|
||||
context.getChannel());
|
||||
} else if (context.getArgs()[0].equalsIgnoreCase("from")){
|
||||
sendMessage(Translator.translateToEnglish(input), context.getChannel());
|
||||
}
|
||||
|
|
|
@ -120,7 +120,6 @@ public class Playlist {
|
|||
* Gets a 'shuffled index' from a given list length. That means:
|
||||
* - A random number from 0 to (listLength-1) - threshold*(listLength), where threshold is some percentage of
|
||||
* recent songs that should be ignored; for example, the most recent 20% of the playlist can be ignored.
|
||||
* - A greater likelihood for numbers closer to 0 (those which have not been played in a while).
|
||||
* @param listLength The number of items in a potential list to choose from.
|
||||
* @return A pseudo-random choice as to which item to pick from the list.
|
||||
*/
|
||||
|
@ -128,7 +127,6 @@ public class Playlist {
|
|||
float threshold = 0.2f;
|
||||
int trueLength = listLength - (int)(threshold*(float)listLength);
|
||||
Random rand = new Random();
|
||||
//TODO Add in a small gradient in chance for a song to be picked.
|
||||
return rand.nextInt(trueLength);
|
||||
}
|
||||
|
||||
|
|
|
@ -49,11 +49,11 @@ public class MessageUtils {
|
|||
* @param channel The channel to send the message on.
|
||||
* @return The message that was sent, or null if the file could not be found.
|
||||
*/
|
||||
public static IMessage sendFile(File file, IChannel channel){
|
||||
public static IMessage sendFile(File file, String content, IChannel channel){
|
||||
return RequestBuffer.request(() -> {
|
||||
IMessage msg = null;
|
||||
try {
|
||||
msg = channel.sendFile(file);
|
||||
msg = channel.sendFile(content, file);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue