Skip to content

Commit

Permalink
_id kullanımı arttı
Browse files Browse the repository at this point in the history
  • Loading branch information
Akif9748 committed Oct 11, 2022
1 parent efc7cbc commit ebcba9e
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 54 deletions.
10 changes: 4 additions & 6 deletions buttons/rol.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@



module.exports = (interaction, rolid) => {
module.exports = (interaction, roleId) => {



if (interaction.member.roles.cache.has(rolid)) {
interaction.member.roles.remove(rolid).then(r =>
if (interaction.member.roles.cache.has(roleId)) {
interaction.member.roles.remove(roleId).then(r =>
interaction.reply({ content: "Rolü başarıyla aldım", ephemeral: true })
).catch(e => interaction.reply({ content: "Rolü alamadım", ephemeral: true }))

} else {
interaction.member.roles.add(rolid).then(r =>
interaction.member.roles.add(roleId).then(r =>
interaction.reply({ content: "Rolü başarıyla verdim", ephemeral: true })
).catch(e => interaction.reply({ content: "Rolü veremedim", ephemeral: true }))
}
Expand Down
4 changes: 2 additions & 2 deletions commands/ekonomi/atc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ exports.run = async (client, message, args) => {

const get = id => client.users.cache.get(id)?.tag || "~~" + id + "~~";

const veri = await UserModel.find().sort({ para: -1 }).select("para userid").limit(30);
const veri = await UserModel.find().sort({ para: -1 }).select("para").limit(30);


const gonder = veri.map((rank, index) =>
`**${index + 1}.** ${get(rank.userid)} • ATC: **${parsenum(rank.para)}**`
`**${index + 1}.** ${get(rank._id)} • ATC: **${parsenum(rank.para)}**`
)

const embeds = [ new MessageEmbed()
Expand Down
4 changes: 2 additions & 2 deletions commands/ekonomi/sıralama.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ exports.run = async (client, message, args) => {
sort[path + ".seviye"] = -1;
sort[path + ".xp"] = -1;

const veri = await UserModel.find(query).select(path + " userid").sort(sort).limit(30)
const veri = await UserModel.find(query).select(path).sort(sort).limit(30)

const gonder = veri.map((rank, index) =>
`**${index + 1}.** ${get(rank.userid)} ${seviye(rank.seviye)} • XP: **${rank.xp}**`
`**${index + 1}.** ${get(rank._id)} ${seviye(rank.seviye)} • XP: **${rank.xp}**`
)

const embeds = [new MessageEmbed().setName("Seviye Sıralaması")
Expand Down
13 changes: 6 additions & 7 deletions events/interactionCreate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { ButtonRolModel } = require("../util/models/")
const { ButtonRole } = require("../util/models/")
const Discord = require('discord.js');

/**
Expand All @@ -16,18 +16,17 @@ module.exports = async interaction => {

if (["rolbuton", "rolsil"].includes(interaction.customId)) {
try {
const buton = await ButtonRolModel.findOne({ messageid: interaction.message.id });
const buton = await ButtonRole.findById(interaction.message.id)
if (!buton) return;

if (interaction.customId === "rolsil") {
if (interaction.member.id == buton.authorid) {
if (interaction.member.id !== buton.authorId) return;
await buton.remove();
return interaction.message.delete();

await ButtonRolModel.deleteOne({ messageid: interaction.message.id });
return interaction.message.delete();
}
}
else
return await require("../buttons/rol")(interaction, buton.rolid, buton.authorid);
return await require("../buttons/rol")(interaction, buton.roleId);

} catch (e) { console.error(e) }

Expand Down
13 changes: 6 additions & 7 deletions interactions/butonrol.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageEmbed, MessageActionRow, MessageButton, CommandInteraction, Client } = require("discord.js")
const { ButtonRolModel } = require("../util/models/")
const { ButtonRole } = require("../util/models/")



Expand All @@ -19,7 +19,7 @@ exports.run = async (client, interaction) => {


const rol = interaction.options.getRole('rol');

const kanal = interaction.options.getChannel('kanal') || interaction.channel;
if (rol.name === "@everyone") return interaction.reply({ ephemeral: true, content: "Everyone rolünu kimseden alamam." })
if (interaction.guild.me.roles.highest.position <= rol.position) return interaction.reply({ ephemeral: true, content: "Bu rol benim rolumden üstün, bu yüzden rol veremem." })

Expand All @@ -43,11 +43,10 @@ exports.run = async (client, interaction) => {
const embed = new MessageEmbed()
.setTitle(açıklama).setName("Buton Rol")
.setDescription("Rolu almak için butona basın, tekrar basarsanız rolu geri alırım.")
await interaction.reply("Tamamdır!");
await interaction.deleteReply();
const m = await interaction.channel.send({ embeds: [embed], components: [row] });
await interaction.reply("Rol butonu oluşturuldu!");
const m = await kanal.send({ embeds: [embed], components: [row] });

await ButtonRolModel.create({ rolid: rol.id, authorid: interaction.user.id, messageid: m.id });
await ButtonRole.create({ roleId: rol.id, authorId: interaction.user.id, _id: m.id, channelId: kanal.id, guildId: interaction.guild.id });

};

Expand All @@ -56,4 +55,4 @@ exports.data = new SlashCommandBuilder()
.setDescription('Buton rol sistemi ayarlar!')
.addRoleOption(option => option.setName('rol').setDescription('Rolu gir!').setRequired(true))
.addStringOption(option => option.setName('açıklama').setDescription('Buton rol başlatırken içine yazılacak şey!'))

.addChannelOption(option => option.setName('kanal').addChannelType(0).setDescription('Buton rol başlatılacak kanal!'))
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@discordjs/rest": "^0.1.0-canary.0",
"async-g-i-s": "^1.2.0",
"canvas": "^2.10.1",
"discord.js": "^13.11.0",
"discord.js": "^13.12.0",
"figlet": "^1.5.2",
"mongoose": "^6.6.5",
"parse-ms": "^2.1.0",
Expand Down
4 changes: 2 additions & 2 deletions util/alair.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ module.exports = class Alair extends Discord.Client {
kisi.blacklist = true;
await kisi.save();
}
const kisiler = await UserModel.find({ blacklist: true }, "blacklist");
this.blacklist = kisiler.map(kisi => kisi.userid);
const kisiler = await UserModel.find({ blacklist: true }, "_id");
this.blacklist = kisiler.map(kisi => kisi._id);
return this.blacklist;
}

Expand Down
4 changes: 2 additions & 2 deletions util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const türler = {
};

/* methods */
const User = async (userid, select = "") => await UserModel.findOne({ userid }, select) || await UserModel.create({ userid });
const Guild = async (guildId, select = "") => await GuildModel.findOne({ guildId }, select) || await GuildModel.create({ guildId });
const User = async (_id, select = "") => await UserModel.findById(_id, select) || await UserModel.create({ _id });
const Guild = async (_id, select = "") => await GuildModel.findById(_id, select) || await GuildModel.create({ _id });
const delay = ms => new Promise(r => setTimeout(r, ms));
const parsems = sure => {
const asr = ms(sure);
Expand Down
10 changes: 10 additions & 0 deletions util/models/button_role.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const mongoose = require('mongoose');

module.exports = mongoose.model('button_role',
new mongoose.Schema({
_id: { type: String, unique: true },
authorId: String,
roleId: String,
channelId: String,
guildId: String,
}, { versionKey: false }));
12 changes: 5 additions & 7 deletions util/models/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
const ButtonRolModel = require("./roleButton"),
GuildModel = require("./guild"),
UserModel = require("./user"),
Custom = require("./custom");

/**
* Alair ana model dosyası / Ara katman
*/

module.exports = {
GuildModel, ButtonRolModel,
UserModel, Custom
GuildModel: require("./guild"),
ButtonRole: require("./button_role"),
UserModel: require("./user"),
Custom: require("./custom"),
};
8 changes: 0 additions & 8 deletions util/models/roleButton.js

This file was deleted.

2 changes: 1 addition & 1 deletion util/models/user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const mongoose = require('mongoose');

const userSema = new mongoose.Schema({
userid: { type: String, unique: true },
_id: { type: String, unique: true },
blacklist: Boolean,

// numbers:
Expand Down

0 comments on commit ebcba9e

Please sign in to comment.