start livepagination.ts

master
Kit Kasune 3 years ago
parent 10e0e5a454
commit 15c272e48e
  1. 28
      .idea/workspace.xml
  2. 64
      util/ts/livepagination.ts

@ -4,9 +4,10 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="826c705b-a7fa-4ece-b82a-e278fca7d494" name="Changes" comment="higher ani name for natsuki staff"> <list default="true" id="826c705b-a7fa-4ece-b82a-e278fca7d494" name="Changes" comment="extra images now show on char tag add">
<change afterPath="$PROJECT_DIR$/util/ts/livepagination.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/commands/anime/char.js" beforeDir="false" afterPath="$PROJECT_DIR$/commands/anime/char.js" afterDir="false" /> <change beforePath="$PROJECT_DIR$/util/ts/pagination.ts" beforeDir="false" afterPath="$PROJECT_DIR$/util/ts/pagination.ts" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -44,15 +45,22 @@
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" /> <property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" /> <property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" /> <property name="WebServerToolWindowFactoryState" value="false" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" /> <property name="last_opened_file_path" value="$PROJECT_DIR$/util/ts" />
<property name="node.js.detected.package.eslint" value="true" /> <property name="node.js.detected.package.eslint" value="true" />
<property name="node.js.detected.package.tslint" value="true" /> <property name="node.js.detected.package.tslint" value="true" />
<property name="node.js.selected.package.eslint" value="(autodetect)" /> <property name="node.js.selected.package.eslint" value="(autodetect)" />
<property name="node.js.selected.package.tslint" value="(autodetect)" /> <property name="node.js.selected.package.tslint" value="(autodetect)" />
<property name="nodejs_package_manager_path" value="npm" /> <property name="nodejs_package_manager_path" value="npm" />
<property name="settings.editor.selected.configurable" value="preferences.pluginManager" /> <property name="settings.editor.selected.configurable" value="preferences.pluginManager" />
<property name="ts.external.directory.path" value="C:\Users\clarkjr1836\Downloads\WebStorm-2021.2.2.win\plugins\JavaScriptLanguage\jsLanguageServicesImpl\external" />
<property name="ts.rename.search.for.dynamic.occurrences" value="true" />
<property name="vue.rearranger.settings.migration" value="true" /> <property name="vue.rearranger.settings.migration" value="true" />
</component> </component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="C:\Users\clarkjr1836\Desktop\bot\Natsuki\util\ts" />
</key>
</component>
<component name="RunAnythingCache"> <component name="RunAnythingCache">
<option name="myCommands"> <option name="myCommands">
<command value="npm run dev" /> <command value="npm run dev" />
@ -100,7 +108,7 @@
<workItem from="1640147904557" duration="6966000" /> <workItem from="1640147904557" duration="6966000" />
<workItem from="1641588609694" duration="320000" /> <workItem from="1641588609694" duration="320000" />
<workItem from="1641840125341" duration="1415000" /> <workItem from="1641840125341" duration="1415000" />
<workItem from="1642537991410" duration="1236000" /> <workItem from="1642537991410" duration="3454000" />
</task> </task>
<task id="LOCAL-00001" summary="not even gonna explain"> <task id="LOCAL-00001" summary="not even gonna explain">
<created>1640148826800</created> <created>1640148826800</created>
@ -130,7 +138,14 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1640214318896</updated> <updated>1640214318896</updated>
</task> </task>
<option name="localTasksCounter" value="5" /> <task id="LOCAL-00005" summary="extra images now show on char tag add">
<created>1642539309483</created>
<option name="number" value="00005" />
<option name="presentableId" value="LOCAL-00005" />
<option name="project" value="LOCAL" />
<updated>1642539309483</updated>
</task>
<option name="localTasksCounter" value="6" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@ -154,6 +169,7 @@
<MESSAGE value="stoopid errors" /> <MESSAGE value="stoopid errors" />
<MESSAGE value="e" /> <MESSAGE value="e" />
<MESSAGE value="list characters in anime" /> <MESSAGE value="list characters in anime" />
<option name="LAST_COMMIT_MESSAGE" value="list characters in anime" /> <MESSAGE value="extra images now show on char tag add" />
<option name="LAST_COMMIT_MESSAGE" value="extra images now show on char tag add" />
</component> </component>
</project> </project>

@ -0,0 +1,64 @@
import {TextChannel, Message, MessageEmbed, Client, MessageReaction, ReactionCollector, DiscordAPIError} from 'discord.js';
import {Pagination} from './pagination';
export class LivePagination extends Pagination {
knownMax: number;
private _onScrollAttempt: (pagination: LivePagination, pos: number, exists: boolean, inBounds: boolean) => void;
constructor (channel: TextChannel, pages: MessageEmbed[], originalMessage: Message, client: Client, loopPages?: boolean, message?: Message) {
super(channel, pages, originalMessage, client, loopPages, message);
};
public setOnScrollAttemptHandler(func: (pagination: LivePagination, pos: number, exists: boolean, inBounds: boolean) => void) {
this._onScrollAttempt = func;
return this;
};
public async start(options?: {endTime?: number, time?: number, startPage?: number, user?: 'any' | string}): Promise<LivePagination> {
if (!this._onScrollAttempt) {LivePagination.throwNoScrollAttempt();}
await super.start(options);
return this;
}
public async setControllers(endTime: number, user: 'any' | string): Promise<LivePagination> {
if (!this._onScrollAttempt) {LivePagination.throwNoScrollAttempt();}
await super.setControllers(endTime, user);
return this;
};
public async setPage(page: number): Promise<LivePagination> {
if (!this._onScrollAttempt) {LivePagination.throwNoScrollAttempt();}
this._onScrollAttempt(this, page, typeof this.pages[page] !== 'undefined' && this.pages[page] !== null, typeof this.knownMax === 'number' ? page < this.knownMax : true);
await super.setPage(page);
return this;
};
private static throwNoScrollAttempt() {
throw new Error("Fatal Pagination Error: You tried to start the LivePagination without setting a scrollAttemptEvent. This is necessary to allow the pagination to be built as the user scrolls. If you don't know what you're doing here, just make a Pagination instead.");
}
set onScrollAttempt(func: (pagination: LivePagination, pos: number, exists: boolean, inBounds: boolean) => void) {
this._onScrollAttempt = func;
};
}
interface ExtraControls {
}
interface ControllerData {
endTime: number,
enabled: boolean,
lastInteraction: Date,
collector: ReactionCollector
}
Loading…
Cancel
Save