Add files via upload

This commit is contained in:
Koala 2024-08-18 13:35:50 +08:00 committed by GitHub
parent 42fad2b342
commit 4316327407
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 356 additions and 9 deletions

View file

@ -42,14 +42,15 @@ tasks.build {
dependencies {
implementation group: 'net.dv8tion', name: 'JDA', version: '5.0.2'
implementation group: 'pw.chew', name: 'jda-chewtils', version: '2.0-SNAPSHOT'
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.3.0-alpha16'
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.4.12'
implementation group: 'io.github.cdimascio', name: 'java-dotenv', version: '5.2.2'
implementation group: 'org.xerial', name: 'sqlite-jdbc', version: '3.36.0.3'
implementation group: 'org.xerial', name: 'sqlite-jdbc', version: '3.41.2.2'
implementation group: 'com.zaxxer', name: 'HikariCP', version: '5.0.1'
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.3.0-alpha16'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'
implementation group: 'me.xdrop', name: 'fuzzywuzzy', version: '1.4.0'
implementation 'org.apache.httpcomponents:httpclient:4.5.13'
implementation group: 'org.json', name: 'json', version: '20220320'
implementation group: 'org.apache.httpcomponents', name:'httpclient', version: '4.5.13'
implementation group: 'org.json', name: 'json', version: '20231013'
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
implementation 'org.mongodb:mongodb-driver-sync:5.1.2'
}

View file

@ -17,6 +17,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Bot {
public static EventWaiter eventWaiter;
private static final Logger LOGGER = LoggerFactory.getLogger(Bot.class);
public Bot() throws InterruptedException {
@ -25,9 +26,8 @@ public class Bot {
// Set the client settings
client.setOwnerId(Config.get("owner_id"));
client.setStatus(OnlineStatus.ONLINE);
client.setActivity(Activity.listening("for loopholes"));
addCommands(client);
EventWaiter eventWaiter = new EventWaiter();
eventWaiter = new EventWaiter();
// Finalize the command client
CommandClient commandClient = client.build();

View file

@ -2,6 +2,11 @@ package github.io.koala3353.bot.commands;
import com.jagrosh.jdautilities.command.SlashCommand;
import com.jagrosh.jdautilities.command.SlashCommandEvent;
import github.io.koala3353.bot.database.MongoDBPojo;
import net.dv8tion.jda.api.EmbedBuilder;
import java.awt.*;
import java.time.OffsetDateTime;
public class BalanceCommand extends SlashCommand {
public BalanceCommand() {
@ -11,6 +16,18 @@ public class BalanceCommand extends SlashCommand {
@Override
protected void execute(SlashCommandEvent event) {
event.reply("Balance command is not implemented yet!").queue();
long userId = event.getUser().getIdLong();
// Get the balance of the user
int balance = MongoDBPojo.getUser(userId).getBalance();
EmbedBuilder embed = new EmbedBuilder();
embed.setAuthor(event.getUser().getEffectiveName() + "'s Balance", null, event.getUser().getAvatarUrl());
embed.setTimestamp(OffsetDateTime.now());
embed.setDescription("You have <:shekels:906039266650505256> " + balance + " shekels\n\n" +
"Use the shop to spend your shekels!\n" +
"**Pro tip:** Start your adventure to earn more!");
embed.setColor(Color.decode("#4A2C6E"));
event.replyEmbeds(embed.build()).setEphemeral(true).queue();
}
}

View file

@ -2,6 +2,14 @@ package github.io.koala3353.bot.commands;
import com.jagrosh.jdautilities.command.SlashCommand;
import com.jagrosh.jdautilities.command.SlashCommandEvent;
import github.io.koala3353.bot.database.MongoDBPojo;
import github.io.koala3353.bot.database.User;
import net.dv8tion.jda.api.EmbedBuilder;
import java.awt.*;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.List;
public class ProfileCommand extends SlashCommand {
public ProfileCommand() {
@ -11,6 +19,25 @@ public class ProfileCommand extends SlashCommand {
@Override
protected void execute(SlashCommandEvent event) {
event.reply("Profile command is not implemented yet!").queue();
long userId = event.getUser().getIdLong();
User dbUser = MongoDBPojo.getUser(userId);
int balance = dbUser.getBalance();
int uniqueItemsOwned = dbUser.getItems().size();
List<String> suitsSelected = dbUser.getSuit();
String suitsSelectedString = String.join(", ", suitsSelected);
boolean hasEscaped = dbUser.isEscaped();
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setAuthor(event.getUser().getEffectiveName() + "'s Profile", null, event.getUser().getAvatarUrl());
embedBuilder.addField("**Balance:**", "<:shekels:906039266650505256> " + balance + " shekels", false);
embedBuilder.addField("**Unique items owned:** ", uniqueItemsOwned + "", false);
embedBuilder.addField("**Suits selected:** ", suitsSelectedString, false);
embedBuilder.addField("**Has escaped:** ", hasEscaped ? "Yes" : "No", false);
embedBuilder.setDescription("Check out your profile!");
embedBuilder.setColor(Color.decode("#4A2C6E"));
embedBuilder.setThumbnail(event.getJDA().getSelfUser().getAvatarUrl());
embedBuilder.setTimestamp(OffsetDateTime.now());
event.replyEmbeds(embedBuilder.build()).setEphemeral(true).queue();
}
}

View file

@ -2,6 +2,16 @@ package github.io.koala3353.bot.commands;
import com.jagrosh.jdautilities.command.SlashCommand;
import com.jagrosh.jdautilities.command.SlashCommandEvent;
import com.jagrosh.jdautilities.menu.ButtonEmbedPaginator;
import com.jagrosh.jdautilities.menu.Paginator;
import github.io.koala3353.bot.Bot;
import github.io.koala3353.bot.database.MongoDBPojo;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.MessageEmbed;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
public class ViewInventoryCommand extends SlashCommand {
public ViewInventoryCommand() {
@ -11,6 +21,10 @@ public class ViewInventoryCommand extends SlashCommand {
@Override
protected void execute(SlashCommandEvent event) {
event.reply("Inventory command is not implemented yet!").queue();
event.reply("Loading your inventory...").setEphemeral(true).queue();
EmbedBuilder embed = new EmbedBuilder();
embed.setAuthor(event.getUser().getEffectiveName() + "'s Inventory", null, event.getUser().getAvatarUrl());
}
}

View file

@ -0,0 +1,77 @@
package github.io.koala3353.bot.database;
import net.dv8tion.jda.api.entities.emoji.Emoji;
public class Item {
String name;
String description;
String item_id;
int cost;
String emoji;
public Item() {}
public String getName() {
return name;
}
public Item setName(String name) {
this.name = name;
return this;
}
public String getDescription() {
return description;
}
public Item setDescription(String description) {
this.description = description;
return this;
}
public String getItem_id() {
return item_id;
}
public Item setItem_id(String item_id) {
this.item_id = item_id;
return this;
}
public int getCost() {
return cost;
}
public boolean isBuyable() {
return cost > 0;
}
public Item setCost(int cost) {
this.cost = cost;
return this;
}
public String getEmoji() {
return emoji;
}
public Item setEmoji(String emoji) {
this.emoji = emoji;
return this;
}
public Emoji getEmojiObject() {
return Emoji.fromFormatted(this.emoji);
}
@Override
public String toString() {
return "Item{" +
"name='" + name + '\'' +
", description='" + description + '\'' +
", id='" + item_id + '\'' +
", cost=" + cost +
", emoji='" + emoji + '\'' +
'}';
}
}

View file

@ -0,0 +1,87 @@
package github.io.koala3353.bot.database;
import static com.mongodb.MongoClientSettings.getDefaultCodecRegistry;
import static com.mongodb.client.model.Filters.eq;
import static org.bson.codecs.configuration.CodecRegistries.fromProviders;
import static org.bson.codecs.configuration.CodecRegistries.fromRegistries;
import org.bson.codecs.configuration.CodecProvider;
import org.bson.codecs.configuration.CodecRegistry;
import org.bson.codecs.pojo.PojoCodecProvider;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.slf4j.Logger;
import java.util.ArrayList;
import java.util.List;
public class MongoDBPojo {
private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(MongoDBPojo.class);
public static User getUser(long discordId) {
CodecProvider pojoCodecProvider = PojoCodecProvider.builder().automatic(true).build();
CodecRegistry pojoCodecRegistry = fromRegistries(getDefaultCodecRegistry(), fromProviders(pojoCodecProvider));
// Replace the uri string with your MongoDB deployment's connection string
String uri = "mongodb+srv://keenebrigado:s2jwxTBHPbFxxtNO@rpg-loophole.oc40e.mongodb.net/?retryWrites=true&w=majority&appName=rpg-loophole";
try (MongoClient mongoClient = MongoClients.create(uri)) {
MongoDatabase database = mongoClient.getDatabase("rpg").withCodecRegistry(pojoCodecRegistry);
MongoCollection<User> collection = database.getCollection("user", User.class);
User user = collection.find(eq("discord", discordId)).first();
LOGGER.info("Retrieved user from MongoDB successfully " + user.toString());
return user;
}
}
public static User addUser(long discordId) {
CodecProvider pojoCodecProvider = PojoCodecProvider.builder().automatic(true).build();
CodecRegistry pojoCodecRegistry = fromRegistries(getDefaultCodecRegistry(), fromProviders(pojoCodecProvider));
// Replace the uri string with your MongoDB deployment's connection string
String uri = "mongodb+srv://keenebrigado:s2jwxTBHPbFxxtNO@rpg-loophole.oc40e.mongodb.net/?retryWrites=true&w=majority&appName=rpg-loophole";
try (MongoClient mongoClient = MongoClients.create(uri)) {
MongoDatabase database = mongoClient.getDatabase("rpg").withCodecRegistry(pojoCodecRegistry);
MongoCollection<User> collection = database.getCollection("user", User.class);
User user = new User(discordId);
collection.insertOne(user);
LOGGER.info("Added user to MongoDB successfully " + user.toString());
return user;
}
}
// Items
public static Item getItem(String itemId) {
CodecProvider pojoCodecProvider = PojoCodecProvider.builder().automatic(true).build();
CodecRegistry pojoCodecRegistry = fromRegistries(getDefaultCodecRegistry(), fromProviders(pojoCodecProvider));
// Replace the uri string with your MongoDB deployment's connection string
String uri = "mongodb+srv://keenebrigado:s2jwxTBHPbFxxtNO@rpg-loophole.oc40e.mongodb.net/?retryWrites=true&w=majority&appName=rpg-loophole";
try (MongoClient mongoClient = MongoClients.create(uri)) {
MongoDatabase database = mongoClient.getDatabase("rpg").withCodecRegistry(pojoCodecRegistry);
MongoCollection<Item> collection = database.getCollection("items", Item.class);
Item item = collection.find(eq("id", itemId)).first();
LOGGER.info("Retrieved item from MongoDB successfully " + item.toString());
return item;
}
}
public static List<Item> getItems() {
CodecProvider pojoCodecProvider = PojoCodecProvider.builder().automatic(true).build();
CodecRegistry pojoCodecRegistry = fromRegistries(getDefaultCodecRegistry(), fromProviders(pojoCodecProvider));
// Replace the uri string with your MongoDB deployment's connection string
String uri = "mongodb+srv://keenebrigado:s2jwxTBHPbFxxtNO@rpg-loophole.oc40e.mongodb.net/?retryWrites=true&w=majority&appName=rpg-loophole";
try (MongoClient mongoClient = MongoClients.create(uri)) {
MongoDatabase database = mongoClient.getDatabase("rpg").withCodecRegistry(pojoCodecRegistry);
MongoCollection<Item> collection = database.getCollection("items", Item.class);
List<Item> items = new ArrayList<>();
collection.find().into(items);
LOGGER.info("Retrieved items from MongoDB successfully " + items);
return items;
}
}
public static void main(String[] args) {
// Test the MongoDB connection
getUser(959233424890142801L);
//addUser(959233424890142801);
getItems();
}
}

View file

@ -0,0 +1,90 @@
package github.io.koala3353.bot.database;
import java.util.ArrayList;
import java.util.List;
public class User {
long discord;
List<UserItem> items;
int balance;
int loop;
boolean escaped;
List<String> suit;
public User(long discord) {
this.discord = discord;
this.items = new ArrayList<>();
this.balance = 0;
this.loop = 0;
this.escaped = false;
this.suit = new ArrayList<>();
}
public User() {}
public long getDiscord() {
return discord;
}
public User setDiscord(long discord) {
this.discord = discord;
return this;
}
public List<UserItem> getItems() {
return items;
}
public User setItems(List<UserItem> items) {
this.items = items;
return this;
}
public int getBalance() {
return balance;
}
public User setBalance(int balance) {
this.balance = balance;
return this;
}
public int getLoop() {
return loop;
}
public User setLoop(int loop) {
this.loop = loop;
return this;
}
public boolean isEscaped() {
return escaped;
}
public User setEscaped(boolean escaped) {
this.escaped = escaped;
return this;
}
public List<String> getSuit() {
return suit;
}
public User setSuit(List<String> suit) {
this.suit = suit;
return this;
}
@Override
public String toString() {
return "User{" +
"discord=" + discord +
", items=" + items +
", balance=" + balance +
", loop=" + loop +
", escaped=" + escaped +
", suit=" + suit +
'}';
}
}

View file

@ -0,0 +1,34 @@
package github.io.koala3353.bot.database;
public class UserItem {
int amount;
String item;
public UserItem() {}
public int getAmount() {
return amount;
}
public UserItem setAmount(int amount) {
this.amount = amount;
return this;
}
public String getItem() {
return item;
}
public UserItem setItem(String item) {
this.item = item;
return this;
}
@Override
public String toString() {
return "UserItem{" +
"amount=" + amount +
", item='" + item + '\'' +
'}';
}
}