@@ -144,52 +144,48 @@ public function handle()
144
144
$ name = $ log ->cid ;
145
145
}
146
146
147
- // Discord ID is not null (message has not yet been sent)
148
- if ($ log ->discord_id !== null ){
149
- // Update Disconnect Message
150
- try {
151
- $ discord = new DiscordClient ();
152
- $ data = $ discord ->ControllerDisconnect ($ log ->discord_id , $ log ->callsign , $ name , $ log ->session_start , $ log ->duration );
153
- } catch (\Exception $ e ) {
154
- $ discord = new DiscordClient ();
155
- $ discord ->sendMessageWithEmbed (env ('DISCORD_WEB_LOGS ' ), 'Discord Controller Disconnect Error ' , $ e ->getMessage ());
156
- }
157
-
158
- // Remove Discord Role
159
- if ($ log ->user && $ log ->user ->hasDiscord () && $ log ->user ->member_of_czqo ){
160
- $ discord = new DiscordClient ();
161
-
162
- $ discord ->removeRole ($ log ->user ->discord_user_id , '1278868454606377040 ' );
163
- }
164
- }
165
-
166
- $ log ->discord_id = null ;
167
- $ log ->save ;
168
-
169
- //If there is an associated roster member, give them the hours and set as active
170
- if ($ rosterMember = $ log ->rosterMember ) {
171
-
172
- // Set variables
173
- $ currency = $ log ->session_start ->floatDiffInMinutes (Carbon::now ()) / 60 ;
174
- $ monthly_hours = $ log ->session_start ->floatDiffInMinutes (Carbon::now ()) / 60 ;
147
+ // Check if Controller is Authorised to open a position (training/certified)
148
+ if (in_array ($ session ->cid , $ allRoster )) {
149
+ // Controller is authorised, send message if discord_id is not set
150
+ if ($ session ->discord_id == null ){
151
+ // Discord Message
152
+ try {
153
+ $ discord = new DiscordClient ();
154
+ $ discord_id = $ discord ->ControllerConnection ($ controller ->callsign , $ name );
155
+
156
+ $ session ->discord_id = $ discord_id ;
157
+ $ session ->save ();
158
+ } catch (\Exception $ e ) {
159
+ $ discord = new DiscordClient ();
160
+ $ discord ->sendMessageWithEmbed (env ('DISCORD_WEB_LOGS ' ), 'Discord Controller Connect Error ' , $ e ->getMessage ());
161
+ }
175
162
176
- // Controller is either Certified or In Training
177
- if (($ rosterMember ->certification == 'certified ' || $ rosterMember ->certification == 'training ' )) {
163
+ // Add Discord Role
164
+ if ($ session ->user && $ session ->user ->hasDiscord () && $ session ->user ->member_of_czqo ){
165
+ $ discord = new DiscordClient ();
178
166
179
- // Only add hours if more than 30mins (Disabled to 01mins until policy update)
180
- if ($ currency > 0.00 ){
181
- $ rosterMember ->currency += $ currency ;
182
- $ rosterMember ->monthly_hours += $ monthly_hours ;
183
- $ rosterMember ->save ();
167
+ $ discord ->assignRole ($ session ->user ->discord_user_id , '1278868454606377040 ' );
168
+ }
184
169
}
170
+ } else {
171
+ // Controller is not authorised. Let Senior Team know.
172
+ if ($ session ->discord_id == null ){
173
+ try {
174
+ // Send Discord Message
175
+ $ discord = new DiscordClient ();
176
+ $ discord_id = $ discord ->sendMessageWithEmbed ('482817715489341441 ' , 'Controller Unauthorised to Control ' , '<@&482816721280040964>, ' .$ session ->cid .' has just connected onto VATSIM as ' .$ session ->callsign .' on <t: ' .Carbon::now ()->timestamp .':F>.
177
+
178
+ **They are not authorised to open this position.** ' );
185
179
186
- // Set user as active if more than 1 hour
187
- if ($ rosterMember ->currency > 0.99 ){
188
- $ rosterMember ->active = 1 ;
189
- $ rosterMember ->save ();
180
+ // Save ID so it doesnt keep spamming
181
+ $ session ->discord_id = $ discord_id ;
182
+ $ session ->save ();
183
+ } catch (\Exception $ e ) {
184
+ $ discord = new DiscordClient ();
185
+ $ discord ->sendMessageWithEmbed (env ('DISCORD_WEB_LOGS ' ), 'Unauthorised Controller Notification Error ' , $ e ->getMessage ());
186
+ }
190
187
}
191
188
}
192
- }
193
189
}
194
190
}
195
191
}
0 commit comments