├── .gitignore ├── .gitattributes ├── index.php ├── phpcord └── src │ └── phpcord │ ├── runtime │ ├── tick │ │ ├── TimingEntry.php │ │ ├── Tickable.php │ │ └── Timing.php │ └── network │ │ ├── packet │ │ ├── HeartbeatPacket.php │ │ ├── Packet.php │ │ ├── PresencePacket.php │ │ ├── ResumePacket.php │ │ ├── IdentifyPacket.php │ │ ├── IntentMessageBuffer.php │ │ ├── VoiceStateUpdatePacket.php │ │ └── MessageBuffer.php │ │ ├── opcode │ │ ├── HeartbeatHandler.php │ │ ├── HeartbeatACKHandler.php │ │ ├── OpCodeHandler.php │ │ ├── ReconnectHandler.php │ │ ├── InvalidSessionHandler.php │ │ ├── DispatchHandler.php │ │ ├── Opcodes.php │ │ └── HelloHandler.php │ │ ├── MessageSender.php │ │ └── SessionDetails.php │ ├── event │ ├── role │ │ ├── RoleCreateEvent.php │ │ ├── RoleEvent.php │ │ ├── RoleUpdateEvent.php │ │ └── RoleDeleteEvent.php │ ├── voice │ │ ├── VoiceJoinEvent.php │ │ ├── VoiceStateUpdateEvent.php │ │ ├── VoiceMoveEvent.php │ │ ├── VoiceLeaveEvent.php │ │ ├── VoiceDeafEvent.php │ │ ├── VoiceMuteEvent.php │ │ ├── VoiceUndeafEvent.php │ │ ├── VoiceUnmuteEvent.php │ │ └── VoiceEvent.php │ ├── message │ │ ├── MessageEditEvent.php │ │ ├── MessageSendEvent.php │ │ ├── MessageEvent.php │ │ └── MessageDeleteEvent.php │ ├── member │ │ ├── MemberAddEvent.php │ │ ├── MemberRemoveEvent.php │ │ ├── MemberEvent.php │ │ └── MemberUpdateEvent.php │ ├── channel │ │ ├── ChannelCreateEvent.php │ │ ├── ChannelDeleteEvent.php │ │ ├── ChannelUpdateEvent.php │ │ └── ChannelEvent.php │ ├── client │ │ ├── ClientReadyEvent.php │ │ └── ClientPingUpdateEvent.php │ ├── Cancellable.php │ ├── Event.php │ ├── guild │ │ ├── GuildCreateEvent.php │ │ ├── GuildEvent.php │ │ ├── GuildUserBanEvent.php │ │ ├── GuildUpdateEvent.php │ │ ├── GuildUserUnbanEvent.php │ │ ├── EmojisUpdateEvent.php │ │ └── GuildDeleteEvent.php │ ├── CancellableTrait.php │ └── interaction │ │ ├── InteractionEvent.php │ │ ├── ButtonPressEvent.php │ │ ├── ModalFormSubmitEvent.php │ │ ├── SelectMenuSubmitEvent.php │ │ └── SlashCommandEvent.php │ ├── channel │ ├── types │ │ ├── guild │ │ │ ├── thread │ │ │ │ ├── PublicThread.php │ │ │ │ ├── NewsThread.php │ │ │ │ ├── PrivateThread.php │ │ │ │ └── ThreadMember.php │ │ │ ├── GuildNewsChannel.php │ │ │ ├── GuildStageVoiceChannel.php │ │ │ └── GuildCategoryChannel.php │ │ └── dm │ │ │ └── GroupDMChannel.php │ └── helper │ │ ├── InvitableTrait.php │ │ └── SearchFilter.php │ ├── exception │ ├── EnumException.php │ ├── EventException.php │ ├── InternetException.php │ ├── ClosureSyntaxException.php │ ├── FileNotFoundException.php │ ├── IndexNotFoundException.php │ └── NotImplementedException.php │ ├── utils │ ├── NonInstantiableTrait.php │ ├── time │ │ ├── TimePeriod.php │ │ └── TimePeriodMap.php │ ├── SingletonTrait.php │ ├── helper │ │ ├── FileHelper.php │ │ ├── SPL.php │ │ └── Reflector.php │ ├── enum │ │ ├── EnumParameterHandle.php │ │ └── EnumToolsTrait.php │ ├── presence │ │ └── ActivityType.php │ ├── error │ │ └── ErrorTrapResult.php │ ├── InternetAddress.php │ ├── RtcRegion.php │ ├── CollectionNotifier.php │ └── Regex.php │ ├── guild │ ├── IGuild.php │ ├── permissible │ │ ├── data │ │ │ ├── IPermissionData.php │ │ │ └── BasePermissionData.php │ │ └── Permission.php │ ├── GuildBase.php │ ├── components │ │ ├── WebhookTypes.php │ │ ├── WelcomeScreen.php │ │ ├── Ban.php │ │ └── WelcomeScreenChannel.php │ ├── data │ │ ├── MFALevel.php │ │ ├── NSFWLevel.php │ │ ├── VerificationLevel.php │ │ └── SystemChannelFlags.php │ └── auditlog │ │ ├── AuditLogChange.php │ │ └── AuditLog.php │ ├── message │ ├── component │ │ ├── IComponent.php │ │ ├── IChildComponent.php │ │ ├── ComponentTypes.php │ │ ├── ActionRow.php │ │ └── ComponentMap.php │ ├── Sendable.php │ ├── sendable │ │ └── parts │ │ │ ├── EmbedFooter.php │ │ │ ├── EmbedProvider.php │ │ │ ├── EmbedMedia.php │ │ │ ├── EmbedField.php │ │ │ └── EmbedAuthor.php │ ├── MessageFlags.php │ ├── Reaction.php │ └── MessageReference.php │ ├── voice │ ├── websocket │ │ ├── packet │ │ │ ├── VoicePacket.php │ │ │ ├── VoiceHeartbeatPacket.php │ │ │ └── VoiceIdentifyPacket.php │ │ ├── handler │ │ │ ├── VoiceOpCodeHandler.php │ │ │ └── VoiceHelloHandler.php │ │ ├── VoiceOpCodeHandlerMap.php │ │ └── VoiceOpCodes.php │ ├── VoiceRequest.php │ ├── VoiceConnectionPool.php │ └── VoiceRequestPool.php │ ├── interaction │ ├── component │ │ └── IModalComponent.php │ ├── slash │ │ ├── options │ │ │ ├── RoleCommandOption.php │ │ │ ├── UserCommandOption.php │ │ │ ├── BooleanCommandOption.php │ │ │ ├── AttachmentCommandOption.php │ │ │ ├── SubCommandGroupOption.php │ │ │ ├── MentionableCommandOption.php │ │ │ ├── SubCommandOption.php │ │ │ ├── SlashCommandOption.php │ │ │ ├── ChannelCommandOption.php │ │ │ ├── SlashCommandOptionTypes.php │ │ │ ├── StringCommandOption.php │ │ │ ├── IntegerCommandOption.php │ │ │ └── NumberCommandOption.php │ │ ├── SlashCommandTypes.php │ │ └── SlashCommandChoice.php │ ├── InteractionData.php │ ├── InteractionTypes.php │ └── InteractionResponseTypes.php │ ├── intent │ ├── IntentHandler.php │ └── impl │ │ ├── InteractionHandler.php │ │ ├── ClientHandler.php │ │ ├── MessageHandler.php │ │ └── MemberHandler.php │ ├── Version.php │ ├── async │ ├── GarbageTrait.php │ ├── net │ │ └── Response.php │ ├── completable │ │ └── ICompletable.php │ └── AsyncPool.php │ ├── autoload │ ├── Autoloadable.php │ └── DynamicAutoloader.php │ ├── logger │ ├── CustomLoggerTrait.php │ ├── AttachableLogger.php │ └── ColorMap.php │ ├── image │ ├── Dimension.php │ └── Icon.php │ ├── cache │ └── DefaultMappingsCache.php │ └── scheduler │ └── TaskHandler.php └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | tests/ -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | listen(MessageSendEvent::class, function (MessageSendEvent $event): void { 12 | if (!$event->getMessage()->getAuthor()->isBot()) { 13 | $event->getMessage()->reply(MessageBuilder::build('This is a dummy message.')); 14 | } 15 | }); 16 | 17 | $discord->login('your bot token'); -------------------------------------------------------------------------------- /phpcord/src/phpcord/runtime/tick/TimingEntry.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\runtime\tick; 18 | 19 | class TimingEntry { 20 | 21 | 22 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/role/RoleCreateEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\role; 18 | 19 | class RoleCreateEvent extends RoleEvent { } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/voice/VoiceJoinEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\voice; 18 | 19 | class VoiceJoinEvent extends VoiceEvent { } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/message/MessageEditEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\message; 18 | 19 | class MessageEditEvent extends MessageEvent { } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/message/MessageSendEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\message; 18 | 19 | class MessageSendEvent extends MessageEvent { } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/member/MemberAddEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\member; 18 | 19 | class MemberAddEvent extends MemberEvent { 20 | 21 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/voice/VoiceStateUpdateEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\voice; 18 | 19 | class VoiceStateUpdateEvent extends VoiceEvent { } -------------------------------------------------------------------------------- /phpcord/src/phpcord/channel/types/guild/thread/PublicThread.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\channel\types\guild\thread; 18 | 19 | class PublicThread extends Thread { } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/channel/ChannelCreateEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\channel; 18 | 19 | final class ChannelCreateEvent extends ChannelEvent { } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/channel/ChannelDeleteEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\channel; 18 | 19 | final class ChannelDeleteEvent extends ChannelEvent { } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/channel/ChannelUpdateEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\channel; 18 | 19 | final class ChannelUpdateEvent extends ChannelEvent { } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/member/MemberRemoveEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\member; 18 | 19 | class MemberRemoveEvent extends MemberEvent { 20 | 21 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/channel/types/guild/GuildNewsChannel.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\channel\types\guild; 18 | 19 | class GuildNewsChannel extends GuildTextChannel { } -------------------------------------------------------------------------------- /phpcord/src/phpcord/channel/types/guild/thread/NewsThread.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\channel\types\guild\thread; 18 | 19 | class NewsThread extends PublicThread { } -------------------------------------------------------------------------------- /phpcord/src/phpcord/channel/types/guild/thread/PrivateThread.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\channel\types\guild\thread; 18 | 19 | class PrivateThread extends Thread { } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/client/ClientReadyEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\client; 18 | 19 | use phpcord\event\Event; 20 | 21 | class ClientReadyEvent extends Event { } -------------------------------------------------------------------------------- /phpcord/src/phpcord/exception/EnumException.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\exception; 18 | 19 | use LogicException; 20 | 21 | final class EnumException extends LogicException { } -------------------------------------------------------------------------------- /phpcord/src/phpcord/exception/EventException.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\exception; 18 | 19 | use LogicException; 20 | 21 | final class EventException extends LogicException { } -------------------------------------------------------------------------------- /phpcord/src/phpcord/utils/NonInstantiableTrait.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\utils; 18 | 19 | trait NonInstantiableTrait { 20 | 21 | private function __construct() { } 22 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/channel/types/guild/GuildStageVoiceChannel.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\channel\types\guild; 18 | 19 | class GuildStageVoiceChannel extends GuildVoiceChannel { } -------------------------------------------------------------------------------- /phpcord/src/phpcord/exception/InternetException.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\exception; 18 | 19 | use LogicException; 20 | 21 | final class InternetException extends LogicException { } -------------------------------------------------------------------------------- /phpcord/src/phpcord/runtime/tick/Tickable.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\runtime\tick; 18 | 19 | interface Tickable { 20 | 21 | public function tick(int $currentTick): void; 22 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/exception/ClosureSyntaxException.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\exception; 18 | 19 | use LogicException; 20 | 21 | final class ClosureSyntaxException extends LogicException { } -------------------------------------------------------------------------------- /phpcord/src/phpcord/exception/FileNotFoundException.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\exception; 18 | 19 | use LogicException; 20 | 21 | final class FileNotFoundException extends LogicException { } -------------------------------------------------------------------------------- /phpcord/src/phpcord/exception/IndexNotFoundException.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\exception; 18 | 19 | use LogicException; 20 | 21 | final class IndexNotFoundException extends LogicException { } -------------------------------------------------------------------------------- /phpcord/src/phpcord/exception/NotImplementedException.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\exception; 18 | 19 | use LogicException; 20 | 21 | class NotImplementedException extends LogicException { } -------------------------------------------------------------------------------- /phpcord/src/phpcord/guild/IGuild.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\guild; 18 | 19 | interface IGuild { 20 | 21 | public function getId(): int; 22 | 23 | public function getName(): string; 24 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/message/component/IComponent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\message\component; 18 | 19 | use JsonSerializable; 20 | 21 | interface IComponent extends JsonSerializable { 22 | 23 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/Cancellable.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event; 18 | 19 | interface Cancellable { 20 | 21 | public function cancel(): void; 22 | 23 | public function isCancelled(): bool; 24 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/Event.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event; 18 | 19 | abstract class Event { 20 | 21 | public function call(): void { 22 | EventRegistry::getInstance()->callEvent($this); 23 | } 24 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/message/Sendable.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\message; 18 | 19 | interface Sendable { 20 | 21 | public function getContentType(): string; 22 | 23 | public function getBody(): string; 24 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/voice/websocket/packet/VoicePacket.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\voice\websocket\packet; 18 | 19 | use phpcord\runtime\network\packet\Packet; 20 | 21 | abstract class VoicePacket extends Packet { } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/guild/GuildCreateEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\guild; 18 | 19 | /** 20 | * Called on startup for each guild that loaded 21 | */ 22 | final class GuildCreateEvent extends GuildEvent { } -------------------------------------------------------------------------------- /phpcord/src/phpcord/interaction/component/IModalComponent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\interaction\component; 18 | 19 | use phpcord\message\component\IChildComponent; 20 | 21 | interface IModalComponent extends IChildComponent { 22 | 23 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/interaction/slash/options/RoleCommandOption.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\interaction\slash\options; 18 | 19 | class RoleCommandOption extends SlashCommandOption { 20 | 21 | public function getType(): int { 22 | return SlashCommandOptionTypes::ROLE(); 23 | } 24 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/interaction/slash/options/UserCommandOption.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\interaction\slash\options; 18 | 19 | class UserCommandOption extends SlashCommandOption { 20 | 21 | public function getType(): int { 22 | return SlashCommandOptionTypes::USER(); 23 | } 24 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/interaction/slash/options/BooleanCommandOption.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\interaction\slash\options; 18 | 19 | class BooleanCommandOption extends SlashCommandOption { 20 | 21 | public function getType(): int { 22 | return SlashCommandOptionTypes::BOOLEAN(); 23 | } 24 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/interaction/InteractionData.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\interaction; 18 | 19 | abstract class InteractionData { 20 | 21 | abstract public static function fromArray(array $array): ?static; 22 | 23 | abstract public static function handle(Interaction $interaction): void; 24 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/interaction/slash/options/AttachmentCommandOption.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\interaction\slash\options; 18 | 19 | class AttachmentCommandOption extends SlashCommandOption { 20 | 21 | public function getType(): int { 22 | return SlashCommandOptionTypes::ATTACHMENT(); 23 | } 24 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/interaction/slash/options/SubCommandGroupOption.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\interaction\slash\options; 18 | 19 | class SubCommandGroupOption extends SubCommandOption { 20 | 21 | public function getType(): int { 22 | return SlashCommandOptionTypes::SUB_COMMAND_GROUP(); 23 | } 24 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/interaction/slash/options/MentionableCommandOption.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\interaction\slash\options; 18 | 19 | class MentionableCommandOption extends SlashCommandOption { 20 | 21 | public function getType(): int { 22 | return SlashCommandOptionTypes::MENTIONABLE(); 23 | } 24 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/utils/time/TimePeriod.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\utils\time; 18 | class TimePeriod { 19 | 20 | public function __construct(private int $seconds) { } 21 | 22 | public function format(string $format): string { 23 | return TimePeriodMap::getInstance()->apply($this->seconds, $format); 24 | } 25 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/message/component/IChildComponent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\message\component; 18 | 19 | use JsonSerializable; 20 | use phpcord\interaction\Interaction; 21 | 22 | interface IChildComponent extends JsonSerializable { 23 | 24 | public static function onInteract(Interaction $interaction): void; 25 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/intent/IntentHandler.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\intent; 18 | 19 | use phpcord\runtime\network\packet\IntentMessageBuffer; 20 | 21 | interface IntentHandler { 22 | 23 | /** 24 | * @param IntentMessageBuffer $buffer 25 | * 26 | * @return void 27 | */ 28 | public function handle(IntentMessageBuffer $buffer): void; 29 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/Version.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord; 18 | 19 | interface Version { 20 | 21 | public const NAME = 'phpcord'; 22 | 23 | public const FULL_NAME = 'phpcord v' . self::VERSION; 24 | 25 | public const VERSION = '3.0.0-ALPHA'; 26 | 27 | public const GATEWAY_VERSION = 10; 28 | 29 | public const VOICE_GATEWAY_VERSION = 3; 30 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/guild/permissible/data/IPermissionData.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\guild\permissible\data; 18 | 19 | interface IPermissionData { 20 | 21 | public function hasPermission(int $permission): bool; 22 | 23 | public function setPermission(int $permission): void; 24 | 25 | public function removePermission(int $permission): void; 26 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/utils/SingletonTrait.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\utils; 18 | 19 | trait SingletonTrait { 20 | 21 | /** @var static|null $instance */ 22 | protected static ?self $instance = null; 23 | 24 | private function __construct() { } 25 | 26 | public static function getInstance(): static { 27 | return self::$instance ??= new static; 28 | } 29 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/async/GarbageTrait.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\async; 18 | 19 | trait GarbageTrait { 20 | 21 | /** @var bool $garbage */ 22 | private bool $garbage = false; 23 | 24 | /** 25 | * @return bool 26 | */ 27 | public function isGarbage(): bool { 28 | return $this->garbage; 29 | } 30 | 31 | public function setGarbage(): void { 32 | $this->garbage = true; 33 | } 34 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/role/RoleEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\role; 18 | 19 | use phpcord\event\Event; 20 | use phpcord\guild\permissible\Role; 21 | 22 | abstract class RoleEvent extends Event { 23 | 24 | public function __construct(private Role $role) { } 25 | 26 | /** 27 | * @return Role 28 | */ 29 | public function getRole(): Role { 30 | return $this->role; 31 | } 32 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/CancellableTrait.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event; 18 | 19 | trait CancellableTrait { 20 | 21 | /** @var bool $cancelled */ 22 | private bool $cancelled = false; 23 | 24 | public function cancel(): void { 25 | $this->cancelled = true; 26 | } 27 | 28 | /** 29 | * @return bool 30 | */ 31 | public function isCancelled(): bool { 32 | return $this->cancelled; 33 | } 34 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/voice/websocket/handler/VoiceOpCodeHandler.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\voice\websocket\handler; 18 | 19 | use phpcord\voice\VoiceConnection; 20 | 21 | abstract class VoiceOpCodeHandler { 22 | 23 | /** 24 | * @param VoiceConnection $connection 25 | * @param array $payload 26 | * 27 | * @return void 28 | */ 29 | abstract public function handle(VoiceConnection $connection, array $payload): void; 30 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/autoload/Autoloadable.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\autoload; 18 | 19 | /** 20 | * @internal 21 | */ 22 | interface Autoloadable { 23 | 24 | /** 25 | * Registers a namespace base with its corresponding path to the autoloader 26 | * 27 | * @param string $namespace 28 | * @param string $path 29 | * 30 | * @return void 31 | */ 32 | public function load(string $namespace, string $path): void; 33 | 34 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/voice/VoiceMoveEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\voice; 18 | 19 | use phpcord\async\completable\Completable; 20 | use phpcord\channel\types\guild\GuildVoiceChannel; 21 | 22 | class VoiceMoveEvent extends VoiceEvent { 23 | 24 | /** 25 | * @return Completable 26 | */ 27 | public function getOldChannel(): Completable { 28 | return $this->getOldState()->getChannel(); 29 | } 30 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/guild/GuildEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\guild; 18 | 19 | use phpcord\event\Event; 20 | use phpcord\guild\Guild; 21 | 22 | abstract class GuildEvent extends Event { 23 | 24 | /** 25 | * @param Guild $guild 26 | */ 27 | public function __construct(private Guild $guild) { } 28 | 29 | /** 30 | * @return Guild 31 | */ 32 | public function getGuild(): Guild { 33 | return $this->guild; 34 | } 35 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/utils/helper/FileHelper.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\utils\helper; 18 | 19 | use phpcord\utils\NonInstantiableTrait; 20 | use function str_replace; 21 | use const DIRECTORY_SEPARATOR; 22 | 23 | final class FileHelper { 24 | use NonInstantiableTrait; 25 | 26 | public static function printFilter(string $path): string { 27 | return str_replace('\\', '/', str_replace(DATA_PATH, 'phpcord://', str_replace(SRC_PATH, 'core://', $path))); 28 | } 29 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/utils/helper/SPL.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\utils\helper; 18 | 19 | use function is_object; 20 | use function spl_object_hash; 21 | use function spl_object_id; 22 | 23 | final class SPL { 24 | 25 | public static function id(object|int $object): int { 26 | return (is_object($object) ? spl_object_id($object) : $object); 27 | } 28 | 29 | public static function hash(object $object): string { 30 | return spl_object_hash($object); 31 | } 32 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/message/MessageEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\message; 18 | 19 | use phpcord\event\Event; 20 | use phpcord\message\Message; 21 | 22 | abstract class MessageEvent extends Event { 23 | 24 | /** 25 | * @param Message $message 26 | */ 27 | public function __construct(private Message $message) { } 28 | 29 | /** 30 | * @return Message 31 | */ 32 | public function getMessage(): Message { 33 | return $this->message; 34 | } 35 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/role/RoleUpdateEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\role; 18 | 19 | use JetBrains\PhpStorm\Pure; 20 | use phpcord\guild\permissible\Role; 21 | 22 | class RoleUpdateEvent extends RoleEvent { 23 | 24 | #[Pure] public function __construct(Role $role, private ?Role $old) { 25 | parent::__construct($role); 26 | } 27 | 28 | /** 29 | * @return Role|null 30 | */ 31 | public function getOldRole(): ?Role { 32 | return $this->old; 33 | } 34 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/logger/CustomLoggerTrait.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\logger; 18 | 19 | use function basename; 20 | 21 | trait CustomLoggerTrait { 22 | 23 | /** @var Logger|null $logger */ 24 | private ?Logger $logger = null; 25 | 26 | /** 27 | * Returns the logger for the class with a custom name 28 | * 29 | * @return Logger 30 | */ 31 | public function getLogger(): Logger { 32 | return ($this->logger ??= new Logger(basename(static::class))); 33 | } 34 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/voice/VoiceLeaveEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\voice; 18 | 19 | use phpcord\async\completable\Completable; 20 | use phpcord\channel\types\guild\GuildVoiceChannel; 21 | 22 | class VoiceLeaveEvent extends VoiceEvent { 23 | 24 | /** 25 | * @return Completable 26 | */ 27 | public function getChannel(): Completable { 28 | return $this->getOldState()->getGuild()->getChannel($this->getOldState()->getChannelId()); 29 | } 30 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/member/MemberEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\member; 18 | 19 | use phpcord\event\Event; 20 | use phpcord\guild\GuildMember; 21 | 22 | abstract class MemberEvent extends Event { 23 | 24 | /** 25 | * @param GuildMember $member 26 | */ 27 | public function __construct(private GuildMember $member) { } 28 | 29 | /** 30 | * @return GuildMember 31 | */ 32 | public function getMember(): GuildMember { 33 | return $this->member; 34 | } 35 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/channel/ChannelEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\channel; 18 | 19 | use phpcord\channel\GuildChannel; 20 | use phpcord\event\Event; 21 | 22 | abstract class ChannelEvent extends Event { 23 | 24 | /** 25 | * @param GuildChannel $channel 26 | */ 27 | public function __construct(private GuildChannel $channel) { } 28 | 29 | /** 30 | * @return GuildChannel 31 | */ 32 | public function getChannel(): GuildChannel { 33 | return $this->channel; 34 | } 35 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/interaction/slash/SlashCommandTypes.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\interaction\slash; 18 | 19 | use phpcord\utils\enum\EnumTrait; 20 | 21 | /** 22 | * @method static int CHAT_INPUT() 23 | * @method static int USER() 24 | * @method static int MESSAGE() 25 | */ 26 | final class SlashCommandTypes { 27 | use EnumTrait; 28 | 29 | protected static function make(): void { 30 | self::register('CHAT_INPUT', 1); 31 | self::register('USER', 2); 32 | self::register('MESSAGE', 3); 33 | } 34 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/image/Dimension.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\image; 18 | 19 | final class Dimension { 20 | 21 | /** 22 | * @param int $width 23 | * @param int $height 24 | */ 25 | public function __construct(private int $width, private int $height) { } 26 | 27 | /** 28 | * @return int 29 | */ 30 | public function getWidth(): int { 31 | return $this->width; 32 | } 33 | 34 | /** 35 | * @return int 36 | */ 37 | public function getHeight(): int { 38 | return $this->height; 39 | } 40 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/interaction/InteractionEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\interaction; 18 | 19 | use phpcord\event\Event; 20 | use phpcord\interaction\Interaction; 21 | 22 | class InteractionEvent extends Event { 23 | 24 | /** 25 | * @param Interaction $interaction 26 | */ 27 | public function __construct(private Interaction $interaction) { } 28 | 29 | /** 30 | * @return Interaction 31 | */ 32 | public function getInteraction(): Interaction { 33 | return $this->interaction; 34 | } 35 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/runtime/network/packet/HeartbeatPacket.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\runtime\network\packet; 18 | 19 | use phpcord\runtime\network\opcode\Opcodes; 20 | 21 | class HeartbeatPacket extends Packet { 22 | 23 | /** 24 | * @param int $lastSequence 25 | */ 26 | public function __construct(private int $lastSequence) { } 27 | 28 | public function getOpCode(): int { 29 | return Opcodes::HEARTBEAT(); 30 | } 31 | 32 | public function getPayload(): string { 33 | return $this->lastSequence; 34 | } 35 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/guild/GuildBase.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\guild; 18 | 19 | abstract class GuildBase implements IGuild { 20 | 21 | /** 22 | * @param int $id 23 | * @param string $name 24 | */ 25 | public function __construct(protected int $id, protected string $name) {} 26 | 27 | 28 | public function getId(): int { 29 | return $this->id; 30 | } 31 | 32 | public function getName(): string { 33 | return $this->name; 34 | } 35 | 36 | abstract public static function fromArray(array $array): ?static; 37 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/guild/components/WebhookTypes.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\guild\components; 18 | 19 | use phpcord\utils\enum\EnumTrait; 20 | 21 | /** 22 | * @method static int INCOMING() 23 | * @method static int CHANNEL_FOLLOWER() 24 | * @method static int APPLICATION() 25 | */ 26 | final class WebhookTypes { 27 | use EnumTrait; 28 | 29 | protected static function make(): void { 30 | self::register('INCOMING', 0); 31 | self::register('CHANNEL_FOLLOWER', 1); 32 | self::register('APPLICATION', 2); 33 | } 34 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/image/Icon.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\image; 18 | 19 | class Icon { 20 | 21 | /** 22 | * @param string $iconHash 23 | * @param string $iconUrl 24 | */ 25 | public function __construct(private string $iconHash, private string $iconUrl) { } 26 | 27 | /** 28 | * @return string 29 | */ 30 | public function getHash(): string { 31 | return $this->iconHash; 32 | } 33 | 34 | /** 35 | * @return string 36 | */ 37 | public function getUrl(): string { 38 | return $this->iconUrl; 39 | } 40 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/utils/enum/EnumParameterHandle.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\utils\enum; 18 | 19 | use Closure; 20 | 21 | /** 22 | * @internal 23 | */ 24 | final class EnumParameterHandle { 25 | 26 | /** 27 | * @param Closure $fn 28 | */ 29 | public function __construct(private Closure $fn) { } 30 | 31 | /** 32 | * @param mixed ...$parameter 33 | * 34 | * @internal 35 | * 36 | * @return mixed 37 | */ 38 | public function run(mixed ...$parameter): mixed { 39 | return ($this->fn)(...$parameter); 40 | } 41 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/guild/data/MFALevel.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\guild\data; 18 | 19 | use phpcord\utils\enum\EnumTrait; 20 | 21 | /** 22 | * @method static int NONE() guild has no 2FA requirement for moderation actions 23 | * @method static int ELEVATED() guild has a 2FA requirement for moderation actions 24 | * 25 | * MFA = MultiFactorAuthorization 26 | */ 27 | final class MFALevel { 28 | use EnumTrait; 29 | 30 | protected static function make(): void { 31 | self::register('NONE', 0); 32 | self::register('ELEVATED', 1); 33 | } 34 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/client/ClientPingUpdateEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\client; 18 | 19 | use phpcord\event\Cancellable; 20 | use phpcord\event\CancellableTrait; 21 | use phpcord\event\Event; 22 | 23 | class ClientPingUpdateEvent extends Event implements Cancellable { 24 | use CancellableTrait; 25 | 26 | /** 27 | * @param int $ping the new ping 28 | */ 29 | public function __construct(private int $ping) { } 30 | 31 | /** 32 | * @return int 33 | */ 34 | public function getPing(): int { 35 | return $this->ping; 36 | } 37 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/guild/data/NSFWLevel.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\guild\data; 18 | 19 | use phpcord\utils\enum\EnumTrait; 20 | 21 | /** 22 | * @method static int DEFAULT() 23 | * @method static int EXPLICIT() 24 | * @method static int SAFE() 25 | * @method static int AGE_RESTRICTED() 26 | */ 27 | final class NSFWLevel { 28 | use EnumTrait; 29 | 30 | protected static function make(): void { 31 | self::register('DEFAULT', 0); 32 | self::register('EXPLICIT', 1); 33 | self::register('SAFE', 2); 34 | self::register('AGE_RESTRICTED', 3); 35 | } 36 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/runtime/network/opcode/HeartbeatHandler.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\runtime\network\opcode; 18 | 19 | use phpcord\runtime\network\MessageSender; 20 | use phpcord\runtime\network\Network; 21 | use phpcord\runtime\network\packet\MessageBuffer; 22 | 23 | class HeartbeatHandler extends OpCodeHandler { 24 | 25 | public function getOpCode(): int { 26 | return Opcodes::HEARTBEAT(); 27 | } 28 | 29 | public function handle(MessageSender $sender, MessageBuffer $buffer): void { 30 | Network::getInstance()->getGateway()->heartbeat(); 31 | } 32 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/guild/GuildUserBanEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\guild; 18 | 19 | use JetBrains\PhpStorm\Pure; 20 | use phpcord\guild\Guild; 21 | use phpcord\user\User; 22 | 23 | class GuildUserBanEvent extends GuildEvent { 24 | 25 | /** 26 | * @param Guild $guild 27 | * @param User $user 28 | */ 29 | #[Pure] public function __construct(Guild $guild, private User $user) { 30 | parent::__construct($guild); 31 | } 32 | 33 | /** 34 | * @return User 35 | */ 36 | public function getUser(): User { 37 | return $this->user; 38 | } 39 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/guild/GuildUpdateEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\guild; 18 | 19 | use JetBrains\PhpStorm\Pure; 20 | use phpcord\guild\Guild; 21 | 22 | class GuildUpdateEvent extends GuildEvent { 23 | 24 | /** 25 | * @param Guild $guild 26 | * @param Guild|null $oldGuild 27 | */ 28 | #[Pure] public function __construct(Guild $guild, private ?Guild $oldGuild) { 29 | parent::__construct($guild); 30 | } 31 | 32 | /** 33 | * @return Guild|null 34 | */ 35 | public function getOldGuild(): ?Guild { 36 | return $this->oldGuild; 37 | } 38 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/guild/GuildUserUnbanEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\guild; 18 | 19 | use JetBrains\PhpStorm\Pure; 20 | use phpcord\guild\Guild; 21 | use phpcord\user\User; 22 | 23 | class GuildUserUnbanEvent extends GuildEvent { 24 | 25 | /** 26 | * @param Guild $guild 27 | * @param User $user 28 | */ 29 | #[Pure] public function __construct(Guild $guild, private User $user) { 30 | parent::__construct($guild); 31 | } 32 | 33 | /** 34 | * @return User 35 | */ 36 | public function getUser(): User { 37 | return $this->user; 38 | } 39 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/runtime/network/MessageSender.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\runtime\network; 18 | 19 | use phpcord\runtime\network\packet\Packet; 20 | 21 | interface MessageSender { 22 | 23 | /** 24 | * Writes a buffer to the sender as response 25 | * 26 | * @param string $buffer 27 | * 28 | * @return bool 29 | */ 30 | public function write(string $buffer): bool; 31 | 32 | /** 33 | * Sends a packet to the sender as response 34 | * 35 | * @param Packet $packet 36 | * 37 | * @return bool 38 | */ 39 | public function sendPacket(Packet $packet): bool; 40 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/runtime/network/opcode/HeartbeatACKHandler.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\runtime\network\opcode; 18 | 19 | use phpcord\runtime\network\MessageSender; 20 | use phpcord\runtime\network\Network; 21 | use phpcord\runtime\network\packet\MessageBuffer; 22 | 23 | class HeartbeatACKHandler extends OpCodeHandler { 24 | 25 | public function getOpCode(): int { 26 | return Opcodes::HEARTBEAT_ACK(); 27 | } 28 | 29 | public function handle(MessageSender $sender, MessageBuffer $buffer): void { 30 | Network::getInstance()->getGateway()->onHeartbeatACK($buffer); 31 | } 32 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/intent/impl/InteractionHandler.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\intent\impl; 18 | 19 | use phpcord\intent\IntentHandler; 20 | use phpcord\event\interaction\InteractionEvent; 21 | use phpcord\interaction\Interaction; 22 | use phpcord\runtime\network\packet\IntentMessageBuffer; 23 | 24 | class InteractionHandler implements IntentHandler { 25 | 26 | public function handle(IntentMessageBuffer $buffer): void { 27 | (new InteractionEvent(($interaction = Interaction::fromArray($buffer->data()))))->call(); 28 | 29 | $interaction->getData()::handle($interaction); 30 | } 31 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/message/component/ComponentTypes.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\message\component; 18 | 19 | use phpcord\utils\enum\EnumTrait; 20 | 21 | /** 22 | * @method static int ACTION_ROW() 23 | * @method static int BUTTON() 24 | * @method static int SELECT_MENU() 25 | * @method static int TEXT_INPUT() 26 | */ 27 | final class ComponentTypes { 28 | use EnumTrait; 29 | 30 | protected static function make(): void { 31 | self::register('ACTION_ROW', 1); 32 | self::register('BUTTON', 2); 33 | self::register('SELECT_MENU', 3); 34 | self::register('TEXT_INPUT', 4); 35 | } 36 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/runtime/network/packet/Packet.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\runtime\network\packet; 18 | 19 | use function json_encode; 20 | 21 | abstract class Packet { 22 | 23 | abstract public function getPayload(): mixed; 24 | 25 | abstract public function getOpCode(): int; 26 | 27 | /** 28 | * @param int|null $sequenceNumber 29 | * 30 | * @return string 31 | */ 32 | public function encode(?int $sequenceNumber = null): string { 33 | return json_encode((($sequenceNumber ? ['s' => $sequenceNumber] : []) + ['op' => $this->getOpCode(), 'd' => $this->getPayload()])); 34 | } 35 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/member/MemberUpdateEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\member; 18 | 19 | use JetBrains\PhpStorm\Pure; 20 | use phpcord\guild\GuildMember; 21 | 22 | class MemberUpdateEvent extends MemberEvent { 23 | 24 | /** 25 | * @param GuildMember $oldMember 26 | * @param GuildMember $member 27 | */ 28 | #[Pure] public function __construct(private GuildMember $oldMember, GuildMember $member) { 29 | parent::__construct($member); 30 | } 31 | 32 | /** 33 | * @return GuildMember 34 | */ 35 | public function getOldMember(): GuildMember { 36 | return $this->oldMember; 37 | } 38 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/voice/VoiceDeafEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\voice; 18 | 19 | use JetBrains\PhpStorm\Pure; 20 | use phpcord\voice\VoiceState; 21 | 22 | class VoiceDeafEvent extends VoiceEvent { 23 | 24 | /** 25 | * @param VoiceState $state 26 | * @param VoiceState $oldState 27 | * @param bool $self 28 | */ 29 | #[Pure] public function __construct(VoiceState $state, VoiceState $oldState, private bool $self) { 30 | parent::__construct($state, $oldState); 31 | } 32 | 33 | /** 34 | * @return bool 35 | */ 36 | public function self(): bool { 37 | return $this->self; 38 | } 39 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/voice/VoiceMuteEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\voice; 18 | 19 | use JetBrains\PhpStorm\Pure; 20 | use phpcord\voice\VoiceState; 21 | 22 | class VoiceMuteEvent extends VoiceEvent { 23 | 24 | /** 25 | * @param VoiceState $state 26 | * @param VoiceState $oldState 27 | * @param bool $self 28 | */ 29 | #[Pure] public function __construct(VoiceState $state, VoiceState $oldState, private bool $self) { 30 | parent::__construct($state, $oldState); 31 | } 32 | 33 | /** 34 | * @return bool 35 | */ 36 | public function self(): bool { 37 | return $this->self; 38 | } 39 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/interaction/ButtonPressEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\interaction; 18 | 19 | use JetBrains\PhpStorm\Pure; 20 | use phpcord\interaction\Interaction; 21 | 22 | class ButtonPressEvent extends InteractionEvent { 23 | 24 | public function __construct(Interaction $interaction, private string $customId) { 25 | parent::__construct($interaction); 26 | } 27 | 28 | /** 29 | * @return string 30 | */ 31 | public function getCustomId(): string { 32 | return $this->customId; 33 | } 34 | 35 | #[Pure] public function getName(): string { 36 | return $this->getCustomId(); 37 | } 38 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/voice/VoiceUndeafEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\voice; 18 | 19 | use JetBrains\PhpStorm\Pure; 20 | use phpcord\voice\VoiceState; 21 | 22 | class VoiceUndeafEvent extends VoiceEvent { 23 | 24 | /** 25 | * @param VoiceState $state 26 | * @param VoiceState $oldState 27 | * @param bool $self 28 | */ 29 | #[Pure] public function __construct(VoiceState $state, VoiceState $oldState, private bool $self) { 30 | parent::__construct($state, $oldState); 31 | } 32 | 33 | /** 34 | * @return bool 35 | */ 36 | public function self(): bool { 37 | return $this->self; 38 | } 39 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/voice/VoiceUnmuteEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\voice; 18 | 19 | use JetBrains\PhpStorm\Pure; 20 | use phpcord\voice\VoiceState; 21 | 22 | class VoiceUnmuteEvent extends VoiceEvent { 23 | 24 | /** 25 | * @param VoiceState $state 26 | * @param VoiceState $oldState 27 | * @param bool $self 28 | */ 29 | #[Pure] public function __construct(VoiceState $state, VoiceState $oldState, private bool $self) { 30 | parent::__construct($state, $oldState); 31 | } 32 | 33 | /** 34 | * @return bool 35 | */ 36 | public function self(): bool { 37 | return $this->self; 38 | } 39 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/runtime/network/opcode/OpCodeHandler.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\runtime\network\opcode; 18 | 19 | use phpcord\runtime\network\MessageSender; 20 | use phpcord\runtime\network\packet\MessageBuffer; 21 | 22 | abstract class OpCodeHandler { 23 | 24 | /** 25 | * @internal 26 | * 27 | * @return int 28 | */ 29 | abstract public function getOpCode(): int; 30 | 31 | /** 32 | * @internal 33 | * 34 | * @param MessageSender $sender 35 | * @param MessageBuffer $buffer 36 | * 37 | * @return void 38 | */ 39 | abstract public function handle(MessageSender $sender, MessageBuffer $buffer): void; 40 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/utils/helper/Reflector.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\utils\helper; 18 | 19 | use ReflectionException; 20 | use ReflectionProperty; 21 | 22 | /** 23 | * @internal 24 | */ 25 | final class Reflector { 26 | 27 | /** 28 | * @param object $object 29 | * @param string $name 30 | * @param mixed $value 31 | * 32 | * @return void 33 | */ 34 | public static function modifyProperty(object $object, string $name, mixed $value): void { 35 | try { 36 | ($r = new ReflectionProperty($object, $name))->setAccessible(true); 37 | $r->setValue($object, $value); 38 | } catch (ReflectionException) { } 39 | } 40 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/guild/EmojisUpdateEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\guild; 18 | 19 | use JetBrains\PhpStorm\Pure; 20 | use phpcord\guild\Guild; 21 | use phpcord\message\Emoji; 22 | use phpcord\utils\Collection; 23 | 24 | class EmojisUpdateEvent extends GuildEvent { 25 | 26 | /** 27 | * @param Guild $guild 28 | * @param Collection $emojis 29 | */ 30 | #[Pure] public function __construct(Guild $guild, private Collection $emojis) { 31 | parent::__construct($guild); 32 | } 33 | 34 | /** 35 | * @return Collection 36 | */ 37 | public function getEmojis(): Collection { 38 | return $this->emojis; 39 | } 40 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/guild/GuildDeleteEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\guild; 18 | 19 | use JetBrains\PhpStorm\Pure; 20 | use phpcord\guild\Guild; 21 | 22 | /** 23 | * This event is called when either a guild gets deleted or the bot gets kicked out of it 24 | */ 25 | class GuildDeleteEvent extends GuildEvent { 26 | 27 | #[Pure] public function __construct(?Guild $guild, private int $guildId) { 28 | parent::__construct($guild); 29 | } 30 | 31 | /** 32 | * In case the guild was unavailable previously 33 | * 34 | * @return int 35 | */ 36 | public function getGuildId(): int { 37 | return $this->guildId; 38 | } 39 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/runtime/network/SessionDetails.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\runtime\network; 18 | 19 | final class SessionDetails { 20 | 21 | /** 22 | * Contains the heartbeat interval in ms, this will most likely be a value between 41000-42000 23 | * @var int $heartbeatInterval 24 | */ 25 | public int $heartbeatInterval; 26 | 27 | /** 28 | * Contains the session id from the last hello 29 | * Used to reconnect to the socket 30 | * @var string $sessionId 31 | */ 32 | public string $sessionId; 33 | 34 | public function completed(): bool { 35 | return (isset($this->heartbeatInterval) and isset($this->sessionId)); 36 | } 37 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/runtime/network/opcode/ReconnectHandler.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\runtime\network\opcode; 18 | 19 | use phpcord\runtime\network\MessageSender; 20 | use phpcord\runtime\network\Network; 21 | use phpcord\runtime\network\packet\MessageBuffer; 22 | 23 | class ReconnectHandler extends OpCodeHandler { 24 | 25 | public function getOpCode(): int { 26 | return Opcodes::RECONNECT_RECEIVE(); 27 | } 28 | 29 | public function handle(MessageSender $sender, MessageBuffer $buffer): void { 30 | Network::getInstance()->getLogger()->warning('Received a reconnect request'); 31 | Network::getInstance()->getGateway()->open(); 32 | } 33 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/utils/presence/ActivityType.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\utils\presence; 18 | 19 | use phpcord\utils\enum\EnumTrait; 20 | 21 | /** 22 | * @method static int GAME() 23 | * @method static int STREAMING() 24 | * @method static int LISTENING() 25 | * @method static int WATCHING() 26 | * @method static int CUSTOM() 27 | * @method static int COMPETING() 28 | */ 29 | final class ActivityType { 30 | use EnumTrait; 31 | 32 | protected static function make(): void { 33 | self::register('Game', 0); 34 | self::register('Streaming', 1); 35 | self::register('Listening', 2); 36 | self::register('Watching', 3); 37 | self::register('Custom', 4); 38 | self::register('Competing', 5); 39 | } 40 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/interaction/ModalFormSubmitEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\interaction; 18 | 19 | use phpcord\interaction\Interaction; 20 | use phpcord\utils\Collection; 21 | 22 | class ModalFormSubmitEvent extends InteractionEvent { 23 | 24 | public function __construct(Interaction $interaction, private string $formId, private Collection $components) { 25 | parent::__construct($interaction); 26 | } 27 | 28 | /** 29 | * @return string 30 | */ 31 | public function getFormId(): string { 32 | return $this->formId; 33 | } 34 | 35 | /** 36 | * @return Collection [customId => string] 37 | */ 38 | public function getComponents(): Collection { 39 | return $this->components; 40 | } 41 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/voice/websocket/packet/VoiceHeartbeatPacket.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\voice\websocket\packet; 18 | 19 | use phpcord\voice\websocket\VoiceOpCodes; 20 | use function microtime; 21 | use function time; 22 | 23 | class VoiceHeartbeatPacket extends VoicePacket { 24 | 25 | /** @var float $nonce */ 26 | private float $nonce; 27 | 28 | /** 29 | * @param float|null $customNonce 30 | */ 31 | public function __construct(?float $customNonce = null) { 32 | $this->nonce = $customNonce ?? (int) (microtime(true) * 1000); 33 | } 34 | 35 | public function getOpCode(): int { 36 | return VoiceOpCodes::HEARTBEAT(); 37 | } 38 | 39 | public function getPayload(): float { 40 | return $this->nonce; 41 | } 42 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/interaction/InteractionTypes.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\interaction; 18 | 19 | use phpcord\utils\enum\EnumTrait; 20 | 21 | /** 22 | * @method static int PING() 23 | * @method static int APPLICATION_COMMAND() 24 | * @method static int MESSAGE_COMPONENT() 25 | * @method static int APPLICATION_COMMAND_AUTOCOMPLETE() 26 | * @method static int MODAL_SUBMIT() 27 | */ 28 | final class InteractionTypes { 29 | use EnumTrait; 30 | 31 | protected static function make(): void { 32 | self::register('PING', 1); 33 | self::register('APPLICATION_COMMAND', 2); 34 | self::register('MESSAGE_COMPONENT', 3); 35 | self::register('APPLICATION_COMMAND_AUTOCOMPLETE', 4); 36 | self::register('MODAL_SUBMIT', 5); 37 | } 38 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/utils/enum/EnumToolsTrait.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\utils\enum; 18 | 19 | use JetBrains\PhpStorm\Pure; 20 | 21 | /** 22 | * @internal 23 | */ 24 | trait EnumToolsTrait { 25 | use EnumTrait; 26 | 27 | public static function __getMemberRaw(string $name): mixed { 28 | return self::$members->get($name); 29 | } 30 | 31 | #[Pure] public static function __getMembers(): array { 32 | return self::$members->asArray(); 33 | } 34 | 35 | /** 36 | * @param mixed $value 37 | * 38 | * @return string|null the name of the member or null 39 | */ 40 | public static function __findValue(mixed $value): ?string { 41 | foreach (self::$members as $k => $v) if ($v === $value) return $k; 42 | return null; 43 | } 44 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/utils/error/ErrorTrapResult.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\utils\error; 18 | 19 | use Closure; 20 | 21 | class ErrorTrapResult { 22 | 23 | /** 24 | * @param bool $failure 25 | * @param mixed $result 26 | */ 27 | public function __construct(private bool $failure, private mixed $result) { } 28 | 29 | /** 30 | * @return bool 31 | */ 32 | public function isFailed(): bool { 33 | return $this->failure; 34 | } 35 | 36 | public function success(Closure $closure): ErrorTrapResult { 37 | if (!$this->failure) $closure($this->result); 38 | return $this; 39 | } 40 | 41 | public function fail(Closure $closure): ErrorTrapResult { 42 | if ($this->failure) $closure($this->result); 43 | return $this; 44 | } 45 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/runtime/network/packet/PresencePacket.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\runtime\network\packet; 18 | 19 | use JetBrains\PhpStorm\ArrayShape; 20 | use JetBrains\PhpStorm\Pure; 21 | use phpcord\runtime\network\opcode\Opcodes; 22 | use phpcord\utils\presence\Status; 23 | 24 | class PresencePacket extends Packet { 25 | 26 | /** 27 | * @param Status $status 28 | */ 29 | public function __construct(private Status $status) { } 30 | 31 | #[Pure] #[ArrayShape(['since' => "\int|null", 'afk' => "bool", 'status' => "string", 'activities' => "\null[]|\phpcord\utils\presence\Activity[]"])] 32 | public function getPayload(): array { 33 | return $this->status->jsonSerialize(); 34 | } 35 | 36 | public function getOpCode(): int { 37 | return Opcodes::PRESENCE_UPDATE(); 38 | } 39 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/guild/data/VerificationLevel.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\guild\data; 18 | 19 | use phpcord\utils\enum\EnumTrait; 20 | 21 | /** 22 | * @method static int NONE() unrestricted 23 | * @method static int LOW() must have verified email on account 24 | * @method static int MEDIUM() must be registered on Discord for longer than 5 minutes 25 | * @method static int HIGH() must be a member of the server for longer than 10 minutes 26 | * @method static int VERY_HIGH() must have a verified phone number 27 | */ 28 | final class VerificationLevel { 29 | use EnumTrait; 30 | 31 | protected static function make(): void { 32 | self::register('NONE', 0); 33 | self::register('LOW', 1); 34 | self::register('MEDIUM', 2); 35 | self::register('HIGH', 3); 36 | self::register('VERY_HIGH', 4); 37 | } 38 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/message/sendable/parts/EmbedFooter.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\message\sendable\parts; 18 | 19 | use JetBrains\PhpStorm\ArrayShape; 20 | use JsonSerializable; 21 | 22 | class EmbedFooter implements JsonSerializable { 23 | 24 | /** 25 | * @param string $text 26 | * @param string|null $iconUrl This either be an icon URL or an attachment 27 | * @param string|null $proxyUrl 28 | */ 29 | public function __construct(private string $text, private ?string $iconUrl = null, private ?string $proxyUrl = null) { } 30 | 31 | #[ArrayShape(['text' => "string", 'icon_url' => "null|string", 'proxy_icon_url' => "null|string"])] 32 | public function jsonSerialize(): array { 33 | return [ 34 | 'text' => $this->text, 35 | 'icon_url' => $this->iconUrl, 36 | 'proxy_icon_url' => $this->proxyUrl 37 | ]; 38 | } 39 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/runtime/tick/Timing.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\runtime\tick; 18 | 19 | use phpcord\utils\Collection; 20 | use phpcord\utils\SingletonTrait; 21 | use function microtime; 22 | 23 | final class Timing { 24 | use SingletonTrait; 25 | 26 | /** 27 | * @var Collection $timingRecords 28 | * @phpstan-var Collection 29 | */ 30 | private Collection $timingRecords; 31 | 32 | public function __construct() { $this->timingRecords = new Collection(); } 33 | 34 | public function record(string $name): void { 35 | $this->timingRecords->set($name, $this->time()); 36 | } 37 | 38 | public function stop(string $name): float { 39 | return ($this->time() - $this->timingRecords->reduce($name, $this->time())); 40 | } 41 | 42 | private function time(): float { 43 | return (microtime(true) * 1000); 44 | } 45 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/guild/auditlog/AuditLogChange.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\guild\auditlog; 18 | 19 | use JetBrains\PhpStorm\Pure; 20 | 21 | class AuditLogChange { 22 | 23 | public function __construct(private string $key, private mixed $oldValue, private mixed $newValue) { } 24 | 25 | /** 26 | * @return string 27 | */ 28 | public function getKey(): string { 29 | return $this->key; 30 | } 31 | 32 | /** 33 | * @return mixed 34 | */ 35 | public function getOldValue(): mixed { 36 | return $this->oldValue; 37 | } 38 | 39 | /** 40 | * @return mixed 41 | */ 42 | public function getNewValue(): mixed { 43 | return $this->newValue; 44 | } 45 | 46 | #[Pure] public static function fromArray(array $array): AuditLogChange { 47 | return new AuditLogChange($array['key'], @$array['old_value'], @$array['new_value']); 48 | } 49 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/async/net/Response.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\async\net; 18 | 19 | use function json_decode; 20 | 21 | final class Response { 22 | 23 | /** 24 | * @param int $code 25 | * @param string $payload 26 | * @param string[] $headers 27 | */ 28 | public function __construct(private int $code, private string $payload, private array $headers = []) { } 29 | 30 | /** 31 | * @return int 32 | */ 33 | public function getCode(): int { 34 | return $this->code; 35 | } 36 | 37 | /** 38 | * @return string[] 39 | */ 40 | public function getHeaders(): array { 41 | return $this->headers; 42 | } 43 | 44 | /** 45 | * @return string 46 | */ 47 | public function getPayload(): string { 48 | return $this->payload; 49 | } 50 | 51 | public function decode(): array { 52 | return json_decode($this->getPayload(), true); 53 | } 54 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/message/sendable/parts/EmbedProvider.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\message\sendable\parts; 18 | 19 | use JetBrains\PhpStorm\ArrayShape; 20 | use JsonSerializable; 21 | 22 | class EmbedProvider implements JsonSerializable { 23 | 24 | /** 25 | * @param string $name 26 | * @param string|null $url 27 | */ 28 | public function __construct(private string $name, private ?string $url = null) { } 29 | 30 | /** 31 | * @return string 32 | */ 33 | public function getName(): string { 34 | return $this->name; 35 | } 36 | 37 | /** 38 | * @return string|null 39 | */ 40 | public function getUrl(): ?string { 41 | return $this->url; 42 | } 43 | 44 | #[ArrayShape(['name' => "string", 'url' => "null|string"])] public function jsonSerialize(): array { 45 | return [ 46 | 'name' => $this->name, 47 | 'url' => $this->url 48 | ]; 49 | } 50 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/runtime/network/opcode/InvalidSessionHandler.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\runtime\network\opcode; 18 | 19 | use phpcord\runtime\network\MessageSender; 20 | use phpcord\runtime\network\Network; 21 | use phpcord\runtime\network\packet\MessageBuffer; 22 | use phpcord\scheduler\Scheduler; 23 | 24 | class InvalidSessionHandler extends OpCodeHandler { 25 | 26 | public function getOpCode(): int { 27 | return Opcodes::INVALID_SESSION(); 28 | } 29 | 30 | public function handle(MessageSender $sender, MessageBuffer $buffer): void { 31 | Network::getInstance()->getGateway()->resetSessionDetails(); 32 | Network::getInstance()->getGateway()->close(); 33 | Network::getInstance()->getLogger()->notice('Session invalidated, reconnecting in 2 seconds...'); 34 | Scheduler::getInstance()->delay(fn() => Network::getInstance()->getGateway()->open(), 40); 35 | } 36 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/guild/permissible/Permission.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\guild\permissible; 18 | 19 | final class Permission { 20 | 21 | public function __construct(private int $permissionBit = 0) { } 22 | 23 | public function set(int $permission): void { 24 | $this->permissionBit |= $permission; 25 | } 26 | 27 | public function has(int $permission): bool { 28 | return (($this->permissionBit & $permission) === $permission); 29 | } 30 | 31 | public function remove(int $permissionBit): void { 32 | $this->permissionBit &= ~$permissionBit; 33 | } 34 | 35 | /** 36 | * @param int $permissionBit 37 | */ 38 | public function setPermissionBit(int $permissionBit): void { 39 | $this->permissionBit = $permissionBit; 40 | } 41 | 42 | /** 43 | * @return int 44 | */ 45 | public function getPermissionBit(): int { 46 | return $this->permissionBit; 47 | } 48 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/channel/helper/InvitableTrait.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\channel\helper; 18 | 19 | use phpcord\async\completable\Completable; 20 | use phpcord\http\RestAPI; 21 | 22 | trait InvitableTrait { 23 | 24 | /** 25 | * @param int $maxUses 26 | * @param int $maxAge 27 | * @param bool $temporary 28 | * @param bool $unique 29 | * @param string|null $reason 30 | * 31 | * @return Completable 32 | */ 33 | public function createInvitation(int $maxUses, int $maxAge, bool $temporary = false, bool $unique = false, string $reason = null): Completable { 34 | return RestAPI::getInstance()->createInvitation($this->getId(), [ 35 | 'max_uses' => $maxUses, 36 | 'max_age' => $maxAge, 37 | 'temporary' => $temporary, 38 | 'unique' => $unique 39 | ], $reason); 40 | } 41 | 42 | /** 43 | * @return int 44 | */ 45 | abstract public function getId(): int; 46 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/async/completable/ICompletable.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\async\completable; 18 | 19 | use Closure; 20 | use Exception; 21 | 22 | interface ICompletable { 23 | 24 | /** 25 | * Registers a successor that will be executed if everything succeed and the result is valid 26 | * 27 | * @param Closure $closure 28 | * 29 | * @return $this 30 | */ 31 | public function then(Closure $closure): self; 32 | 33 | /** 34 | * Registers a crash handler that will be executed once the script crashed 35 | * 36 | * @param Closure $closure 37 | * 38 | * @return self 39 | */ 40 | public function catch(Closure $closure): self; 41 | 42 | /** 43 | * @internal 44 | * 45 | * @param Exception|mixed $value Exception object will cause the completable to execute catch, otherwise then 46 | * 47 | * @return void 48 | */ 49 | public function complete(mixed $value): void; 50 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/runtime/network/packet/ResumePacket.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\runtime\network\packet; 18 | 19 | use JetBrains\PhpStorm\ArrayShape; 20 | use phpcord\runtime\network\opcode\Opcodes; 21 | 22 | /** 23 | * @internal 24 | */ 25 | class ResumePacket extends Packet { 26 | 27 | /** 28 | * @param string $token 29 | * @param string $sessionId 30 | * @param int $lastSeq 31 | */ 32 | public function __construct(private string $token, private string $sessionId, private int $lastSeq) { } 33 | 34 | /** 35 | * @return int 36 | */ 37 | public function getOpCode(): int { 38 | return Opcodes::RESUME(); 39 | } 40 | 41 | #[ArrayShape(['token' => "string", 'session_id' => "string", 'seq' => "int"])] public function getPayload(): array { 42 | return [ 43 | 'token' => $this->token, 44 | 'session_id' => $this->sessionId, 45 | 'seq' => $this->lastSeq 46 | ]; 47 | } 48 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/message/sendable/parts/EmbedMedia.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\message\sendable\parts; 18 | 19 | use JetBrains\PhpStorm\ArrayShape; 20 | use JsonSerializable; 21 | 22 | class EmbedMedia implements JsonSerializable { 23 | 24 | /** 25 | * @param string $url An url to an image or attachment 26 | * @param string|null $proxyUrl 27 | * @param int|null $height 28 | * @param int|null $width 29 | */ 30 | public function __construct(private string $url, private ?string $proxyUrl = null, private ?int $height = null, private ?int $width = null) { } 31 | 32 | #[ArrayShape(['url' => "string", 'proxy_url' => "null|string", 'height' => "int|null", 'width' => "int|null"])] 33 | public function jsonSerialize(): array { 34 | return [ 35 | 'url' => $this->url, 36 | 'proxy_url' => $this->proxyUrl, 37 | 'height' => $this->height, 38 | 'width' => $this->width 39 | ]; 40 | } 41 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/role/RoleDeleteEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\role; 18 | 19 | use phpcord\event\Event; 20 | use phpcord\guild\permissible\Role; 21 | 22 | class RoleDeleteEvent extends Event { 23 | 24 | /** 25 | * @param Role|null $role 26 | * @param int $roleId 27 | * @param int $guildId 28 | */ 29 | public function __construct(private ?Role $role, private int $roleId, private int $guildId) { } 30 | 31 | /** 32 | * May not be existent, since it returns the cached role 33 | * Any modifications on it will fail 34 | * 35 | * @return Role|null 36 | */ 37 | public function getRole(): ?Role { 38 | return $this->role; 39 | } 40 | 41 | /** 42 | * @return int 43 | */ 44 | public function getRoleId(): int { 45 | return $this->roleId; 46 | } 47 | 48 | /** 49 | * @return int 50 | */ 51 | public function getGuildId(): int { 52 | return $this->guildId; 53 | } 54 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/interaction/SelectMenuSubmitEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\interaction; 18 | 19 | use JetBrains\PhpStorm\Pure; 20 | use phpcord\interaction\Interaction; 21 | 22 | class SelectMenuSubmitEvent extends InteractionEvent { 23 | 24 | /** 25 | * @param Interaction $interaction 26 | * @param string $customId 27 | * @param array $selectedValues 28 | */ 29 | #[Pure] public function __construct(Interaction $interaction, private string $customId, private array $selectedValues) { 30 | parent::__construct($interaction); 31 | } 32 | 33 | /** 34 | * @return string 35 | */ 36 | public function getCustomId(): string { 37 | return $this->customId; 38 | } 39 | 40 | /** 41 | * Returns the selected values, will at least contain one element 42 | * 43 | * @return string[] 44 | */ 45 | public function getSelectedValues(): array { 46 | return $this->selectedValues; 47 | } 48 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/guild/data/SystemChannelFlags.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\guild\data; 18 | 19 | use phpcord\utils\enum\EnumTrait; 20 | 21 | /** 22 | * @method static int SUPPRESS_JOIN_NOTIFICATIONS() Suppress member join notifications 23 | * @method static int SUPPRESS_PREMIUM_SUBSCRIPTIONS() Suppress server boost notifications 24 | * @method static int SUPPRESS_GUILD_REMINDER_NOTIFICATIONS() Suppress server setup tips 25 | * @method static int SUPPRESS_JOIN_NOTIFICATION_REPLIES() Hide member join sticker reply buttons 26 | */ 27 | final class SystemChannelFlags { 28 | use EnumTrait; 29 | 30 | protected static function make(): void { 31 | self::register('SUPPRESS_JOIN_NOTIFICATIONS', 1 << 0); 32 | self::register('SUPPRESS_PREMIUM_SUBSCRIPTIONS', 1 << 1); 33 | self::register('SUPPRESS_GUILD_REMINDER_NOTIFICATIONS', 1 << 2); 34 | self::register('SUPPRESS_JOIN_NOTIFICATION_REPLIES', 1 << 3); 35 | } 36 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/voice/VoiceRequest.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\voice; 18 | 19 | class VoiceRequest { 20 | 21 | public string $token; 22 | 23 | public string $sessionId; 24 | 25 | public string $endpoint; 26 | 27 | public bool $hasServerUpdate = false; 28 | 29 | /** 30 | * @param int $guildId 31 | * @param int $userId 32 | */ 33 | public function __construct(public int $guildId, public int $userId) { } 34 | 35 | public function tryComplete(): void { 36 | if (!$this->canComplete()) return; 37 | VoiceRequestPool::getInstance()->removeRequest($this); 38 | VoiceConnectionPool::getInstance()->registerConnection(new VoiceConnection($this->endpoint, $this->token, $this->sessionId, $this->guildId, $this->userId)); 39 | } 40 | 41 | public function canComplete(): bool { 42 | return (isset($this->token) and isset($this->sessionId) and isset($this->endpoint) and $this->hasServerUpdate); 43 | } 44 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/runtime/network/packet/IdentifyPacket.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\runtime\network\packet; 18 | 19 | use JetBrains\PhpStorm\ArrayShape; 20 | use phpcord\runtime\network\opcode\Opcodes; 21 | use phpcord\Version; 22 | use const PHP_OS; 23 | 24 | class IdentifyPacket extends Packet { 25 | 26 | /** 27 | * @param string $token 28 | * @param int $intents 29 | */ 30 | public function __construct(private string $token, private int $intents) { } 31 | 32 | public function getOpCode(): int { 33 | return Opcodes::IDENTIFY(); 34 | } 35 | 36 | #[ArrayShape(['token' => "string", 'intents' => "int", 'properties' => "array"])] public function getPayload(): array { 37 | return [ 38 | 'token' => $this->token, 39 | 'intents' => $this->intents, 40 | 'properties' => [ 41 | '$os' => PHP_OS, 42 | '$browser' => Version::FULL_NAME, 43 | '$device' => Version::FULL_NAME 44 | ] 45 | ]; 46 | } 47 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/interaction/slash/options/SubCommandOption.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\interaction\slash\options; 18 | 19 | use JetBrains\PhpStorm\ArrayShape; 20 | use JetBrains\PhpStorm\Pure; 21 | 22 | class SubCommandOption extends SlashCommandOption { 23 | 24 | /** 25 | * @param string $name 26 | * @param string $description 27 | * @param bool $required 28 | * @param SlashCommandOption[] $options 29 | */ 30 | #[Pure] public function __construct(string $name, string $description, bool $required = false, private array $options = []) { 31 | parent::__construct($name, $description, $required); 32 | } 33 | 34 | public function getType(): int { 35 | return SlashCommandOptionTypes::SUB_COMMAND(); 36 | } 37 | 38 | #[ArrayShape(['options' => "\phpcord\interaction\slash\options\SlashCommandOption[]"])] public function serializeOther(): array { 39 | return [ 40 | 'options' => $this->options 41 | ]; 42 | } 43 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/logger/AttachableLogger.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\logger; 18 | 19 | interface AttachableLogger { 20 | 21 | /** 22 | * Logs an information 23 | * 24 | * @param string $info 25 | * 26 | * @return void 27 | */ 28 | public function info(string $info): void; 29 | 30 | /** 31 | * Logs a notice which is basically a warning with less importance -> ignorable 32 | * 33 | * @param string $notice 34 | * 35 | * @return void 36 | */ 37 | public function notice(string $notice): void; 38 | 39 | /** 40 | * Logs a warning that is no emergency but should be observed 41 | * 42 | * @param string $warning 43 | * 44 | * @return void 45 | */ 46 | public function warning(string $warning): void; 47 | 48 | /** 49 | * Logs a critical error that cannot be resolved 50 | * 51 | * @param string $error 52 | * 53 | * @return void 54 | */ 55 | public function error(string $error): void; 56 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/interaction/slash/options/SlashCommandOption.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\interaction\slash\options; 18 | 19 | use JsonSerializable; 20 | 21 | abstract class SlashCommandOption implements JsonSerializable { 22 | 23 | /** 24 | * @param string $name 25 | * @param string $description 26 | * @param bool $required 27 | */ 28 | public function __construct(private string $name, private string $description, private bool $required = false) { } 29 | 30 | /** 31 | * One of @see SlashCommandOptionTypes 32 | * 33 | * @return int 34 | */ 35 | abstract public function getType(): int; 36 | 37 | public function jsonSerialize(): array { 38 | return ([ 39 | 'type' => $this->getType(), 40 | 'name' => $this->name, 41 | 'description' => $this->description, 42 | 'required' => $this->required 43 | ] + $this->serializeOther()); 44 | } 45 | 46 | public function serializeOther(): array { return []; } 47 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/intent/impl/ClientHandler.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\intent\impl; 18 | 19 | use phpcord\application\Application; 20 | use phpcord\Client; 21 | use phpcord\Discord; 22 | use phpcord\event\client\ClientReadyEvent; 23 | use phpcord\intent\IntentHandler; 24 | use phpcord\intent\Intents; 25 | use phpcord\runtime\network\Network; 26 | use phpcord\runtime\network\packet\IntentMessageBuffer; 27 | use phpcord\user\User; 28 | 29 | class ClientHandler implements IntentHandler { 30 | 31 | public function handle(IntentMessageBuffer $buffer): void { 32 | $d = $buffer->data(); 33 | switch ($buffer->name()) { 34 | case Intents::READY(): 35 | Network::getInstance()->getGateway()->getSessionDetails()->sessionId = $d['session_id']; 36 | Discord::getInstance()->__setClient(new Client(User::fromArray($d['user']), Application::fromArray($d['application']))); 37 | (new ClientReadyEvent())->call(); 38 | break; 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/message/MessageFlags.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\message; 18 | 19 | use phpcord\utils\enum\EnumTrait; 20 | 21 | /** 22 | * @method static int CROSSPOSTED() 23 | * @method static int IS_CROSSPOST() 24 | * @method static int SUPPRESS_EMBEDS() 25 | * @method static int SOURCE_MESSAGE_DELETED() 26 | * @method static int URGENT() 27 | * @method static int HAS_THREAD() 28 | * @method static int EPHEMERAL() 29 | * @method static int LOADING() 30 | */ 31 | final class MessageFlags { 32 | use EnumTrait; 33 | 34 | protected static function make(): void { 35 | self::register('CROSSPOSTED', 1 << 0); 36 | self::register('IS_CROSSPOST', 1 << 1); 37 | self::register('SUPPRESS_EMBEDS', 1 << 2); 38 | self::register('SOURCE_MESSAGE_DELETED', 1 << 3); 39 | self::register('URGENT', 1 << 4); 40 | self::register('HAS_THREAD', 1 << 5); 41 | self::register('EPHEMERAL', 1 << 6); 42 | self::register('LOADING', 1 << 7); 43 | } 44 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/channel/helper/SearchFilter.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\channel\helper; 18 | 19 | use phpcord\utils\NonInstantiableTrait; 20 | 21 | final class SearchFilter { 22 | use NonInstantiableTrait; 23 | 24 | private array $options = []; 25 | 26 | public function setAfter(int $id): SearchFilter { 27 | $this->options['after'] = $id; 28 | return $this; 29 | } 30 | 31 | public function setBefore(int $id): SearchFilter { 32 | $this->options['before'] = $id; 33 | return $this; 34 | } 35 | 36 | public function setAround(int $id): SearchFilter { 37 | $this->options['around'] = $id; 38 | return $this; 39 | } 40 | 41 | public function setLimit(int $count): SearchFilter { 42 | $this->options['limit'] = $count; 43 | return $this; 44 | } 45 | 46 | public function asArray(): array { 47 | return $this->options; 48 | } 49 | 50 | public static function build(): SearchFilter { 51 | return new SearchFilter(); 52 | } 53 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/runtime/network/packet/IntentMessageBuffer.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\runtime\network\packet; 18 | 19 | use JetBrains\PhpStorm\Pure; 20 | 21 | final class IntentMessageBuffer extends MessageBuffer { 22 | 23 | /** 24 | * @param string $buffer 25 | * @param int|null $receiveTimestamp 26 | */ 27 | #[Pure] public function __construct(string $buffer, ?int $receiveTimestamp = null) { 28 | parent::__construct($buffer, $receiveTimestamp); 29 | } 30 | 31 | public function name(): ?string { 32 | return @$this->asArray()['t']; 33 | } 34 | 35 | public function data(): array { 36 | return $this->asArray()['d']; 37 | } 38 | 39 | /** 40 | * @param MessageBuffer $buffer 41 | * 42 | * @return IntentMessageBuffer 43 | */ 44 | #[Pure] public static function fromMessageBuffer(MessageBuffer $buffer): IntentMessageBuffer { 45 | return new IntentMessageBuffer($buffer->getBuffer(), $buffer->getReceiveTimestamp()); 46 | } 47 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/runtime/network/packet/VoiceStateUpdatePacket.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\runtime\network\packet; 18 | 19 | use JetBrains\PhpStorm\ArrayShape; 20 | use phpcord\runtime\network\opcode\Opcodes; 21 | 22 | class VoiceStateUpdatePacket extends Packet { 23 | 24 | /** 25 | * @param int $guildId 26 | * @param int $channelId 27 | * @param bool $mute 28 | * @param bool $deaf 29 | */ 30 | public function __construct(private int $guildId, private int $channelId, private bool $mute = false, private bool $deaf = false) { } 31 | 32 | #[ArrayShape(['guild_id' => "int", 'channel_id' => "int", 'self_mute' => "bool", 'self_deaf' => "bool"])] 33 | public function getPayload(): array|string { 34 | return [ 35 | 'guild_id' => $this->guildId, 36 | 'channel_id' => $this->channelId, 37 | 'self_mute' => $this->mute, 38 | 'self_deaf' => $this->deaf 39 | ]; 40 | } 41 | 42 | public function getOpCode(): int { 43 | return Opcodes::VOICE_STATE_UPDATE(); 44 | } 45 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/interaction/InteractionResponseTypes.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\interaction; 18 | 19 | use phpcord\utils\enum\EnumTrait; 20 | 21 | /** 22 | * @method static int PONG() 23 | * @method static int CHANNEL_MESSAGE_WITH_SOURCE() 24 | * @method static int DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE() 25 | * @method static int DEFERRED_UPDATE_MESSAGE() 26 | * @method static int UPDATE_MESSAGE() 27 | * @method static int APPLICATION_COMMAND_AUTOCOMPLETE_RESULT() 28 | * @method static int MODAL() 29 | */ 30 | final class InteractionResponseTypes { 31 | use EnumTrait; 32 | 33 | protected static function make(): void { 34 | self::register('PONG', 1); 35 | self::register('CHANNEL_MESSAGE_WITH_SOURCE', 4); 36 | self::register('DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE', 5); 37 | self::register('DEFERRED_UPDATE_MESSAGE', 6); 38 | self::register('UPDATE_MESSAGE', 7); 39 | self::register('APPLICATION_COMMAND_AUTOCOMPLETE_RESULT', 8); 40 | self::register('MODAL', 9); 41 | } 42 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/runtime/network/opcode/DispatchHandler.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\runtime\network\opcode; 18 | 19 | use phpcord\intent\IntentPool; 20 | use phpcord\runtime\network\MessageSender; 21 | use phpcord\runtime\network\Network; 22 | use phpcord\runtime\network\packet\MessageBuffer; 23 | 24 | class DispatchHandler extends OpCodeHandler { 25 | 26 | /** 27 | * @internal 28 | * 29 | * @return int 30 | */ 31 | public function getOpCode(): int { 32 | return Opcodes::DISPATCH(); 33 | } 34 | 35 | /** 36 | * @internal 37 | * 38 | * @param MessageSender $sender 39 | * @param MessageBuffer $buffer 40 | * 41 | * @return void 42 | */ 43 | public function handle(MessageSender $sender, MessageBuffer $buffer): void { 44 | if (!isset($buffer->asArray()['t'])) { 45 | Network::getInstance()->getLogger()->error('Payload ' . $buffer . ' is invalid due to no intent was specified.'); 46 | return; 47 | } 48 | IntentPool::getInstance()->dispatch($buffer); 49 | } 50 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/voice/websocket/packet/VoiceIdentifyPacket.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\voice\websocket\packet; 18 | 19 | use JetBrains\PhpStorm\ArrayShape; 20 | use phpcord\voice\websocket\VoiceOpCodes; 21 | 22 | class VoiceIdentifyPacket extends VoicePacket { 23 | 24 | /** 25 | * @param int $serverId 26 | * @param int $userId 27 | * @param string $sessionId 28 | * @param string $token 29 | */ 30 | public function __construct(private int $serverId, private int $userId, private string $sessionId, private string $token) { } 31 | 32 | #[ArrayShape(['server_id' => "string", 'user_id' => "string", 'session_id' => "string", 'token' => "string"])] 33 | public function getPayload(): array { 34 | return [ 35 | 'server_id' => (string) $this->serverId, 36 | 'user_id' => (string) $this->userId, 37 | 'session_id' => $this->sessionId, 38 | 'token' => $this->token 39 | ]; 40 | } 41 | 42 | public function getOpCode(): int { 43 | return VoiceOpCodes::IDENTIFY(); 44 | } 45 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/guild/permissible/data/BasePermissionData.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\guild\permissible\data; 18 | 19 | use JetBrains\PhpStorm\Pure; 20 | use phpcord\guild\permissible\Permission; 21 | 22 | class BasePermissionData implements IPermissionData { 23 | 24 | /** @var Permission $permission */ 25 | private Permission $permission; 26 | 27 | #[Pure] public function __construct(int $permission = 0) { 28 | $this->permission = new Permission($permission); 29 | } 30 | 31 | #[Pure] public function hasPermission(int $permission): bool { 32 | return $this->permission->has($permission); 33 | } 34 | 35 | public function setPermission(int $permission): void { 36 | $this->permission->set($permission); 37 | } 38 | 39 | public function removePermission(int $permission): void { 40 | $this->permission->remove($permission); 41 | } 42 | 43 | /** 44 | * @return Permission 45 | */ 46 | public function getPermission(): Permission { 47 | return $this->permission; 48 | } 49 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/cache/DefaultMappingsCache.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\cache; 18 | 19 | use phpcord\utils\Collection; 20 | use phpcord\utils\SingletonTrait; 21 | use RuntimeException; 22 | use function array_shift; 23 | 24 | /** 25 | * @internal 26 | * 27 | * @method string classloader(string $default = null) 28 | */ 29 | final class DefaultMappingsCache { 30 | use SingletonTrait; 31 | 32 | /** 33 | * @var Collection $mappings 34 | * @phpstan-var Collection 35 | */ 36 | private Collection $mappings; 37 | 38 | public function __construct() { 39 | $this->mappings = new Collection(); 40 | } 41 | 42 | public function __call(string $name, array $arguments) { 43 | if (!$this->mappings->contains($name) and !count($arguments)) 44 | throw new RuntimeException('Failed to request cache entry ' . $name . ' with no fallback value set.'); 45 | $v = $this->mappings->get($name); 46 | if ($v === null) $this->mappings->set($name, ($v = array_shift($arguments))); 47 | return $v; 48 | } 49 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/message/Reaction.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\message; 18 | 19 | use JetBrains\PhpStorm\Pure; 20 | 21 | class Reaction { 22 | 23 | /** 24 | * @param PartialEmoji $emoji 25 | * @param int $count 26 | * @param bool $self 27 | */ 28 | public function __construct(private PartialEmoji $emoji, private int $count, private bool $self) { } 29 | 30 | /** 31 | * @return PartialEmoji 32 | */ 33 | public function getEmoji(): PartialEmoji { 34 | return $this->emoji; 35 | } 36 | 37 | /** 38 | * @return int 39 | */ 40 | public function getCount(): int { 41 | return $this->count; 42 | } 43 | 44 | /** 45 | * Returns whether the current bot reacted with this emoji 46 | * 47 | * @return bool 48 | */ 49 | public function isSelf(): bool { 50 | return $this->self; 51 | } 52 | 53 | #[Pure] public static function fromArray(array $array): Reaction { 54 | return new Reaction(PartialEmoji::fromArray($array['emoji']), $array['count'] ?? -1, $array['me'] ?? false); 55 | } 56 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/utils/InternetAddress.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\utils; 18 | 19 | use InvalidArgumentException; 20 | use function explode; 21 | use function substr_count; 22 | 23 | class InternetAddress { 24 | 25 | /** 26 | * @param string $ip a valid IPv4 address 27 | * @param int $port [0-65535] 28 | */ 29 | public function __construct(protected string $ip, protected int $port) { } 30 | 31 | /** 32 | * @return string 33 | */ 34 | public function getIp(): string { 35 | return $this->ip; 36 | } 37 | 38 | /** 39 | * @return int 40 | */ 41 | public function getPort(): int { 42 | return $this->port; 43 | } 44 | 45 | public function __toString(): string { 46 | return $this->ip . ':' . $this->port; 47 | } 48 | 49 | public static function fromString(string $address): InternetAddress { 50 | if (substr_count($address, ':') !== 1) throw new InvalidArgumentException('Address ' . $address . ' is invalid!'); 51 | return new InternetAddress(...explode(':', $address)); 52 | } 53 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/interaction/slash/options/ChannelCommandOption.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\interaction\slash\options; 18 | 19 | use JetBrains\PhpStorm\ArrayShape; 20 | use JetBrains\PhpStorm\Pure; 21 | use phpcord\channel\ChannelTypes; 22 | 23 | class ChannelCommandOption extends SlashCommandOption { 24 | 25 | /** 26 | * @param string $name 27 | * @param string $description 28 | * @param bool $required 29 | * 30 | * @param int[] $channelTypes 31 | * an array of channel types the options will be restricted to @see ChannelTypes 32 | */ 33 | #[Pure] public function __construct(string $name, string $description, bool $required = false, private array $channelTypes = []) { 34 | parent::__construct($name, $description, $required); 35 | } 36 | 37 | public function getType(): int { 38 | return SlashCommandOptionTypes::CHANNEL(); 39 | } 40 | 41 | #[ArrayShape(['channel_types' => "int[]"])] public function serializeOther(): array { 42 | return [ 43 | 'channel_types' => $this->channelTypes 44 | ]; 45 | } 46 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/guild/components/WelcomeScreen.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\guild\components; 18 | 19 | use phpcord\utils\Collection; 20 | use phpcord\utils\Factory; 21 | 22 | class WelcomeScreen { 23 | 24 | /** 25 | * @var Collection 26 | * @phpstan-var Collection 27 | */ 28 | private Collection $welcomeChannels; 29 | 30 | public function __construct(private ?string $description, array $welcomeChannels) { 31 | $this->welcomeChannels = new Collection($welcomeChannels); 32 | } 33 | 34 | /** 35 | * @return string|null 36 | */ 37 | public function getDescription(): ?string { 38 | return $this->description; 39 | } 40 | 41 | /** 42 | * @return Collection 43 | */ 44 | public function getWelcomeChannels(): Collection { 45 | return $this->welcomeChannels; 46 | } 47 | 48 | public static function fromArray(array $array): WelcomeScreen { 49 | return new WelcomeScreen(@$array['description'], Factory::createWelcomeScreenChannelArray($array['welcome_channels'] ?? [])); 50 | } 51 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/voice/websocket/VoiceOpCodeHandlerMap.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\voice\websocket; 18 | 19 | use phpcord\utils\Collection; 20 | use phpcord\utils\SingletonTrait; 21 | use phpcord\voice\VoiceConnection; 22 | use phpcord\voice\websocket\handler\VoiceHelloHandler; 23 | use phpcord\voice\websocket\handler\VoiceOpCodeHandler; 24 | 25 | final class VoiceOpCodeHandlerMap { 26 | use SingletonTrait; 27 | 28 | /** 29 | * @var Collection $handlers 30 | * @phpstan-var Collection 31 | */ 32 | private Collection $handlers; 33 | 34 | public function __construct() { 35 | $this->handlers = new Collection(); 36 | 37 | $this->register(new VoiceHelloHandler(), VoiceOpCodes::HELLO()); 38 | } 39 | 40 | public function register(VoiceOpCodeHandler $handler, int ...$opcodes): void { 41 | foreach ($opcodes as $opcode) $this->handlers->set($opcode, $handler); 42 | } 43 | 44 | public function handle(VoiceConnection $connection, array $payload): void { 45 | $this->handlers->get($payload['op'])?->handle($connection, $payload); 46 | } 47 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/message/MessageDeleteEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\message; 18 | 19 | use phpcord\async\completable\Completable; 20 | use phpcord\channel\TextChannel; 21 | use phpcord\Discord; 22 | use phpcord\event\Event; 23 | use phpcord\guild\Guild; 24 | 25 | class MessageDeleteEvent extends Event { 26 | 27 | /** 28 | * @param int|null $guildId 29 | * @param int $channelId 30 | * @param int $id 31 | */ 32 | public function __construct(private ?int $guildId, private int $channelId, private int $id) { } 33 | 34 | /** 35 | * @return int 36 | */ 37 | public function getId(): int { 38 | return $this->id; 39 | } 40 | 41 | public function getGuild(): ?Guild { 42 | if (!$this->guildId) return null; 43 | return Discord::getInstance()->getClient()->getGuilds()->get($this->guildId); 44 | } 45 | 46 | /** 47 | * @return Completable 48 | */ 49 | public function getChannel(): Completable { 50 | return ($this->guildId ? $this->getGuild()->getChannel($this->channelId) : Discord::getInstance()->getClient()->getChannel($this->channelId)); 51 | } 52 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/voice/websocket/VoiceOpCodes.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\voice\websocket; 18 | 19 | use phpcord\utils\enum\EnumTrait; 20 | 21 | /** 22 | * @method static int IDENTIFY() 23 | * @method static int SELECT() 24 | * @method static int READY() 25 | * @method static int HEARTBEAT() 26 | * @method static int SESSION() 27 | * @method static int SPEAKING() 28 | * @method static int HEARTBEAT_ACK() 29 | * @method static int RESUME() 30 | * @method static int HELLO() 31 | * @method static int RESUMED() 32 | * @method static int CLIENT_DISCONNECT() 33 | */ 34 | final class VoiceOpCodes { 35 | use EnumTrait; 36 | 37 | protected static function make(): void { 38 | self::register('Identify', 0); 39 | self::register('Select', 1); 40 | self::register('Ready', 2); 41 | self::register('Heartbeat', 3); 42 | self::register('Session', 4); 43 | self::register('Speaking', 5); 44 | self::register('Heartbeat ACK', 6); 45 | self::register('Resume', 7); 46 | self::register('Hello', 8); 47 | self::register('Resumed', 9); 48 | self::register('Client Disconnect', 13); 49 | } 50 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/async/AsyncPool.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\async; 18 | 19 | use phpcord\runtime\tick\Tickable; 20 | use phpcord\utils\Collection; 21 | use phpcord\utils\helper\SPL; 22 | use phpcord\utils\SingletonTrait; 23 | 24 | final class AsyncPool implements Tickable { 25 | use SingletonTrait; 26 | 27 | /** 28 | * @var Collection $threads 29 | * @phpstan-var Collection $threads 30 | */ 31 | private Collection $threads; 32 | 33 | public function __construct() { 34 | $this->threads = new Collection(); 35 | } 36 | 37 | /** 38 | * Starts the thread and stores it to the cache, so it can be completed later 39 | * 40 | * @param Thread $thread 41 | * 42 | * @return void 43 | */ 44 | public function submitThread(Thread $thread): void { 45 | $this->threads->set(SPL::id($thread), $thread); 46 | $thread->start(); 47 | } 48 | 49 | public function tick(int $currentTick): void { 50 | /** @var Thread $thread */ 51 | foreach ($this->threads as $id => $thread) { 52 | if ($thread->isGarbage()) { 53 | $thread->onCompletion(); 54 | $this->threads->unset($id); 55 | } 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/interaction/slash/options/SlashCommandOptionTypes.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\interaction\slash\options; 18 | 19 | use phpcord\utils\enum\EnumTrait; 20 | 21 | /** 22 | * @method static int SUB_COMMAND() 23 | * @method static int SUB_COMMAND_GROUP() 24 | * @method static int STRING() 25 | * @method static int INTEGER() 26 | * @method static int BOOLEAN() 27 | * @method static int USER() 28 | * @method static int CHANNEL() 29 | * @method static int ROLE() 30 | * @method static int MENTIONABLE() 31 | * @method static int NUMBER() 32 | * @method static int ATTACHMENT() 33 | */ 34 | final class SlashCommandOptionTypes { 35 | use EnumTrait; 36 | 37 | protected static function make(): void { 38 | self::register('SUB_COMMAND', 1); 39 | self::register('SUB_COMMAND_GROUP', 2); 40 | self::register('STRING', 3); 41 | self::register('INTEGER', 4); 42 | self::register('BOOLEAN', 5); 43 | self::register('USER', 6); 44 | self::register('CHANNEL', 7); 45 | self::register('ROLE', 8); 46 | self::register('MENTIONABLE', 9); 47 | self::register('NUMBER', 10); 48 | self::register('ATTACHMENT', 11); 49 | } 50 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/scheduler/TaskHandler.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\scheduler; 18 | 19 | use Closure; 20 | use phpcord\runtime\tick\Ticker; 21 | 22 | class TaskHandler { 23 | 24 | /** @var int $lastTick the last time the task was executed / initialized */ 25 | private int $lastTick; 26 | 27 | /** 28 | * @param Closure $closure 29 | * @phpstan-param Closure(): void 30 | * @param int $delay_or_period 31 | * @param bool $repeating 32 | */ 33 | public function __construct(private Closure $closure, private int $delay_or_period, private bool $repeating = false) { 34 | $this->lastTick = Ticker::getInstance()->getCurrentTick(); 35 | } 36 | 37 | public function isExecutingNow(): bool { 38 | return ((Ticker::getInstance()->getCurrentTick() - $this->lastTick) >= $this->delay_or_period); 39 | } 40 | 41 | public function execute(): void { 42 | ($this->closure)(); 43 | if (!$this->repeating) { 44 | $this->cancel(); 45 | return; 46 | } 47 | $this->lastTick = Ticker::getInstance()->getCurrentTick(); 48 | } 49 | 50 | public function cancel(): void { 51 | Scheduler::getInstance()->cancelTask($this); 52 | } 53 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/guild/components/Ban.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\guild; 18 | 19 | use phpcord\async\completable\Completable; 20 | use phpcord\http\RestAPI; 21 | use phpcord\user\User; 22 | use phpcord\utils\Utils; 23 | 24 | class Ban { 25 | 26 | /** 27 | * @param User $user 28 | * @param int $guildId 29 | * @param string|null $reason 30 | */ 31 | public function __construct(private User $user, private int $guildId, private ?string $reason) { } 32 | 33 | /** 34 | * @return User 35 | */ 36 | public function getUser(): User { 37 | return $this->user; 38 | } 39 | 40 | /** 41 | * @return string|null 42 | */ 43 | public function getReason(): ?string { 44 | return $this->reason; 45 | } 46 | 47 | /** 48 | * @return Completable 49 | */ 50 | public function remove(): Completable { 51 | return RestAPI::getInstance()->removeBan($this->guildId, $this->getUser()->getId()); 52 | } 53 | 54 | public static function fromArray(array $array): ?Ban { 55 | if (!Utils::contains($array, 'user', 'guild_id')) return null; 56 | return new Ban(User::fromArray($array['user']), $array['guild_id'], @$array['reason']); 57 | } 58 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/autoload/DynamicAutoloader.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\autoload; 18 | 19 | use phpcord\cache\DefaultMappingsCache; 20 | use function file_exists; 21 | use function serialize; 22 | use function spl_autoload_register; 23 | use function str_replace; 24 | use const DIRECTORY_SEPARATOR; 25 | 26 | final class DynamicAutoloader implements Autoloadable { 27 | 28 | /** 29 | * @var array $loadElements 30 | * @phpstan-var array 31 | */ 32 | private array $loadElements = []; 33 | 34 | public function __construct() { 35 | $this->autoload(); 36 | } 37 | 38 | public function load(string $namespace, string $path): void { 39 | $this->loadElements[$namespace] = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; 40 | DefaultMappingsCache::getInstance()->classloader(serialize($this)); 41 | } 42 | 43 | public function autoload(): void { 44 | spl_autoload_register(function (string $class): void { 45 | foreach ($this->loadElements as $namespace => $path) 46 | if (file_exists(($target = str_replace('\\', '/', $path . str_replace($namespace, '', $class) . '.php')))) 47 | require $target; 48 | }); 49 | } 50 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/interaction/slash/options/StringCommandOption.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\interaction\slash\options; 18 | 19 | use JetBrains\PhpStorm\ArrayShape; 20 | use JetBrains\PhpStorm\Pure; 21 | use phpcord\interaction\slash\SlashCommandChoice; 22 | 23 | class StringCommandOption extends SlashCommandOption { 24 | 25 | /** @var SlashCommandChoice[] $choices */ 26 | private array $choices; 27 | 28 | /** 29 | * @param string $name 30 | * @param string $description 31 | * @param bool $required 32 | * @param array $choices 33 | * @param bool $autocomplete todo: implement this 34 | */ 35 | #[Pure] public function __construct(string $name, string $description, bool $required = false, array $choices = [], private bool $autocomplete = false) { 36 | parent::__construct($name, $description, $required); 37 | $this->choices = SlashCommandChoice::createOptionArray($choices); 38 | } 39 | 40 | public function getType(): int { 41 | return SlashCommandOptionTypes::STRING(); 42 | } 43 | 44 | #[ArrayShape(['choices' => "array"])] public function serializeOther(): array { 45 | return [ 46 | 'choices' => $this->choices 47 | ]; 48 | } 49 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/channel/types/guild/GuildCategoryChannel.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\channel\types\guild; 18 | 19 | use InvalidArgumentException; 20 | use phpcord\async\completable\Completable; 21 | use phpcord\channel\ChannelBuilder; 22 | use phpcord\channel\ChannelTypes; 23 | use phpcord\channel\GuildChannel; 24 | use phpcord\utils\Utils; 25 | 26 | class GuildCategoryChannel extends GuildChannel { 27 | 28 | /** 29 | * @param ChannelBuilder $builder 30 | * 31 | * @return Completable 32 | */ 33 | public function createChannel(ChannelBuilder $builder): Completable { 34 | if ($builder->getType() === ChannelTypes::GUILD_CATEGORY()) throw new InvalidArgumentException('Cannot put a category channel inside a category'); 35 | $builder->setParent($this->getId()); 36 | return $this->getGuild()->createChannel($builder); 37 | } 38 | 39 | public static function fromArray(array $array): ?self { 40 | if (!Utils::contains($array, 'id', 'guild_id', 'name', 'position')) return null; 41 | return new GuildCategoryChannel($array['id'], $array['guild_id'], $array['name'], $array['position'], null, $array['permission_overwrites'] ?? []); 42 | } 43 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/message/sendable/parts/EmbedField.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\message\sendable\parts; 18 | 19 | use JetBrains\PhpStorm\ArrayShape; 20 | use JsonSerializable; 21 | 22 | class EmbedField implements JsonSerializable { 23 | 24 | /** 25 | * @param string $name 26 | * @param string $value description 27 | * @param bool $inline set to true to display the field in one line aligned with the others 28 | */ 29 | public function __construct(private string $name, private string $value, private bool $inline = false) { } 30 | 31 | /** 32 | * @return string 33 | */ 34 | public function getName(): string { 35 | return $this->name; 36 | } 37 | 38 | /** 39 | * @return string 40 | */ 41 | public function getValue(): string { 42 | return $this->value; 43 | } 44 | 45 | /** 46 | * @return bool 47 | */ 48 | public function isInline(): bool { 49 | return $this->inline; 50 | } 51 | 52 | #[ArrayShape(['name' => "string", 'value' => "string", 'inline' => "bool"])] 53 | public function jsonSerialize(): array { 54 | return [ 55 | 'name' => $this->name, 56 | 'value' => $this->value, 57 | 'inline' => $this->inline 58 | ]; 59 | } 60 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/runtime/network/opcode/Opcodes.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\runtime\network\opcode; 18 | 19 | use phpcord\utils\enum\EnumTrait; 20 | 21 | /** 22 | * @method static int DISPATCH() 23 | * @method static int HEARTBEAT() 24 | * @method static int IDENTIFY() 25 | * @method static int PRESENCE_UPDATE() 26 | * @method static int VOICE_STATE_UPDATE() 27 | * @method static int RESUME() 28 | * @method static int RECONNECT_RECEIVE() 29 | * @method static int REQUEST_GUILD_MEMBER() 30 | * @method static int INVALID_SESSION() 31 | * @method static int HELLO() 32 | * @method static int HEARTBEAT_ACK() 33 | */ 34 | final class Opcodes { 35 | use EnumTrait; 36 | 37 | protected static function make(): void { 38 | self::register('DISPATCH', 0); 39 | self::register('HEARTBEAT', 1); 40 | self::register('IDENTIFY', 2); 41 | self::register('PRESENCE_UPDATE', 3); 42 | self::register('VOICE_STATE_UPDATE', 4); 43 | self::register('RESUME', 6); 44 | self::register('RECONNECT_RECEIVE', 7); 45 | self::register('REQUEST_GUILD_MEMBER', 8); 46 | self::register('INVALID_SESSION', 9); 47 | self::register('HELLO', 10); 48 | self::register('HEARTBEAT_ACK', 11); 49 | } 50 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/channel/types/dm/GroupDMChannel.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\channel\types\dm; 18 | 19 | use phpcord\user\User; 20 | use phpcord\utils\Factory; 21 | 22 | class GroupDMChannel extends DMChannel { 23 | 24 | /** 25 | * @param int $id 26 | * @param int $lastMessageId 27 | * @param User[] $recipients 28 | * @param int $ownerId 29 | */ 30 | public function __construct(int $id, int $lastMessageId, array $recipients, private int $ownerId) { 31 | parent::__construct($id, $lastMessageId, $recipients); 32 | } 33 | 34 | /** 35 | * @return int 36 | */ 37 | public function getOwnerId(): int { 38 | return $this->ownerId; 39 | } 40 | 41 | public function getOwner(): ?User { 42 | return $this->getRecipients()->get($this->getOwnerId()); 43 | } 44 | 45 | public static function fromArray(array $array): ?self { 46 | return new GroupDMChannel($array['id'], $array['last_message_id'], Factory::createUserArray($array['recipients']), $array['owner_id']); 47 | } 48 | 49 | public function replaceBy(DMChannel $channel): void { 50 | if (!$channel instanceof GroupDMChannel) return; 51 | $this->ownerId = $channel->getOwnerId(); 52 | parent::replaceBy($channel); 53 | } 54 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/interaction/SlashCommandEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\interaction; 18 | 19 | use JetBrains\PhpStorm\Pure; 20 | use phpcord\channel\Channel; 21 | use phpcord\guild\GuildMember; 22 | use phpcord\guild\permissible\Role; 23 | use phpcord\interaction\Interaction; 24 | use phpcord\user\User; 25 | use phpcord\utils\Collection; 26 | 27 | class SlashCommandEvent extends InteractionEvent { 28 | 29 | /** 30 | * @var Collection $args 31 | * @phpstan-var Collection 32 | */ 33 | private Collection $args; 34 | 35 | /** 36 | * @param Interaction $interaction 37 | * @param string $name 38 | * @param User[]|float[]|Channel[]|Role[]|int[]|string[]|GuildMember[] $args 39 | */ 40 | public function __construct(Interaction $interaction, private string $name, array $args) { 41 | parent::__construct($interaction); 42 | $this->args = new Collection($args); 43 | } 44 | 45 | /** 46 | * @return string 47 | */ 48 | public function getName(): string { 49 | return $this->name; 50 | } 51 | 52 | /** 53 | * @return Collection 54 | */ 55 | public function getArgs(): Collection { 56 | return $this->args; 57 | } 58 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/guild/components/WelcomeScreenChannel.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\guild\components; 18 | 19 | use JetBrains\PhpStorm\Pure; 20 | use phpcord\message\PartialEmoji; 21 | 22 | class WelcomeScreenChannel { 23 | 24 | /** 25 | * @param int $id 26 | * @param string|null $description 27 | * @param PartialEmoji|null $emoji 28 | */ 29 | public function __construct(private int $id, private ?string $description, private ?PartialEmoji $emoji) { } 30 | 31 | /** 32 | * @return int 33 | */ 34 | public function getId(): int { 35 | return $this->id; 36 | } 37 | 38 | /** 39 | * @return string|null 40 | */ 41 | public function getDescription(): ?string { 42 | return $this->description; 43 | } 44 | 45 | /** 46 | * @return PartialEmoji|null 47 | */ 48 | public function getEmoji(): ?PartialEmoji { 49 | return $this->emoji; 50 | } 51 | 52 | #[Pure] public static function fromArray(array $array): ?WelcomeScreenChannel { 53 | if (!isset($array['channel_id'])) return null; 54 | return new WelcomeScreenChannel($array['channel_id'], @$array['description'], ((@$array['emoji_id'] or @$array['emoji_name']) ? new PartialEmoji(@$array['emoji_name'], @$array['emoji_id']) : null)); 55 | } 56 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/logger/ColorMap.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\logger; 18 | 19 | use phpcord\utils\enum\EnumTrait; 20 | 21 | /** 22 | * @method static string DEFAULT() 23 | * @method static string BLACK() 24 | * @method static string RED() 25 | * @method static string GREEN() 26 | * @method static string YELLOW() 27 | * @method static string ORANGE() 28 | * @method static string LIGHTGREEN() 29 | * @method static string BLUE() 30 | * @method static string PURPLE() 31 | * @method static string CYAN() 32 | * @method static string WHITE() 33 | * @method static string GREY() 34 | */ 35 | final class ColorMap { 36 | use EnumTrait; 37 | 38 | protected static function make(): void { 39 | self::register("default", "\033[0m"); 40 | self::register("black", "\033[30m"); 41 | self::register("red", "\033[31m"); 42 | self::register("green", "\033[32m"); 43 | self::register("yellow", "\033[93m"); 44 | self::register("orange", "\033[33m"); 45 | self::register("lightgreen", "\033[92m"); 46 | self::register("blue", "\033[34m"); 47 | self::register("purple", "\033[35m"); 48 | self::register("cyan", "\033[36m"); 49 | self::register("white", "\033[98m"); 50 | self::register("grey", "\033[37m"); 51 | } 52 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/utils/RtcRegion.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\utils; 18 | 19 | use JetBrains\PhpStorm\Pure; 20 | 21 | final class RtcRegion { 22 | 23 | public function __construct(private string $id, private string $name, private bool $custom, private bool $deprecated, private bool $optimal) { } 24 | 25 | /** 26 | * @return string 27 | */ 28 | public function getId(): string { 29 | return $this->id; 30 | } 31 | 32 | /** 33 | * @return string 34 | */ 35 | public function getName(): string { 36 | return $this->name; 37 | } 38 | 39 | /** 40 | * @return bool 41 | */ 42 | public function isCustom(): bool { 43 | return $this->custom; 44 | } 45 | 46 | /** 47 | * @return bool 48 | */ 49 | public function isDeprecated(): bool { 50 | return $this->deprecated; 51 | } 52 | 53 | /** 54 | * @return bool 55 | */ 56 | public function isOptimal(): bool { 57 | return $this->optimal; 58 | } 59 | 60 | #[Pure] public static function fromArray(array $array): ?RtcRegion { 61 | if (!Utils::contains($array, 'id', 'name')) return null; 62 | return new RtcRegion($array['id'], $array['name'], $array['custom'] ?? false, $array['deprecated'] ?? false, $array['optimal'] ?? false); 63 | } 64 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/voice/VoiceConnectionPool.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\voice; 18 | 19 | use phpcord\runtime\tick\Tickable; 20 | use phpcord\utils\Collection; 21 | use phpcord\utils\helper\SPL; 22 | use phpcord\utils\SingletonTrait; 23 | 24 | final class VoiceConnectionPool implements Tickable { 25 | use SingletonTrait; 26 | 27 | /** 28 | * @var Collection 29 | * @phpstan-var Collection 30 | */ 31 | private Collection $connections; 32 | 33 | public function __construct() { 34 | $this->connections = new Collection(); 35 | } 36 | 37 | /** 38 | * @param VoiceConnection $connection 39 | * 40 | * @return void 41 | */ 42 | public function registerConnection(VoiceConnection $connection): void { 43 | $this->connections->add($connection); 44 | } 45 | 46 | /** 47 | * @param int|VoiceConnection $connection 48 | * 49 | * @return VoiceConnection|null 50 | */ 51 | public function getConnection(int|VoiceConnection $connection): ?VoiceConnection { 52 | return $this->connections->get(SPL::id($connection)); 53 | } 54 | 55 | public function tick(int $currentTick): void { 56 | $this->connections->foreach(fn(VoiceConnection $connection) => $connection->tick($currentTick)); 57 | } 58 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/interaction/slash/SlashCommandChoice.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\interaction\slash; 18 | 19 | use JetBrains\PhpStorm\ArrayShape; 20 | use JetBrains\PhpStorm\Pure; 21 | use JsonSerializable; 22 | use function is_scalar; 23 | use function is_string; 24 | 25 | class SlashCommandChoice implements JsonSerializable { 26 | 27 | /** 28 | * @param string $name 29 | * @param float|int|string $value 30 | */ 31 | public function __construct(private string $name, private float|int|string $value) { } 32 | 33 | /** 34 | * @internal 35 | * 36 | * @param array $array 37 | * 38 | * @return SlashCommandChoice[] 39 | */ 40 | #[Pure] public static function createOptionArray(array $array): array { 41 | $options = []; 42 | foreach ($array as $k => $v) { 43 | if ($v instanceof SlashCommandChoice) { 44 | $options[] = $v; 45 | continue; 46 | } 47 | if (!is_scalar($v) or !is_string($k)) continue; 48 | $options[] = new SlashCommandChoice($k, $v); 49 | } 50 | return $options; 51 | } 52 | 53 | #[ArrayShape(['name' => "string", 'value' => "float|int|string"])] public function jsonSerialize(): array { 54 | return [ 55 | 'name' => $this->name, 56 | 'value' => $this->value 57 | ]; 58 | } 59 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/voice/websocket/handler/VoiceHelloHandler.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\voice\websocket\handler; 18 | 19 | use phpcord\runtime\tick\Ticker; 20 | use phpcord\Version; 21 | use phpcord\voice\VoiceConnection; 22 | use phpcord\voice\websocket\packet\VoiceIdentifyPacket; 23 | use RuntimeException; 24 | 25 | class VoiceHelloHandler extends VoiceOpCodeHandler { 26 | 27 | /** 28 | * @param VoiceConnection $connection 29 | * @param array $payload 30 | * 31 | * @return void 32 | */ 33 | public function handle(VoiceConnection $connection, array $payload): void { 34 | $data = $payload['d']; 35 | if ($data['v'] !== Version::VOICE_GATEWAY_VERSION) throw new RuntimeException('Voice gateway version ' . $data['v'] . ' is not supported. Current version: ' . Version::VOICE_GATEWAY_VERSION); 36 | 37 | if (!isset($data['heartbeat_interval'])) return; 38 | $connection->heartbeatInterval = ($data['heartbeat_interval'] / Ticker::MS_PER_TICK - 10); 39 | $connection->lastHeartbeat = Ticker::getInstance()->getCurrentTick(); 40 | $connection->heartbeat(); 41 | $connection->sendPacket(new VoiceIdentifyPacket($connection->getGuildId(), $connection->getUserId(), $connection->getSessionId(), $connection->getToken())); 42 | } 43 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/event/voice/VoiceEvent.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\event\voice; 18 | 19 | use JetBrains\PhpStorm\Pure; 20 | use phpcord\async\completable\Completable; 21 | use phpcord\channel\types\guild\GuildVoiceChannel; 22 | use phpcord\event\Event; 23 | use phpcord\guild\Guild; 24 | use phpcord\guild\GuildMember; 25 | use phpcord\voice\VoiceState; 26 | 27 | abstract class VoiceEvent extends Event { 28 | 29 | /** 30 | * @param VoiceState $state 31 | * @param VoiceState|null $oldState 32 | */ 33 | public function __construct(private VoiceState $state, private ?VoiceState $oldState = null) { } 34 | 35 | /** 36 | * @return VoiceState 37 | */ 38 | public function getState(): VoiceState { 39 | return $this->state; 40 | } 41 | 42 | /** 43 | * @return VoiceState|null 44 | */ 45 | public function getOldState(): ?VoiceState { 46 | return $this->oldState; 47 | } 48 | 49 | #[Pure] public function getMember(): GuildMember { 50 | return $this->state->getMember(); 51 | } 52 | 53 | public function getGuild(): Guild { 54 | return $this->state->getGuild(); 55 | } 56 | 57 | /** 58 | * @return Completable 59 | */ 60 | public function getChannel(): Completable { 61 | return $this->getState()->getChannel(); 62 | } 63 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/runtime/network/packet/MessageBuffer.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\runtime\network\packet; 18 | 19 | use JetBrains\PhpStorm\Pure; 20 | use function json_decode; 21 | use function microtime; 22 | 23 | class MessageBuffer { 24 | 25 | /** @var int $receiveTimestamp */ 26 | protected int $receiveTimestamp; 27 | 28 | private ?array $decodedArray = null; 29 | 30 | /** 31 | * @param string $buffer 32 | * @param int|null $receiveTimestamp 33 | */ 34 | public function __construct(public string $buffer, ?int $receiveTimestamp = null) { 35 | $this->receiveTimestamp = $receiveTimestamp ?? (int) (microtime(true) * 1000); 36 | } 37 | 38 | public function getBuffer(): string { 39 | return $this->buffer; 40 | } 41 | 42 | public function asArray(): array { 43 | if ($this->decodedArray) return $this->decodedArray; 44 | return ($this->decodedArray = json_decode($this->buffer, true)); 45 | } 46 | 47 | #[Pure] public function packetIntent(): IntentMessageBuffer { 48 | return IntentMessageBuffer::fromMessageBuffer($this); 49 | } 50 | 51 | public function __toString(): string { 52 | return $this->buffer; 53 | } 54 | 55 | /** 56 | * @return int 57 | */ 58 | public function getReceiveTimestamp(): int { 59 | return $this->receiveTimestamp; 60 | } 61 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/utils/CollectionNotifier.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\utils; 18 | 19 | use Closure; 20 | 21 | final class CollectionNotifier extends Collection { 22 | 23 | /** 24 | * @var Collection $setListener 25 | * @phpstan-var Collection 26 | */ 27 | private Collection $setListener; 28 | 29 | /** 30 | * @var Collection $removeListener 31 | * @phpstan-var Collection 32 | */ 33 | private Collection $removeListener; 34 | 35 | public function __construct(array $array = []) { 36 | parent::__construct($array); 37 | $this->setListener = new Collection(); 38 | $this->removeListener = new Collection(); 39 | } 40 | 41 | public function registerSetListener(Closure $closure): void { 42 | $this->setListener->add($closure); 43 | } 44 | 45 | public function registerRemoveListener(Closure $closure): void { 46 | $this->removeListener->add($closure); 47 | } 48 | 49 | public function set(mixed $key, mixed $value): void { 50 | parent::set($key, $value); 51 | $this->setListener->foreach(fn(Closure $closure) => $closure($key, $value)); 52 | } 53 | 54 | public function unset(mixed $key): bool { 55 | $result = parent::unset($key); 56 | $this->removeListener->foreach(fn(Closure $closure) => $closure($key)); 57 | return $result; 58 | } 59 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/voice/VoiceRequestPool.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\voice; 18 | 19 | use phpcord\utils\Collection; 20 | use phpcord\utils\SingletonTrait; 21 | 22 | final class VoiceRequestPool { 23 | use SingletonTrait; 24 | 25 | /** 26 | * @var Collection $requests 27 | * @phpstan-var Collection< 28 | */ 29 | private Collection $requests; 30 | 31 | public function __construct() { 32 | $this->requests = new Collection(); 33 | } 34 | 35 | /** 36 | * @param VoiceRequest $request 37 | * 38 | * @return void 39 | */ 40 | public function addRequest(VoiceRequest $request): void { 41 | $this->requests->set($request->guildId, $request); 42 | } 43 | 44 | /** 45 | * @param int $guildId 46 | * 47 | * @return VoiceRequest|null 48 | */ 49 | public function getRequest(int $guildId): ?VoiceRequest { 50 | return $this->requests->get($guildId); 51 | } 52 | 53 | /** 54 | * @param int|VoiceRequest $request 55 | * 56 | * @return void 57 | */ 58 | public function removeRequest(int|VoiceRequest $request): void { 59 | $this->requests->unset(($request instanceof VoiceRequest ? $request->guildId : $request)); 60 | } 61 | 62 | /** 63 | * @return Collection 64 | */ 65 | public function getRequests(): Collection { 66 | return $this->requests; 67 | } 68 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/channel/types/guild/thread/ThreadMember.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\channel\types\guild\thread; 18 | 19 | use phpcord\utils\Timestamp; 20 | use phpcord\utils\Utils; 21 | 22 | class ThreadMember { 23 | 24 | /** 25 | * @param int $id 26 | * @param int $threadId 27 | * @param Timestamp $joinTimestamp 28 | * @param int $flags 29 | */ 30 | public function __construct(private int $id, private int $threadId, private Timestamp $joinTimestamp, private int $flags) { } 31 | 32 | /** 33 | * @return int 34 | */ 35 | public function getId(): int { 36 | return $this->id; 37 | } 38 | 39 | /** 40 | * @return int 41 | */ 42 | public function getThreadId(): int { 43 | return $this->threadId; 44 | } 45 | 46 | /** 47 | * @return Timestamp 48 | */ 49 | public function getJoinTimestamp(): Timestamp { 50 | return $this->joinTimestamp; 51 | } 52 | 53 | /** 54 | * @return int 55 | */ 56 | public function getFlags(): int { 57 | return $this->flags; 58 | } 59 | 60 | public static function fromArray(array $array): ?ThreadMember { 61 | if (!Utils::contains($array, 'user_id', 'id', 'flags', 'join_timestamp')) return null; 62 | return new ThreadMember($array['user_id'], $array['id'], Timestamp::fromDate($array['join_timestamp']), $array['flags']); 63 | } 64 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # phpcord v3 2 | 3 | Discord 4 | 5 | ## Into 6 | Phpcord is an unofficial [Discord API](https://discord.com/developers/docs) wrapper that allows you to simply create bots for Discord servers. 7 | 8 | v3 is the successor of v1 (and phpcord v2 which was never finished) 9 | 10 | The leading difference between those two versions (v1 -> v3) is mainly a better network handling, faster tick and asynchronous webapi - requests. 11 | 12 | v3 also supports way more features than the older versions, it supports (except voice) nearly every single feature available in the latest discord version, which makes it a great alternative to other discord libraries. 13 | 14 | ##Features 15 | 16 | ✅ Asynchronous 17 | 18 | ✅ Fast and reliable - Tick speed increased + much more performant with less resources 19 | 20 | ✅ Slash Command and Message Component support 21 | 22 | ✅ Discord Threads 23 | 24 | ✅ Easy and documented API 25 | 26 | ❌ Voice Support (not yet, this might follow in a future update) 27 | 28 | ## Installation 29 | You can simply download this repository from GitHub and drop it into your local folder, it does not require any composer installations but can be installed via composer. 30 | Edit index.php as a starting point for your projects or create a new file. 31 | 32 | ## API Documentation 33 | *Soon.* 34 | 35 | ## Requirements 36 | - PHP Version: >= [8.0](https://www.php.net/downloads) 37 | - Required Extensions: [ext-sockets](https://www.php.net/manual/sockets.installation.php), [ext-pthreads](https://pecl.php.net/package/pthreads), [ext-curl](https://www.php.net/manual/curl.installation.php), [ext-openssl](https://www.php.net/manual/openssl.installation.php) 38 | - 1GB RAM (real usage depends on bot size) -------------------------------------------------------------------------------- /phpcord/src/phpcord/message/component/ActionRow.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\message\component; 18 | 19 | use JetBrains\PhpStorm\ArrayShape; 20 | use phpcord\utils\Collection; 21 | 22 | class ActionRow implements IComponent { 23 | 24 | /** 25 | * @var Collection $components 26 | * @phpstan-var Collection 27 | */ 28 | private Collection $components; 29 | 30 | /** 31 | * @param IChildComponent[] $components 32 | */ 33 | public function __construct(array $components = []) { 34 | $this->components = new Collection($components); 35 | $this->validate(); 36 | } 37 | 38 | /** 39 | * @param IChildComponent $component 40 | * 41 | * @return ActionRow 42 | */ 43 | public function add(IChildComponent $component): ActionRow { 44 | $this->components->add($component); 45 | $this->validate(); 46 | return $this; 47 | } 48 | 49 | public static function new(IChildComponent ...$components): ActionRow { 50 | return new ActionRow($components); 51 | } 52 | 53 | private function validate(): void { 54 | // todo 55 | } 56 | 57 | #[ArrayShape(['type' => "int", 'components' => "phpcord\message\component\Button[]"])] 58 | public function jsonSerialize(): array { 59 | return [ 60 | 'type' => ComponentTypes::ACTION_ROW(), 61 | 'components' => array_values($this->components->asArray()) 62 | ]; 63 | } 64 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/intent/impl/MessageHandler.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\intent\impl; 18 | 19 | use phpcord\channel\Channel; 20 | use phpcord\channel\TextChannel; 21 | use phpcord\event\message\MessageDeleteEvent; 22 | use phpcord\event\message\MessageSendEvent; 23 | use phpcord\event\message\MessageEditEvent; 24 | use phpcord\intent\IntentHandler; 25 | use phpcord\intent\Intents; 26 | use phpcord\message\Message; 27 | use phpcord\runtime\network\packet\IntentMessageBuffer; 28 | use phpcord\utils\Utils; 29 | 30 | class MessageHandler implements IntentHandler { 31 | 32 | public function handle(IntentMessageBuffer $buffer): void { 33 | switch ($buffer->name()) { 34 | case Intents::MESSAGE_CREATE(): 35 | if ($message = Message::fromArray($buffer->data())) (new MessageSendEvent($message))->call(); 36 | break; 37 | 38 | case Intents::MESSAGE_UPDATE(): 39 | if ($message = Message::fromArray($buffer->data())) (new MessageEditEvent($message))->call(); 40 | break; 41 | 42 | case Intents::MESSAGE_DELETE(): 43 | if (Utils::contains(($d = $buffer->data()), 'id', 'channel_id')) { 44 | $event = new MessageDeleteEvent(@$d['guild_id'], $d['channel_id'], $d['id']); 45 | $event->getChannel()->then(fn(?TextChannel $channel) => $channel?->onMessageDelete($d['id'])); 46 | $event->call(); 47 | } 48 | break; 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/runtime/network/opcode/HelloHandler.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\runtime\network\opcode; 18 | 19 | use phpcord\Discord; 20 | use phpcord\intent\Intents; 21 | use phpcord\runtime\network\MessageSender; 22 | use phpcord\runtime\network\Network; 23 | use phpcord\runtime\network\packet\MessageBuffer; 24 | use phpcord\runtime\network\packet\ResumePacket; 25 | use phpcord\runtime\network\packet\IdentifyPacket; 26 | 27 | class HelloHandler extends OpCodeHandler { 28 | 29 | public function getOpCode(): int { 30 | return Opcodes::HELLO(); 31 | } 32 | 33 | /** 34 | * @param MessageSender $sender 35 | * @param MessageBuffer $buffer 36 | * 37 | * @return void 38 | */ 39 | public function handle(MessageSender $sender, MessageBuffer $buffer): void { 40 | $details = Network::getInstance()->getGateway()->getSessionDetails(); 41 | $details->heartbeatInterval = $buffer->asArray()['d']['heartbeat_interval']; 42 | Network::getInstance()->getGateway()->startHeartbeatTask(); 43 | if ($details->completed()) { 44 | $sender->sendPacket(new ResumePacket(Discord::getInstance()->getToken(), Network::getInstance()->getGateway()->getSessionDetails()->sessionId, Network::getInstance()->getGateway()->getLastSequence())); 45 | return; 46 | } 47 | $sender->sendPacket(new IdentifyPacket(Discord::getInstance()->getToken(), Intents::all())); 48 | } 49 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/guild/auditlog/AuditLog.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\guild\auditlog; 18 | 19 | use phpcord\user\User; 20 | use phpcord\utils\Collection; 21 | use phpcord\utils\Factory; 22 | 23 | class AuditLog { 24 | 25 | /** 26 | * @var Collection $entries 27 | * @phpstan-var Collection 28 | */ 29 | private Collection $entries; 30 | 31 | /** 32 | * @var Collection $users 33 | * @phpstan-var Collection 34 | */ 35 | private Collection $users; 36 | 37 | /** 38 | * @param AuditLogEntry[] $entries 39 | * @param User[] $users 40 | * @param array $guildScheduledEvents 41 | * @param array $webhooks 42 | */ 43 | public function __construct(array $entries, array $users, array $guildScheduledEvents = [], array $webhooks = []) { 44 | $this->entries = new Collection($entries); 45 | $this->users = new Collection($users); 46 | } 47 | 48 | /** 49 | * @return Collection 50 | */ 51 | public function getEntries(): Collection { 52 | return $this->entries; 53 | } 54 | 55 | /** 56 | * @return Collection 57 | */ 58 | public function getUsers(): Collection { 59 | return $this->users; 60 | } 61 | 62 | public static function fromArray(array $array): AuditLog { 63 | return new AuditLog(Factory::createAuditLogEntryArray($array['audit_log_entries']), Factory::createUserArray($array['users'])); 64 | } 65 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/utils/time/TimePeriodMap.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\utils\time; 18 | 19 | use Closure; 20 | use phpcord\utils\Collection; 21 | use phpcord\utils\SingletonTrait; 22 | use function floor; 23 | use function is_array; 24 | use function str_replace; 25 | 26 | final class TimePeriodMap { 27 | use SingletonTrait; 28 | 29 | private Collection $patterns; 30 | 31 | public function __construct() { 32 | $this->patterns = new Collection(); 33 | $this->loadPatterns(); 34 | } 35 | 36 | private function loadPatterns(): void { 37 | $this->registerPattern('%h', fn(int $seconds) => floor($seconds / 3600) % 24); 38 | $this->registerPattern('%i', fn(int $seconds) => floor($seconds / 60) % 60); 39 | $this->registerPattern('%s', fn(int $seconds) => $seconds % 60); 40 | $this->registerPattern('%d', fn(int $seconds) => floor($seconds / 86400)); 41 | } 42 | 43 | public function registerPattern(string|array $patterns, Closure $closure): void { 44 | foreach ((is_array($patterns) ? $patterns : [$patterns]) as $pattern) 45 | $this->patterns->set($pattern, $closure); 46 | } 47 | 48 | public function apply(int $seconds, string $format): string { 49 | $this->patterns->foreach(function (string $key, Closure $mapping) use ($seconds, &$format): void { 50 | $format = str_replace($key, $mapping($seconds), $format); 51 | }); 52 | return $format; 53 | } 54 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/interaction/slash/options/IntegerCommandOption.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\interaction\slash\options; 18 | 19 | use JetBrains\PhpStorm\ArrayShape; 20 | use JetBrains\PhpStorm\Pure; 21 | use phpcord\interaction\slash\SlashCommandChoice; 22 | 23 | class IntegerCommandOption extends SlashCommandOption { 24 | 25 | /** @var SlashCommandChoice[] $choices */ 26 | private array $choices; 27 | 28 | /** 29 | * @param string $name 30 | * @param string $description 31 | * @param bool $required 32 | * @param int|null $min 33 | * @param int|null $max 34 | * @param array $choices 35 | * @param bool $autocomplete todo: implement this 36 | */ 37 | #[Pure] public function __construct(string $name, string $description, bool $required = false, private ?int $min = null, private ?int $max = null, array $choices = [], private bool $autocomplete = false) { 38 | parent::__construct($name, $description, $required); 39 | $this->choices = SlashCommandChoice::createOptionArray($choices); 40 | } 41 | 42 | public function getType(): int { 43 | return SlashCommandOptionTypes::INTEGER(); 44 | } 45 | 46 | #[ArrayShape(['min_value' => "int|null", 'max_value' => "int|null", 'choices' => "array"])] public function serializeOther(): array { 47 | return [ 48 | 'min_value' => $this->min, 49 | 'max_value' => $this->max, 50 | 'choices' => $this->choices 51 | ]; 52 | } 53 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/utils/Regex.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\utils; 18 | 19 | use function in_array; 20 | use function preg_match; 21 | use function preg_match_all; 22 | use function preg_replace; 23 | use function preg_split; 24 | 25 | class Regex { 26 | 27 | /** 28 | * @param string $string 29 | * @param string $pattern 30 | * 31 | * @return array 32 | */ 33 | public static function split(string $string, string $pattern): array { 34 | return preg_split($pattern, $string); 35 | } 36 | 37 | /** 38 | * @param string $string 39 | * @param string $pattern 40 | * 41 | * @return bool 42 | */ 43 | public static function match(string $string, string $pattern): bool { 44 | return (preg_match($pattern, $string, $matches) === 1 and in_array($string, $matches, true)); 45 | } 46 | 47 | /** 48 | * @param string $string 49 | * @param string $pattern 50 | * 51 | * @return array 52 | */ 53 | public static function matchAll(string $string, string $pattern): array { 54 | return (preg_match_all($pattern, $string, $matches) ? $matches[0] : []); 55 | } 56 | 57 | /** 58 | * @param string $string 59 | * @param string $pattern 60 | * @param string $replacement 61 | * 62 | * @return string 63 | */ 64 | public static function replace(string $string, string $pattern, string $replacement): string { 65 | return preg_replace($pattern, $replacement, $string); 66 | } 67 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/interaction/slash/options/NumberCommandOption.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\interaction\slash\options; 18 | 19 | use JetBrains\PhpStorm\ArrayShape; 20 | use JetBrains\PhpStorm\Pure; 21 | use phpcord\interaction\slash\SlashCommandChoice; 22 | 23 | class NumberCommandOption extends SlashCommandOption { 24 | 25 | /** @var SlashCommandChoice[] $choices */ 26 | private array $choices; 27 | 28 | /** 29 | * @param string $name 30 | * @param string $description 31 | * @param bool $required 32 | * @param float|null $min 33 | * @param float|null $max 34 | * @param array $choices 35 | * @param bool $autocomplete todo: implement this 36 | */ 37 | #[Pure] public function __construct(string $name, string $description, bool $required = false, private ?float $min = null, private ?float $max = null, array $choices = [], private bool $autocomplete = false) { 38 | parent::__construct($name, $description, $required); 39 | $this->choices = SlashCommandChoice::createOptionArray($choices); 40 | } 41 | 42 | public function getType(): int { 43 | return SlashCommandOptionTypes::NUMBER(); 44 | } 45 | 46 | #[ArrayShape(['min_value' => "float|null", 'max_value' => "float|null", 'choices' => "array"])] public function serializeOther(): array { 47 | return [ 48 | 'min_value' => $this->min, 49 | 'max_value' => $this->max, 50 | 'choices' => $this->choices 51 | ]; 52 | } 53 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/intent/impl/MemberHandler.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\intent\impl; 18 | 19 | use phpcord\event\member\MemberAddEvent; 20 | use phpcord\event\member\MemberRemoveEvent; 21 | use phpcord\event\member\MemberUpdateEvent; 22 | use phpcord\guild\GuildMember; 23 | use phpcord\intent\IntentHandler; 24 | use phpcord\intent\Intents; 25 | use phpcord\runtime\network\packet\IntentMessageBuffer; 26 | 27 | class MemberHandler implements IntentHandler { 28 | 29 | public function handle(IntentMessageBuffer $buffer): void { 30 | switch ($buffer->name()) { 31 | case Intents::GUILD_MEMBER_ADD(): 32 | (new MemberAddEvent($member = GuildMember::fromArray($buffer->data())))->call(); 33 | $member->getGuild()->getMembers()->set($member->getId(), $member); 34 | break; 35 | 36 | case Intents::GUILD_MEMBER_UPDATE(): 37 | $member = GuildMember::fromArray($buffer->data()); 38 | if (!$member->getGuild()) return; // this is an unexpected case 39 | (new MemberUpdateEvent($member->getGuild()->getMembers()->get($member->getId()), $member))->call(); 40 | $member->getGuild()->getMembers()->set($member->getId(), $member); 41 | break; 42 | 43 | case Intents::GUILD_MEMBER_REMOVE(): 44 | (new MemberRemoveEvent($member = GuildMember::fromArray($buffer->data())))->call(); 45 | $member->getGuild()->getMembers()->set($member->getId(), $member); 46 | break; 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/message/component/ComponentMap.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\message\component; 18 | 19 | use phpcord\interaction\component\TextInput; 20 | use phpcord\utils\Collection; 21 | use phpcord\utils\SingletonTrait; 22 | 23 | final class ComponentMap { 24 | use SingletonTrait; 25 | 26 | /** 27 | * @var Collection $components 28 | * @phpstan-var Collection<> 29 | */ 30 | private Collection $components; 31 | 32 | public function __construct() { 33 | $this->components = new Collection(); 34 | 35 | $this->register(ComponentTypes::ACTION_ROW(), ActionRow::class); 36 | $this->register(ComponentTypes::BUTTON(), Button::class); 37 | $this->register(ComponentTypes::SELECT_MENU(), SelectMenu::class); 38 | $this->register(ComponentTypes::TEXT_INPUT(), TextInput::class); 39 | } 40 | 41 | /** 42 | * @param int $type 43 | * 44 | * @param string $component 45 | * @phpstan-param class-string 46 | * 47 | * @return void 48 | */ 49 | public function register(int $type, string $component): void { 50 | $this->components->set($type, $component); 51 | } 52 | 53 | /** 54 | * @param int $type 55 | * 56 | * @return string|null 57 | * @phpstan-return class-string|null 58 | */ 59 | public function get(int $type): ?string { 60 | return $this->components->get($type); 61 | } 62 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/message/MessageReference.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\message; 18 | 19 | use JetBrains\PhpStorm\ArrayShape; 20 | use JetBrains\PhpStorm\Pure; 21 | use JsonSerializable; 22 | 23 | final class MessageReference implements JsonSerializable { 24 | 25 | /** 26 | * @param int $id 27 | * @param int|null $channelId 28 | * @param int|null $guildId 29 | */ 30 | public function __construct(private int $id, private ?int $channelId = null, private ?int $guildId = null) { } 31 | 32 | /** 33 | * @param Message $message 34 | * 35 | * @return MessageReference 36 | */ 37 | #[Pure] public static function fromMessage(Message $message): MessageReference { 38 | return new MessageReference($message->getId(), $message->getChannelId(), $message->getGuildId()); 39 | } 40 | 41 | /** 42 | * @return int 43 | */ 44 | public function getId(): int { 45 | return $this->id; 46 | } 47 | 48 | /** 49 | * @return int|null 50 | */ 51 | public function getGuildId(): ?int { 52 | return $this->guildId; 53 | } 54 | 55 | /** 56 | * @return int 57 | */ 58 | public function getChannelId(): int { 59 | return $this->channelId; 60 | } 61 | 62 | #[ArrayShape(['message_id' => "int", 'channel_id' => "int", 'guild_id' => "int|null"])] public function jsonSerialize(): array { 63 | return [ 64 | 'message_id' => $this->id, 65 | 'channel_id' => $this->channelId, 66 | 'guild_id' => $this->guildId 67 | ]; 68 | } 69 | } -------------------------------------------------------------------------------- /phpcord/src/phpcord/message/sendable/parts/EmbedAuthor.php: -------------------------------------------------------------------------------- 1 | >| Y \| |_> >\ \___( <_> )| | \// /_/ | 8 | * | __/ |___| /| __/ \___ >\____/ |__| \____ | 9 | * |__| \/ |__| \/ \/ 10 | * 11 | * 12 | * This library is developed by HimmelKreis4865 © 2022 13 | * 14 | * https://github.com/HimmelKreis4865/phpcord 15 | */ 16 | 17 | namespace phpcord\message\sendable\parts; 18 | 19 | use JetBrains\PhpStorm\ArrayShape; 20 | use JsonSerializable; 21 | 22 | class EmbedAuthor implements JsonSerializable { 23 | 24 | /** 25 | * @param string $name 26 | * @param string|null $url 27 | * @param string|null $iconUrl An url or attachment 28 | * @param string|null $proxyIconUrl 29 | */ 30 | public function __construct(private string $name, private ?string $url = null, private ?string $iconUrl = null, private ?string $proxyIconUrl = null) { } 31 | 32 | /** 33 | * @return string 34 | */ 35 | public function getName(): string { 36 | return $this->name; 37 | } 38 | 39 | /** 40 | * @return string|null 41 | */ 42 | public function getUrl(): ?string { 43 | return $this->url; 44 | } 45 | 46 | /** 47 | * @return string|null 48 | */ 49 | public function getIconUrl(): ?string { 50 | return $this->iconUrl; 51 | } 52 | 53 | /** 54 | * @return string|null 55 | */ 56 | public function getProxyIconUrl(): ?string { 57 | return $this->proxyIconUrl; 58 | } 59 | 60 | #[ArrayShape(['name' => "string", 'url' => "null|string", 'icon_url' => "null|string", 'proxy_icon_url' => "null|string"])] 61 | public function jsonSerialize(): array { 62 | return [ 63 | 'name' => $this->name, 64 | 'url' => $this->url, 65 | 'icon_url' => $this->iconUrl, 66 | 'proxy_icon_url' => $this->proxyIconUrl 67 | ]; 68 | } 69 | } --------------------------------------------------------------------------------