forked from Together-Java/TjBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
287 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/org/togetherjava/discordbot/commands/commands/ExampleCommandDB.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.togetherjava.discordbot.commands.commands; | ||
|
||
import de.ialistannen.commandprocrastination.autodiscovery.ActiveCommand; | ||
import de.ialistannen.commandprocrastination.command.tree.CommandNode; | ||
import de.ialistannen.commandprocrastination.parsing.ParseException; | ||
import org.togetherjava.discordbot.commands.CommandContext; | ||
import org.togetherjava.discordbot.db.autogen.tables.pojos.Test; | ||
import org.togetherjava.discordbot.db.repositories.ExampleRepository; | ||
|
||
import static de.ialistannen.commandprocrastination.parsing.defaults.StringParsers.greedyPhrase; | ||
|
||
@ActiveCommand(name = "example", parentClass = BasePrefixCommand.class) | ||
@SuppressWarnings("unused") | ||
public class ExampleCommandDB extends CommandNode<CommandContext> { | ||
|
||
private ExampleRepository repository; | ||
|
||
@SuppressWarnings("unused") | ||
public ExampleCommandDB(CommandContext context) { | ||
super("example"); | ||
repository = new ExampleRepository(context); | ||
setCommand(this::execute); | ||
} | ||
|
||
private void execute(CommandContext context) throws ParseException { | ||
repository.add(new Test(null, context.getRequestContext().getUser().getName(), context.shift(greedyPhrase()))); | ||
for(Test value: repository.getAll()){ | ||
context.getRequestContext().getChannel().sendMessage(value.getText()).queue(); | ||
} | ||
|
||
for(Test value: repository.getAll()){ | ||
value.setText(value.getText() + "UPDATE TEST"); | ||
repository.update(value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/java/org/togetherjava/discordbot/db/repositories/ExampleRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.togetherjava.discordbot.db.repositories; | ||
|
||
import org.togetherjava.discordbot.commands.CommandContext; | ||
import org.togetherjava.discordbot.db.autogen.tables.daos.TestDao; | ||
import org.togetherjava.discordbot.db.autogen.tables.pojos.Test; | ||
import org.togetherjava.discordbot.db.repository.SimpleRepository; | ||
import java.util.List; | ||
|
||
/** | ||
* can use the dao or the DSLContext to write queries, the dao having most things pre written | ||
*/ | ||
public class ExampleRepository extends SimpleRepository<Test> { | ||
|
||
private TestDao dao; | ||
|
||
public ExampleRepository(CommandContext context){ | ||
super(context); | ||
dao = new TestDao(dslContext.configuration()); | ||
} | ||
|
||
@Override | ||
public void add(Test item) { | ||
dao.insert(item); | ||
} | ||
|
||
@Override | ||
public void update(Test item) { | ||
dao.update(item); | ||
} | ||
|
||
@Override | ||
public void remove(Test item) { | ||
dao.delete(item); | ||
} | ||
|
||
@Override | ||
public List<Test> getAll() { | ||
return dao.findAll(); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/org/togetherjava/discordbot/db/repository/Repository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.togetherjava.discordbot.db.repository; | ||
|
||
import java.util.List; | ||
|
||
public interface Repository<T> { | ||
|
||
void add(T item); | ||
|
||
void update(T item); | ||
|
||
void remove(T item); | ||
|
||
List<T> getAll(); | ||
|
||
} | ||
|
15 changes: 15 additions & 0 deletions
15
src/main/java/org/togetherjava/discordbot/db/repository/SimpleRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.togetherjava.discordbot.db.repository; | ||
|
||
import org.jooq.*; | ||
import org.jooq.impl.DSL; | ||
import org.togetherjava.discordbot.commands.CommandContext; | ||
|
||
public abstract class SimpleRepository<T> implements Repository<T> { | ||
|
||
protected DSLContext dslContext; | ||
|
||
public SimpleRepository(CommandContext context) { | ||
dslContext = DSL.using(context.getConfig().getDburl()); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/org/togetherjava/discordbot/events/modmail/ModMailListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.togetherjava.discordbot.events.modmail; | ||
|
||
import lombok.NonNull; | ||
import net.dv8tion.jda.api.JDA; | ||
import net.dv8tion.jda.api.entities.Member; | ||
import net.dv8tion.jda.api.entities.TextChannel; | ||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; | ||
import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent; | ||
import net.dv8tion.jda.api.hooks.ListenerAdapter; | ||
import org.togetherjava.discordbot.config.TjBotConfig; | ||
import javax.annotation.Nonnull; | ||
import java.util.List; | ||
|
||
|
||
|
||
public class ModMailListener extends ListenerAdapter { | ||
private TextChannel moderation; | ||
|
||
public ModMailListener(JDA jda, TjBotConfig config) { | ||
List<TextChannel> channels = jda.getTextChannelsByName(config.getModerationChannel(), false); | ||
if(channels.isEmpty()){ | ||
throw new IllegalArgumentException("Moderation channel is invalid, does not exist"); | ||
} | ||
moderation = channels.get(0); | ||
} | ||
|
||
@Override | ||
public void onPrivateMessageReceived(@Nonnull PrivateMessageReceivedEvent event) { | ||
if (!event.getAuthor().isBot()) { | ||
String message = "<@" + event.getAuthor().getId() + ">: " + event.getMessage().getContentRaw(); | ||
moderation.sendMessage(message).queue(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onGuildMessageReceived(@NonNull GuildMessageReceivedEvent event) { | ||
if(!event.getMessage().getTextChannel().equals(moderation)){ | ||
return; | ||
} | ||
|
||
List<Member> mentioned = event.getMessage().getMentionedMembers(); | ||
if (!event.getAuthor().isBot() && !mentioned.isEmpty()) { | ||
mentioned.get(0).getUser().openPrivateChannel().queue((channel) -> | ||
channel.sendMessage(event.getMessage()).queue()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CREATE TABLE IF NOT EXISTS TEST | ||
( | ||
ID INTEGER AUTO_INCREMENT PRIMARY KEY, | ||
MEMBER varchar(30) NOT NULL, | ||
TEXT varchar(30) NOT NULL | ||
); |
Oops, something went wrong.