Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Created by Aaron Mc. with a WTFPL license. http://www.wtfpl.net/ */
- import scala.collection._;
- import scala.collection.mutable.{Set => mSet}
- import scala._;
- import scala.concurrent._;
- import scala.util.control.Breaks._;
- import sys.process._;
- import net.dv8tion.jda.core._;
- import net.dv8tion.jda.client._;
- import net.dv8tion.jda.core.entities._;
- import net.dv8tion.jda.core.events.message.{MessageReceivedEvent => MRE};
- import net.dv8tion.jda.core.hooks.ListenerAdapter;
- import java.awt.{Color => jColor};
- import net.dv8tion.jda.client.entities.Group;
- import net.dv8tion.jda.core.AccountType;
- import net.dv8tion.jda.core.entities.MessageEmbed.{Field => mField};
- import net.dv8tion.jda.core.JDA;
- import net.dv8tion.jda.core.JDABuilder;
- import net.dv8tion.jda.core.Permission;
- import net.dv8tion.jda.core.exceptions.PermissionException;
- import net.dv8tion.jda.core.exceptions.RateLimitedException;
- import java._;
- import javax._;
- package bot {
- class command (inp: String, des: String, outp: (String, MRE) => String, restrict: Boolean = false, restrictionList: Array[String] = Array("")) {
- val input: String = inp;
- val desc: String = des;
- val restricted: Boolean = restrict;
- val allowed: Array[String] = restrictionList;
- def out(a: String, b: MRE): String = {
- return outp(a, b);
- };
- };
- class msgListener() extends ListenerAdapter {
- override def onMessageReceived (event: MRE): Unit = {
- Global.evt = event;
- var jda: JDA = event.getJDA();
- var author: User = event.getAuthor();
- var message: Message = event.getMessage();
- var channel: MessageChannel = event.getChannel();
- val msg: String = message.getContent().toString()
- println("> " + event.getAuthor().getId() + ": " + msg);
- Global.currentChannel = channel;
- if (msg(0) == '$') channel.sendMessage(Global.commatch(event).toString()).queue;
- }
- }
- object Global {
- val isBot: Boolean = false;
- var botCommanders: Array[String] = Array("129663334784958465","294621373530112001", "221623241666461697", "144290567788953601");
- var userCommanders: Array[String] = Array("129663334784958465","294621373530112001");
- var commanders: Array[String] = if (isBot) botCommanders else userCommanders;
- var canRun: Boolean = true;
- var evt: MRE = null;
- var currentChannel: Any = 3;
- val commands = mSet.empty[command];
- def commatch (eventi: MRE): String = {
- var ctxstr: String = eventi.getMessage().getContent().toString();
- var auth: String = eventi.getAuthor().getId();
- var within: Array[String] = ctxstr.split(" ", 2);
- try {
- val ret: String = {
- Global.commands.find(a => a.input == within(0).toLowerCase()) match {
- case Some(com) => if (within.length < 2) return com.desc else if (!com.restricted || com.allowed.exists(x => x == auth)) return com.out(within(1), eventi) else if (Global.isBotI) return "You do not have permission to access that command!" else return "";
- case None => if ((botCommanders.exists(x => x == auth) && isBot) || (userCommanders.exists(x => x == auth) && !isBot)) return "Not a command" else return "";
- }
- };
- println("-->" + ret);
- return ret;
- } catch {
- case e: Throwable => {
- try {
- println("Not a command:\n\t\"" + ctxstr + "\"");
- } catch {
- case e: Exception => println(e);
- };
- }
- println("Error");
- return "Error";
- };
- }
- }
- object cfs {
- def stp (inp: String, evta: MRE): String = {
- Global.canRun = false;
- return ""
- }
- def emb (inp: String, evta: MRE): String = {
- var instruction: Array[String] = Array(" ", "00 ff 00", " ");
- var unstruction: Array[String] = inp.split("><", 0);
- val guk: EmbedBuilder = new EmbedBuilder;
- for (i <- 0 to (if (unstruction.length <= 3) (unstruction.length - 1) else 2)) {
- instruction(i) = unstruction(i);
- }
- if (unstruction.length <= 3) {
- guk.addField(new mField("_", "_", false));
- } else {
- var guffin: Array[Array[String]] = unstruction.slice(3, unstruction.length).grouped(2).toArray;
- for (abkadu <- 0 to (guffin.length -1)) {
- guk.addField(new mField(guffin(abkadu)(0), guffin(abkadu)(1), false));
- }
- }
- var cols: Array[Int] = instruction(1).split(" ", 3).map(e => Integer.parseInt(e, 16));
- guk.setTitle(instruction(0));
- guk.setAuthor(Global.evt.getAuthor().getName(), Global.evt.getAuthor().getAvatarUrl(), null);
- guk.setDescription(instruction(2));
- guk.setColor(new jColor(cols(0), cols(1), cols(2)));
- evta.getChannel match {
- case it: MessageChannel => {
- evta.getMessage.editMessage(new MessageBuilder().setEmbed(guk.build()).build()).queue();
- }
- }
- return ""
- }
- def say (inp: String, evt: MRE): String = {
- evt.getChannel.deleteMessageById(evt.getMessage.getId());
- return inp;
- }
- def men(inp: String, evt: MRE): String = {
- Global.canRun = true;
- evt.getChannel.deleteMessageById(evt.getMessage.getId());
- var instruction: Array[String] = inp.split(" ", 3);
- try {
- var i: Int = instruction(0).toInt
- evt.getChannel match {
- case it: MessageChannel => {
- val thread = new Thread {
- override def run {
- while (i > 0 && Global.canRun){
- i = i-1;
- it.sendMessage("<@" + instruction(2) + ">").queue();
- Thread.sleep(instruction(1).toInt);
- };
- }
- }
- thread.start
- }
- }
- return " ";
- } catch {
- case e: Throwable => return "error";
- }
- }
- def rep(inp: String, evt: MRE): String = {
- Global.canRun = true;
- evt.getChannel.deleteMessageById(evt.getMessage.getId());
- var instruction: Array[String] = inp.split(" ", 2);
- try {
- var i: Int = instruction(0).toInt;
- evt.getChannel match {
- case it: MessageChannel => {
- val thread = new Thread {
- override def run {
- while (i > 0 && Global.canRun){
- i = i - 1;
- it.sendMessage(instruction(1)).queue();
- Thread.sleep(1500);
- };
- }
- }
- thread.start
- }
- }
- return " ";
- } catch {
- case e: Throwable => return "error";
- }
- }
- }
- object Preface {
- def comInit () = {
- Global.commands.add(new command("$say", "Repeats text after command.", cfs.say, true, Global.commanders));
- Global.commands.add(new command("$stop", "Breaks loops.", cfs.stp, true, Global.commanders));
- Global.commands.add(new command("$repeat", "Type the ammount of times you want the text to repeat. Then type the text you want repeated.", cfs.rep, true, Global.commanders));
- Global.commands.add(new command("$mention", "Type the ammount of times you want the mention to repeat and the millisecond delay. Then type the ID of who to mention.", cfs.men, true, Global.commanders));
- Global.commands.add(new command("$embed", "Type a message to send in an embed. Format Title><RR GG BB><Description{><Field Title><Field Value}", cfs.emb, true, Global.commanders));
- }
- def jdaInit () = {
- try {
- if (Global.isBot) {
- var jda: JDA = new JDABuilder(AccountType.BOT).setToken("Secret Bot Token").addListener(new msgListener()).buildBlocking();
- } else {
- var jda: JDA = new JDABuilder(AccountType.CLIENT).setToken("Secret User Token").addListener(new msgListener()).buildBlocking();
- } }
- catch {
- case e: Throwable => e.printStackTrace();
- }
- }
- }
- object Main {
- def main (args: Array[String]):Unit = {
- Preface.comInit();
- Preface.jdaInit();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement