mirror of
https://github.com/ION606/selmerBot.git
synced 2026-05-15 05:36:54 +00:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e03b689d6d | |||
| 1d30414304 | |||
| 0d3935d5c6 | |||
| af5b206652 | |||
| 3b464aecbf | |||
| 374ecbffea | |||
| d8ca1d5055 | |||
| ae63a93940 | |||
| f122f84a0c | |||
| 29e42c745e | |||
| 388c65c6dc | |||
| eb828a59c0 | |||
| a1df043f86 | |||
| e23f238c89 |
+149
-142
@@ -2,150 +2,157 @@ let d = new Date();
|
||||
const START = d.getTime();
|
||||
|
||||
|
||||
const { MongoClient, ServerApiVersion } = require('mongodb');
|
||||
const mongouri = process.env.MONGODB_URI; //DO NOT RUN LOCALLY (no process.env)
|
||||
resetShop = false;
|
||||
|
||||
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
||||
let collectiontemp;
|
||||
client.connect(err => {
|
||||
collectiontemp = client.db("main").collection("shop");
|
||||
// perform actions on the collection object
|
||||
collectiontemp.insertMany(
|
||||
[
|
||||
{ name: 'Grapes', cost: 2, icon: '🍇', sect: 'Food' },
|
||||
{ name: 'Melon', cost: 5, icon: '🍈', sect: 'Food' },
|
||||
{ name: 'Watermelon', cost: 5, icon: '🍉', sect: 'Food' },
|
||||
{ name: 'Tangerine', cost: 3, icon: '🍊', sect: 'Food' },
|
||||
{ name: 'Lemon', cost: 3, icon: '🍋', sect: 'Food' },
|
||||
{ name: 'Banana', cost: 4, icon: '🍌', sect: 'Food' },
|
||||
{ name: 'Pineapple', cost: 4, icon: '🍍', sect: 'Food' },
|
||||
{ name: 'Mango', cost: 3, icon: '🥭', sect: 'Food' },
|
||||
{ name: 'Red Apple', cost: 3, icon: '🍎', sect: 'Food' },
|
||||
{ name: 'Green Apple', cost: 3, icon: '🍏', sect: 'Food' },
|
||||
{ name: 'Pear', cost: 3, icon: '🍐', sect: 'Food' },
|
||||
{ name: 'Peach', cost: 3, icon: '🍑', sect: 'Food' },
|
||||
{ name: 'Cherries', cost: 4, icon: '🍒', sect: 'Food' },
|
||||
{ name: 'Strawberry', cost: 3, icon: '🍓', sect: 'Food' },
|
||||
{ name: 'Blueberries', cost: 3, icon: '🫐', sect: 'Food' },
|
||||
{ name: 'Kiwi', cost: 3, icon: '🥝', sect: 'Food' },
|
||||
{ name: 'Tomato', cost: 4, icon: '🍅', sect: 'Food' },
|
||||
{ name: 'Olive', cost: 4, icon: '🫒', sect: 'Food' },
|
||||
{ name: 'Coconut', cost: 3, icon: '🥥', sect: 'Food' },
|
||||
{ name: 'Avocado', cost: 3, icon: '🥑', sect: 'Food' },
|
||||
{ name: 'Eggplant', cost: 10, icon: '🍆', sect: 'Food' },
|
||||
{ name: 'Potato', cost: 3, icon: '🥔', sect: 'Food' },
|
||||
{ name: 'Carrot', cost: 3, icon: '🥕', sect: 'Food' },
|
||||
{ name: 'Ear of Corn', cost: 3, icon: '🌽', sect: 'Food' },
|
||||
{ name: 'Hot Pepper', cost: 3, icon: '🌶️', sect: 'Food' },
|
||||
{ name: 'Bell Pepper', cost: 3, icon: '🫑', sect: 'Food' },
|
||||
{ name: 'Cucumber', cost: 3, icon: '🥒', sect: 'Food' },
|
||||
{ name: 'Leafy Green', cost: 3, icon: '🥬', sect: 'Food' },
|
||||
{ name: 'Broccoli', cost: 2, icon: '🥦', sect: 'Food' },
|
||||
{ name: 'Garlic', cost: 3, icon: '🧄', sect: 'Food' },
|
||||
{ name: 'Onion', cost: 3, icon: '🧅', sect: 'Food' },
|
||||
{ name: 'Mushroom', cost: 3, icon: '🍄', sect: 'Food' },
|
||||
{ name: 'Peanuts', cost: 4, icon: '🥜', sect: 'Food' },
|
||||
{ name: 'Chestnut', cost: 3, icon: '🌰', sect: 'Food' },
|
||||
{ name: 'Bread', cost: 5, icon: '🍞', sect: 'Food' },
|
||||
{ name: 'Croissant', cost: 7, icon: '🥐', sect: 'Food' },
|
||||
{ name: 'Baguette Bread', cost: 10, icon: '🥖', sect: 'Food' },
|
||||
{ name: 'Flatbread', cost: 9, icon: '🫓', sect: 'Food' },
|
||||
{ name: 'Pretzel', cost: 5, icon: '🥨', sect: 'Food' },
|
||||
{ name: 'Bagel', cost: 4, icon: '🥯', sect: 'Food' },
|
||||
{ name: 'Pancakes', cost: 5, icon: '🥞', sect: 'Food' },
|
||||
{ name: 'Waffle', cost: 5, icon: '🧇', sect: 'Food' },
|
||||
{ name: 'Cheese Wedge', cost: 3, icon: '🧀', sect: 'Food' },
|
||||
{ name: 'Meat on the Bone', cost: 5, icon: '🍖', sect: 'Food' },
|
||||
{ name: 'Checken Leg', cost: 5, icon: '🍗', sect: 'Food' },
|
||||
{ name: 'Cut of Meat', cost: 4, icon: '🥩', sect: 'Food' },
|
||||
{ name: 'Bacon', cost: 4, icon: '🥓', sect: 'Food' },
|
||||
{ name: 'Hamburger', cost: 5, icon: '🍔', sect: 'Food' },
|
||||
{ name: 'French Fries', cost: 3, icon: '🍟', sect: 'Food' },
|
||||
{ name: 'Pizza', cost: 6, icon: '🍕', sect: 'Food' },
|
||||
{ name: 'Hot Dog', cost: 3, icon: '🌭', sect: 'Food' },
|
||||
{ name: 'Sandwich', cost: 3, icon: '🥪', sect: 'Food' },
|
||||
{ name: 'Taco', cost: 3, icon: '🌮', sect: 'Food' },
|
||||
{ name: 'Burrito', cost: 5, icon: '🌯', sect: 'Food' },
|
||||
{ name: 'Tamale', cost: 5, icon: '🫔', sect: 'Food' },
|
||||
{ name: 'Stuffed Flatbread', cost: 5, icon: '🥙', sect: 'Food' },
|
||||
{ name: 'Falafel', cost: 4, icon: '🧆', sect: 'Food' },
|
||||
{ name: 'Egg', cost: 3, icon: '🥚', sect: 'Food' },
|
||||
{ name: 'Hot Pot', cost: 12, icon: '🍲', sect: 'Food' },
|
||||
{ name: 'Fondue', cost: 8, icon: '🫕', sect: 'Food' },
|
||||
{ name: 'Green Salad', cost: 3, icon: '🥗', sect: 'Food' },
|
||||
{ name: 'Popcorn', cost: 3, icon: '🍿', sect: 'Food' },
|
||||
{ name: 'Butter', cost: 2, icon: '🧈', sect: 'Food' },
|
||||
{ name: 'Salt', cost: 2, icon: '🧂', sect: 'Food' },
|
||||
{ name: 'Canned Food', cost: 3, icon: '🥫', sect: 'Food' },
|
||||
{ name: 'Bento Box', cost: 7, icon: '🍱', sect: 'Food' },
|
||||
{ name: 'Rice Cracker', cost: 1, icon: '🍘', sect: 'Food' },
|
||||
{ name: 'Rice Ball', cost: 3, icon: '🍙', sect: 'Food' },
|
||||
{ name: 'Cooked Rice', cost: 3, icon: '🍚', sect: 'Food' },
|
||||
{ name: 'Curry Rice', cost: 4, icon: '🍛', sect: 'Food' },
|
||||
{ name: 'Ramen', cost: 4, icon: '🍜', sect: 'Food' },
|
||||
{ name: 'Spaghetti', cost: 5, icon: '🍝', sect: 'Food' },
|
||||
{ name: 'Roasted Sweet Potato', cost: 3, icon: '🍠', sect: 'Food' },
|
||||
{ name: 'Oden', cost: 3, icon: '🍢', sect: 'Food' },
|
||||
{ name: 'Sushi', cost: 4, icon: '🍣', sect: 'Food' },
|
||||
{ name: 'Fried Shrimp', cost: 3, icon: '🍤', sect: 'Food' },
|
||||
{ name: 'Fish Cake', cost: 3, icon: '🍥', sect: 'Food' },
|
||||
{ name: 'Moon Cake', cost: 3, icon: '🥮', sect: 'Food' },
|
||||
{ name: 'Dango', cost: 3, icon: '🍡', sect: 'Food' },
|
||||
{ name: 'Dumpling', cost: 3, icon: '🥟', sect: 'Food' },
|
||||
{ name: 'Fortune Cookie', cost: 3, icon: '🥠', sect: 'Food' },
|
||||
{ name: 'Oyster', cost: 4, icon: '🦪', sect: 'Food' },
|
||||
{ name: 'Ice Cream Cone', cost: 3, icon: '🍦', sect: 'Food' },
|
||||
{ name: 'Shaved Ice', cost: 3, icon: '🍧', sect: 'Food' },
|
||||
{ name: 'Ice Cream', cost: 3, icon: '🍨', sect: 'Food' },
|
||||
{ name: 'Doughnut', cost: 3, icon: '🍩', sect: 'Food' },
|
||||
{ name: 'Cookie', cost: 3, icon: '🍪', sect: 'Food' },
|
||||
{ name: 'Birthday Cake', cost: 7, icon: '🎂', sect: 'Food' },
|
||||
{ name: 'Shortcake', cost: 4, icon: '🍰', sect: 'Food' },
|
||||
{ name: 'Cupcake', cost: 3, icon: '🧁', sect: 'Food' },
|
||||
{ name: 'Pie', cost: 4, icon: '🥧', sect: 'Food' },
|
||||
{ name: 'Chocolate Bar', cost: 2, icon: '🍫', sect: 'Food' },
|
||||
{ name: 'Candy', cost: 1, icon: '🍬', sect: 'Food' },
|
||||
{ name: 'Lollipop', cost: 1, icon: '🍭', sect: 'Food' },
|
||||
{ name: 'Custard', cost: 3, icon: '🍮', sect: 'Food' },
|
||||
{ name: 'Honey Pot', cost: 3, icon: '🍯', sect: 'Food' },
|
||||
{ name: 'Baby Bottle', cost: 3, icon: '🍼', sect: 'Food' },
|
||||
{ name: 'Glass of Milk', cost: 3, icon: '🥛', sect: 'Food' },
|
||||
{ name: 'Coffee', cost: 3, icon: '☕', sect: 'Food' },
|
||||
{ name: 'Teapot', cost: 3, icon: '🫖', sect: 'Food' },
|
||||
{ name: 'Tea', cost: 3, icon: '🍵', sect: 'Food' },
|
||||
{ name: 'Sake', cost: 3, icon: '🍶', sect: 'Food' },
|
||||
{ name: 'Champagne', cost: 3, icon: '🍾', sect: 'Food' },
|
||||
{ name: 'Wine Glass', cost: 3, icon: '🍷', sect: 'Food' },
|
||||
{ name: 'Cocktail Glass', cost: 3, icon: '🍸', sect: 'Food' },
|
||||
{ name: 'Tropical Drink', cost: 3, icon: '🍹', sect: 'Food' },
|
||||
{ name: 'Beer Mug', cost: 3, icon: '🍺', sect: 'Food' },
|
||||
{ name: 'Tumbler', cost: 3, icon: '🥃', sect: 'Food' },
|
||||
{ name: 'Soda', cost: 3, icon: '🥤', sect: 'Food' },
|
||||
{ name: 'Bubble Tea', cost: 3, icon: '🧋', sect: 'Food' },
|
||||
{ name: 'Beverage Box', cost: 30, icon: '🧃', sect: 'Food' },
|
||||
{ name: 'Mate', cost: 3, icon: '🧉', sect: 'Food' },
|
||||
|
||||
//Weapons
|
||||
{ name: 'Swords_special', cost: 3, icon: '⚔️', sect: 'Weapons' },
|
||||
{ name: 'Boomerang', cost: 300, icon: '🪃', sect: 'Weapons' },
|
||||
{ name: 'Boomerang', cost: 200, icon: '🏹', sect: 'Weapons' },
|
||||
{ name: 'Knife', cost: 20, icon: '🔪', sect: 'Weapons' },
|
||||
{ name: 'Dagger', cost: 60, icon: '🗡', sect: 'Weapons' },
|
||||
{ name: 'Shield', cost: 100, icon: '🛡', sect: 'Weapons' },
|
||||
{ name: 'Axe', cost: 40, icon: '🪓', sect: 'Weapons' },
|
||||
{ name: 'Trident', cost: 140, icon: '🔱', sect: 'Weapons' },
|
||||
{ name: 'Scissors', cost: 10, icon: '✂️', sect: 'Weapons' },
|
||||
if (resetShop) {
|
||||
const { MongoClient, ServerApiVersion } = require('mongodb');
|
||||
const mongouri = process.env.MONGODB_URI; //DO NOT RUN LOCALLY (no process.env)
|
||||
|
||||
//Potions (of varying sections)
|
||||
{ name: 'HP Potion', cost: 20, icon: 'CUSTOM|healing_potion', sect: 'HP' },
|
||||
{ name: 'MP Potion', cost: 15, icon: 'CUSTOM|mana_potion', sect: 'MP' },
|
||||
{ name: 'Super HP Potion', cost: 50, icon: 'CUSTOM|superior_healing_potion', sect: 'HP' },
|
||||
{ name: 'Super MP Potion', cost: 40, icon: 'CUSTOM|superior_mana_potion', sect: 'MP' }
|
||||
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
||||
let collectiontemp;
|
||||
client.connect(err => {
|
||||
collectiontemp = client.db("main").collection("shop");
|
||||
// perform actions on the collection object
|
||||
collectiontemp.insertMany(
|
||||
[
|
||||
{ name: 'Grapes', cost: 2, icon: '🍇', sect: 'Food' },
|
||||
{ name: 'Melon', cost: 5, icon: '🍈', sect: 'Food' },
|
||||
{ name: 'Watermelon', cost: 5, icon: '🍉', sect: 'Food' },
|
||||
{ name: 'Tangerine', cost: 3, icon: '🍊', sect: 'Food' },
|
||||
{ name: 'Lemon', cost: 3, icon: '🍋', sect: 'Food' },
|
||||
{ name: 'Banana', cost: 4, icon: '🍌', sect: 'Food' },
|
||||
{ name: 'Pineapple', cost: 4, icon: '🍍', sect: 'Food' },
|
||||
{ name: 'Mango', cost: 3, icon: '🥭', sect: 'Food' },
|
||||
{ name: 'Red Apple', cost: 3, icon: '🍎', sect: 'Food' },
|
||||
{ name: 'Green Apple', cost: 3, icon: '🍏', sect: 'Food' },
|
||||
{ name: 'Pear', cost: 3, icon: '🍐', sect: 'Food' },
|
||||
{ name: 'Peach', cost: 3, icon: '🍑', sect: 'Food' },
|
||||
{ name: 'Cherries', cost: 4, icon: '🍒', sect: 'Food' },
|
||||
{ name: 'Strawberry', cost: 3, icon: '🍓', sect: 'Food' },
|
||||
{ name: 'Blueberries', cost: 3, icon: '🫐', sect: 'Food' },
|
||||
{ name: 'Kiwi', cost: 3, icon: '🥝', sect: 'Food' },
|
||||
{ name: 'Tomato', cost: 4, icon: '🍅', sect: 'Food' },
|
||||
{ name: 'Olive', cost: 4, icon: '🫒', sect: 'Food' },
|
||||
{ name: 'Coconut', cost: 3, icon: '🥥', sect: 'Food' },
|
||||
{ name: 'Avocado', cost: 3, icon: '🥑', sect: 'Food' },
|
||||
{ name: 'Eggplant', cost: 10, icon: '🍆', sect: 'Food' },
|
||||
{ name: 'Potato', cost: 3, icon: '🥔', sect: 'Food' },
|
||||
{ name: 'Carrot', cost: 3, icon: '🥕', sect: 'Food' },
|
||||
{ name: 'Ear of Corn', cost: 3, icon: '🌽', sect: 'Food' },
|
||||
{ name: 'Hot Pepper', cost: 3, icon: '🌶️', sect: 'Food' },
|
||||
{ name: 'Bell Pepper', cost: 3, icon: '🫑', sect: 'Food' },
|
||||
{ name: 'Cucumber', cost: 3, icon: '🥒', sect: 'Food' },
|
||||
{ name: 'Leafy Green', cost: 3, icon: '🥬', sect: 'Food' },
|
||||
{ name: 'Broccoli', cost: 2, icon: '🥦', sect: 'Food' },
|
||||
{ name: 'Garlic', cost: 3, icon: '🧄', sect: 'Food' },
|
||||
{ name: 'Onion', cost: 3, icon: '🧅', sect: 'Food' },
|
||||
{ name: 'Mushroom', cost: 3, icon: '🍄', sect: 'Food' },
|
||||
{ name: 'Peanuts', cost: 4, icon: '🥜', sect: 'Food' },
|
||||
{ name: 'Chestnut', cost: 3, icon: '🌰', sect: 'Food' },
|
||||
{ name: 'Bread', cost: 5, icon: '🍞', sect: 'Food' },
|
||||
{ name: 'Croissant', cost: 7, icon: '🥐', sect: 'Food' },
|
||||
{ name: 'Baguette Bread', cost: 10, icon: '🥖', sect: 'Food' },
|
||||
{ name: 'Flatbread', cost: 9, icon: '🫓', sect: 'Food' },
|
||||
{ name: 'Pretzel', cost: 5, icon: '🥨', sect: 'Food' },
|
||||
{ name: 'Bagel', cost: 4, icon: '🥯', sect: 'Food' },
|
||||
{ name: 'Pancakes', cost: 5, icon: '🥞', sect: 'Food' },
|
||||
{ name: 'Waffle', cost: 5, icon: '🧇', sect: 'Food' },
|
||||
{ name: 'Cheese Wedge', cost: 3, icon: '🧀', sect: 'Food' },
|
||||
{ name: 'Meat on the Bone', cost: 5, icon: '🍖', sect: 'Food' },
|
||||
{ name: 'Checken Leg', cost: 5, icon: '🍗', sect: 'Food' },
|
||||
{ name: 'Cut of Meat', cost: 4, icon: '🥩', sect: 'Food' },
|
||||
{ name: 'Bacon', cost: 4, icon: '🥓', sect: 'Food' },
|
||||
{ name: 'Hamburger', cost: 5, icon: '🍔', sect: 'Food' },
|
||||
{ name: 'French Fries', cost: 3, icon: '🍟', sect: 'Food' },
|
||||
{ name: 'Pizza', cost: 6, icon: '🍕', sect: 'Food' },
|
||||
{ name: 'Hot Dog', cost: 3, icon: '🌭', sect: 'Food' },
|
||||
{ name: 'Sandwich', cost: 3, icon: '🥪', sect: 'Food' },
|
||||
{ name: 'Taco', cost: 3, icon: '🌮', sect: 'Food' },
|
||||
{ name: 'Burrito', cost: 5, icon: '🌯', sect: 'Food' },
|
||||
{ name: 'Tamale', cost: 5, icon: '🫔', sect: 'Food' },
|
||||
{ name: 'Stuffed Flatbread', cost: 5, icon: '🥙', sect: 'Food' },
|
||||
{ name: 'Falafel', cost: 4, icon: '🧆', sect: 'Food' },
|
||||
{ name: 'Egg', cost: 3, icon: '🥚', sect: 'Food' },
|
||||
{ name: 'Hot Pot', cost: 12, icon: '🍲', sect: 'Food' },
|
||||
{ name: 'Fondue', cost: 8, icon: '🫕', sect: 'Food' },
|
||||
{ name: 'Green Salad', cost: 3, icon: '🥗', sect: 'Food' },
|
||||
{ name: 'Popcorn', cost: 3, icon: '🍿', sect: 'Food' },
|
||||
{ name: 'Butter', cost: 2, icon: '🧈', sect: 'Food' },
|
||||
{ name: 'Salt', cost: 2, icon: '🧂', sect: 'Food' },
|
||||
{ name: 'Canned Food', cost: 3, icon: '🥫', sect: 'Food' },
|
||||
{ name: 'Bento Box', cost: 7, icon: '🍱', sect: 'Food' },
|
||||
{ name: 'Rice Cracker', cost: 1, icon: '🍘', sect: 'Food' },
|
||||
{ name: 'Rice Ball', cost: 3, icon: '🍙', sect: 'Food' },
|
||||
{ name: 'Cooked Rice', cost: 3, icon: '🍚', sect: 'Food' },
|
||||
{ name: 'Curry Rice', cost: 4, icon: '🍛', sect: 'Food' },
|
||||
{ name: 'Ramen', cost: 4, icon: '🍜', sect: 'Food' },
|
||||
{ name: 'Spaghetti', cost: 5, icon: '🍝', sect: 'Food' },
|
||||
{ name: 'Roasted Sweet Potato', cost: 3, icon: '🍠', sect: 'Food' },
|
||||
{ name: 'Oden', cost: 3, icon: '🍢', sect: 'Food' },
|
||||
{ name: 'Sushi', cost: 4, icon: '🍣', sect: 'Food' },
|
||||
{ name: 'Fried Shrimp', cost: 3, icon: '🍤', sect: 'Food' },
|
||||
{ name: 'Fish Cake', cost: 3, icon: '🍥', sect: 'Food' },
|
||||
{ name: 'Moon Cake', cost: 3, icon: '🥮', sect: 'Food' },
|
||||
{ name: 'Dango', cost: 3, icon: '🍡', sect: 'Food' },
|
||||
{ name: 'Dumpling', cost: 3, icon: '🥟', sect: 'Food' },
|
||||
{ name: 'Fortune Cookie', cost: 3, icon: '🥠', sect: 'Food' },
|
||||
{ name: 'Oyster', cost: 4, icon: '🦪', sect: 'Food' },
|
||||
{ name: 'Ice Cream Cone', cost: 3, icon: '🍦', sect: 'Food' },
|
||||
{ name: 'Shaved Ice', cost: 3, icon: '🍧', sect: 'Food' },
|
||||
{ name: 'Ice Cream', cost: 3, icon: '🍨', sect: 'Food' },
|
||||
{ name: 'Doughnut', cost: 3, icon: '🍩', sect: 'Food' },
|
||||
{ name: 'Cookie', cost: 3, icon: '🍪', sect: 'Food' },
|
||||
{ name: 'Birthday Cake', cost: 7, icon: '🎂', sect: 'Food' },
|
||||
{ name: 'Shortcake', cost: 4, icon: '🍰', sect: 'Food' },
|
||||
{ name: 'Cupcake', cost: 3, icon: '🧁', sect: 'Food' },
|
||||
{ name: 'Pie', cost: 4, icon: '🥧', sect: 'Food' },
|
||||
{ name: 'Chocolate Bar', cost: 2, icon: '🍫', sect: 'Food' },
|
||||
{ name: 'Candy', cost: 1, icon: '🍬', sect: 'Food' },
|
||||
{ name: 'Lollipop', cost: 1, icon: '🍭', sect: 'Food' },
|
||||
{ name: 'Custard', cost: 3, icon: '🍮', sect: 'Food' },
|
||||
{ name: 'Honey Pot', cost: 3, icon: '🍯', sect: 'Food' },
|
||||
{ name: 'Baby Bottle', cost: 3, icon: '🍼', sect: 'Food' },
|
||||
{ name: 'Glass of Milk', cost: 3, icon: '🥛', sect: 'Food' },
|
||||
{ name: 'Coffee', cost: 3, icon: '☕', sect: 'Food' },
|
||||
{ name: 'Teapot', cost: 3, icon: '🫖', sect: 'Food' },
|
||||
{ name: 'Tea', cost: 3, icon: '🍵', sect: 'Food' },
|
||||
{ name: 'Sake', cost: 3, icon: '🍶', sect: 'Food' },
|
||||
{ name: 'Champagne', cost: 3, icon: '🍾', sect: 'Food' },
|
||||
{ name: 'Wine Glass', cost: 3, icon: '🍷', sect: 'Food' },
|
||||
{ name: 'Cocktail Glass', cost: 3, icon: '🍸', sect: 'Food' },
|
||||
{ name: 'Tropical Drink', cost: 3, icon: '🍹', sect: 'Food' },
|
||||
{ name: 'Beer Mug', cost: 3, icon: '🍺', sect: 'Food' },
|
||||
{ name: 'Tumbler', cost: 3, icon: '🥃', sect: 'Food' },
|
||||
{ name: 'Soda', cost: 3, icon: '🥤', sect: 'Food' },
|
||||
{ name: 'Bubble Tea', cost: 3, icon: '🧋', sect: 'Food' },
|
||||
{ name: 'Beverage Box', cost: 30, icon: '🧃', sect: 'Food' },
|
||||
{ name: 'Mate', cost: 3, icon: '🧉', sect: 'Food' },
|
||||
|
||||
]);
|
||||
});
|
||||
//Weapons
|
||||
// { name: 'Swords_special', cost: 3, icon: '⚔️', sect: 'Weapons', double: false },
|
||||
{ name: 'Boomerang', cost: 300, icon: '🪃', sect: 'Weapons', double: false, def: false },
|
||||
{ name: 'Crossbow', cost: 200, icon: '🏹', sect: 'Weapons', double: true, def: false },
|
||||
{ name: 'Knife', cost: 20, icon: '🔪', sect: 'Weapons', double: false, def: false },
|
||||
{ name: 'Dagger', cost: 60, icon: '🗡', sect: 'Weapons', double: false, def: false },
|
||||
{ name: 'Shield', cost: 100, icon: '🛡', sect: 'Weapons', double: false, def: true },
|
||||
{ name: 'Axe', cost: 40, icon: '🪓', sect: 'Weapons', double: false, def: false },
|
||||
{ name: 'Trident', cost: 140, icon: '🔱', sect: 'Weapons', double: false, def: false },
|
||||
{ name: 'Scissors', cost: 10, icon: '✂️', sect: 'Weapons', double: false, def: false },
|
||||
|
||||
client.close().then(function() {
|
||||
const END = d.getTime();
|
||||
console.log(`Total time in SECONDS: ${(((END - START) % 60000) / 1000).toFixed(0)} ms!`);
|
||||
});
|
||||
//Potions (of varying sections)
|
||||
{ name: 'HP Potion', cost: 20, icon: 'CUSTOM|healing_potion', sect: 'HP' },
|
||||
{ name: 'MP Potion', cost: 15, icon: 'CUSTOM|mana_potion', sect: 'MP' },
|
||||
{ name: 'Super HP Potion', cost: 50, icon: 'CUSTOM|superior_healing_potion', sect: 'HP' },
|
||||
{ name: 'Super MP Potion', cost: 40, icon: 'CUSTOM|superior_mana_potion', sect: 'MP' }
|
||||
|
||||
]);
|
||||
});
|
||||
|
||||
client.close().then(function() {
|
||||
const END = d.getTime();
|
||||
console.log(`Total time in SECONDS: ${(((END - START) % 60000) / 1000).toFixed(0)} ms!`);
|
||||
});
|
||||
} else {
|
||||
console.log('To reset the main shop, please change the variable "resetShop" in the "COMPLETE_INIT.js" file to true');
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 91 KiB |
@@ -0,0 +1,109 @@
|
||||
const { MongoClient, ServerApiVersion, ConnectionClosedEvent } = require('mongodb');
|
||||
const { exit } = require('process');
|
||||
const { checkResponses } = require('./wordlist.js');
|
||||
|
||||
|
||||
//Error checking function (message deleted error fix)
|
||||
//message.channel.send("Oops, there's been an error, please contact support!");
|
||||
async function messageExists(message) {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
message.channel.messages.fetch(message.id)
|
||||
.then((fetchedMessage) => {
|
||||
resolve(true);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
resolve(false);
|
||||
})
|
||||
} catch (err) { resolve(false); }
|
||||
|
||||
resolve(true);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
async function getResponse(convo, bot) {
|
||||
const response = await bot.openai.createCompletion({
|
||||
model: "text-davinci-002",
|
||||
prompt: convo,
|
||||
temperature: 0.9,
|
||||
max_tokens: 150,
|
||||
top_p: 1,
|
||||
frequency_penalty: 0,
|
||||
presence_penalty: 0.6,
|
||||
stop: [" Human:", " AI:"],
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
async function convoManager(clientinp, bot, message) {
|
||||
|
||||
//Just in case, make sure it can't be changed
|
||||
const client = clientinp;
|
||||
const dbo = client.db("DM").collection(message.author.id);
|
||||
|
||||
if (message.content.startsWith('!')) {
|
||||
if (message.content.split(' ')[0] == '!startconvo') {
|
||||
//Check if a conversation already exists
|
||||
dbo.find({'_id': {$exists: true}}).toArray((err, docs) => {
|
||||
if (docs[0] != undefined) {
|
||||
return message.channel.send("You're already in a conversation");
|
||||
} else {
|
||||
dbo.insertOne({convo: 'Human: Hello\nAI: Hello'});
|
||||
return message.channel.send('-----Started Conversation-----\nuse _!endconvo_ to end the conversation!\n\n_Disclaimer: Your conversation data is stored for the duration of the conversation to help Selmer Bot better understand what you are saying *then deleted*_\n\n');
|
||||
}
|
||||
});
|
||||
|
||||
} else if (message.content.split(' ')[0] == '!endconvo') {
|
||||
dbo.drop();
|
||||
return message.channel.send('-----Ended Conversation-----\nSee you next time!');
|
||||
} else {
|
||||
return message.channel.send('UNUSABLE DM COMMAND DETECTED');
|
||||
}
|
||||
} else {
|
||||
dbo.find({convo: {$exists: true}}).toArray(async function (err, docs) {
|
||||
const doc = docs[0];
|
||||
if (!doc) { return message.reply('You aren\'t currently in a conversation\nUse _!startconvo_ to start one!'); }
|
||||
|
||||
//Checking Section
|
||||
const check = checkResponses(message.content, "I'm sorry, I can't do that");
|
||||
if (check != null) { return message.reply(check); }
|
||||
|
||||
|
||||
let convo = doc.convo;
|
||||
convo += `\nHuman: ${message.content}\n`;;
|
||||
|
||||
//Get the response
|
||||
const r = await getResponse(convo, bot);
|
||||
|
||||
let response = r.data.choices[0].text;
|
||||
|
||||
convo += (response + '\n');
|
||||
|
||||
dbo.updateOne(doc, {$set: {convo: convo}});
|
||||
response = response.replaceAll('AI: ', '').replaceAll('AI:\n', '');
|
||||
|
||||
//Very buggy so I'm adding this for now
|
||||
message.channel.send(response);
|
||||
|
||||
//Note: Work with the following later
|
||||
/* messageExists(message).then((e) => {
|
||||
console.log(e);
|
||||
if (e) { return message.reply(response); }
|
||||
message.channel.send(response);
|
||||
}) */
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//"Hello! discord_user:"
|
||||
module.exports = {
|
||||
name: 'chat',
|
||||
description: 'chat',
|
||||
convoManager,
|
||||
execute(message, args, Discord, Client, bot) {
|
||||
message.reply("Please DM Selmer bot to use this command!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
-----WEBHOOKS ARE RECIEVED AND MONITORED HERE-----
|
||||
https://glitch.com/edit/#!/selmer-bot-listener
|
||||
--------------------------------------------------
|
||||
*/
|
||||
|
||||
const { MongoClient, ServerApiVersion } = require('mongodb');
|
||||
const { MessageActionRow, MessageSelectMenu } = require('discord.js');
|
||||
|
||||
|
||||
//Called from the dropdown menu
|
||||
async function createSubscriptionManual(bot, interaction, id, priceID) {
|
||||
const stripe = bot.stripe;
|
||||
const mongouri = bot.mongouri;
|
||||
|
||||
//Start Error Checking
|
||||
if (!id) { console.log('....What? How?'); return interaction.editReply("Uh oh, something happened with the Stripe Discord ID check, please contact support!"); }
|
||||
|
||||
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
||||
new Promise(async function(resolve, reject) {
|
||||
client.connect(async (err) => {
|
||||
if (err) { return console.log(err); }
|
||||
|
||||
const dbo = client.db('main').collection('authorized');
|
||||
await dbo.findOne({'discordID': id}).then(async (doc) => {
|
||||
var userID;
|
||||
|
||||
if (doc != undefined) {
|
||||
client.close();
|
||||
|
||||
reject(`An account with the tag <@${id}> already exists!`);
|
||||
} else {
|
||||
const stripeUser = await stripe.customers.create({
|
||||
metadata: { 'discordID': id }
|
||||
});
|
||||
userID = stripeUser.id;
|
||||
|
||||
//Add to the database (I have to wait for the insertion)
|
||||
await dbo.insertOne({stripeID: userID, discordID: id, paid: false, startDateUTC: null, tier: 0}).then(() => { client.close(); resolve(userID); });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}).then(async (userID) => {
|
||||
|
||||
//Deal with the session
|
||||
const billingPortalSession = await stripe.billingPortal.sessions.create({
|
||||
customer: userID,
|
||||
return_url: "https://linktr.ee/selmerbot",
|
||||
});
|
||||
|
||||
|
||||
const session = await stripe.checkout.sessions.create(
|
||||
{
|
||||
payment_method_types: ["card"],
|
||||
line_items: [
|
||||
{
|
||||
price: priceID,
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
customer: userID,
|
||||
mode: "subscription",
|
||||
success_url: billingPortalSession.url,
|
||||
cancel_url: "https://linktr.ee/selmerbot"
|
||||
});
|
||||
|
||||
interaction.editReply(session.url);
|
||||
}).catch((err) => { interaction.editReply(err); })
|
||||
}
|
||||
|
||||
|
||||
async function changeSubscriptionManual(bot, message) {
|
||||
const stripe = bot.stripe;
|
||||
const mongouri = bot.mongouri;
|
||||
const id = message.author.id;
|
||||
|
||||
//Start Error Checking
|
||||
if (!id) { return console.log('....What? How?'); }
|
||||
|
||||
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
||||
new Promise(async function(resolve, reject) {
|
||||
client.connect(async (err) => {
|
||||
if (err) { return console.log(err); }
|
||||
|
||||
const dbo = client.db('main').collection('authorized');
|
||||
await dbo.findOne({'discordID': id}).then(async (doc) => {
|
||||
var userID;
|
||||
|
||||
if (doc != undefined) {
|
||||
userID = doc.stripeID;
|
||||
client.close();
|
||||
resolve(userID);
|
||||
} else {
|
||||
client.close();
|
||||
|
||||
reject(`No user with the ID of <@${message.author.id}>`);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}).then(async (userID) => {
|
||||
const session = await stripe.billingPortal.sessions.create({
|
||||
customer: userID,
|
||||
return_url: "https://linktr.ee/selmerbot",
|
||||
});
|
||||
message.reply(session.url);
|
||||
// console.log(session.url);
|
||||
}).catch((err) => {
|
||||
message.reply(err);
|
||||
// console.log(err);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function createDropDown(bot, message) {
|
||||
// const stripe = bot.stripe;
|
||||
|
||||
const stripe = bot.stripe;
|
||||
|
||||
const pl = [];
|
||||
const vl = [];
|
||||
stripe.products.list({
|
||||
limit: 3,
|
||||
}).then((prod) => {
|
||||
prod.data.forEach((obj) => {
|
||||
const pricePromise = stripe.prices.retrieve(obj.default_price);
|
||||
var newObj = {label: obj.name, description: null, value: `${obj.default_price}`}
|
||||
pl.push(pricePromise);
|
||||
vl.push(newObj);
|
||||
});
|
||||
|
||||
let n = Promise.all(pl);
|
||||
let i = 0;
|
||||
n.then((t) => {
|
||||
t.forEach(data => {
|
||||
let price = data.unit_amount/100;
|
||||
vl[i].description = `The $${price} tier`;
|
||||
i++;
|
||||
});
|
||||
|
||||
|
||||
const row = new MessageActionRow()
|
||||
.addComponents(
|
||||
new MessageSelectMenu()
|
||||
.setCustomId(`${message.author.id}|premium`)
|
||||
.setPlaceholder('Nothing selected')
|
||||
.addOptions(vl)
|
||||
);
|
||||
|
||||
message.channel.send({ content: `Please choose a tier`, components: [row] });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function handleInp(bot, message) {
|
||||
if (message.content == '!premium help') {
|
||||
message.reply('Use _!premium buy_ to get premium or use _!premium manage_ to change or cancel your subscription\n_Disclaimer: Selmer Bot uses Stripe to manage payments. Read more at *https://stripe.com/ *_');
|
||||
} else if (message.content == '!premium buy') {
|
||||
createDropDown(bot, message);
|
||||
} else if (message.content == '!premium manage') {
|
||||
changeSubscriptionManual(bot, message)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
name: 'premium',
|
||||
description: 'everything payment',
|
||||
execute(message, args, Discord, Client, bot) {
|
||||
message.reply("Please DM Selmer bot to use this command!");
|
||||
}, handleInp, createSubscriptionManual
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
//Remember to strip all non-alpha chars from string (including ' )
|
||||
|
||||
wordlist = {
|
||||
pay: ['pay me', 'give me money', 'send money', 'send me money', 'send cash', 'PayPal me', 'venmo me', 'cashapp me', 'cash app me'],
|
||||
name: ['what is your name', 'whats your name', 'what are you called']
|
||||
}
|
||||
|
||||
|
||||
function checkResponses(convoOG, answer) {
|
||||
if (answer.indexOf("I'm sorry, I can't do that") == -1) { console.log('what?'); return 'none'}
|
||||
// remove all uneccesary chars
|
||||
convo = convoOG.replace(/\W/g, ' ').toLowerCase();
|
||||
|
||||
var b = 'none';
|
||||
wordlist.name.forEach((w) => { if (convo.includes(w)) { b = 'name'; return }})
|
||||
wordlist.pay.forEach((w) => { if (convo.includes(w)) { b = 'pay'; return }})
|
||||
|
||||
if (b === 'pay') {
|
||||
//Exctract the number
|
||||
var amt = convoOG.match(/(\d+)/)[0];
|
||||
|
||||
|
||||
if (matches) {
|
||||
currency = convoOG[convoOG.indexOf(amt) - 1];
|
||||
//Do something with pay API to get the amount here
|
||||
}
|
||||
} else if (b == 'name') {
|
||||
return 'My name is Selmer Bot!';
|
||||
} else { return null; }
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
module.exports = { checkResponses }
|
||||
@@ -9,9 +9,9 @@ module.exports = {
|
||||
//.setDescription('My professional resume')
|
||||
.setImage('https://github.com/ION606/selmerBot/blob/main/Sleemer_Bringsjorgend.png?raw=true')
|
||||
.addFields(
|
||||
{name: 'My Epithets:', value: "Pearls of Wisdom"},
|
||||
{name: '\t1. ', value: "Negative money is the best money"},
|
||||
{name: '\t2. ', value: "There is no god, only logic"}
|
||||
{name: 'My Epithets:', value: "~~Pearls of Wisdom~~"},
|
||||
{name: '\t__Epithet 1__', value: "_Negative money is the best money_"},
|
||||
{name: '\t__Epithet 2__', value: "_There is no god, only logic_"}
|
||||
);
|
||||
|
||||
message.channel.send({ embeds: [newEmbed] });
|
||||
|
||||
@@ -1,212 +0,0 @@
|
||||
//@ts-check
|
||||
const { MessageActionRow, MessageButton, MessageSelectMenu } = require('discord.js');
|
||||
const { STATE } = require('./econ');
|
||||
const { winGame, getCustomEmoji } = require('./external_game_functions.js');
|
||||
const { changeTurn } = require('../turnManager.js');
|
||||
|
||||
|
||||
function postActionBar(thread, user_dbo) {
|
||||
const row = new MessageActionRow()
|
||||
.addComponents(
|
||||
new MessageButton()
|
||||
.setCustomId('ATTACK')
|
||||
.setLabel('ATTACK')
|
||||
.setStyle('DANGER'),
|
||||
new MessageButton()
|
||||
.setCustomId('HEAL')
|
||||
.setLabel('HEAL')
|
||||
.setStyle('SUCCESS'),
|
||||
new MessageButton()
|
||||
.setCustomId('DEFEND')
|
||||
.setLabel('DEFEND')
|
||||
.setStyle('PRIMARY'),
|
||||
new MessageButton()
|
||||
.setCustomId('ITEMS')
|
||||
.setLabel('ITEMS')
|
||||
.setStyle('SECONDARY')
|
||||
);
|
||||
|
||||
thread.send({ content: `Your turn <@${user_dbo.s.namespace.collection}>!`, components: [row] });
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called by "attack"
|
||||
*/
|
||||
function attack_special() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
//Bow special phrase: Σ>―(´・ω・`)→
|
||||
function attack(client, user_dbo, other_dbo, bot, thread, command, mongouri, items, xp_collection, interaction) {
|
||||
//Get the weapon
|
||||
user_dbo.find({'equipped': {$exists: true}}).toArray(function(err, docs) {
|
||||
const doc = docs[0];
|
||||
const all_weapons = doc.equipped.weapons;
|
||||
const weapon = all_weapons.main;
|
||||
|
||||
var dmg = 0;
|
||||
|
||||
//No weapons (punch)
|
||||
if (weapon == null) {
|
||||
dmg = doc.rank;
|
||||
} else {
|
||||
dmg = (doc.rank - 1) + Math.round(weapon.cost/5);
|
||||
}
|
||||
|
||||
other_dbo.find({'equipped': {$exists: true}}).toArray(function (err, docs) {
|
||||
const odoc = docs[0];
|
||||
|
||||
//Handle defending
|
||||
if (odoc.state == STATE.DEFENDING) {
|
||||
var def = odoc.rank - doc.rank;
|
||||
//Make sure we don't go negative
|
||||
if (def < 0) { def = 0; }
|
||||
|
||||
dmg /= 2 + def;
|
||||
}
|
||||
|
||||
var new_hp = odoc.hpmp.hp -= dmg;
|
||||
if (new_hp <= 0) {
|
||||
winGame(client, bot, client.db(user_dbo.s.namespace.db), user_dbo, xp_collection, interaction.message);
|
||||
} else {
|
||||
other_dbo.updateOne({'equipped': {$exists: true}}, { $set: { 'hpmp.hp' :new_hp }});
|
||||
}
|
||||
});
|
||||
|
||||
})
|
||||
|
||||
//Check for a "special" animation
|
||||
|
||||
|
||||
//Change turns
|
||||
changeTurn(client, bot, interaction);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called by "item"
|
||||
*/
|
||||
async function heal(interaction, client, user_dbo, bot, thread, command, mongouri, items) {
|
||||
if (interaction.message.content.toLowerCase().indexOf('Which item would you like to use?') != -1) {
|
||||
// The person picked out an item
|
||||
}
|
||||
//Get the 'healing' items (stored in "{item}: num" format)
|
||||
user_dbo.find({'equipped': {$exists: true}}).toArray(async function(err, docs) {
|
||||
const doc = docs[0];
|
||||
const rawitems = doc.equipped.items;
|
||||
const items = rawitems.filter(function(f) { return (f.sect.toLowerCase() == 'hp') });
|
||||
|
||||
|
||||
if (JSON.stringify(items) == '[]') {
|
||||
postActionBar(thread, user_dbo);
|
||||
return interaction.editReply("You don't have any items!");
|
||||
} else { console.log(JSON.stringify(items))}
|
||||
|
||||
var itemlist = [];
|
||||
|
||||
items.forEach(function(item) {
|
||||
let n = item.name;
|
||||
|
||||
let h = (doc.rank - 1) + Math.round(item.cost/10);
|
||||
|
||||
itemlist.push({label: n, description: `Restores ${h} health (${item.num})`, value: `${n}`});
|
||||
});
|
||||
|
||||
|
||||
//Find something to heal with
|
||||
const row = new MessageActionRow()
|
||||
.addComponents(
|
||||
new MessageSelectMenu()
|
||||
.setCustomId(`${interaction.user.id}|heal`)
|
||||
.setPlaceholder('Nothing selected')
|
||||
.addOptions(itemlist),
|
||||
// .addOptions([
|
||||
// {
|
||||
// label: 'Select me',
|
||||
// description: 'This is a description',
|
||||
// value: 'first_option',
|
||||
// },
|
||||
// {
|
||||
// label: 'You can select me too',
|
||||
// description: 'This is also a description',
|
||||
// value: 'second_option',
|
||||
// },
|
||||
// ])
|
||||
);
|
||||
|
||||
await interaction.editReply({ content: 'Please choose a health potion!', components: [row] });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//Gets items by section/name, reacts with them to the message, when pressed, trigger a response
|
||||
function item() {
|
||||
throw 'THE "ITEM" COMMAND HAS NOT BEEN SET UP YET!';
|
||||
}
|
||||
|
||||
|
||||
function defend(user_dbo, bot, thread, command, mongouri, items) {
|
||||
user_dbo.find({'equipped': {$exists: true}}).toArray(function(err, docs) {
|
||||
const doc = docs[0];
|
||||
const all_weapons = doc.get('weapons');
|
||||
const shield = all_weapons.get('secondary');
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function usePotion(interaction, client, user_dbo, bot, thread, command, mongouri) {
|
||||
const name = interaction.values[0];
|
||||
const cursor = user_dbo.find({'equipped.items': {$exists: true}});
|
||||
|
||||
let doc = cursor.next().then((result) => {
|
||||
var allitems = Array.from(result.equipped.items);
|
||||
let items = allitems.filter((it) => { return it.name == name; })[0];
|
||||
let ind = allitems.findIndex((it) => { return it.name == name; })
|
||||
|
||||
//Apply the item's effects
|
||||
if (name.toLowerCase().indexOf('hp') != -1) {
|
||||
let h = (result.rank - 1) + Math.round(items.cost/10);
|
||||
user_dbo.updateOne({"game": {$exists: true}}, { $set: {'hpmp.hp': (result.hpmp.hp + h)}})
|
||||
}
|
||||
|
||||
//Deal with the item itself
|
||||
//If there's more than 1, subtract 1
|
||||
if (items.num > 1) { items.num -= 1; allitems[ind] = items; }
|
||||
else { allitems.splice(ind, 1) }
|
||||
|
||||
user_dbo.updateOne({'equipped.items': {$exists: true}}, {$set: {'equipped.items': allitems}});
|
||||
})
|
||||
|
||||
|
||||
changeTurn(client, bot, interaction);
|
||||
postActionBar(thread, user_dbo);
|
||||
}
|
||||
|
||||
|
||||
function cast() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
async function handle(client, user_dbo, other_dbo, bot, thread, command, mongouri, items, interaction, xp_collection) {
|
||||
if (command == 'initalize') {
|
||||
return postActionBar(thread, user_dbo);
|
||||
} else if (command == 'attack') {
|
||||
attack(client, user_dbo, other_dbo, bot, thread, command, mongouri, items, xp_collection, interaction);
|
||||
postActionBar(thread, other_dbo);
|
||||
} else if (command == 'items') {
|
||||
item();
|
||||
} else if (command == 'heal') {
|
||||
heal(interaction, client, user_dbo, bot, thread, command, mongouri, items); //.then(() => {postActionBar(thread, other_dbo)});
|
||||
} else if (command == 'usepotion') {
|
||||
usePotion(interaction, client, user_dbo, bot, thread, command, mongouri);
|
||||
}
|
||||
|
||||
// initiate(user_dbo, other_dbo, command, message);
|
||||
}
|
||||
|
||||
module.exports = { handle, postActionBar }
|
||||
+51
-38
@@ -2,6 +2,9 @@ const { MongoClient, ServerApiVersion } = require('mongodb');
|
||||
// const { update } = require('apt');
|
||||
const { Collection, Client, Formatters, Intents } = require('discord.js');
|
||||
const { CLIENT_ODBC } = require('mysql/lib/protocol/constants/client');
|
||||
const { time } = require('@discordjs/builders');
|
||||
|
||||
let currencySymbol = '$';
|
||||
|
||||
//Declair an "enum" to help with BASE calculations
|
||||
const BASE = {
|
||||
@@ -39,7 +42,7 @@ function CreateNewCollection(message, client, server, id, opponent = null, game
|
||||
if (!collinfo) {
|
||||
message.reply("You didn't have a place in my databases, so I created one for you!\nPlease try your command again!")
|
||||
let hp_mp = {maxhp: BASE.HP, hp: BASE.HP, maxmp: BASE.MP, mp: BASE.MP}
|
||||
dbo.insertOne({balance: 10, rank: 1, lastdayworked: 0, xp: 0, hpmp: hp_mp, game: game, opponent: opponent, state: STATE.IDLE, equipped: { weapons: {main: null, secondary: null}, items: {}}});
|
||||
dbo.insertOne({balance: 10, rank: 1, lastdayworked: 0, xp: 0, hpmp: hp_mp, game: game, gamesettings: {battle: {class: 'none', ultimate: true}}, opponent: opponent, state: STATE.IDLE, equipped: { weapons: {main: null, secondary: null}, items: {}}});
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -91,7 +94,11 @@ function addxp(message, dbo, amt, xp_list) {
|
||||
|
||||
function getBalance(dbo, message) {
|
||||
dbo.find({"balance": {$exists: true}}).toArray(function(err, doc) {
|
||||
return message.reply('Your current balance is $' + String(doc[0].balance));
|
||||
let bal = 0;
|
||||
if (doc[0] && doc[0].balance) {
|
||||
bal = doc[0].balance;
|
||||
}
|
||||
return message.reply(`<@${message.author.id}>, your current balance is ${currencySymbol}${bal}`);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -114,26 +121,25 @@ function convertCurrency(id, amt, dbo) {
|
||||
}
|
||||
|
||||
function checkAndUpdateBal(dbo, item, message, args) {
|
||||
let b = false;
|
||||
dbo.find({"balance": {$exists: true}}).toArray(b = function(err, doc) {
|
||||
if (!String(doc)) {
|
||||
message.reply("Your account doesn't exist, please contact the mods for support");
|
||||
return false;
|
||||
}
|
||||
return new Promise(function(resolve, reject) {
|
||||
dbo.find({"balance": {$exists: true}}).toArray(b = function(err, doc) {
|
||||
if (!String(doc)) {
|
||||
message.reply("Your account doesn't exist, please contact the mods for support");
|
||||
return false;
|
||||
}
|
||||
|
||||
const icost = args[0] * item.cost;
|
||||
if (doc[0].balance < icost) {
|
||||
message.reply("Insufficient funds!");
|
||||
return false;
|
||||
} else {
|
||||
let temp = doc[0];
|
||||
dbo.updateOne({balance: temp.balance, rank: temp.rank, lastdayworked: temp.lastdayworked}, { $set: { balance: doc[0].balance -= icost }});
|
||||
message.reply("You have bought " + item.name + " for $" + icost + "!");
|
||||
return true;
|
||||
}
|
||||
const icost = args[0] * item.cost;
|
||||
if (doc[0].balance < icost) {
|
||||
message.reply("Insufficient funds!");
|
||||
resolve(false);
|
||||
} else {
|
||||
let temp = doc[0];
|
||||
dbo.updateOne({balance: temp.balance, rank: temp.rank, lastdayworked: temp.lastdayworked}, { $set: { balance: doc[0].balance -= icost }});
|
||||
message.reply(`You have bought ${item.name} for ${currencySymbol}${icost}!`);
|
||||
resolve(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
@@ -142,25 +148,29 @@ function buy(id, message, args, dbo, shop, xp_list) {
|
||||
if (!isNum(args[0])) { return message.reply("Please enter a number for query 2"); }
|
||||
|
||||
let query = args[1];
|
||||
let item = shop.filter(function (item) { return item.name.toLowerCase() == query.toLowerCase(); });
|
||||
let item = shop.filter(function (item) { return item.name.toLowerCase() == query.toLowerCase(); })[0];
|
||||
|
||||
if (!String(item)) { return message.reply("This item does not exist!"); }
|
||||
|
||||
let success = Boolean(checkAndUpdateBal(dbo, item[0], message, args));
|
||||
if (!success) { return; }
|
||||
// let success = Boolean(checkAndUpdateBal(dbo, item, message, args));
|
||||
checkAndUpdateBal(dbo, item, message, args).then((success) => {
|
||||
if (!success) { return } //The message is handled in the CheckAndUpdateBal() function
|
||||
|
||||
var newObj = { name: item[0].name, cost: item[0].cost, icon: item[0].icon, sect: item[0].sect};
|
||||
var newObj = { name: item.name, cost: item.cost, icon: item.icon, sect: item.sect};
|
||||
|
||||
addxp(message, dbo, Math.ceil(item[0].cost * 1.2), xp_list);
|
||||
addxp(message, dbo, Math.ceil(item.cost * 1.2), xp_list);
|
||||
|
||||
dbo.find(newObj, {$exists: true}).toArray(function(err, doc) {
|
||||
if(String(doc)) {
|
||||
let newnum = doc[0].num + Number(args[0]);
|
||||
dbo.updateOne({ name: item[0].name }, {$set: {num: newnum}});
|
||||
} else {
|
||||
dbo.insertOne({ name: item[0].name, cost: item[0].cost, icon: item[0].icon, sect: item[0].sect, num: Number(args[0])});
|
||||
}
|
||||
});
|
||||
dbo.find(newObj, {$exists: true}).toArray(function(err, doc) {
|
||||
if(String(doc)) {
|
||||
let newnum = doc[0].num + Number(args[0]);
|
||||
dbo.updateOne({ name: item.name }, {$set: {num: newnum}});
|
||||
} else {
|
||||
// dbo.insertOne({ name: item.name, cost: item.cost, icon: item.icon, sect: item.sect, num: Number(args[0])}); //Causes "cyclic dependancy"
|
||||
dbo.insertOne(item);
|
||||
dbo.updateOne(item, { $set: {num: Number(args[0]) }});
|
||||
}
|
||||
});
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
@@ -201,7 +211,7 @@ function sell(id, message, args, dbo, shop, xp_list) {
|
||||
|
||||
addxp(message, dbo, Math.ceil(functional_item.cost * 1.2), xp_list);
|
||||
|
||||
message.reply(`You've sold ${num} ${String(functional_item.name)} for $${amountSoldFor}`);
|
||||
message.reply(`You've sold ${num} ${String(functional_item.name)} for ${currencySymbol}${amountSoldFor}`);
|
||||
} else {
|
||||
message.reply("You don't own this item!");
|
||||
}
|
||||
@@ -214,7 +224,7 @@ function work(dbo, message, xp_list) {
|
||||
let date = fulldate.getDate();
|
||||
dbo.find({"lastdayworked": {$exists: true}}).toArray(function(err, doc) {
|
||||
if (!String(doc)) { return message.reply("Your account doesn't exist, please contact the mods for support"); }
|
||||
if (doc[0].lastdayworked == 111111) {//date
|
||||
if (doc[0].lastdayworked == date) {//date
|
||||
message.reply("You've already worked today, try again tomorrow!");
|
||||
} else {
|
||||
//Amount to be paid
|
||||
@@ -225,7 +235,7 @@ function work(dbo, message, xp_list) {
|
||||
//Update the amount to the new TOTAL balance
|
||||
dbo.updateOne({"balance": {$exists: true}}, { $set: { balance: doc[0].balance + amt, lastdayworked: date }});
|
||||
addxp(message, dbo, xp_earned, xp_list);
|
||||
message.channel.send('<@' + message.author.id + '> worked and earned $' + amt +' and ' + String(xp_earned) + ' xp!');
|
||||
message.channel.send(`<@${message.author.id}> worked and earned ${currencySymbol}${amt} and ${xp_earned} xp!`);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -235,10 +245,11 @@ function printInventory(dbo, message) {
|
||||
let tempstring = "";
|
||||
dbo.find().toArray(function(err, docs){
|
||||
docs.forEach(val => {
|
||||
if (!val.balance) {
|
||||
if (!val.balance && val.name != undefined) {
|
||||
tempstring += String(val.num) + " " + val.name + " (" + val.icon + ")\n";
|
||||
}
|
||||
});
|
||||
|
||||
if (tempstring == "") { tempstring += "You have nothing in your inventory!"; }
|
||||
message.reply(tempstring);
|
||||
});
|
||||
@@ -266,7 +277,7 @@ function getShop(message, args, items, bot) {
|
||||
}
|
||||
|
||||
const items2 = items.filter(function(f) { return (f.sect.toLowerCase() == args[0].toLowerCase()) }).slice((ind - 1)*10, (ind - 1)*10+10);
|
||||
newText = Formatters.codeBlock(items2.map(i => `${i.icon} (${i.name}): \$${i.cost}`).join('\n'));
|
||||
newText = Formatters.codeBlock(items2.map(i => `${i.icon} (${i.name}): $${i.cost}`).join('\n')); //${currencySymbol} doesn't owrk for some reason
|
||||
|
||||
if (noinp) {
|
||||
newText += `(Use ${bot.prefix}shop [type] [page number] to access other pages)`;
|
||||
@@ -305,6 +316,8 @@ module.exports = {
|
||||
const dbo = db.collection(id);
|
||||
if (err) { return console.log(err); }
|
||||
|
||||
currencySymbol = bot.currencysymbolmmain;
|
||||
|
||||
//test area
|
||||
if (command == 'xp' || command == 'adbal') {
|
||||
//Selmer Dev only command
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
// EVERYTHING IN THIS FILE SHOULD BE ABLE TO RUN INDEPENDANTLY OF THE BOT
|
||||
|
||||
|
||||
const Stripe = require('stripe');
|
||||
const APIKey = process.env.APIKey // require('./config.json').APIKey;
|
||||
const stripe = Stripe(APIKey);
|
||||
const mongouri = process.env.APIKey // require('./config.json').mongooseURI;
|
||||
const { MongoClient, ServerApiVersion } = require('mongodb');
|
||||
|
||||
|
||||
function cleardb(db) {
|
||||
//Triggers about a week before the end of the month and clears out all the "spam" entries
|
||||
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
||||
new Promise(async function(resolve, reject) {
|
||||
client.connect(async (err) => {
|
||||
const dbo = client.db('main').collection(db);
|
||||
dbo.find({paid: false, tier: 0}).toArray((err, docs) => {
|
||||
if (err) { return console.log(err); }
|
||||
|
||||
if (docs[0] != undefined) {
|
||||
//Add them all to an array and resolve because deleting in a find() causes cyclic dependancies
|
||||
resolve(docs);
|
||||
} else {
|
||||
reject();
|
||||
}
|
||||
});
|
||||
});
|
||||
}).then((docs) => {
|
||||
const dbo = client.db('main').collection(db);
|
||||
const d = new Date().toUTCString();
|
||||
|
||||
//Keep track of what was collected (chack later?)
|
||||
var newObj = {db: db, date: d, count: 0, results: []};
|
||||
|
||||
docs.forEach(i => {
|
||||
//{discord id, stripe id}
|
||||
newObj.results.push({did: i.discordID, sid: i.stripeID});
|
||||
newObj.count ++;
|
||||
|
||||
try {
|
||||
//For some reason, these aren't deleted in Stripe, just archived so they can't do anything new
|
||||
//See https://stripe.com/docs/api/customers/delete
|
||||
stripe.customers.del(i.stripeID);
|
||||
} catch (err) { console.log("err"); }
|
||||
});
|
||||
|
||||
dbo.deleteMany({paid: false, tier: 0});
|
||||
|
||||
//Add the newObj to another collection (ordered by date?)
|
||||
const spam_coll = client.db('main').collection("spam_collection_results");
|
||||
|
||||
spam_coll.insertOne(newObj);
|
||||
}).catch((err) => { console.log('none'); });
|
||||
|
||||
client.close();
|
||||
}
|
||||
|
||||
module.exports = { cleardb }
|
||||
|
||||
//Does not include the day check, see the "selmer-bot-listener" app for that
|
||||
@@ -0,0 +1,39 @@
|
||||
const { convoManager } = require('./API/chat.js');
|
||||
const { handleInp } = require('./API/stripe');
|
||||
const { MongoClient, ServerApiVersion, ConnectionClosedEvent } = require('mongodb');
|
||||
|
||||
function handle_dm(message, bot) {
|
||||
if (message.author.bot) { return; }
|
||||
|
||||
if (!message.content.startsWith('!') || message.content.split(' ')[0] == '!startconvo' || message.content.split(' ')[0] == '!endconvo') {
|
||||
const member = bot.guilds.cache.get(bot.home_server).members.cache.get(message.author.id);
|
||||
|
||||
const client = new MongoClient(bot.mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
||||
client.connect(async (err) => {
|
||||
if (err) { return console.log(err); }
|
||||
|
||||
const dbo = client.db('main').collection('authorized');
|
||||
dbo.find({id: message.author}).toArray((err, docs) => {
|
||||
|
||||
//Only available to Selmer Bot devs, testers and "authorized" users
|
||||
if (docs[0] != undefined || member.roles.cache.has('944048889038774302') || member.roles.cache.has('946610800418762792')) {
|
||||
convoManager(client, bot, message);
|
||||
} else {
|
||||
message.reply("You have to be a premium subscriber to use this feature!\n_support coming soon_");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
client.close();
|
||||
} else if (message.content.indexOf('!premium') != -1) {
|
||||
handleInp(bot, message);
|
||||
} else {
|
||||
return message.reply('UNUSABLE DM COMMAND DETECTED');
|
||||
}
|
||||
|
||||
//Selmer Bot is conversing with them
|
||||
|
||||
}
|
||||
|
||||
|
||||
module.exports = { handle_dm }
|
||||
@@ -0,0 +1,328 @@
|
||||
//@ts-check
|
||||
const { MessageActionRow, MessageButton, MessageSelectMenu, Client, CommandInteractionOptionResolver } = require('discord.js');
|
||||
const { STATE } = require('../db/econ');
|
||||
const { winGame, getCustomEmoji } = require('./external_game_functions.js');
|
||||
const { changeTurn } = require('../turnManager.js');
|
||||
const { game_class_battle } = require('./game_classes');
|
||||
const { MongoClient } = require('mongodb');
|
||||
const { convertSnowflakeToDate } = require('../db/addons/snowflake');
|
||||
|
||||
|
||||
function postActionBar(thread, user_dbo) {
|
||||
user_dbo.find({'hpmp.hp': {$exists: true}}).toArray((err, docs) => {
|
||||
const hp = docs[0].hpmp.hp;
|
||||
const mp = docs[0].hpmp.mp;
|
||||
let row;
|
||||
|
||||
if (docs[0].gamesettings.battle.class != 'none' && docs[0].gamesettings.battle.ultimate) {
|
||||
row = new MessageActionRow()
|
||||
.addComponents(
|
||||
new MessageButton()
|
||||
.setCustomId('ATTACK')
|
||||
.setLabel('ATTACK')
|
||||
.setStyle('DANGER'),
|
||||
new MessageButton()
|
||||
.setCustomId('HEAL')
|
||||
.setLabel('HEAL')
|
||||
.setStyle('SUCCESS'),
|
||||
new MessageButton()
|
||||
.setCustomId('DEFEND')
|
||||
.setLabel('DEFEND')
|
||||
.setStyle('PRIMARY'),
|
||||
new MessageButton()
|
||||
.setCustomId('ULTIMATE')
|
||||
.setLabel('ULTIMATE')
|
||||
.setStyle('DANGER')
|
||||
);
|
||||
} else {
|
||||
//If the ultimate can't be used, change the menu
|
||||
row = new MessageActionRow()
|
||||
.addComponents(
|
||||
new MessageButton()
|
||||
.setCustomId('ATTACK')
|
||||
.setLabel('ATTACK')
|
||||
.setStyle('DANGER'),
|
||||
new MessageButton()
|
||||
.setCustomId('HEAL')
|
||||
.setLabel('HEAL')
|
||||
.setStyle('SUCCESS'),
|
||||
new MessageButton()
|
||||
.setCustomId('DEFEND')
|
||||
.setLabel('DEFEND')
|
||||
.setStyle('PRIMARY'),
|
||||
);
|
||||
}
|
||||
/*
|
||||
//UNDER DEVELOPMENT
|
||||
new MessageButton()
|
||||
.setCustomId('ITEMS')
|
||||
.setLabel('ITEMS')
|
||||
.setStyle('SECONDARY')
|
||||
*/
|
||||
|
||||
thread.send({ content: `Your turn <@${user_dbo.s.namespace.collection}>!\nHP: ${hp}\t|\tMP: ${mp}`, components: [row] });
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called by "attack"
|
||||
* @param {game_class_battle} gclass
|
||||
*/
|
||||
function attack_special(client, user_dbo, other_dbo, bot, thread, xp_collection, interaction, gclass) {
|
||||
const atk = gclass.specialAttack;
|
||||
if (!atk) { return thread.send("You don't have a class, and so can't use an ultimate!"); }
|
||||
|
||||
user_dbo.find({'rank': {$exists: true}}).toArray((err, docs) => {
|
||||
const doc = docs[0];
|
||||
|
||||
//Check if the user can use ultimate
|
||||
if (atk.dmg.split('*')[0] == 'r') {
|
||||
const rank = doc.rank;
|
||||
const dmg = Number(atk.dmg.split('*')[1]) * rank;
|
||||
attack(client, user_dbo, other_dbo, bot, thread, xp_collection, interaction, dmg);
|
||||
}
|
||||
})
|
||||
|
||||
//Apply a "stunned" effect
|
||||
if (atk.prone == true) {
|
||||
other_dbo.updateOne({'state': {$exists: true}}, {$set: {state: STATE.PRONE}});
|
||||
thread.send(`<@${interaction.user.id}> was knocked prone and lost 1 turn!`);
|
||||
}
|
||||
|
||||
changeTurn(client, bot, interaction);
|
||||
}
|
||||
|
||||
|
||||
//Bow special phrase: Σ>―(´・ω・`)→
|
||||
function attack(client, user_dbo, other_dbo, bot, thread, xp_collection, interaction, preset_damage = 0) {
|
||||
//Get the weapon
|
||||
user_dbo.find({'equipped': {$exists: true}}).toArray(function(err, docs) {
|
||||
const doc = docs[0];
|
||||
const all_weapons = doc.equipped.weapons;
|
||||
const weapon = all_weapons.main;
|
||||
|
||||
var dmg = 0;
|
||||
|
||||
//No weapons (punch)
|
||||
if (preset_damage > 0) {
|
||||
dmg = preset_damage;
|
||||
} else {
|
||||
if (weapon == null) {
|
||||
dmg = doc.rank;
|
||||
} else {
|
||||
dmg = (doc.rank - 1) + Math.round(weapon.cost/5);
|
||||
}
|
||||
}
|
||||
|
||||
other_dbo.find({'equipped': {$exists: true}}).toArray(function (err, docs) {
|
||||
const odoc = docs[0];
|
||||
|
||||
//Handle defending
|
||||
if (odoc.state == STATE.DEFENDING) {
|
||||
var def = odoc.rank - doc.rank;
|
||||
//Make sure we don't go negative
|
||||
if (def < 0) { def = 0; }
|
||||
|
||||
dmg /= 2 + def;
|
||||
}
|
||||
|
||||
var new_hp = odoc.hpmp.hp -= dmg;
|
||||
if (new_hp <= 0) {
|
||||
winGame(client, bot, client.db(user_dbo.s.namespace.db), user_dbo, xp_collection, interaction.message);
|
||||
} else {
|
||||
other_dbo.updateOne({'equipped': {$exists: true}}, { $set: { 'hpmp.hp': new_hp, state: STATE.FIGHTING }});
|
||||
|
||||
//Change turns
|
||||
changeTurn(client, bot, interaction);
|
||||
}
|
||||
});
|
||||
|
||||
})
|
||||
|
||||
//Check for a "special" animation
|
||||
}
|
||||
|
||||
|
||||
|
||||
async function heal(interaction, client, user_dbo, bot, thread, command, mongouri, items) {
|
||||
if (interaction.message.content.toLowerCase().indexOf('Which item would you like to use?') != -1) {
|
||||
// The person picked out an item
|
||||
//I think this is unecessary
|
||||
}
|
||||
|
||||
//Get the 'healing' items (stored in "{item}: num" format)
|
||||
user_dbo.find({'equipped': {$exists: true}}).toArray(async function(err, docs) {
|
||||
const doc = docs[0];
|
||||
const rawitems = doc.equipped.items;
|
||||
if (JSON.stringify(rawitems) == '{}') {
|
||||
interaction.editReply("You don't have any items!");
|
||||
return postActionBar(thread, user_dbo);
|
||||
}
|
||||
|
||||
console.log(rawitems);
|
||||
const items = rawitems.filter(function(f) { return (f.sect.toLowerCase() == 'hp') });
|
||||
|
||||
if (JSON.stringify(items) == '[]') {
|
||||
interaction.editReply("You don't have any healing items!");
|
||||
return postActionBar(thread, user_dbo);
|
||||
} else { console.log(JSON.stringify(items))}
|
||||
|
||||
var itemlist = [];
|
||||
|
||||
items.forEach(function(item) {
|
||||
let n = item.name;
|
||||
|
||||
let h = (doc.rank - 1) + Math.round(item.cost/10);
|
||||
|
||||
itemlist.push({label: n, description: `Restores ${h} health (${item.num})`, value: `${n}`});
|
||||
});
|
||||
|
||||
|
||||
//Find something to heal with
|
||||
const row = new MessageActionRow()
|
||||
.addComponents(
|
||||
new MessageSelectMenu()
|
||||
.setCustomId(`${interaction.user.id}|heal`)
|
||||
.setPlaceholder('Nothing selected')
|
||||
.addOptions(itemlist),
|
||||
);
|
||||
|
||||
await interaction.editReply({ content: 'Please choose a health potion!', components: [row] });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//Gets items by section/name, reacts with them to the message, when pressed, trigger a response
|
||||
function presentItems(interaction, client, user_dbo, bot, thread) {
|
||||
// throw 'THE "ITEM" COMMAND HAS NOT BEEN SET UP YET!';
|
||||
user_dbo.find({'equipped': {$exists: true}}).toArray(async function(err, docs) {
|
||||
const doc = docs[0];
|
||||
const items = doc.equipped.items;
|
||||
// const items = rawitems.filter(function(f) { return (f.sect.toLowerCase() == 'hp') });
|
||||
|
||||
|
||||
if (JSON.stringify(items) == '[]' || JSON.stringify(items) == '{}') {
|
||||
interaction.editReply("You don't have any items!");
|
||||
return postActionBar(thread, user_dbo);
|
||||
} else { console.log(JSON.stringify(items))}
|
||||
|
||||
var itemlist = [];
|
||||
|
||||
items.forEach(function(item) {
|
||||
let n = item.name;
|
||||
|
||||
|
||||
|
||||
itemlist.push({label: n, description: `${item.num} equipped!`, value: `${n}`});
|
||||
});
|
||||
|
||||
|
||||
//Find something to heal with
|
||||
const row = new MessageActionRow()
|
||||
.addComponents(
|
||||
new MessageSelectMenu()
|
||||
.setCustomId(`${interaction.user.id}|item`)
|
||||
.setPlaceholder('Nothing selected')
|
||||
.addOptions(itemlist)
|
||||
);
|
||||
|
||||
await interaction.editReply({ content: 'Please choose an item!', components: [row] });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function defend(client, interaction, user_dbo, bot, thread) {
|
||||
user_dbo.find({'equipped': {$exists: true}}).toArray(function(err, docs) {
|
||||
const doc = docs[0];
|
||||
const all_weapons = doc.equipped.weapons;
|
||||
|
||||
//They don't have a shield
|
||||
if (all_weapons == undefined) {
|
||||
thread.send("You don't have a shield equipped!");
|
||||
}
|
||||
const shield = all_weapons.secondary;
|
||||
|
||||
//Change state
|
||||
user_dbo.updateOne({state: {$exists: true}}, {$set: {state: STATE.DEFENDING}});
|
||||
|
||||
changeTurn(client, bot, interaction);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function usePotion(interaction, client, user_dbo, bot, thread) {
|
||||
const name = interaction.values[0];
|
||||
const cursor = user_dbo.find({'equipped.items': {$exists: true}});
|
||||
|
||||
let doc = cursor.next().then((result) => {
|
||||
var allitems = Array.from(result.equipped.items);
|
||||
let items = allitems.filter((it) => { return it.name == name; })[0];
|
||||
let ind = allitems.findIndex((it) => { return it.name == name; })
|
||||
|
||||
//Apply the item's effects
|
||||
if (name.toLowerCase().indexOf('hp') != -1) {
|
||||
let h = (result.rank - 1) + Math.round(items.cost/10);
|
||||
user_dbo.updateOne({"game": {$exists: true}}, { $set: {'hpmp.hp': (result.hpmp.hp + h)}})
|
||||
}
|
||||
|
||||
//Deal with the item itself
|
||||
//If there's more than 1, subtract 1
|
||||
if (items.num > 1) { items.num -= 1; allitems[ind] = items; }
|
||||
else { allitems.splice(ind, 1) }
|
||||
|
||||
user_dbo.updateOne({'equipped.items': {$exists: true}}, {$set: {'equipped.items': allitems}});
|
||||
})
|
||||
|
||||
|
||||
changeTurn(client, bot, interaction);
|
||||
postActionBar(thread, user_dbo);
|
||||
}
|
||||
|
||||
|
||||
function cast() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {MongoClient} client
|
||||
* @param {*} user_dbo
|
||||
* @param {*} other_dbo
|
||||
* @param {Client} bot
|
||||
* @param {*} thread
|
||||
* @param {String} command
|
||||
* @param {String} mongouri
|
||||
* @param {String[]} items
|
||||
* @param {*} interaction
|
||||
* @param {Map<string, Map>} xp_collection
|
||||
*/
|
||||
async function handle(client, user_dbo, other_dbo, bot, thread, command, mongouri, items, interaction, xp_collection) {
|
||||
|
||||
if (command == 'initalize') {
|
||||
return postActionBar(thread, user_dbo);
|
||||
} else if (command == 'attack') {
|
||||
attack(client, user_dbo, other_dbo, bot, thread, xp_collection, interaction);
|
||||
postActionBar(thread, other_dbo);
|
||||
} else if (command == 'items') {
|
||||
presentItems(interaction, client, user_dbo, bot, thread); //Maybe like wands?
|
||||
} else if (command == 'heal') {
|
||||
heal(interaction, client, user_dbo, bot, thread, command, mongouri, items); //.then(() => {postActionBar(thread, other_dbo)});
|
||||
} else if (command == 'usepotion') {
|
||||
usePotion(interaction, client, user_dbo, bot, thread);
|
||||
} else if (command == 'defend') {
|
||||
defend(client, interaction, user_dbo, bot, thread);
|
||||
postActionBar(thread, user_dbo);
|
||||
} else if (command == 'ultimate') {
|
||||
user_dbo.find({'gamesettings': {$exists: true}}).toArray((err, docs) => {
|
||||
var gclass = new game_class_battle(docs[0].gamesettings.battle.class);
|
||||
attack_special(client, user_dbo, other_dbo, bot, thread, xp_collection, interaction, gclass);
|
||||
postActionBar(thread, user_dbo);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = { handle, postActionBar }
|
||||
@@ -1,5 +1,5 @@
|
||||
//@ts-check
|
||||
const { addxp, STATE, BASE } = require("./econ.js");
|
||||
const { addxp, STATE, BASE } = require("../db/econ");
|
||||
const turnManger = require('../turnManager.js');
|
||||
|
||||
|
||||
@@ -11,10 +11,11 @@ function loseGame(user_dbo, xp_collection, message, bot = null) {
|
||||
if (doc == undefined) { return message.reply("Oops! There's been an error! Please contact support if this problem persists!"); }
|
||||
if (doc.game == null) { return message.reply("You're not even in a game and you're trying to quit! Sad..."); }
|
||||
|
||||
var addbal;
|
||||
//If this function was called from "winGame", return
|
||||
if (doc.opponent) {
|
||||
//If remove some money (looting) [maybe implement a "friendly" game setting later with no looting]
|
||||
var addbal = doc.rank * 2;
|
||||
addbal = doc.rank * 2;
|
||||
if (doc.balance - addbal < 5) { addbal = addbal - doc.balance; }
|
||||
if (doc.balance > 5) {
|
||||
user_dbo.updateOne(doc, { $set: { balance: doc.balance - addbal}});
|
||||
@@ -54,18 +55,25 @@ function winGame(client, bot, db, user_dbo, xp_collection, message) {
|
||||
//Update the player with xp
|
||||
user_dbo.updateOne({"game": {$exists: true}}, { $set: { game: null, opponent: null, state: STATE.IDLE, xp: doc.xp + (BASE.XP * doc.rank), 'hpmp.hp': doc.hpmp.maxhp, 'hpmp.mp': doc.hpmp.maxmp }});
|
||||
|
||||
const channel = bot.channels.cache.get(message.channel.parentId);
|
||||
channel.send(`<@${user_dbo.s.namespace.collection}> just won a game of "${docs[0].game}"!`);
|
||||
message.channel.delete();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function equipItem(client, bot, db, dbo, message) {
|
||||
|
||||
if (!bot.inDebugMode) { return; }
|
||||
let items = [
|
||||
{ name: 'HP Potion', cost: 20, icon: 'CUSTOM|healing_potion', sect: 'HP', num: 2 },
|
||||
{ name: 'Super HP Potion', cost: 50, icon: 'CUSTOM|super_healing_potion', sect: 'HP', num: 2 },
|
||||
{ name: 'MP Potion', cost: 15, icon: 'CUSTOM|mana_potion', sect: 'MP', num: 2 }
|
||||
]
|
||||
for (let i = 1; i <= 10; i ++) {
|
||||
|
||||
items.push({ name: `${String.fromCharCode(i + 64)}`, cost: i * 10, icon: 'N/A', sect: 'N/A', num: i })
|
||||
}
|
||||
|
||||
dbo.updateMany({}, {$set: {'equipped.items': items}});
|
||||
}
|
||||
@@ -1,16 +1,23 @@
|
||||
// @ts-check
|
||||
// // @ts-check //Disabled
|
||||
|
||||
const { MongoClient, ServerApiVersion } = require('mongodb');
|
||||
let ecoimport = require("./econ.js");
|
||||
let { handle } = require("./battle.js"); //PROBLEM (CIRCULAR DEPENDANCY)
|
||||
let snowflake = require("./addons/snowflake.js");
|
||||
let ecoimport = require("../db/econ.js");
|
||||
|
||||
//#region Game Imports
|
||||
const battle = require("./battle.js");
|
||||
const ttt = require('./tictactoe.js');
|
||||
|
||||
//#endregion
|
||||
|
||||
let snowflake = require("../db/addons/snowflake.js");
|
||||
const STATE = ecoimport.STATE;
|
||||
const BASE = ecoimport.BASE;
|
||||
|
||||
const { winGame, loseGame, equipItem } = require('./external_game_functions.js');
|
||||
const { chooseClass, presentClasses } = require('./game_classes.js');
|
||||
|
||||
//Has a list of all games (used to change player state)
|
||||
const allGames = ['battle'];
|
||||
const allGames = ['battle', 'Tic Tac Toe'];
|
||||
// const { NULL } = require('mysql/lib/protocol/constants/types');
|
||||
|
||||
|
||||
@@ -23,6 +30,7 @@ async function Initialize(bot, user_dbo, command, message, first, second, other_
|
||||
return new Promise(async function(resolve, reject) {
|
||||
user_dbo.find({"game": {$exists: true}}).toArray(function(err, docs){
|
||||
let doc = docs[0];
|
||||
console.log(command);
|
||||
if (allGames.indexOf(command) != -1) {
|
||||
if (other_dbo != null) {
|
||||
user_dbo.updateOne( { "game": {$exists: true} }, { $set: { game: command, opponent: other_dbo.s.namespace.collection, state: STATE.FIGHTING }});
|
||||
@@ -130,15 +138,52 @@ function hpmp(message, command, dbo) {
|
||||
}
|
||||
|
||||
|
||||
function equip(client, message, command, dbo, bot) {
|
||||
function equip(message, args, command, dbo, bot, shop) {
|
||||
const inp = args[1];
|
||||
|
||||
//Check if the user is already in a game
|
||||
dbo.find({'game': {$exists: true}}).toArray(function(err, docs) {
|
||||
const doc = docs[0];
|
||||
|
||||
if (doc.game != null) {
|
||||
ret = true;
|
||||
console.log(doc.game);
|
||||
return message.reply('You can\'t equip while in a game!');
|
||||
}
|
||||
|
||||
//If the thing is a shield, add it to secondary
|
||||
if (inp.toLowerCase().indexOf('shield') != -1) {
|
||||
dbo.find({def: true}).toArray(function(err, docs) {
|
||||
if (docs[0] != undefined) {
|
||||
dbo.updateOne({}, {$set: {'equipped.weapons.secondary': docs[0]}});
|
||||
} else {
|
||||
message.reply("You don't own a shield!");
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
//Else, equip the weapon(s)
|
||||
|
||||
dbo.find({name: inp, sect: 'Weapons'}).toArray(function(err, docs) {
|
||||
if (docs[0] != undefined) {
|
||||
//Equip the weapon
|
||||
dbo.updateOne({}, {$set: {'equipped.weapons.main': docs[0]}});
|
||||
} else {
|
||||
message.reply(`You don't own any ${inp}s!`);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
|
||||
//#region GAME SPECIFIC
|
||||
|
||||
|
||||
//#region Game Handlers
|
||||
|
||||
function in_game_redirector(bot, interaction, threadname, doc, client, mongouri, items, xp_collection) {
|
||||
|
||||
//Maybe fix this later......
|
||||
@@ -154,7 +199,11 @@ function in_game_redirector(bot, interaction, threadname, doc, client, mongouri,
|
||||
const game = docs[0].game
|
||||
|
||||
switch (game) {
|
||||
case 'battle': handle(client, dbo, other, bot, thread, interaction.customId.toLowerCase(), mongouri, items, interaction, xp_collection);
|
||||
case 'battle': battle.handle(client, dbo, other, bot, thread, interaction.customId.toLowerCase(), mongouri, items, interaction, xp_collection);
|
||||
break;
|
||||
|
||||
case 'Tic Tac Toe': ttt.handle(client, db, dbo, other, bot, thread, null, doc, interaction, xp_collection);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -165,8 +214,6 @@ module.exports ={
|
||||
description: "Play a game using Selmer Bot!",
|
||||
async execute(bot, message, args, command, Discord, mongouri, items, xp_collection) {
|
||||
|
||||
if (!bot.inDebugMode) { return message.reply("This command is currently in development!"); }
|
||||
|
||||
|
||||
//#region Setup
|
||||
const id = message.author.id;
|
||||
@@ -188,7 +235,6 @@ module.exports ={
|
||||
|
||||
//Check for a second person and create a second database entry if neccessary
|
||||
if (message.mentions.users.first() != undefined) {
|
||||
//#TODO //FIX THIS (NOT THE RIGHT CLIENT 100% OF THE TIME!!!!!!!)
|
||||
ecoimport.CreateNewCollection(message, client, server, message.mentions.users.first().id);
|
||||
}
|
||||
|
||||
@@ -245,15 +291,41 @@ module.exports ={
|
||||
// message.reply(`${first} [${name_first}], ${second} [${name_second}]`); throw 'ERR';
|
||||
const threadname = `${name_first.username} VS ${name_second.username} [${newCommand.toUpperCase()}]`;
|
||||
var newObj = {0: id, 1: other_discord.id, turn: 0, thread: threadname};
|
||||
|
||||
if (newCommand.replaceAll(" ", "").toLowerCase() == 'tictactoe') { newCommand = 'Tic Tac Toe'; }
|
||||
|
||||
if (newCommand === 'Tic Tac Toe') {
|
||||
//Create the new board
|
||||
let newboard = ["", "", "", "", "", "", "", "", ""];
|
||||
newObj.board = newboard;
|
||||
let symbols;
|
||||
|
||||
/*DOES NOT WORK
|
||||
if (msg.content.lastIndexOf('>') == msg.content.lenth) {
|
||||
symbols = ['X', 'O'];
|
||||
} else {
|
||||
symbols = msg.content.substring(msg.content.lastIndexOf('>') + 2).split(' ');
|
||||
}
|
||||
*/
|
||||
newObj.symbols = ['X', 'O'];
|
||||
}
|
||||
|
||||
serverinbotdb.insertOne(newObj);
|
||||
|
||||
//#endregion
|
||||
|
||||
|
||||
|
||||
//Need this for all 2 player games
|
||||
const result = Initialize(bot, dbo, newCommand, msg, id, other_discord.id, other);
|
||||
|
||||
if (newCommand == 'battle') {
|
||||
const result = Initialize(bot, dbo, newCommand, msg, id, other_discord.id, other);
|
||||
result.then(function (thread) {
|
||||
handle(client, dbo, other, bot, thread, 'initalize', mongouri, items, null, xp_collection);
|
||||
battle.handle(client, dbo, other, bot, thread, 'initalize', mongouri, items, null, xp_collection);
|
||||
});
|
||||
} else if (newCommand == 'Tic Tac Toe') {
|
||||
result.then(function (thread) {
|
||||
ttt.handle(client, db, dbo, other, bot, thread, 'initalize', mongouri, null, xp_collection);
|
||||
});
|
||||
}
|
||||
} else if (command == 'quit') {
|
||||
@@ -276,20 +348,35 @@ module.exports ={
|
||||
} else if (command == 'hp' || command == 'mp') {
|
||||
hpmp(message, command, dbo);
|
||||
} else if (command == 'equip') {
|
||||
equipItem(client, bot, db, dbo, message);
|
||||
// equipItem(client, bot, db, dbo, message);
|
||||
equip(message, args, command, dbo, bot, items);
|
||||
} else if (command == 'classes') {
|
||||
presentClasses(message, args[1]);
|
||||
}
|
||||
//#endregion
|
||||
|
||||
//#region game-specific commands
|
||||
else {
|
||||
//Make change to new name if necessary
|
||||
if (command.replaceAll(" ", "").toLowerCase() == 'tictactoe') { command = 'Tic Tac Toe'; }
|
||||
|
||||
if (game == 'battle' || command == 'battle') {
|
||||
if (!bot.inDebugMode) { return message.reply("This command is currently in development!"); }
|
||||
|
||||
//Handle sending the request and making sure the user exists here
|
||||
let other_discord = message.mentions.users.first();
|
||||
if (other_discord == undefined) {
|
||||
return message.reply(`${args[1]} is not a valid user!`);
|
||||
}
|
||||
|
||||
message.channel.send(`${other_discord}, <@${message.author.id}> has invited you to play "battle", to accept, please reply to this message with _!game accept_`);
|
||||
message.channel.send(`${other_discord}, <@${message.author.id}> has invited you to play _"battle"_. To accept, please reply to this message with _!game accept_`);
|
||||
} else if (game == 'Tic Tac Toe' || command == 'Tic Tac Toe') {
|
||||
let other_discord = message.mentions.users.first();
|
||||
if (other_discord == undefined) {
|
||||
return message.reply(`${args[1]} is not a valid user!`);
|
||||
}
|
||||
|
||||
message.channel.send(`${other_discord}, <@${message.author.id}> has invited you to play _"Tic Tac Toe"_. To accept, please reply to this message with _!game accept_`);
|
||||
}
|
||||
|
||||
//Catch statement (invalid command)
|
||||
@@ -306,3 +393,6 @@ module.exports ={
|
||||
client.close();
|
||||
}, allGames, in_game_redirector
|
||||
}
|
||||
|
||||
|
||||
//#endregion
|
||||
@@ -0,0 +1,88 @@
|
||||
//Leave this as it's own file in case I want to expand the classes in the future
|
||||
|
||||
const { MessageActionRow, MessageSelectMenu } = require("discord.js");
|
||||
|
||||
|
||||
//#region multiplayer games
|
||||
|
||||
/**
|
||||
* A temporary container to keep track of what abilities each class has
|
||||
* @param {string} name - the name of the class ('fighter', 'wizard', etc.)
|
||||
* @property { Boolean } canUseWeapons
|
||||
* @property { Boolean } canUseSpells
|
||||
* @example var myClass = new game_class('wizard');
|
||||
*/
|
||||
class game_class_battle {
|
||||
constructor(name = 'none') {
|
||||
if (name == 'fighter') {
|
||||
this.canUseWeapons = true;
|
||||
this.canUseSpells = false;
|
||||
this.specialAttack = {
|
||||
icon: 'spatkfight',
|
||||
dmg: 'r*2.5',
|
||||
prone: false
|
||||
};
|
||||
this.description = 'More damage, less effects!';
|
||||
} else if (name == 'wizard') {
|
||||
this.canUseWeapons = false;
|
||||
this.canUseSpells = true;
|
||||
this.specialAttack = {
|
||||
icon: 'spatkwiz',
|
||||
dmg: 'r*2.0',
|
||||
prone: true
|
||||
}
|
||||
this.description = 'Less damage, more effects!';
|
||||
} else if (name == 'none') {
|
||||
//The player doesn't have a class
|
||||
this.canUseSpells = undefined;
|
||||
this.canUseWeapons = undefined;
|
||||
this.specialAttack = undefined;
|
||||
this.description = undefined;
|
||||
}
|
||||
|
||||
this.className = name;
|
||||
}
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
//#region functions
|
||||
function presentClasses(message, game) {
|
||||
let classes;
|
||||
|
||||
if (game == 'battle') {
|
||||
classes = [new game_class_battle('fighter'), new game_class_battle('wizard')];
|
||||
} else {
|
||||
return message.reply('Please use the following format for this command: _!game class [game name]_');
|
||||
}
|
||||
|
||||
var classList = [];
|
||||
|
||||
classes.forEach(function(c) {
|
||||
let n = c.className;
|
||||
|
||||
classList.push({label: n, description: `${c.description}`, value: `${n}`});
|
||||
});
|
||||
|
||||
const row = new MessageActionRow()
|
||||
.addComponents(
|
||||
new MessageSelectMenu()
|
||||
.setCustomId(`${message.author.id}|class`)
|
||||
.setPlaceholder('none')
|
||||
.addOptions(classList)
|
||||
)
|
||||
|
||||
message.reply({ content: `Please choose your class <@${message.author.id}>`, components: [row] });
|
||||
}
|
||||
|
||||
|
||||
function chooseClass(user_dbo, message, game) {
|
||||
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
module.exports = { game_class_battle, presentClasses, chooseClass }
|
||||
@@ -0,0 +1,149 @@
|
||||
// @ts-check
|
||||
|
||||
const wait = require('node:timers/promises').setTimeout;
|
||||
const { MessageActionRow, MessageButton, MessageSelectMenu, Client, CommandInteractionOptionResolver } = require('discord.js');
|
||||
const { STATE } = require('../db/econ');
|
||||
const { winGame, getCustomEmoji } = require('./external_game_functions.js');
|
||||
const { changeTurn } = require('../turnManager.js');
|
||||
const { game_class_battle } = require('./game_classes');
|
||||
const { MongoClient } = require('mongodb');
|
||||
const { convertSnowflakeToDate } = require('../db/addons/snowflake');
|
||||
|
||||
//This function is blatantly stolen from https://alialaa.com/blog/tic-tac-toe-js
|
||||
function isTerminal(board) {
|
||||
//Return False if board in empty
|
||||
if (board.every(cell => !cell)) return false;
|
||||
let nums = [0, 0, 0]
|
||||
|
||||
//Checking Horizontal Wins
|
||||
if (board[0] === board[1] && board[0] === board[2] && board[0]) {
|
||||
nums = [0, 1, 2];
|
||||
return {'winner': board[0], 'direction': 'H', 'row': 1, 'nums': nums};
|
||||
}
|
||||
if (board[3] === board[4] && board[3] === board[5] && board[3]) {
|
||||
nums = [3, 4, 5];
|
||||
return {'winner': board[3], 'direction': 'H', 'row': 2, 'nums': nums};
|
||||
}
|
||||
if (board[6] === board[7] && board[6] === board[8] && board[6]) {
|
||||
nums = [6, 7, 8];
|
||||
return {'winner': board[6], 'direction': 'H', 'row': 3, 'nums': nums};
|
||||
}
|
||||
|
||||
//Checking Vertical Wins
|
||||
if (board[0] === board[3] && board[0] === board[6] && board[0]) {
|
||||
nums = [0, 3, 6];
|
||||
return {'winner': board[0], 'direction': 'V', 'column': 1, 'nums': nums};
|
||||
}
|
||||
if (board[1] === board[4] && board[1] === board[7] && board[1]) {
|
||||
nums = [1, 4, 7];
|
||||
return {'winner': board[1], 'direction': 'V', 'column': 2, 'nums': nums};
|
||||
}
|
||||
if (board[2] === board[5] && board[2] === board[8] && board[2]) {
|
||||
nums = [2, 5, 8];
|
||||
return {'winner': board[2], 'direction': 'V', 'column': 3, 'nums': nums};
|
||||
}
|
||||
|
||||
//Checking Diagonal Wins
|
||||
if (board[0] === board[4] && board[0] === board[8] && board[0]) {
|
||||
nums = [0, 4, 8];
|
||||
return {'winner': board[0], 'direction': 'D', 'diagonal': 'main', 'nums': nums};
|
||||
}
|
||||
if (board[2] === board[4] && board[2] === board[6] && board[2]) {
|
||||
nums = [2, 4, 6];
|
||||
return {'winner': board[2], 'direction': 'D', 'diagonal': 'counter', 'nums': nums};
|
||||
}
|
||||
|
||||
//If no winner but the board is full, then it's a draw
|
||||
if (board.every(cell => cell)) {
|
||||
return {'winner': 'draw'};
|
||||
}
|
||||
|
||||
//return false otherwise
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//I know it's sloppy, but when 'initial' is true, 'interaction' will actually be 'thread'
|
||||
function postActionBar(interaction, user_dbo, board, won, initial = false) {
|
||||
let componentlist = [];
|
||||
let newRow = new MessageActionRow();
|
||||
|
||||
for (let i = 0; i < 9; i ++) {
|
||||
let button;
|
||||
|
||||
if (!won) {
|
||||
if (!board[i]) {
|
||||
button = new MessageButton()
|
||||
.setCustomId(`ttt|${i}`)
|
||||
.setLabel('-')
|
||||
.setStyle('SUCCESS')
|
||||
} else {
|
||||
button = new MessageButton()
|
||||
.setCustomId(`ttt|${i}`)
|
||||
.setLabel(board[i])
|
||||
.setStyle('DANGER')
|
||||
.setDisabled(true);
|
||||
}
|
||||
} else {
|
||||
if (i in won.nums) {
|
||||
button = new MessageButton()
|
||||
.setCustomId(`ttt|${i}`)
|
||||
.setLabel('W')
|
||||
.setStyle('SUCCESS')
|
||||
} else {
|
||||
button = new MessageButton()
|
||||
.setCustomId(`ttt|${i}`)
|
||||
.setLabel('F')
|
||||
.setStyle('DANGER')
|
||||
.setDisabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
newRow.addComponents(button);
|
||||
|
||||
if ((i + 1) % 3 == 0) {
|
||||
//Add the row to the list of rows
|
||||
componentlist.push(newRow);
|
||||
newRow = new MessageActionRow();
|
||||
}
|
||||
}
|
||||
|
||||
console.log(componentlist);
|
||||
|
||||
if (initial) {
|
||||
interaction.send({ content: `Your turn <@${user_dbo.s.namespace.collection}>!`, components: componentlist });
|
||||
} else {
|
||||
interaction.update({ content: `Your turn <@${user_dbo.s.namespace.collection}>!`, components: componentlist });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function handle(client, db, dbo, other, bot, thread, command, doc, interaction, xp_collection) {
|
||||
|
||||
if (command == 'initalize') {
|
||||
let board = ["", "", "", "", "", "", "", "", ""];
|
||||
postActionBar(thread, dbo, board, false,true);
|
||||
} else {
|
||||
//Change the board
|
||||
let square = Number(interaction.customId.split('|')[1]);
|
||||
let symbol = doc.symbols[doc.turn];
|
||||
let board = doc.board;
|
||||
board[square] = symbol;
|
||||
client.db('B|S' + bot.user.id).collection(dbo.s.namespace.db.substr(0, dbo.s.namespace.db.length - 6)).updateOne({'board': {$exists: true}}, {$set: {board: board}});
|
||||
|
||||
//Check if the game is over
|
||||
let won = isTerminal(board);
|
||||
|
||||
if (!won) {
|
||||
changeTurn(client, bot, interaction);
|
||||
postActionBar(interaction, other, board, false);
|
||||
changeTurn(client, bot, interaction);
|
||||
} else {
|
||||
postActionBar(interaction, dbo, board, won);
|
||||
await wait(7000);
|
||||
winGame(client, bot, db, dbo, xp_collection, interaction.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { handle }
|
||||
@@ -0,0 +1,130 @@
|
||||
const { MongoClient, ServerApiVersion } = require('mongodb');
|
||||
const { createSubscriptionManual } = require('./API/stripe.js');
|
||||
|
||||
|
||||
async function handle_interaction(interaction, mongouri, turnManager, bot, STATE, items, xp_collection) {
|
||||
if (interaction.isButton()) {
|
||||
const battlecommandlist = ['ATTACK', 'HEAL', 'DEFEND', 'ITEMS', 'ULTIMATE'];
|
||||
const singleCommandGames = ['ttt'];
|
||||
|
||||
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
||||
client.connect(async (err) => {
|
||||
|
||||
if (battlecommandlist.indexOf(interaction.customId) != -1) {
|
||||
await interaction.deferReply();
|
||||
|
||||
let current_user = turnManager.getTurn(client, bot, interaction);
|
||||
|
||||
current_user.then(function (result) {
|
||||
const id = result[0];
|
||||
const doc = result[1];
|
||||
const threadname = doc.thread;
|
||||
const dbo = client.db(interaction.guildId + '[ECON]').collection(id);
|
||||
|
||||
dbo.find({ 'state': {$exists: true} }).toArray(async function (err, docs) {
|
||||
if (interaction.user.id == id) {
|
||||
|
||||
//Check State
|
||||
if (docs[0].state != STATE.IDLE) {
|
||||
//Do turn stuff
|
||||
bot.commands.get('game').in_game_redirector(bot, interaction, threadname, doc, client, mongouri, items, xp_collection);
|
||||
}
|
||||
|
||||
//remove the old interation message
|
||||
await interaction.message.delete();
|
||||
|
||||
if (interaction.customId.toLowerCase() != 'heal') {
|
||||
interaction.editReply(`<@${interaction.user.id}> used _${interaction.customId.toLowerCase()}_!`);
|
||||
}
|
||||
} else {
|
||||
console.log("It's not your turn!");
|
||||
}
|
||||
});
|
||||
});
|
||||
} else if (interaction.customId.split('|')[0] == 'ttt') {
|
||||
let current_user = turnManager.getTurn(client, bot, interaction);
|
||||
current_user.then(function (result) {
|
||||
const id = result[0];
|
||||
|
||||
if (interaction.user.id == id) {
|
||||
const doc = result[1];
|
||||
const threadname = doc.thread;
|
||||
|
||||
let board = result.board;
|
||||
|
||||
bot.commands.get('game').in_game_redirector(bot, interaction, threadname, doc, client, mongouri, items, xp_collection, board);
|
||||
} else {
|
||||
console.log("It's not your turn!");
|
||||
}
|
||||
});
|
||||
} //else ifs here
|
||||
});
|
||||
|
||||
client.close();
|
||||
}
|
||||
|
||||
//Menu Selection
|
||||
else if (interaction.isSelectMenu()) {
|
||||
const id = interaction.customId.substring(0, interaction.customId.indexOf('|'))
|
||||
// const command = interaction.customId.substring(interaction.customId.indexOf('|'), interaction.customId.length - interaction.customId.indexOf('|'))
|
||||
|
||||
if (interaction.customId.toLowerCase().indexOf('|heal') != -1) {
|
||||
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
||||
client.connect(err => {
|
||||
console.log(id);
|
||||
if (id != interaction.user.id) { return; }
|
||||
|
||||
let current_user = turnManager.getTurn(client, bot, interaction);
|
||||
current_user.then(function(result) {
|
||||
const doc = result[1];
|
||||
const threadname = doc.thread;
|
||||
const dbo = client.db(interaction.guildId + '[ECON]').collection(id);
|
||||
|
||||
dbo.find({ 'state': {$exists: true} }).toArray(async function (err, docs) {
|
||||
if (interaction.user.id == id) {
|
||||
await interaction.deferReply();
|
||||
|
||||
//Check State
|
||||
if (docs[0].state == STATE.FIGHTING) {
|
||||
interaction.customId = 'usepotion';
|
||||
//Do turn stuff
|
||||
bot.commands.get('game').in_game_redirector(bot, interaction, threadname, doc, client, mongouri, items, xp_collection);
|
||||
}
|
||||
|
||||
interaction.editReply(`<@${interaction.user.id}> used a _${interaction.values[0]}_!`);
|
||||
|
||||
//remove the old interation message
|
||||
await interaction.message.delete();
|
||||
|
||||
} else {
|
||||
console.log("It's not your turn!");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//Get all chars from after "CUSTOM|" to the end of the str
|
||||
// let name = item.icon.substr(7, item.icon.length - 6);
|
||||
});
|
||||
} else if (interaction.customId.toLowerCase().indexOf('|item') != -1) {
|
||||
|
||||
} else if (interaction.customId.split('|')[1] == 'premium') {
|
||||
//Check if the person subscribing and the person clicking are the same (group DM catch)
|
||||
const user = interaction.customId.split('|')[0];
|
||||
if (interaction.user.id == user) {
|
||||
// await interaction.deferReply();
|
||||
await interaction.update({ content: 'TIER SELECTED PLEASE HOLD', components: [] });
|
||||
await createSubscriptionManual(bot, interaction, user, interaction.values[0]);
|
||||
|
||||
//Handle the interaction here
|
||||
}
|
||||
}
|
||||
|
||||
//menu else ifs here
|
||||
} //other selection types here
|
||||
}
|
||||
|
||||
|
||||
module.exports = { handle_interaction }
|
||||
|
||||
//values: [ 'price_1LI5pzFtuywsbrwdlY1gWMkV' ]
|
||||
//values: [ 'price_1LIpROFtuywsbrwdmxOb8Baj' ]
|
||||
@@ -6,19 +6,19 @@ module.exports ={
|
||||
if (args[0] == 'econ') {
|
||||
let temp = "***Selmer Bot Commands (Econ):***\n";
|
||||
temp += bot.commands.get('econ').econHelp();
|
||||
temp += `\n\n(remember to use '${bot.prefix}' before the command!)`;
|
||||
temp += `\n\n(remember to use _'${bot.prefix}'_ before the command!)`;
|
||||
return message.channel.send(temp);
|
||||
}
|
||||
else if (args[0] == 'game') {
|
||||
let temp = "***Selmer Bot Commands (Games):***\n";
|
||||
temp += bot.commands.get('game').allGames.join(", ");
|
||||
temp += `\n\n(remember to use '${bot.prefix}' before the command!)`;
|
||||
temp += `\n\n(remember to use _'${bot.prefix}game'_ before the command!)`;
|
||||
return message.channel.send(temp);
|
||||
}
|
||||
|
||||
let temp = "***Selmer Bot Commands:***\n";
|
||||
|
||||
bot.commands.sort((a, b) => {a.name[0] < b.name[0]});
|
||||
bot.commands.sort((a, b) => {if (a.name && b.name) { return a.name[0] < b.name[0]} else {return false;} });
|
||||
|
||||
bot.commands.forEach((comm) => {
|
||||
if (comm.name != 'verify') {
|
||||
@@ -27,9 +27,13 @@ module.exports ={
|
||||
}
|
||||
else if (comm.name == 'game') {
|
||||
temp += `game - use _!help game_\n`;
|
||||
}
|
||||
} /* else if (comm.name == 'setup') {
|
||||
temp += `setup - use _!setup_\n`;
|
||||
}*/
|
||||
else {
|
||||
temp += `${comm.name.toLowerCase()} - _${comm.description}_\n`;
|
||||
if (comm.name && comm.description) {
|
||||
temp += `${comm.name.toLowerCase()} - _${comm.description}_\n`;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
+28
-3
@@ -1,5 +1,7 @@
|
||||
//THESE STRUCTURES SUPPORTS TWO PLAYERS ONLY!!!!
|
||||
|
||||
const { STATE } = require("./db/econ");
|
||||
|
||||
|
||||
|
||||
//Determines who's turn it currently is
|
||||
@@ -38,10 +40,33 @@ function getTurn(client, bot, interaction) {
|
||||
function changeTurn(client, bot, interaction) {
|
||||
const db = client.db('B|S' + bot.user.id);
|
||||
const dbo = db.collection(interaction.member.guild.id);
|
||||
|
||||
dbo.find({turn: {$exists: true}}).toArray(function (err, docs) {
|
||||
let turn = docs[0].turn;
|
||||
turn = Number(!turn);
|
||||
dbo.updateOne(docs[0], {$set: {turn: turn}});
|
||||
let turnnumer = docs[0].turn;
|
||||
turnnumer = Number(!turnnumer);
|
||||
|
||||
//Check for prone, and change it if necessary
|
||||
let turnInfo = getTurn(client, bot, interaction);
|
||||
|
||||
turnInfo.then(id = (turn => {
|
||||
var id;
|
||||
// console.log(turn); throw 1;
|
||||
for (const [key, value] of Object.entries(turn[1])) {
|
||||
if (key == turnnumer) { id = value; break; }
|
||||
}
|
||||
|
||||
|
||||
const other_dbo = client.db(interaction.member.guild.id + '[ECON]').collection(id);
|
||||
|
||||
other_dbo.find({'state': {$exists: true}}).toArray((err, docs) => {
|
||||
//If the person was prone, skip their turn
|
||||
if (docs[0].state == STATE.PRONE) {
|
||||
dbo.updateOne({'turn': {$exists: true}}, {$set: {state: STATE.FIGHTING}});
|
||||
} else {
|
||||
dbo.updateOne({'turn': {$exists: true}}, {$set: {turn: turnnumer}});
|
||||
}
|
||||
});
|
||||
}))
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -2,30 +2,43 @@ const { Client, Intents, MessageActionRow, MessageButton, MessageSelectMenu } =
|
||||
const Discord = require('discord.js');
|
||||
const { MongoClient, ServerApiVersion } = require('mongodb');
|
||||
const fs = require('fs');
|
||||
// const OpenAI = require('openai-api')
|
||||
const { Configuration, OpenAIApi } = require("openai");
|
||||
const Stripe = require('stripe');
|
||||
|
||||
const turnManager = require('./commands/turnManager.js');
|
||||
const { welcome } = require('./commands/admin/welcome.js');
|
||||
const { handle_interaction } = require('./commands/interactionhandler.js');
|
||||
const { handle_dm } = require('./commands/dm_handler');
|
||||
const { exit } = require('process');
|
||||
const BASE_LVL_XP = 20;
|
||||
|
||||
|
||||
//Token area
|
||||
//#region Token area
|
||||
|
||||
//Adding integration for development mode
|
||||
let token;
|
||||
let IDM = false;
|
||||
let home_server;
|
||||
|
||||
let MLAIKEY;
|
||||
let StripeAPIKey;
|
||||
|
||||
if (process.env.token != undefined) {
|
||||
//Use "setx NAME VALUE" in the local powershell terminal to set
|
||||
token = process.env.token;
|
||||
home_server = process.env.home_server;
|
||||
MLAIKEY = process.env.MLAIKEY;
|
||||
StripeAPIKey = process.env.StripeAPIKey;
|
||||
} else {
|
||||
token = require('./config.json').token;
|
||||
home_server = require('./config.json').home_server;
|
||||
IDM = true;
|
||||
MLAIKEY = require('./config.json').MLAIKEY;
|
||||
StripeAPIKey = require('./config.json').StripeAPIKey;
|
||||
}
|
||||
|
||||
// const { token } = require('./config.json');
|
||||
//Heroku part
|
||||
// const { token } = process.env.token;
|
||||
//#endregion
|
||||
|
||||
const bot = new Client({
|
||||
intents: [
|
||||
@@ -35,8 +48,12 @@ const bot = new Client({
|
||||
Intents.FLAGS.GUILD_VOICE_STATES,
|
||||
Intents.FLAGS.GUILD_EMOJIS_AND_STICKERS,
|
||||
Intents.FLAGS.GUILD_PRESENCES,
|
||||
Intents.FLAGS.GUILD_MEMBERS
|
||||
Intents.FLAGS.GUILD_MEMBERS,
|
||||
Intents.FLAGS.DIRECT_MESSAGES,
|
||||
Intents.FLAGS.DIRECT_MESSAGE_REACTIONS,
|
||||
Intents.FLAGS.DIRECT_MESSAGE_TYPING,
|
||||
],
|
||||
partials: [ 'CHANNEL' ]
|
||||
});
|
||||
|
||||
const prefix = '!';
|
||||
@@ -45,8 +62,15 @@ bot.prefix = prefix;
|
||||
bot.inDebugMode = IDM;
|
||||
bot.home_server = home_server;
|
||||
|
||||
const configuration = new Configuration({
|
||||
apiKey: MLAIKEY,
|
||||
});
|
||||
bot.openai = new OpenAIApi(configuration);
|
||||
bot.temptext = '';
|
||||
bot.stripe = Stripe(StripeAPIKey);
|
||||
|
||||
//MongoDB integration
|
||||
|
||||
//#region MongoDB integration
|
||||
//Development support
|
||||
let mongouritemp;
|
||||
if (process.env.MONGODB_URI) {
|
||||
@@ -55,43 +79,22 @@ if (process.env.MONGODB_URI) {
|
||||
mongouritemp = require('./config.json');
|
||||
}
|
||||
const mongouri = mongouritemp;
|
||||
bot.mongouri = mongouri;
|
||||
const { connect } = require('mongoose');
|
||||
|
||||
bot.on("guildCreate", guild => {
|
||||
guild.roles.create({ name: 'Selmer Bot Mod' });
|
||||
|
||||
//const role = guild.roles.cache.find((role) => role.name === 'Selmer Bot Mod'); // member.roles.cache.has('role-id-here');
|
||||
const server = bot.guilds.cache.get(guild.id);
|
||||
const owner = server.members.fetch(guild.ownerId).then(function(owner) {
|
||||
owner.send('Thank you for adding Selmer Bot to your server!\nPlease give people you want to have access to Selmer Bot\'s restricted commands the "_Selmer Bot Mod_" role.');
|
||||
owner.send('To help set up Selmer Bot to work better with your server, use _!setup help_ in a channel Selmer Bot is in!');
|
||||
});
|
||||
|
||||
//Set up the server
|
||||
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
||||
client.connect(err => {
|
||||
if (err) { return console.log(err); }
|
||||
|
||||
const dbo = client.db(guild.id).collection('SETUP');
|
||||
dbo.insertMany([{_id: 'WELCOME', 'welcomechannel': null, 'welcomemessage': null, 'welcomebanner': null}]);
|
||||
});
|
||||
|
||||
client.close();
|
||||
});
|
||||
//#endregion MongoDB Integration end
|
||||
|
||||
|
||||
//MongoDB Integration end
|
||||
// let item = items.filter(function (item) { return item.name.toLowerCase() == 'grapes'; });
|
||||
//#region set up bot commands
|
||||
|
||||
// const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js')); // Obsolete?
|
||||
|
||||
bot.commands = new Discord.Collection();
|
||||
const forbiddenFolders = ['db', 'API', 'dev only'];
|
||||
|
||||
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
|
||||
|
||||
|
||||
bot.commands = new Discord.Collection();
|
||||
fs.readdirSync('./commands')
|
||||
.forEach(dir => {
|
||||
if (dir != 'db' && !dir.endsWith('.js')) {
|
||||
if (!forbiddenFolders.includes(dir) && !dir.endsWith('.js')) {
|
||||
fs.readdirSync(`./commands/${dir}`)
|
||||
.filter(file => file.endsWith('.js'))
|
||||
.forEach(file => {
|
||||
@@ -102,17 +105,24 @@ fs.readdirSync('./commands')
|
||||
});
|
||||
|
||||
|
||||
//Set these two manually because all the seperate games can't be included in the command list (all managed by the 'game' file)
|
||||
//Set these two manually because all the seperate games can't be included in the command list (all managed by the 'game' file)
|
||||
let temp_command = require("./commands/db/econ.js");
|
||||
const { STATE } = require('./commands/db/econ.js');
|
||||
bot.commands.set('econ', temp_command);
|
||||
temp_command = require('./commands/db/game.js');
|
||||
temp_command = require('./commands/games/game.js');
|
||||
bot.commands.set('game', temp_command);
|
||||
|
||||
// const econFiles = fs.readdirSync('./commands/inventory').filter(file => file.endsWith('.js'));;
|
||||
// const currency = new Discord.Collection();
|
||||
// const { Users } = require('./commands/currency/dbObjects.js');
|
||||
// i++;
|
||||
//Everything in the API should be handled by specific handler functions
|
||||
const chat = require('./commands/API/chat.js');
|
||||
bot.commands.set('chat', chat);
|
||||
const stripeCommands = require('./commands/API/stripe.js');
|
||||
bot.commands.set('premium', stripeCommands);
|
||||
|
||||
//#endregion
|
||||
|
||||
|
||||
|
||||
//#region bot.[anything] section
|
||||
|
||||
//XP Table section
|
||||
let xp_collection = new Map();
|
||||
@@ -151,112 +161,47 @@ bot.on('ready', async () => {
|
||||
} else {
|
||||
console.log("Testing testing 1 2 5...");
|
||||
}
|
||||
|
||||
|
||||
//Add the money symbol
|
||||
let srv = bot.guilds.cache.get(bot.home_server).emojis.cache;
|
||||
emj = srv.find((g) => { return g.name == 'selmer_coin' });
|
||||
bot.currencysymbolmmain = `${emj}`;
|
||||
});
|
||||
|
||||
|
||||
//Button Section
|
||||
bot.on('interactionCreate', async interaction => {
|
||||
|
||||
if (interaction.isButton()) {
|
||||
const battlecommandlist = ['ATTACK', 'HEAL', 'DEFEND', 'ITEMS'];
|
||||
|
||||
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
||||
client.connect(err => {
|
||||
|
||||
if (battlecommandlist.indexOf(interaction.customId) != -1) {
|
||||
let current_user = turnManager.getTurn(client, bot, interaction);
|
||||
|
||||
current_user.then(function (result) {
|
||||
const id = result[0];
|
||||
const doc = result[1];
|
||||
const threadname = doc.thread;
|
||||
const dbo = client.db(interaction.guildId + '[ECON]').collection(id);
|
||||
|
||||
dbo.find({ 'state': {$exists: true} }).toArray(async function (err, docs) {
|
||||
if (interaction.user.id == id) {
|
||||
await interaction.deferReply();
|
||||
|
||||
//Check State
|
||||
if (docs[0].state == STATE.FIGHTING) {
|
||||
//Do turn stuff
|
||||
bot.commands.get('game').in_game_redirector(bot, interaction, threadname, doc, client, mongouri, items, xp_collection);
|
||||
}
|
||||
|
||||
//remove the old interation message
|
||||
await interaction.message.delete();
|
||||
|
||||
if (interaction.customId.toLowerCase() != 'heal') {
|
||||
interaction.editReply(`<@${interaction.user.id}> used _${interaction.customId.toLowerCase()}_!`);
|
||||
}
|
||||
} else {
|
||||
console.log("It's not your turn!");
|
||||
}
|
||||
});
|
||||
});
|
||||
}//else ifs here
|
||||
});
|
||||
|
||||
client.close();
|
||||
}
|
||||
else if (interaction.isSelectMenu()) {
|
||||
if (interaction.customId.toLowerCase().indexOf('|heal') != -1) {
|
||||
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
||||
client.connect(err => {
|
||||
const id = interaction.customId.substring(0, interaction.customId.indexOf('|'))
|
||||
|
||||
if (id != interaction.user.id) { return; }
|
||||
|
||||
let current_user = turnManager.getTurn(client, bot, interaction);
|
||||
current_user.then(function(result) {
|
||||
const doc = result[1];
|
||||
const threadname = doc.thread;
|
||||
const dbo = client.db(interaction.guildId + '[ECON]').collection(id);
|
||||
|
||||
dbo.find({ 'state': {$exists: true} }).toArray(async function (err, docs) {
|
||||
if (interaction.user.id == id) {
|
||||
await interaction.deferReply();
|
||||
|
||||
//Check State
|
||||
if (docs[0].state == STATE.FIGHTING) {
|
||||
interaction.customId = 'usepotion';
|
||||
//Do turn stuff
|
||||
bot.commands.get('game').in_game_redirector(bot, interaction, threadname, doc, client, mongouri, items, xp_collection);
|
||||
}
|
||||
|
||||
/*
|
||||
let srv = bot.guilds.cache.get(bot.home_server).emojis.cache;
|
||||
let sname;
|
||||
|
||||
if (interaction.customId.toLowerCase() == 'heal' || interaction.customId.toLowerCase() == 'mp') {
|
||||
if (interaction.values[0] == 'HP Potion') { sname = 'healing_potion' }
|
||||
else if (interaction.values[0] == 'MP Potion') { sname = 'mana_potion' }
|
||||
else if (interaction.values[0] == 'Super HP Potion') { sname = 'superior_healing_potion' }
|
||||
else if (interaction.values[0] == 'Super MP Potion') { sname = 'superior_mana_potion' }
|
||||
}
|
||||
|
||||
// emj = srv.find((g) => { return g.name == sname });
|
||||
// console.log(sname, srv);*/
|
||||
|
||||
interaction.editReply(`<@${interaction.user.id}> used a _${interaction.values[0]}_!`);
|
||||
|
||||
|
||||
//remove the old interation message
|
||||
await interaction.message.delete();
|
||||
|
||||
} else {
|
||||
console.log("It's not your turn!");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//Get all chars from after "CUSTOM|" to the end of the str
|
||||
// let name = item.icon.substr(7, item.icon.length - 6);
|
||||
});
|
||||
}
|
||||
}
|
||||
handle_interaction(interaction, mongouri, turnManager, bot, STATE, items, xp_collection);
|
||||
});
|
||||
|
||||
|
||||
|
||||
//Add the bot to a server setup
|
||||
bot.on("guildCreate", guild => {
|
||||
guild.roles.create({ name: 'Selmer Bot Mod' });
|
||||
|
||||
//const role = guild.roles.cache.find((role) => role.name === 'Selmer Bot Mod'); // member.roles.cache.has('role-id-here');
|
||||
const server = bot.guilds.cache.get(guild.id);
|
||||
const owner = server.members.fetch(guild.ownerId).then(function(owner) {
|
||||
owner.send('Thank you for adding Selmer Bot to your server!\nPlease give people you want to have access to Selmer Bot\'s restricted commands the "_Selmer Bot Mod_" role.');
|
||||
owner.send('To help set up Selmer Bot to work better with your server, use _!setup help_ in a channel Selmer Bot is in!');
|
||||
});
|
||||
|
||||
//Set up the server
|
||||
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
||||
client.connect(err => {
|
||||
if (err) { return console.log(err); }
|
||||
|
||||
const dbo = client.db(guild.id).collection('SETUP');
|
||||
dbo.insertMany([{_id: 'WELCOME', 'welcomechannel': null, 'welcomemessage': null, 'welcomebanner': null}]);
|
||||
});
|
||||
|
||||
client.close();
|
||||
});
|
||||
|
||||
|
||||
|
||||
//Welcome new members
|
||||
bot.on('guildMemberAdd', async (member) => {
|
||||
//Check for impartial data
|
||||
@@ -289,6 +234,11 @@ bot.on('guildMemberAdd', async (member) => {
|
||||
|
||||
bot.on('messageCreate', (message) => {
|
||||
|
||||
//DM SECTION
|
||||
if (message.channel.type === "DM") {
|
||||
return handle_dm(message, bot);
|
||||
}
|
||||
|
||||
//Special case, testing server (still need the emojis)
|
||||
if (!bot.inDebugMode && message.guild.id == bot.home_server) { return; }
|
||||
|
||||
@@ -300,28 +250,6 @@ bot.on('messageCreate', (message) => {
|
||||
const command = args.shift().toLowerCase();
|
||||
|
||||
|
||||
if (command == 'welcome') {
|
||||
const row = new MessageActionRow()
|
||||
.addComponents(
|
||||
new MessageButton()
|
||||
.setCustomId('WELCOME')
|
||||
.setLabel('WELCOME')
|
||||
.setStyle('PRIMARY')
|
||||
);
|
||||
|
||||
message.channel.send({ components: [row] });
|
||||
}
|
||||
|
||||
//TEMP
|
||||
if (command == 'emj') {
|
||||
let srv = bot.guilds.cache.get(bot.home_server).emojis.cache;
|
||||
// console.log(srv);
|
||||
emj = srv.find((g) => { return g.name == 'healing_potion' });
|
||||
// console.log(emj); exit();
|
||||
message.channel.send(`${emj}`);
|
||||
}
|
||||
|
||||
//Check if the user has sufficient permission
|
||||
//Performes the command
|
||||
//Admin section
|
||||
if (command == 'reactionrole') { bot.commands.get(command).execute(message, args, Discord, bot); }
|
||||
@@ -339,9 +267,7 @@ bot.on('messageCreate', (message) => {
|
||||
else { bot.commands.get('econ').execute(bot, message, args, command, Discord, mongouri, items, xp_collection); }
|
||||
})
|
||||
|
||||
//Look into integrating MySQL into SelmerBot instead of SQLite
|
||||
//#endregion
|
||||
|
||||
//Last Line(s)
|
||||
// bot.login(token);
|
||||
|
||||
bot.login(token);
|
||||
Generated
+3953
-6
File diff suppressed because it is too large
Load Diff
@@ -18,10 +18,13 @@
|
||||
"mongoose": "^6.3.2",
|
||||
"mysql": "^2.18.1",
|
||||
"node.js": "^0.0.1-security",
|
||||
"npm": "^8.13.2",
|
||||
"openai": "^3.0.0",
|
||||
"play-dl": "^1.9.4",
|
||||
"random-memes": "^3.1.0",
|
||||
"sequelize": "^6.19.0",
|
||||
"sqlite3": "^5.0.3",
|
||||
"stripe": "^9.11.0",
|
||||
"sudo": "^1.0.3",
|
||||
"undici": "^5.4.0",
|
||||
"youtube-mp3-downloader": "^0.7.10",
|
||||
|
||||
Reference in New Issue
Block a user