├── .gitignore ├── LICENSE ├── README.md ├── _update_helper.py ├── assets ├── Burbank.otf ├── ads │ └── _mike_DO_NOT_REMOVE.png ├── background.png ├── new_badge.png ├── overlay.png └── strings.yml ├── bot_helpers ├── exception_helper.py ├── image_helper.py ├── post_helper.py ├── rarity_helper.py ├── request_helper.py └── strings_helper.py ├── constants.py ├── example_results ├── leaks.jpg └── shop.jpg ├── leaks └── leaks.py ├── main.py ├── requirements.txt ├── shop └── shop.py ├── template.env ├── vbucks └── vbucks.py └── version.txt /.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | 3 | __pycache__/ 4 | .vscode/ 5 | 6 | old.zip 7 | temp/ 8 | result/ 9 | *.p 10 | 11 | chromedriver.exe -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Mozilla Public License Version 2.0 2 | ================================== 3 | 4 | 1. Definitions 5 | -------------- 6 | 7 | 1.1. "Contributor" 8 | means each individual or legal entity that creates, contributes to 9 | the creation of, or owns Covered Software. 10 | 11 | 1.2. "Contributor Version" 12 | means the combination of the Contributions of others (if any) used 13 | by a Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | means Covered Software of a particular Contributor. 17 | 18 | 1.4. "Covered Software" 19 | means Source Code Form to which the initial Contributor has attached 20 | the notice in Exhibit A, the Executable Form of such Source Code 21 | Form, and Modifications of such Source Code Form, in each case 22 | including portions thereof. 23 | 24 | 1.5. "Incompatible With Secondary Licenses" 25 | means 26 | 27 | (a) that the initial Contributor has attached the notice described 28 | in Exhibit B to the Covered Software; or 29 | 30 | (b) that the Covered Software was made available under the terms of 31 | version 1.1 or earlier of the License, but not also under the 32 | terms of a Secondary License. 33 | 34 | 1.6. "Executable Form" 35 | means any form of the work other than Source Code Form. 36 | 37 | 1.7. "Larger Work" 38 | means a work that combines Covered Software with other material, in 39 | a separate file or files, that is not Covered Software. 40 | 41 | 1.8. "License" 42 | means this document. 43 | 44 | 1.9. "Licensable" 45 | means having the right to grant, to the maximum extent possible, 46 | whether at the time of the initial grant or subsequently, any and 47 | all of the rights conveyed by this License. 48 | 49 | 1.10. "Modifications" 50 | means any of the following: 51 | 52 | (a) any file in Source Code Form that results from an addition to, 53 | deletion from, or modification of the contents of Covered 54 | Software; or 55 | 56 | (b) any new file in Source Code Form that contains any Covered 57 | Software. 58 | 59 | 1.11. "Patent Claims" of a Contributor 60 | means any patent claim(s), including without limitation, method, 61 | process, and apparatus claims, in any patent Licensable by such 62 | Contributor that would be infringed, but for the grant of the 63 | License, by the making, using, selling, offering for sale, having 64 | made, import, or transfer of either its Contributions or its 65 | Contributor Version. 66 | 67 | 1.12. "Secondary License" 68 | means either the GNU General Public License, Version 2.0, the GNU 69 | Lesser General Public License, Version 2.1, the GNU Affero General 70 | Public License, Version 3.0, or any later versions of those 71 | licenses. 72 | 73 | 1.13. "Source Code Form" 74 | means the form of the work preferred for making modifications. 75 | 76 | 1.14. "You" (or "Your") 77 | means an individual or a legal entity exercising rights under this 78 | License. For legal entities, "You" includes any entity that 79 | controls, is controlled by, or is under common control with You. For 80 | purposes of this definition, "control" means (a) the power, direct 81 | or indirect, to cause the direction or management of such entity, 82 | whether by contract or otherwise, or (b) ownership of more than 83 | fifty percent (50%) of the outstanding shares or beneficial 84 | ownership of such entity. 85 | 86 | 2. License Grants and Conditions 87 | -------------------------------- 88 | 89 | 2.1. Grants 90 | 91 | Each Contributor hereby grants You a world-wide, royalty-free, 92 | non-exclusive license: 93 | 94 | (a) under intellectual property rights (other than patent or trademark) 95 | Licensable by such Contributor to use, reproduce, make available, 96 | modify, display, perform, distribute, and otherwise exploit its 97 | Contributions, either on an unmodified basis, with Modifications, or 98 | as part of a Larger Work; and 99 | 100 | (b) under Patent Claims of such Contributor to make, use, sell, offer 101 | for sale, have made, import, and otherwise transfer either its 102 | Contributions or its Contributor Version. 103 | 104 | 2.2. Effective Date 105 | 106 | The licenses granted in Section 2.1 with respect to any Contribution 107 | become effective for each Contribution on the date the Contributor first 108 | distributes such Contribution. 109 | 110 | 2.3. Limitations on Grant Scope 111 | 112 | The licenses granted in this Section 2 are the only rights granted under 113 | this License. No additional rights or licenses will be implied from the 114 | distribution or licensing of Covered Software under this License. 115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 116 | Contributor: 117 | 118 | (a) for any code that a Contributor has removed from Covered Software; 119 | or 120 | 121 | (b) for infringements caused by: (i) Your and any other third party's 122 | modifications of Covered Software, or (ii) the combination of its 123 | Contributions with other software (except as part of its Contributor 124 | Version); or 125 | 126 | (c) under Patent Claims infringed by Covered Software in the absence of 127 | its Contributions. 128 | 129 | This License does not grant any rights in the trademarks, service marks, 130 | or logos of any Contributor (except as may be necessary to comply with 131 | the notice requirements in Section 3.4). 132 | 133 | 2.4. Subsequent Licenses 134 | 135 | No Contributor makes additional grants as a result of Your choice to 136 | distribute the Covered Software under a subsequent version of this 137 | License (see Section 10.2) or under the terms of a Secondary License (if 138 | permitted under the terms of Section 3.3). 139 | 140 | 2.5. Representation 141 | 142 | Each Contributor represents that the Contributor believes its 143 | Contributions are its original creation(s) or it has sufficient rights 144 | to grant the rights to its Contributions conveyed by this License. 145 | 146 | 2.6. Fair Use 147 | 148 | This License is not intended to limit any rights You have under 149 | applicable copyright doctrines of fair use, fair dealing, or other 150 | equivalents. 151 | 152 | 2.7. Conditions 153 | 154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted 155 | in Section 2.1. 156 | 157 | 3. Responsibilities 158 | ------------------- 159 | 160 | 3.1. Distribution of Source Form 161 | 162 | All distribution of Covered Software in Source Code Form, including any 163 | Modifications that You create or to which You contribute, must be under 164 | the terms of this License. You must inform recipients that the Source 165 | Code Form of the Covered Software is governed by the terms of this 166 | License, and how they can obtain a copy of this License. You may not 167 | attempt to alter or restrict the recipients' rights in the Source Code 168 | Form. 169 | 170 | 3.2. Distribution of Executable Form 171 | 172 | If You distribute Covered Software in Executable Form then: 173 | 174 | (a) such Covered Software must also be made available in Source Code 175 | Form, as described in Section 3.1, and You must inform recipients of 176 | the Executable Form how they can obtain a copy of such Source Code 177 | Form by reasonable means in a timely manner, at a charge no more 178 | than the cost of distribution to the recipient; and 179 | 180 | (b) You may distribute such Executable Form under the terms of this 181 | License, or sublicense it under different terms, provided that the 182 | license for the Executable Form does not attempt to limit or alter 183 | the recipients' rights in the Source Code Form under this License. 184 | 185 | 3.3. Distribution of a Larger Work 186 | 187 | You may create and distribute a Larger Work under terms of Your choice, 188 | provided that You also comply with the requirements of this License for 189 | the Covered Software. If the Larger Work is a combination of Covered 190 | Software with a work governed by one or more Secondary Licenses, and the 191 | Covered Software is not Incompatible With Secondary Licenses, this 192 | License permits You to additionally distribute such Covered Software 193 | under the terms of such Secondary License(s), so that the recipient of 194 | the Larger Work may, at their option, further distribute the Covered 195 | Software under the terms of either this License or such Secondary 196 | License(s). 197 | 198 | 3.4. Notices 199 | 200 | You may not remove or alter the substance of any license notices 201 | (including copyright notices, patent notices, disclaimers of warranty, 202 | or limitations of liability) contained within the Source Code Form of 203 | the Covered Software, except that You may alter any license notices to 204 | the extent required to remedy known factual inaccuracies. 205 | 206 | 3.5. Application of Additional Terms 207 | 208 | You may choose to offer, and to charge a fee for, warranty, support, 209 | indemnity or liability obligations to one or more recipients of Covered 210 | Software. However, You may do so only on Your own behalf, and not on 211 | behalf of any Contributor. You must make it absolutely clear that any 212 | such warranty, support, indemnity, or liability obligation is offered by 213 | You alone, and You hereby agree to indemnify every Contributor for any 214 | liability incurred by such Contributor as a result of warranty, support, 215 | indemnity or liability terms You offer. You may include additional 216 | disclaimers of warranty and limitations of liability specific to any 217 | jurisdiction. 218 | 219 | 4. Inability to Comply Due to Statute or Regulation 220 | --------------------------------------------------- 221 | 222 | If it is impossible for You to comply with any of the terms of this 223 | License with respect to some or all of the Covered Software due to 224 | statute, judicial order, or regulation then You must: (a) comply with 225 | the terms of this License to the maximum extent possible; and (b) 226 | describe the limitations and the code they affect. Such description must 227 | be placed in a text file included with all distributions of the Covered 228 | Software under this License. Except to the extent prohibited by statute 229 | or regulation, such description must be sufficiently detailed for a 230 | recipient of ordinary skill to be able to understand it. 231 | 232 | 5. Termination 233 | -------------- 234 | 235 | 5.1. The rights granted under this License will terminate automatically 236 | if You fail to comply with any of its terms. However, if You become 237 | compliant, then the rights granted under this License from a particular 238 | Contributor are reinstated (a) provisionally, unless and until such 239 | Contributor explicitly and finally terminates Your grants, and (b) on an 240 | ongoing basis, if such Contributor fails to notify You of the 241 | non-compliance by some reasonable means prior to 60 days after You have 242 | come back into compliance. Moreover, Your grants from a particular 243 | Contributor are reinstated on an ongoing basis if such Contributor 244 | notifies You of the non-compliance by some reasonable means, this is the 245 | first time You have received notice of non-compliance with this License 246 | from such Contributor, and You become compliant prior to 30 days after 247 | Your receipt of the notice. 248 | 249 | 5.2. If You initiate litigation against any entity by asserting a patent 250 | infringement claim (excluding declaratory judgment actions, 251 | counter-claims, and cross-claims) alleging that a Contributor Version 252 | directly or indirectly infringes any patent, then the rights granted to 253 | You by any and all Contributors for the Covered Software under Section 254 | 2.1 of this License shall terminate. 255 | 256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all 257 | end user license agreements (excluding distributors and resellers) which 258 | have been validly granted by You or Your distributors under this License 259 | prior to termination shall survive termination. 260 | 261 | ************************************************************************ 262 | * * 263 | * 6. Disclaimer of Warranty * 264 | * ------------------------- * 265 | * * 266 | * Covered Software is provided under this License on an "as is" * 267 | * basis, without warranty of any kind, either expressed, implied, or * 268 | * statutory, including, without limitation, warranties that the * 269 | * Covered Software is free of defects, merchantable, fit for a * 270 | * particular purpose or non-infringing. The entire risk as to the * 271 | * quality and performance of the Covered Software is with You. * 272 | * Should any Covered Software prove defective in any respect, You * 273 | * (not any Contributor) assume the cost of any necessary servicing, * 274 | * repair, or correction. This disclaimer of warranty constitutes an * 275 | * essential part of this License. No use of any Covered Software is * 276 | * authorized under this License except under this disclaimer. * 277 | * * 278 | ************************************************************************ 279 | 280 | ************************************************************************ 281 | * * 282 | * 7. Limitation of Liability * 283 | * -------------------------- * 284 | * * 285 | * Under no circumstances and under no legal theory, whether tort * 286 | * (including negligence), contract, or otherwise, shall any * 287 | * Contributor, or anyone who distributes Covered Software as * 288 | * permitted above, be liable to You for any direct, indirect, * 289 | * special, incidental, or consequential damages of any character * 290 | * including, without limitation, damages for lost profits, loss of * 291 | * goodwill, work stoppage, computer failure or malfunction, or any * 292 | * and all other commercial damages or losses, even if such party * 293 | * shall have been informed of the possibility of such damages. This * 294 | * limitation of liability shall not apply to liability for death or * 295 | * personal injury resulting from such party's negligence to the * 296 | * extent applicable law prohibits such limitation. Some * 297 | * jurisdictions do not allow the exclusion or limitation of * 298 | * incidental or consequential damages, so this exclusion and * 299 | * limitation may not apply to You. * 300 | * * 301 | ************************************************************************ 302 | 303 | 8. Litigation 304 | ------------- 305 | 306 | Any litigation relating to this License may be brought only in the 307 | courts of a jurisdiction where the defendant maintains its principal 308 | place of business and such litigation shall be governed by laws of that 309 | jurisdiction, without reference to its conflict-of-law provisions. 310 | Nothing in this Section shall prevent a party's ability to bring 311 | cross-claims or counter-claims. 312 | 313 | 9. Miscellaneous 314 | ---------------- 315 | 316 | This License represents the complete agreement concerning the subject 317 | matter hereof. If any provision of this License is held to be 318 | unenforceable, such provision shall be reformed only to the extent 319 | necessary to make it enforceable. Any law or regulation which provides 320 | that the language of a contract shall be construed against the drafter 321 | shall not be used to construe this License against a Contributor. 322 | 323 | 10. Versions of the License 324 | --------------------------- 325 | 326 | 10.1. New Versions 327 | 328 | Mozilla Foundation is the license steward. Except as provided in Section 329 | 10.3, no one other than the license steward has the right to modify or 330 | publish new versions of this License. Each version will be given a 331 | distinguishing version number. 332 | 333 | 10.2. Effect of New Versions 334 | 335 | You may distribute the Covered Software under the terms of the version 336 | of the License under which You originally received the Covered Software, 337 | or under the terms of any subsequent version published by the license 338 | steward. 339 | 340 | 10.3. Modified Versions 341 | 342 | If you create software not governed by this License, and you want to 343 | create a new license for such software, you may create and use a 344 | modified version of this License if you rename the license and remove 345 | any references to the name of the license steward (except to note that 346 | such modified license differs from this License). 347 | 348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 349 | Licenses 350 | 351 | If You choose to distribute Source Code Form that is Incompatible With 352 | Secondary Licenses under the terms of this version of the License, the 353 | notice described in Exhibit B of this License must be attached. 354 | 355 | Exhibit A - Source Code Form License Notice 356 | ------------------------------------------- 357 | 358 | This Source Code Form is subject to the terms of the Mozilla Public 359 | License, v. 2.0. If a copy of the MPL was not distributed with this 360 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 361 | 362 | If it is not possible or desirable to put the notice in a particular 363 | file, then You may include the notice in a location (such as a LICENSE 364 | file in a relevant directory) where a recipient would be likely to look 365 | for such a notice. 366 | 367 | You may add additional accurate notices of copyright ownership. 368 | 369 | Exhibit B - "Incompatible With Secondary Licenses" Notice 370 | --------------------------------------------------------- 371 | 372 | This Source Code Form is "Incompatible With Secondary Licenses", as 373 | defined by the Mozilla Public License, v. 2.0. 374 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # How to run 2 | 1. Rename template.env to .env 3 | 2. Fill out the .env file 4 | 4. (Optional) Put your 512x512 PNG file inside the ads folder 5 | 5. Install the dependencies `pip install -r requirements.txt` 6 | 6. Run the main.py file 7 | 8 | ## Run in background in Linux 9 | `nohup python -u main.py & disown` 10 | 11 | ## Example results 12 | ### Shop 13 | ![Shop](https://raw.githubusercontent.com/Developer-Mike/FN-Bot/main/example_results/shop.jpg) 14 | 15 | #### Reply to the tweet with an image of returning items 16 | You can enable it in the .env file (`POST_RETURNING_ITEMS_AS_RESPONSE`) 17 | 18 | ### Leaks 19 | ![Leaks](https://raw.githubusercontent.com/Developer-Mike/FN-Bot/main/example_results/leaks.jpg) 20 | ### V-Bucks 21 | ``` 22 | New V-Bucks Missions for STW are available! 23 | 24 | Canny Valley: 60 25 | 26 | #Fortnite 27 | ``` 28 | -------------------------------------------------------------------------------- /_update_helper.py: -------------------------------------------------------------------------------- 1 | import requests, zipfile, io, os, shutil, glob, tempfile, dotenv 2 | 3 | CURRENT_DIR = os.path.dirname(os.path.abspath(__file__)) 4 | os.chdir(CURRENT_DIR) 5 | 6 | BACKUP_ZIP_PATH = os.path.join(CURRENT_DIR, "old.zip") 7 | TEMP_DIR = os.path.join(CURRENT_DIR, "temp") 8 | ASSETS_DIR = os.path.join(CURRENT_DIR, "assets") 9 | OLD_DOT_ENV_PATH = os.path.join(CURRENT_DIR, "old.env") 10 | DOT_ENV_PATH = os.path.join(CURRENT_DIR, ".env") 11 | GITHUB_REPO_URL = "https://github.com/Developer-Mike/FN-Bot/archive/refs/heads/main.zip" 12 | 13 | # Backup files 14 | if os.path.exists(BACKUP_ZIP_PATH): 15 | os.remove(BACKUP_ZIP_PATH) 16 | 17 | with tempfile.TemporaryDirectory() as temp_dir: 18 | BACKUP_ZIP_TEMP_PATH = shutil.make_archive(os.path.join(temp_dir, "old"), "zip", CURRENT_DIR) 19 | shutil.move(BACKUP_ZIP_TEMP_PATH, BACKUP_ZIP_PATH) 20 | 21 | # Download new files 22 | r = requests.get(GITHUB_REPO_URL) 23 | zip = zipfile.ZipFile(io.BytesIO(r.content)) 24 | zip.extractall(TEMP_DIR) 25 | 26 | NEW_DIR = os.path.join(TEMP_DIR, os.listdir(TEMP_DIR)[0]) 27 | TEMPLATE_DOT_ENV_PATH = os.path.join(NEW_DIR, "template.env") 28 | 29 | # Check if new version is available 30 | with open(os.path.join(CURRENT_DIR, "version.txt"), "r") as version_file: 31 | current_version = version_file.read().strip() 32 | with open(os.path.join(NEW_DIR, "version.txt"), "r") as version_file: 33 | new_version = version_file.read().strip() 34 | 35 | if current_version == new_version: 36 | print("You are already on the latest version.") 37 | exit() 38 | 39 | # Update py files 40 | for source_path in glob.glob(os.path.join(NEW_DIR, "**"), recursive=True): 41 | target_path = source_path.replace(NEW_DIR, CURRENT_DIR) 42 | 43 | # Skip directories 44 | if os.path.isdir(source_path): 45 | continue 46 | 47 | # Skip update helper 48 | if os.path.basename(source_path) == os.path.basename(__file__): 49 | continue 50 | 51 | # Dont replace assets 52 | if target_path.startswith(ASSETS_DIR) and os.path.exists(target_path): 53 | continue 54 | 55 | shutil.copy(source_path, target_path) 56 | 57 | # Update env file 58 | if os.path.exists(OLD_DOT_ENV_PATH): os.remove(OLD_DOT_ENV_PATH) 59 | os.rename(DOT_ENV_PATH, OLD_DOT_ENV_PATH) 60 | 61 | dotenv.load_dotenv(OLD_DOT_ENV_PATH) 62 | shutil.move(TEMPLATE_DOT_ENV_PATH, DOT_ENV_PATH) 63 | 64 | with open(DOT_ENV_PATH, "r") as env_file: 65 | new_env = env_file.readlines() 66 | 67 | with open(DOT_ENV_PATH, "w") as env_file: 68 | for i, line in enumerate(new_env): 69 | if line.startswith("#") or line == "": 70 | continue 71 | key = line.split("=")[0] 72 | 73 | if key in os.environ: 74 | new_env[i] = f"{key}={os.environ[key]}\n" 75 | 76 | env_file.write("".join(new_env)) 77 | 78 | shutil.rmtree(TEMP_DIR) -------------------------------------------------------------------------------- /assets/Burbank.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Developer-Mike/fn-bot/a6648bdb47f8347c9113b49bd2f2726c76842f8a/assets/Burbank.otf -------------------------------------------------------------------------------- /assets/ads/_mike_DO_NOT_REMOVE.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Developer-Mike/fn-bot/a6648bdb47f8347c9113b49bd2f2726c76842f8a/assets/ads/_mike_DO_NOT_REMOVE.png -------------------------------------------------------------------------------- /assets/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Developer-Mike/fn-bot/a6648bdb47f8347c9113b49bd2f2726c76842f8a/assets/background.png -------------------------------------------------------------------------------- /assets/new_badge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Developer-Mike/fn-bot/a6648bdb47f8347c9113b49bd2f2726c76842f8a/assets/new_badge.png -------------------------------------------------------------------------------- /assets/overlay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Developer-Mike/fn-bot/a6648bdb47f8347c9113b49bd2f2726c76842f8a/assets/overlay.png -------------------------------------------------------------------------------- /assets/strings.yml: -------------------------------------------------------------------------------- 1 | shop_post_caption: Shop of {date}\n\n#Fortnite 2 | returning_items_caption: The following items have returned to the shop after a long time!\n\n#Fortnite 3 | item_gone_duration: Gone for {days} days 4 | new_item: New Item 5 | 6 | leaks_post_caption: New leaks of {date}\n\n#Fortnite 7 | 8 | vbucks_text: New V-Bucks Missions for STW are available!\n\n{missions}\n\n#Fortnite -------------------------------------------------------------------------------- /bot_helpers/exception_helper.py: -------------------------------------------------------------------------------- 1 | import functools 2 | 3 | def catch_exceptions(on_exception=None): 4 | def catch_exceptions_decorator(job_func): 5 | @functools.wraps(job_func) 6 | def wrapper(self, *args, **kwargs): 7 | try: 8 | return job_func(self, *args, **kwargs) 9 | except: 10 | import traceback 11 | print(traceback.format_exc()) 12 | 13 | if on_exception is not None: 14 | on_exception(self) 15 | return wrapper 16 | return catch_exceptions_decorator -------------------------------------------------------------------------------- /bot_helpers/image_helper.py: -------------------------------------------------------------------------------- 1 | import requests, os, time 2 | from PIL import Image, UnidentifiedImageError 3 | from io import BytesIO 4 | 5 | import constants 6 | 7 | CORRUPTED_IMAGE_ERRORS = [OSError, UnidentifiedImageError, requests.exceptions.MissingSchema] 8 | 9 | def _from_url_unsafe(url, size=512, mode='RGBA'): 10 | response = requests.get(f"{url}?width={size}", stream=True) 11 | 12 | image = Image.open(BytesIO(response.content)) 13 | return image.convert(mode).resize((size, size), Image.Resampling.LANCZOS) 14 | 15 | def from_url(url, size=512, mode='RGBA'): 16 | try: return _from_url_unsafe(url, size, mode) 17 | except Exception as e: 18 | print(f"Error: {url} is not a valid image.") 19 | 20 | if not (constants.CONTINUE_ON_CORRUPTED_IMAGE and type(e) in CORRUPTED_IMAGE_ERRORS): 21 | raise e 22 | 23 | return Image.new(mode, (size, size), (0, 0, 0, 0)) 24 | 25 | def get_item_image(url, item_id, size=512, mode='RGBA'): 26 | try: 27 | return _from_url_unsafe(url, size, mode) 28 | except Exception as e: 29 | print(f"Error: {url} is not a valid image.") 30 | 31 | if not (constants.CONTINUE_ON_CORRUPTED_IMAGE and type(e) in CORRUPTED_IMAGE_ERRORS): 32 | raise e 33 | 34 | if constants.FALLBACK_IMAGE_FROM_FORTNITE_API: 35 | print("Using fallback image from fortnite-api.com") 36 | 37 | fallback_image_featured = f"https://fortnite-api.com/images/cosmetics/br/{item_id.lower()}/featured.png" 38 | try: return _from_url_unsafe(fallback_image_featured, size, mode) 39 | except: 40 | fallback_image_icon = f"https://fortnite-api.com/images/cosmetics/br/{item_id.lower()}/icon.png" 41 | try: return _from_url_unsafe(fallback_image_icon, size, mode) 42 | except: pass 43 | 44 | return Image.new(mode, (size, size), (0, 0, 0, 0)) 45 | 46 | def with_background(image, background): 47 | background = background.resize(image.size) 48 | background.paste(image, (0, 0), image) 49 | return background 50 | 51 | def from_path(path, size=512): 52 | image = Image.open(path).convert('RGBA') 53 | 54 | if size > 0: 55 | return image.resize((size, size), Image.Resampling.LANCZOS) 56 | else: 57 | return image 58 | 59 | def compress_image(image, save_path): 60 | image.save(save_path, optimize=True, quality=85) 61 | 62 | current_size = (image.width, image.height) 63 | size_step = 250 64 | size_limit = 3000000 65 | 66 | start_time = time.time() 67 | while os.path.getsize(save_path) > size_limit: 68 | image = image.resize(current_size, Image.Resampling.LANCZOS) 69 | image.save(save_path, optimize=True, quality=85) 70 | 71 | current_size[0] -= size_step 72 | current_size[1] -= size_step 73 | 74 | image.close() # Free memory 75 | print(f"Compressed image to {os.path.getsize(save_path)} bytes. Took {round(time.time() - start_time, 2)} seconds.") -------------------------------------------------------------------------------- /bot_helpers/post_helper.py: -------------------------------------------------------------------------------- 1 | import constants 2 | 3 | def post(image, caption, response_to={}): 4 | print(f"Posting. ({image}, {caption}, {response_to})") 5 | caption = caption.replace("\\n", "\n") 6 | 7 | post_ids = {} 8 | 9 | if constants.TWITTER_ENABLED: 10 | print("Posting to Twitter.") 11 | post_ids["twitter"] = _post_twitter_api(image, caption, response_to.get("twitter")) 12 | 13 | print("Post complete.") 14 | return post_ids 15 | 16 | def _post_twitter_api(image, caption, response_to=None): 17 | media_ids = [constants.TWITTER_API_V1.media_upload(image).media_id] if image != None else None 18 | tweet = constants.TWITTER_API.create_tweet(text=caption, media_ids=media_ids, in_reply_to_tweet_id=response_to) 19 | 20 | return tweet.data.get("id") -------------------------------------------------------------------------------- /bot_helpers/rarity_helper.py: -------------------------------------------------------------------------------- 1 | from bot_helpers import image_helper 2 | 3 | RARITY_COLORS = { 4 | "Common": "https://media.fortniteapi.io/images/rarities/v2/rarity_common.png", 5 | "Epic": "https://media.fortniteapi.io/images/rarities/v2/rarity_epic.png", 6 | "Legendary": "https://media.fortniteapi.io/images/rarities/v2/rarity_legendary.png", 7 | "Mythic": "https://media.fortniteapi.io/images/rarities/v2/rarity_mythic.png", 8 | "Rare": "https://media.fortniteapi.io/images/rarities/v2/rarity_rare.png", 9 | "Transcendent": "https://media.fortniteapi.io/images/rarities/v2/rarity_transcendent.png", 10 | "Uncommon": "https://media.fortniteapi.io/images/rarities/v2/rarity_uncommon.png", 11 | 12 | "CUBESeries": "https://media.fortniteapi.io/images/rarities/v2/T-Cube-Background.png", 13 | "DCUSeries": "https://media.fortniteapi.io/images/rarities/v2/T-BlackMonday-Background.png", 14 | "FrozenSeries": "https://media.fortniteapi.io/images/rarities/v2/T_Ui_LavaSeries_Frozen.png", 15 | "CreatorCollabSeries": "https://media.fortniteapi.io/images/rarities/v2/T_Ui_CreatorsCollab_Bg.png", 16 | "LavaSeries": "https://media.fortniteapi.io/images/rarities/v2/T_Ui_LavaSeries_Bg.png", 17 | "MarvelSeries": "https://media.fortniteapi.io/images/rarities/v2/Marvel.png", 18 | "PlatformSeries": "https://media.fortniteapi.io/images/rarities/v2/platformseries.png", 19 | "ShadowSeries": "https://media.fortniteapi.io/images/rarities/v2/T_Ui_LavaSeries_Shadow.png", 20 | "SlurpSeries": "https://media.fortniteapi.io/images/rarities/v2/Slurp.png", 21 | "ColumbusSeries": "https://media.fortniteapi.io/images/rarities/v2/ColumbusSeries.png" 22 | } 23 | 24 | def get_background(rarity_id, series_id): 25 | background_url = RARITY_COLORS.get(series_id, None) 26 | 27 | if background_url is None: 28 | background_url = RARITY_COLORS.get(rarity_id, None) 29 | 30 | if background_url is None: 31 | background_url = RARITY_COLORS[RARITY_COLORS.keys()[0]] 32 | 33 | return image_helper.from_url(background_url, mode='RGB') -------------------------------------------------------------------------------- /bot_helpers/request_helper.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | import constants 4 | 5 | def io_request(url, parameters): 6 | parameters["lang"] = constants.LANG 7 | parameters_string = "&".join([f"{key}={value}" for key, value in parameters.items()]) 8 | 9 | headers = {"Authorization": constants.FORTNITEAPI_IO_KEY} 10 | r = requests.get(f"{url}?{parameters_string}", headers=headers) 11 | 12 | return r.json() -------------------------------------------------------------------------------- /bot_helpers/strings_helper.py: -------------------------------------------------------------------------------- 1 | import yaml, os 2 | import constants 3 | 4 | with open(os.path.join(constants.ASSETS_PATH, "strings.yml"), "r", encoding="utf-8") as f: 5 | STRINGS = yaml.safe_load(f) -------------------------------------------------------------------------------- /constants.py: -------------------------------------------------------------------------------- 1 | import os, dotenv, tweepy 2 | from datetime import datetime 3 | 4 | def _get_env_bool(env_name): 5 | return os.getenv(env_name) in ("true", "1") 6 | 7 | BASE_PATH = os.path.realpath(os.path.abspath(os.path.dirname(__file__))) 8 | ASSETS_PATH = os.path.join(BASE_PATH, "assets") 9 | print(f"Assets path: {ASSETS_PATH}") 10 | FONT_PATH = os.path.join(ASSETS_PATH, "Burbank.otf") 11 | 12 | UTC_MIDNIGHT = datetime.fromisoformat(f"1970-01-01 00:01:00.000+00:00").astimezone().strftime("%H:%M") 13 | 14 | dotenv.load_dotenv(os.path.join(BASE_PATH, ".env")) 15 | 16 | LANG = os.getenv("LANGUAGE") 17 | FORTNITEAPI_IO_KEY = os.getenv("FORTNITEAPI_IO_KEY") 18 | CONTINUE_ON_CORRUPTED_IMAGE = _get_env_bool("CONTINUE_ON_CORRUPTED_IMAGE") 19 | FALLBACK_IMAGE_FROM_FORTNITE_API = _get_env_bool("FALLBACK_IMAGE_FROM_FORTNITE_API") 20 | 21 | POST_RETURNING_ITEMS_AS_RESPONSE = _get_env_bool("POST_RETURNING_ITEMS_AS_RESPONSE") 22 | RETURNING_ITEM_DAY_THRESHOLD = int(os.getenv("RETURNING_ITEM_DAY_THRESHOLD")) 23 | 24 | TWITTER_ENABLED = _get_env_bool("TWITTER_ENABLED") 25 | TWITTER_API = tweepy.Client( 26 | bearer_token=os.getenv("TWITTER_BEARER_TOKEN"), 27 | consumer_key=os.getenv("TWITTER_CONSUMER_KEY"), 28 | consumer_secret=os.getenv("TWITTER_CONSUMER_SECRET"), 29 | access_token=os.getenv("TWITTER_ACCESS_TOKEN"), 30 | access_token_secret=os.getenv("TWITTER_ACCESS_TOKEN_SECRET") 31 | ) 32 | TWITTER_API_V1 = tweepy.API( 33 | auth=tweepy.OAuthHandler( 34 | consumer_key=os.getenv("TWITTER_CONSUMER_KEY"), 35 | consumer_secret=os.getenv("TWITTER_CONSUMER_SECRET"), 36 | access_token=os.getenv("TWITTER_ACCESS_TOKEN"), 37 | access_token_secret=os.getenv("TWITTER_ACCESS_TOKEN_SECRET") 38 | ) 39 | ) 40 | -------------------------------------------------------------------------------- /example_results/leaks.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Developer-Mike/fn-bot/a6648bdb47f8347c9113b49bd2f2726c76842f8a/example_results/leaks.jpg -------------------------------------------------------------------------------- /example_results/shop.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Developer-Mike/fn-bot/a6648bdb47f8347c9113b49bd2f2726c76842f8a/example_results/shop.jpg -------------------------------------------------------------------------------- /leaks/leaks.py: -------------------------------------------------------------------------------- 1 | import os, shutil, math, pickle, time, glob 2 | from PIL import Image, ImageFont, ImageDraw 3 | from datetime import datetime 4 | 5 | from bot_helpers import exception_helper, image_helper, request_helper, post_helper, strings_helper, rarity_helper 6 | import constants 7 | 8 | class LeaksModule: 9 | _LEAKED_ITEM_IMAGE_SIZE = 512 10 | 11 | _LEAKS_MODULE_PATH = os.path.dirname(os.path.abspath(__file__)) 12 | _TEMP_PATH = os.path.join(_LEAKS_MODULE_PATH, "temp") 13 | _RESULT_PATH = os.path.join(_LEAKS_MODULE_PATH, "result") 14 | _LAST_LEAKS_LIST_PATH = os.path.join(_LEAKS_MODULE_PATH, "last_leaks.p") 15 | 16 | _API_LEAKS_URL = "https://fortniteapi.io/v2/items/upcoming" 17 | 18 | def __init__(self): 19 | if not os.path.exists(self._RESULT_PATH): 20 | os.makedirs(self._RESULT_PATH) 21 | 22 | def register(self, schedule): 23 | schedule.every(30).minutes.do(self.update) 24 | 25 | @exception_helper.catch_exceptions() 26 | def update(self): 27 | leaks_json = request_helper.io_request(self._API_LEAKS_URL, {"fields": "id,name,type,images,rarity,series"}) 28 | leaks_date = self._parse_leaks_date(leaks_json) 29 | new_items = self._get_newly_leaked_items(leaks_json) 30 | if len(new_items) == 0: return 31 | 32 | print("New leaks detected!") 33 | 34 | self._generate_icons(leaks_json, new_items) 35 | self._merge_leaks(leaks_date) 36 | 37 | print("Leaks image generated successfully!") 38 | shutil.rmtree(self._TEMP_PATH) 39 | 40 | self._post_image(leaks_date) 41 | 42 | all_items = list(map(lambda x: x["id"], leaks_json["items"])) 43 | pickle.dump(all_items, open(self._LAST_LEAKS_LIST_PATH, "wb")) 44 | 45 | def _parse_leaks_date(self, leaks_json): 46 | return leaks_json['lastUpdate']['date'][:10] 47 | 48 | def _get_newly_leaked_items(self, leaks_json): 49 | last_leaks = (pickle.load(open(self._LAST_LEAKS_LIST_PATH, "rb")) 50 | if os.path.exists(self._LAST_LEAKS_LIST_PATH) 51 | else []) 52 | 53 | new_leaks = [] 54 | for item_json in leaks_json['items']: 55 | item_id = item_json['id'] 56 | 57 | if item_id not in last_leaks: 58 | new_leaks.append(item_id) 59 | 60 | return new_leaks 61 | 62 | def _generate_icons(self, leaks_json, new_items): 63 | leak_items = leaks_json['items'] 64 | 65 | # Create temp folder 66 | if os.path.exists(self._TEMP_PATH): 67 | shutil.rmtree(self._TEMP_PATH) 68 | os.mkdir(self._TEMP_PATH) 69 | 70 | # Load assets 71 | overlay_image = image_helper.from_path(os.path.join(constants.ASSETS_PATH, 'overlay.png')) 72 | new_badge = image_helper.from_path(os.path.join(constants.ASSETS_PATH, "new_badge.png")) 73 | 74 | for leak_item in leak_items: 75 | item_id = leak_item['id'] 76 | if item_id not in new_items: 77 | continue 78 | 79 | # Item Image 80 | item_icon = image_helper.get_item_image(leak_item['images']['icon'], item_id) 81 | 82 | rarity_id = leak_item['rarity']['id'] 83 | series_id = (leak_item.get('series') or {}).get('id', None) 84 | item_background = rarity_helper.get_background(rarity_id, series_id) 85 | 86 | icon_image = image_helper.with_background(item_icon, item_background) 87 | 88 | #Overlay 89 | icon_image.paste(overlay_image, (0, 0), overlay_image) 90 | 91 | # Item Name 92 | item_name = leak_item['name'] 93 | #Smaller text to fit image 94 | font = None 95 | font_size = 45 96 | while font is None or font.getlength(item_name) > 450: 97 | font = ImageFont.truetype(constants.FONT_PATH, font_size) 98 | font_size -= 2 99 | draw = ImageDraw.Draw(icon_image) 100 | draw.text((256, 423), item_name.upper(), font=font, fill='white', anchor='ms') 101 | 102 | # Item Type 103 | type_text = leak_item['type']['name'] 104 | #Smaller text to fit image 105 | font = None 106 | font_size = 30 107 | while font is None or font.getlength(item_name) > 450: 108 | font = ImageFont.truetype(constants.FONT_PATH, font_size) 109 | font_size -= 2 110 | draw = ImageDraw.Draw(icon_image) 111 | draw.text((256, 460), type_text, font=font, fill=(255, 255, 255), anchor='ms') 112 | 113 | # Item Price 114 | font = ImageFont.truetype(constants.FONT_PATH, 40) 115 | draw = ImageDraw.Draw(icon_image) 116 | draw.text((256, 505), "???", font=font, fill='white', anchor='ms') 117 | 118 | #Save image 119 | icon_image.save(os.path.join(self._TEMP_PATH, f'{item_id}.png')) 120 | icon_image.close() 121 | 122 | # Free memory 123 | overlay_image.close() 124 | new_badge.close() 125 | 126 | print(f'Generated images for {len(new_items)} new leaks.') 127 | 128 | def _merge_leaks(self, leaks_date): 129 | leaks_images_paths = sorted(glob.glob(os.path.join(self._TEMP_PATH, "*.png"))) 130 | leaks_count = len(leaks_images_paths) 131 | 132 | column_count = math.ceil(math.sqrt(leaks_count)) 133 | leaks_image_size = self._LEAKED_ITEM_IMAGE_SIZE * column_count 134 | 135 | leaks_image = Image.new("RGB", (leaks_image_size, leaks_image_size)) 136 | leaks_background = Image.open(os.path.join(constants.ASSETS_PATH, "background.png")).convert("RGB").resize((leaks_image_size, leaks_image_size)) 137 | leaks_image.paste(leaks_background, (0, 0)) 138 | leaks_background.close() # Free memory 139 | 140 | for i, leaks_image_path in enumerate(leaks_images_paths): 141 | item_image = image_helper.from_path(leaks_image_path, size=self._LEAKED_ITEM_IMAGE_SIZE) 142 | leaks_image.paste( 143 | item_image, 144 | ((0 + ((i % column_count) * item_image.width)), 145 | (0 + ((i // column_count) * item_image.height))) 146 | ) 147 | item_image.close() # Free memory 148 | 149 | #Credits 150 | try: 151 | credit_images = sorted(glob.glob(os.path.join(constants.ASSETS_PATH, "ads/*.png"))) 152 | spare_cells = column_count ** 2 - leaks_count 153 | for i in range(spare_cells): 154 | if i >= len(credit_images): 155 | continue 156 | 157 | credits_image = image_helper.from_path(credit_images[i], size=self._LEAKED_ITEM_IMAGE_SIZE) 158 | leaks_image.paste(credits_image, (leaks_image_size - self._LEAKED_ITEM_IMAGE_SIZE * (i + 1), leaks_image_size - self._LEAKED_ITEM_IMAGE_SIZE), credits_image) 159 | credits_image.close() # Free memory 160 | except Exception as e: 161 | print(f"Error generating credits ({e})") 162 | 163 | leaks_image.save(os.path.join(self._RESULT_PATH, f'leaks_{leaks_date}.jpg'), optimize=True, quality=85) 164 | 165 | def _post_image(self, leaks_date): 166 | split_date = leaks_date.split('-') 167 | reformatted_date = f'{split_date[2]}/{split_date[1]}/{split_date[0]}' 168 | 169 | post_helper.post( 170 | os.path.join(self._RESULT_PATH, f'leaks_{leaks_date}.jpg'), 171 | strings_helper.STRINGS["leaks_post_caption"].replace('{date}', reformatted_date) 172 | ) -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import time, schedule 2 | 3 | from shop.shop import ShopModule 4 | from leaks.leaks import LeaksModule 5 | from vbucks.vbucks import VBucksModule 6 | 7 | modules = [ShopModule(), LeaksModule(), VBucksModule()] 8 | for module in modules: 9 | module.register(schedule) 10 | print("Initialized module: " + module.__class__.__name__) 11 | print("All modules initialized. Waiting for updates...") 12 | 13 | schedule.run_all() 14 | 15 | while True: 16 | schedule.run_pending() 17 | time.sleep(10) -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | tweepy 2 | pillow 3 | requests 4 | schedule 5 | pyyaml 6 | python-dotenv -------------------------------------------------------------------------------- /shop/shop.py: -------------------------------------------------------------------------------- 1 | import os, shutil, math, pickle, time, glob 2 | from PIL import Image, ImageFont, ImageDraw 3 | from datetime import datetime, timedelta 4 | 5 | from bot_helpers import exception_helper, image_helper, request_helper, post_helper, strings_helper, rarity_helper 6 | import constants 7 | 8 | class ShopModule: 9 | _SHOP_IMAGE_WIDTH = 3000 10 | _RETURNING_ITEMS_IMAGE_WIDTH = 3000 11 | 12 | _SHOP_MODULE_PATH = os.path.dirname(os.path.abspath(__file__)) 13 | _TEMP_PATH = os.path.join(_SHOP_MODULE_PATH, "temp") 14 | _RESULT_PATH = os.path.join(_SHOP_MODULE_PATH, "result") 15 | _LAST_SHOP_UID_PATH = os.path.join(_SHOP_MODULE_PATH, "last_shop_uid.p") 16 | 17 | _API_SHOP_URL = "https://fortniteapi.io/v2/shop" 18 | _RETURN_COLOR = (247, 223, 61) 19 | 20 | def __init__(self): 21 | if not os.path.exists(self._RESULT_PATH): 22 | os.makedirs(self._RESULT_PATH) 23 | 24 | def register(self, schedule): 25 | self.schedule = schedule 26 | schedule.every(1).days.at(constants.UTC_MIDNIGHT).do(self.update) 27 | 28 | def on_exception(self): 29 | self.schedule.every(5).minutes.until(timedelta(minutes=6)).do(self.update) 30 | 31 | @exception_helper.catch_exceptions(on_exception=on_exception) 32 | def update(self): 33 | shop_json = request_helper.io_request(self._API_SHOP_URL, {"fields": "id,name,shopHistory,images"}) 34 | shop_date = self._parse_shop_date(shop_json) 35 | shop_uid = shop_json['lastUpdate']['uid'] 36 | if not self._has_new_shop(shop_uid): raise Exception("No new shop detected") 37 | 38 | print("New shop detected!") 39 | 40 | shop_image_path = os.path.join(self._RESULT_PATH, f'shop_{shop_date}.jpg') 41 | 42 | returning_items_files = self._generate_icons(shop_json, shop_date) 43 | shop_image = self._merge_shop() 44 | image_helper.compress_image(shop_image, shop_image_path) 45 | 46 | print("Shop generated successfully!") 47 | 48 | post_ids = self._post_image(shop_image_path, shop_date) 49 | pickle.dump(shop_uid, open(self._LAST_SHOP_UID_PATH, "wb")) 50 | 51 | if constants.POST_RETURNING_ITEMS_AS_RESPONSE and len(returning_items_files) > 0: 52 | returning_items_image_path = os.path.join(self._RESULT_PATH, f'returning_items_{shop_date}.jpg') 53 | 54 | returning_items_image = self._merge_returning_items(returning_items_files) 55 | image_helper.compress_image(returning_items_image, returning_items_image_path) 56 | 57 | self._post_returning_items_image(returning_items_image_path, post_ids) 58 | 59 | # Remove temp files 60 | shutil.rmtree(self._TEMP_PATH) 61 | 62 | def _parse_shop_date(self, shop_json): 63 | return shop_json['lastUpdate']['date'][:10] 64 | 65 | def _has_new_shop(self, shop_uid): 66 | last_shop_uid = (pickle.load(open(self._LAST_SHOP_UID_PATH, "rb")) 67 | if os.path.exists(self._LAST_SHOP_UID_PATH) 68 | else None) 69 | 70 | return last_shop_uid != shop_uid 71 | 72 | def _generate_icons(self, shop_json, shop_date): 73 | returning_items_files = [] 74 | sections = list(shop_json["currentRotation"].keys()) 75 | shop_offers_json = shop_json['shop'] 76 | 77 | # Create temp folder 78 | if os.path.exists(self._TEMP_PATH): 79 | shutil.rmtree(self._TEMP_PATH) 80 | os.mkdir(self._TEMP_PATH) 81 | 82 | # Load assets 83 | overlay_image = image_helper.from_path(os.path.join(constants.ASSETS_PATH, 'overlay.png')) 84 | new_badge = image_helper.from_path(os.path.join(constants.ASSETS_PATH, "new_badge.png")) 85 | 86 | for offer_i, offer_json in enumerate(shop_offers_json): 87 | is_bundle = offer_json['mainType'] == "bundle" 88 | main_id = ("bundle_" if is_bundle else "") + offer_json['mainId'] 89 | offer_price = offer_json['price']['finalPrice'] 90 | offer_section = offer_json['section']['id'] 91 | 92 | shop_history = offer_json['granted'][0]['shopHistory'] if len(offer_json['granted']) > 0 else [] 93 | 94 | last_seen = None 95 | if shop_history is not None and len(shop_history) >= 2: 96 | if shop_history[-1] == shop_date: 97 | last_seen = shop_history[-2] 98 | else: 99 | last_seen = shop_history[-1] 100 | 101 | if last_seen is not None: 102 | dateloop = datetime.strptime(last_seen, "%Y-%m-%d") 103 | current = datetime.strptime(shop_date, "%Y-%m-%d") 104 | seen_diff = current.date() - dateloop.date() 105 | days_gone = seen_diff.days 106 | else: 107 | days_gone = None 108 | 109 | # Try to get the Battle Royale display asset, if not, get the first one 110 | display_asset = next((display_asset for display_asset in offer_json['displayAssets'] if display_asset['primaryMode'] == 'BattleRoyale'), offer_json['displayAssets'][0]) \ 111 | if len(offer_json['displayAssets']) > 0 else None 112 | item_icon = image_helper.get_item_image(display_asset['url'], main_id) 113 | 114 | item_background_url = display_asset.get("background_texture") 115 | if item_background_url is None: 116 | rarity_id = offer_json['rarity']['id'] 117 | series_id = (offer_json.get('series') or {}).get('id', None) 118 | item_background = rarity_helper.get_background(rarity_id, series_id) 119 | else: 120 | item_background = image_helper.from_url(item_background_url) 121 | 122 | #Save Background 123 | icon_image = image_helper.with_background(item_icon, item_background) 124 | 125 | #Overlay 126 | icon_image.paste(overlay_image, (0, 0), overlay_image) 127 | 128 | if days_gone is None: 129 | icon_image.paste(new_badge, (0, 0), new_badge) 130 | 131 | item_name = offer_json['displayName'] 132 | 133 | #Smaller text to fit image 134 | font = None 135 | font_size = 45 136 | while font is None or font.getlength(item_name) > 450: 137 | font = ImageFont.truetype(constants.FONT_PATH, font_size) 138 | font_size -= 2 139 | 140 | draw = ImageDraw.Draw(icon_image) 141 | draw.text((256, 423), item_name.upper(), font=font, fill='white', anchor='ms') #Writes display name 142 | 143 | info_text = strings_helper.STRINGS["new_item"] 144 | if days_gone is not None: 145 | info_text = strings_helper.STRINGS["item_gone_duration"].replace("{days}", str(days_gone)) 146 | days_gone_text_color = (255, 255, 255) \ 147 | if days_gone is None or days_gone < constants.RETURNING_ITEM_DAY_THRESHOLD \ 148 | else self._RETURN_COLOR 149 | 150 | font = ImageFont.truetype(constants.FONT_PATH, 33) 151 | draw = ImageDraw.Draw(icon_image) 152 | draw.text((256, 463), info_text, font=font, fill=days_gone_text_color, anchor='ms') #Writes info text / date last seen 153 | 154 | font = ImageFont.truetype(constants.FONT_PATH, 40) 155 | draw = ImageDraw.Draw(icon_image) 156 | draw.text((256, 505), str(offer_price), font=font, fill='white', anchor='ms') #Writes price of offer 157 | 158 | section_number = sections.index(offer_section) if offer_section in sections else len(sections) 159 | 160 | #Save image 161 | item_file_name = f'{section_number}_{offer_i}_{main_id}.png' 162 | icon_image.save(os.path.join(self._TEMP_PATH, item_file_name)) 163 | icon_image.close() 164 | 165 | if days_gone is not None and days_gone >= constants.RETURNING_ITEM_DAY_THRESHOLD: 166 | returning_items_files.append(item_file_name) 167 | 168 | # Free memory 169 | overlay_image.close() 170 | new_badge.close() 171 | 172 | print(f'Generated {len(shop_offers_json)} items from the {shop_date} item shop.') 173 | return returning_items_files 174 | 175 | def _merge_shop(self): 176 | offer_image_paths = sorted(glob.glob(os.path.join(self._TEMP_PATH, "*.png"))) 177 | offer_count = len(offer_image_paths) 178 | 179 | column_count = math.ceil(math.sqrt(offer_count)) 180 | row_count = math.ceil(offer_count / column_count) 181 | 182 | offer_image_size = self._SHOP_IMAGE_WIDTH // column_count 183 | shop_image_size = (offer_image_size * column_count, offer_image_size * row_count) 184 | 185 | shop_image = Image.new("RGB", shop_image_size) 186 | shop_background = Image.open(os.path.join(constants.ASSETS_PATH, "background.png")).convert("RGBA").resize(shop_image_size) 187 | shop_image.paste(shop_background, (0, 0)) 188 | shop_background.close() # Free memory 189 | 190 | for i, offer_image_path in enumerate(offer_image_paths): 191 | offer_image = image_helper.from_path(offer_image_path, size=offer_image_size) 192 | shop_image.paste( 193 | offer_image, 194 | ((0 + ((i % column_count) * offer_image.width)), 195 | (0 + ((i // column_count) * offer_image.height))) 196 | ) 197 | offer_image.close() # Free memory 198 | 199 | #Credits 200 | try: 201 | credit_images = sorted(glob.glob(os.path.join(constants.ASSETS_PATH, "ads/*.png"))) 202 | spare_cells = column_count * row_count - offer_count 203 | for i in range(spare_cells): 204 | if i >= len(credit_images): 205 | continue 206 | 207 | credits_image = image_helper.from_path(credit_images[i], size=offer_image_size) 208 | shop_image.paste(credits_image, (shop_image_size[0] - offer_image_size * (i + 1), shop_image_size[1] - offer_image_size), credits_image) 209 | credits_image.close() # Free memory 210 | except Exception as e: 211 | print(f"Error generating credits ({e})") 212 | 213 | return shop_image 214 | 215 | def _post_image(self, image_path, shop_date): 216 | split_date = shop_date.split('-') 217 | reformatted_date = f'{split_date[2]}/{split_date[1]}/{split_date[0]}' 218 | 219 | return post_helper.post( 220 | image_path, 221 | strings_helper.STRINGS["shop_post_caption"].replace('{date}', reformatted_date) 222 | ) 223 | 224 | def _merge_returning_items(self, returning_items_files): 225 | column_count = math.ceil(math.sqrt(len(returning_items_files))) 226 | row_count = math.ceil(len(returning_items_files) / column_count) 227 | 228 | item_image_size = self._RETURNING_ITEMS_IMAGE_WIDTH // column_count 229 | returning_items_image_size = (item_image_size * column_count, item_image_size * row_count) 230 | 231 | returning_items_image = Image.new("RGB", returning_items_image_size) 232 | background = Image.open(os.path.join(constants.ASSETS_PATH, "background.png")).convert("RGBA").resize(returning_items_image_size) 233 | returning_items_image.paste(background, (0, 0)) 234 | background.close() # Free memory 235 | 236 | for i, item_image_path in enumerate(returning_items_files): 237 | item_image_path = os.path.join(self._TEMP_PATH, item_image_path) 238 | 239 | item_image = image_helper.from_path(item_image_path, size=item_image_size) 240 | returning_items_image.paste( 241 | item_image, 242 | ((0 + ((i % column_count) * item_image.width)), 243 | (0 + ((i // column_count) * item_image.height))) 244 | ) 245 | item_image.close() # Free memory 246 | 247 | return returning_items_image 248 | 249 | def _post_returning_items_image(self, image_path, response_to): 250 | return post_helper.post( 251 | image_path, 252 | strings_helper.STRINGS["returning_items_caption"], 253 | response_to 254 | ) 255 | -------------------------------------------------------------------------------- /template.env: -------------------------------------------------------------------------------- 1 | LANGUAGE=en 2 | FORTNITEAPI_IO_KEY=. 3 | CONTINUE_ON_CORRUPTED_IMAGE=true 4 | FALLBACK_IMAGE_FROM_FORTNITE_API=true 5 | 6 | POST_RETURNING_ITEMS_AS_RESPONSE=false 7 | RETURNING_ITEM_DAY_THRESHOLD=100 8 | 9 | TWITTER_ENABLED=true 10 | TWITTER_BEARER_TOKEN=. 11 | TWITTER_CONSUMER_KEY=. 12 | TWITTER_CONSUMER_SECRET=. 13 | TWITTER_ACCESS_TOKEN=. 14 | TWITTER_ACCESS_TOKEN_SECRET=. -------------------------------------------------------------------------------- /vbucks/vbucks.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from datetime import timedelta 3 | 4 | from bot_helpers import exception_helper, post_helper, strings_helper 5 | import constants 6 | 7 | class VBucksModule: 8 | _STW_WORLD_INFO_URL = "https://fortnite-public-service-prod11.ol.epicgames.com/fortnite/api/game/v2/world/info" 9 | _TOKEN_AUTH_URL = "https://account-public-service-prod.ol.epicgames.com/account/api/oauth/token" 10 | _FORTNITE_PC_BASE = "ZWM2ODRiOGM2ODdmNDc5ZmFkZWEzY2IyYWQ4M2Y1YzY6ZTFmMzFjMjExZjI4NDEzMTg2MjYyZDM3YTEzZmM4NGQ=" 11 | 12 | def register(self, schedule): 13 | self.schedule = schedule 14 | schedule.every(1).days.at(constants.UTC_MIDNIGHT).do(self.update) 15 | 16 | def on_exception(self): 17 | self.schedule.every(5).minutes.until(timedelta(minutes=6)).do(self.update) 18 | 19 | @exception_helper.catch_exceptions(on_exception=on_exception) 20 | def update(self): 21 | stw_json = self._get_stw_json() 22 | vbucks_missions = self._get_vbucks_missions(stw_json) 23 | 24 | if sum(vbucks_missions.values()) > 0: 25 | self._post_vbucks_missions(vbucks_missions) 26 | 27 | def _get_stw_json(self): 28 | headers = { 29 | "Content-Type": "application/x-www-form-urlencoded", 30 | "Authorization": f"basic {self._FORTNITE_PC_BASE}" 31 | } 32 | body = { 33 | "grant_type": "client_credentials" 34 | } 35 | r = requests.post(self._TOKEN_AUTH_URL, headers=headers, data=body) 36 | token = r.json()["access_token"] 37 | 38 | headers = { 39 | "Accept-Language": "en-US", 40 | "Authorization": f"bearer {token}" 41 | } 42 | r = requests.get(self._STW_WORLD_INFO_URL, headers=headers) 43 | 44 | return r.json() 45 | 46 | def _get_vbucks_missions(self, stw_json): 47 | vbucks_missions = {} 48 | 49 | for mission_alert_group in stw_json["missionAlerts"]: 50 | theather_name, is_hidden = self._get_theater_info(stw_json, mission_alert_group["theaterId"]) 51 | if is_hidden: continue 52 | 53 | for mission_alert in mission_alert_group["availableMissionAlerts"]: 54 | for mission_reward in mission_alert["missionAlertRewards"]["items"]: 55 | if mission_reward["itemType"] == "AccountResource:currency_mtxswap": 56 | if theather_name not in vbucks_missions: 57 | vbucks_missions[theather_name] = 0 58 | 59 | vbucks_missions[theather_name] += mission_reward["quantity"] 60 | 61 | return vbucks_missions 62 | 63 | 64 | def _get_theater_info(self, stw_json, theater_id): 65 | for theater in stw_json["theaters"]: 66 | if theater["uniqueId"] == theater_id: 67 | return theater["displayName"], theater["bHideLikeTestTheater"] 68 | 69 | def _post_vbucks_missions(self, vbucks_missions): 70 | vbucks_list = [f"{theater_name}: {vbucks_amount}" for theater_name, vbucks_amount in vbucks_missions.items()] 71 | text = strings_helper.STRINGS["vbucks_text"].replace("{missions}", "\\n".join(vbucks_list)) 72 | 73 | post_helper.post(None, text) -------------------------------------------------------------------------------- /version.txt: -------------------------------------------------------------------------------- 1 | 1.4.1 --------------------------------------------------------------------------------