Androz2091 / discord-giveaways

🎉 Complete framework to facilitate the creation of giveaways using discord.js
https://discord-giveaways.js.org
MIT License
334 stars 127 forks source link

Giveaway not continuing after reboot. #255

Closed Dragonizedpizza closed 3 years ago

Dragonizedpizza commented 3 years ago

When I reboot my bot, or the process gets killed, the giveaway does not continue.

Sometimes it does, but sometimes it doesn't.

I think the causes could be: The MongoDB connection disconnecting and connecting again. The giveaway timestamp being passed. idk

Nico105 commented 3 years ago

so are they marked as ended/deleted from the DB or just frozen = continue after another restart? could you check client.giveawaysManager.giveaways.filter(g => !g.ended).length between restarts to check that? What's your updateCountdownEvery and how many giveaways were approximately active at that time?

Dragonizedpizza commented 3 years ago

that is a good question

Dragonizedpizza commented 3 years ago

image for some reason it just says 21 at all times

Nico105 commented 3 years ago

are they instantly frozen after the restart or do they update once/for some duration and then stop?

Nico105 commented 3 years ago

could you maybe try that: https://github.com/Androz2091/discord-giveaways/issues/210#issuecomment-774650273

Dragonizedpizza commented 3 years ago

image yeah no I tried my own method, yours doesn't work

Nico105 commented 3 years ago

image yeah no I tried my own method, yours doesn't work

ah hdym? and g => g.messageID does not return a boolean...

Dragonizedpizza commented 3 years ago

image AHA

Dragonizedpizza commented 3 years ago

image yeah no I tried my own method, yours doesn't work

ah hdym? and g => g.messageID does not return a boolean...

doesn't need to, the fact that it exists should give it output

Dragonizedpizza commented 3 years ago

image like that, if its value is not undefined or null, it should come in the filter

Dragonizedpizza commented 3 years ago

image just to improve my case

Nico105 commented 3 years ago

kk, my bad

could you maybe try that: #210 (comment)

could you try that as said

Nico105 commented 3 years ago

Or could you try Manager.js 398 (de branch= 407) to add await, idk if that could maybe help

Dragonizedpizza commented 3 years ago

my host just went down

Dragonizedpizza commented 3 years ago

sec

Dragonizedpizza commented 3 years ago

image @Nico105 this error when doing the false thing

Nico105 commented 3 years ago

image @Nico105 this error when doing the false thing

client.giveawaysManager._init(); in your bot ready event, you got that?

Dragonizedpizza commented 3 years ago

image I didn't, but it didn't fix the issue.

Dragonizedpizza commented 3 years ago

is it worth mentioning that I'm sharding?

Dragonizedpizza commented 3 years ago
const database = require("../schemas/giveaway");

const { GiveawaysManager } = require("discord-giveaways");
module.exports = class Gmanager extends GiveawaysManager {
  async getAllGiveaways() {
    return await database.find({});
  }
  async refreshStorage() {
    // This should make all shard refreshing their cache with the updated database
    return global.client.shard.broadcastEval(() =>
      this.giveawaysManager.getAllGiveaways()
    );
  }
  async saveGiveaway(messageID, giveawayData) {
    await database.create(giveawayData);
    return true;
  }
  async editGiveaway(messageID, giveawayData) {
    await database
      .findOneAndUpdate({ messageID: messageID }, giveawayData)
      .exec();
    return true;
  }
  async deleteGiveaway(messageID) {
    await database.findOneAndDelete({ messageID: messageID }).exec();
    return true;
  }
};
Dragonizedpizza commented 3 years ago

    this.giveawaysManager = new giveawaysManager(this, {
      updateCountdownEvery: 6969,
      default: {
        botsCanWin: false,
        exemptPermissions: [],
        embedColor: "#034ea2",
        reaction: "🎉",
      },
    }, false);```
Nico105 commented 3 years ago
const database = require("../schemas/giveaway");

const { GiveawaysManager } = require("discord-giveaways");
module.exports = class Gmanager extends GiveawaysManager {
  async getAllGiveaways() {
    return await database.find({});
  }
  async refreshStorage() {
    // This should make all shard refreshing their cache with the updated database
    return global.client.shard.broadcastEval(() =>
      this.giveawaysManager.getAllGiveaways()
    );
  }
  async saveGiveaway(messageID, giveawayData) {
    await database.create(giveawayData);
    return true;
  }
  async editGiveaway(messageID, giveawayData) {
    await database
      .findOneAndUpdate({ messageID: messageID }, giveawayData)
      .exec();
    return true;
  }
  async deleteGiveaway(messageID) {
    await database.findOneAndDelete({ messageID: messageID }).exec();
    return true;
  }
};

check if the .find({}) returns values

Nico105 commented 3 years ago

is it worth mentioning that I'm sharding?

it should not really matter

Nico105 commented 3 years ago

what is the giveaways length before and after a restart without the filter?

Dragonizedpizza commented 3 years ago
Query {
  _mongooseOptions: {},
  _transforms: [],
  _hooks: Kareem { _pres: Map(0) {}, _posts: Map(0) {} },
  _executionCount: 0,
  mongooseCollection: NativeCollection {
    collection: null,
    Promise: [Function: Promise],
    _closed: false,
    opts: {
      schemaUserProvidedOptions: {},
      capped: false,
      autoCreate: undefined,
      Promise: [Function: Promise],
      '$wasForceClosed': undefined
    },
    name: 'giveaways',
    collectionName: 'giveaways',
    conn: NativeConnection {
      base: [Mongoose],
      collections: [Object],
      models: [Object],
      config: [Object],
      replica: false,
      options: null,
      otherDbs: [],
      relatedDbs: {},
      states: [Object: null prototype],
      _readyState: 0,
      _closeCalled: false,
      _hasOpened: false,
      plugins: [],
      id: 0,
      _queue: [],
      _listening: false
    },
    queue: [],
    buffer: true,
    emitter: EventEmitter {
      _events: [Object: null prototype] {},
      _eventsCount: 0,
      _maxListeners: undefined,
      [Symbol(kCapture)]: false
    }
  },
  model: Model { giveaway },
  schema: Schema {
    obj: { giveaways: [Object] },
    paths: {
      'giveaways.messageID': [SchemaString],
      'giveaways.channelID': [SchemaString],
      'giveaways.guildID': [SchemaString],
      'giveaways.startAt': [SchemaNumber],
      'giveaways.endAt': [SchemaNumber],
      'giveaways.ended': [SchemaBoolean],
      'giveaways.winnerCount': [SchemaNumber],
      'giveaways.prize': [SchemaString],
      'giveaways.extraData': [Mixed],
      'giveaways.messages.giveaway': [SchemaString],
      'giveaways.messages.giveawayEnded': [SchemaString],
      'giveaways.messages.inviteToParticipate': [SchemaString],
      'giveaways.messages.timeRemaining': [SchemaString],
      'giveaways.messages.winMessage': [SchemaString],
      'giveaways.messages.embedFooter': [SchemaString],
      'giveaways.messages.noWinner': [SchemaString],
      'giveaways.messages.winners': [SchemaString],
      'giveaways.messages.endedAt': [SchemaString],
      'giveaways.messages.hostedBy': [SchemaString],
      'giveaways.messages.units.seconds': [SchemaString],
      'giveaways.messages.units.minutes': [SchemaString],
      'giveaways.messages.units.hours': [SchemaString],
      'giveaways.messages.units.days': [SchemaString],
      'giveaways.messages.units.pluralS': [SchemaBoolean],
      'giveaways.hostedBy': [SchemaString],
      'giveaways.winnerIDs': [SchemaArray],
      'giveaways.reaction': [SchemaString],
      'giveaways.botsCanWin': [SchemaBoolean],
      'giveaways.embedColor': [SchemaString],
      'giveaways.embedColorEnd': [SchemaString],
      'giveaways.exemptPermissions': [SchemaArray],
      _id: [ObjectId],
      __v: [SchemaNumber]
    },
    aliases: {},
    subpaths: {
      'giveaways.winnerIDs.$': [Mixed],
      'giveaways.exemptPermissions.$': [Mixed]
    },
    virtuals: { id: [VirtualType] },
    singleNestedPaths: {},
    nested: {
      giveaways: true,
      'giveaways.messages': true,
      'giveaways.messages.units': true
    },
    inherits: {},
    callQueue: [],
    _indexes: [],
    methods: {},
    methodOptions: {},
    statics: {},
    tree: {
      giveaways: [Object],
      _id: [Object],
      __v: [Function: Number],
      id: [VirtualType]
    },
    query: {},
    childSchemas: [],
    plugins: [ [Object], [Object], [Object], [Object], [Object], [Object] ],
    '$id': 1,
    s: { hooks: [Kareem] },
    _userProvidedOptions: {},
    options: {
      typePojoToMixed: true,
      typeKey: 'type',
      id: true,
      noVirtualId: false,
      _id: true,
      noId: false,
      validateBeforeSave: true,
      read: null,
      shardKey: null,
      autoIndex: null,
      minimize: true,
      discriminatorKey: '__t',
      optimisticConcurrency: false,
      versionKey: '__v',
      capped: false,
      bufferCommands: true,
      strictQuery: false,
      strict: true,
      pluralization: true
    },
    '$globalPluginsApplied': true
  },
  op: 'find',
  options: {},
  _conditions: {},
  _fields: undefined,
  _update: undefined,
  _path: undefined,
  _distinct: undefined,
  _collection: NodeCollection {
    collection: NativeCollection {
      collection: null,
      Promise: [Function: Promise],
      _closed: false,
      opts: [Object],
      name: 'giveaways',
      collectionName: 'giveaways',
      conn: [NativeConnection],
      queue: [],
      buffer: true,
      emitter: [EventEmitter]
    },
    collectionName: 'giveaways'
  },
  _traceFunction: undefined,
  '$useProjection': true
}
Nico105 commented 3 years ago
Query {
  _mongooseOptions: {},
  _transforms: [],
  _hooks: Kareem { _pres: Map(0) {}, _posts: Map(0) {} },
  _executionCount: 0,
  mongooseCollection: NativeCollection {
    collection: null,
    Promise: [Function: Promise],
    _closed: false,
    opts: {
      schemaUserProvidedOptions: {},
      capped: false,
      autoCreate: undefined,
      Promise: [Function: Promise],
      '$wasForceClosed': undefined
    },
    name: 'giveaways',
    collectionName: 'giveaways',
    conn: NativeConnection {
      base: [Mongoose],
      collections: [Object],
      models: [Object],
      config: [Object],
      replica: false,
      options: null,
      otherDbs: [],
      relatedDbs: {},
      states: [Object: null prototype],
      _readyState: 0,
      _closeCalled: false,
      _hasOpened: false,
      plugins: [],
      id: 0,
      _queue: [],
      _listening: false
    },
    queue: [],
    buffer: true,
    emitter: EventEmitter {
      _events: [Object: null prototype] {},
      _eventsCount: 0,
      _maxListeners: undefined,
      [Symbol(kCapture)]: false
    }
  },
  model: Model { giveaway },
  schema: Schema {
    obj: { giveaways: [Object] },
    paths: {
      'giveaways.messageID': [SchemaString],
      'giveaways.channelID': [SchemaString],
      'giveaways.guildID': [SchemaString],
      'giveaways.startAt': [SchemaNumber],
      'giveaways.endAt': [SchemaNumber],
      'giveaways.ended': [SchemaBoolean],
      'giveaways.winnerCount': [SchemaNumber],
      'giveaways.prize': [SchemaString],
      'giveaways.extraData': [Mixed],
      'giveaways.messages.giveaway': [SchemaString],
      'giveaways.messages.giveawayEnded': [SchemaString],
      'giveaways.messages.inviteToParticipate': [SchemaString],
      'giveaways.messages.timeRemaining': [SchemaString],
      'giveaways.messages.winMessage': [SchemaString],
      'giveaways.messages.embedFooter': [SchemaString],
      'giveaways.messages.noWinner': [SchemaString],
      'giveaways.messages.winners': [SchemaString],
      'giveaways.messages.endedAt': [SchemaString],
      'giveaways.messages.hostedBy': [SchemaString],
      'giveaways.messages.units.seconds': [SchemaString],
      'giveaways.messages.units.minutes': [SchemaString],
      'giveaways.messages.units.hours': [SchemaString],
      'giveaways.messages.units.days': [SchemaString],
      'giveaways.messages.units.pluralS': [SchemaBoolean],
      'giveaways.hostedBy': [SchemaString],
      'giveaways.winnerIDs': [SchemaArray],
      'giveaways.reaction': [SchemaString],
      'giveaways.botsCanWin': [SchemaBoolean],
      'giveaways.embedColor': [SchemaString],
      'giveaways.embedColorEnd': [SchemaString],
      'giveaways.exemptPermissions': [SchemaArray],
      _id: [ObjectId],
      __v: [SchemaNumber]
    },
    aliases: {},
    subpaths: {
      'giveaways.winnerIDs.$': [Mixed],
      'giveaways.exemptPermissions.$': [Mixed]
    },
    virtuals: { id: [VirtualType] },
    singleNestedPaths: {},
    nested: {
      giveaways: true,
      'giveaways.messages': true,
      'giveaways.messages.units': true
    },
    inherits: {},
    callQueue: [],
    _indexes: [],
    methods: {},
    methodOptions: {},
    statics: {},
    tree: {
      giveaways: [Object],
      _id: [Object],
      __v: [Function: Number],
      id: [VirtualType]
    },
    query: {},
    childSchemas: [],
    plugins: [ [Object], [Object], [Object], [Object], [Object], [Object] ],
    '$id': 1,
    s: { hooks: [Kareem] },
    _userProvidedOptions: {},
    options: {
      typePojoToMixed: true,
      typeKey: 'type',
      id: true,
      noVirtualId: false,
      _id: true,
      noId: false,
      validateBeforeSave: true,
      read: null,
      shardKey: null,
      autoIndex: null,
      minimize: true,
      discriminatorKey: '__t',
      optimisticConcurrency: false,
      versionKey: '__v',
      capped: false,
      bufferCommands: true,
      strictQuery: false,
      strict: true,
      pluralization: true
    },
    '$globalPluginsApplied': true
  },
  op: 'find',
  options: {},
  _conditions: {},
  _fields: undefined,
  _update: undefined,
  _path: undefined,
  _distinct: undefined,
  _collection: NodeCollection {
    collection: NativeCollection {
      collection: null,
      Promise: [Function: Promise],
      _closed: false,
      opts: [Object],
      name: 'giveaways',
      collectionName: 'giveaways',
      conn: [NativeConnection],
      queue: [],
      buffer: true,
      emitter: [EventEmitter]
    },
    collectionName: 'giveaways'
  },
  _traceFunction: undefined,
  '$useProjection': true
}

ah did you do console.log(await database)? i meant console.log(await database.find({}))

Dragonizedpizza commented 3 years ago

that is what I did except I didn't await it

Dragonizedpizza commented 3 years ago

image

Nico105 commented 3 years ago

ahm could you show me your schema file because for me it look like this image

Dragonizedpizza commented 3 years ago

ahm could you show me your schema file because for me it look like this image

const { model, Schema } = require("mongoose");

module.exports = model(
  "giveaway",
  new Schema({
    giveaways: {
      messageID: String,
      channelID: String,
      guildID: String,
      startAt: Number,
      endAt: Number,
      ended: Boolean,
      winnerCount: Number,
      prize: String,
      extraData: {
        role: String,
      },
      messages: {
        giveaway: String,
        giveawayEnded: String,
        inviteToParticipate: String,
        timeRemaining: String,
        winMessage: String,
        embedFooter: String,
        noWinner: String,
        winners: String,
        endedAt: String,
        hostedBy: String,
        units: {
          seconds: String,
          minutes: String,
          hours: String,
          days: String,
          pluralS: Boolean,
        },
      },
      hostedBy: String,
      winnerIDs: [],
      reaction: String,
      botsCanWin: Boolean,
      embedColor: String,
      embedColorEnd: String,
      exemptPermissions: [],
      extraData: {},
    },
  })
);
Nico105 commented 3 years ago

image why do you make an extra object? you don't store anything else in the giveaway model so that isn't needed and it also isn't in the example

Dragonizedpizza commented 3 years ago

I think I forgot to remove it from when I was making all the schemas one

Nico105 commented 3 years ago

yeah, remove it, that's very likely the reason why nothing safes properly

const db = mongoose.connection;
db.giveaways = model();
db.stuff1 = model();
db.stuff2 = model();

this is how you should seperate your data after all (I think)

Dragonizedpizza commented 3 years ago

I do do that, and thanks works