├── .github ├── workflows │ ├── requirements.txt │ ├── maven-dev.yml │ ├── maven.yml │ ├── maven-tag.yml │ └── deployer.py └── FUNDING.yml ├── .gitignore ├── src └── main │ ├── resources │ ├── utilfiles │ │ ├── battemplate │ │ └── regtemplate │ ├── images │ │ └── error-waifu-lq.png │ └── config │ │ └── config.properties │ └── java │ └── com │ └── kitsunecode │ └── mms │ └── core │ ├── adapters │ ├── impl │ │ ├── adapterentities │ │ │ └── arknights │ │ │ │ ├── readme.txt │ │ │ │ ├── skin │ │ │ │ ├── CharSkins.java │ │ │ │ ├── Skin.java │ │ │ │ └── SkinData.java │ │ │ │ ├── charword │ │ │ │ ├── CharWords.java │ │ │ │ ├── CharwordMap.java │ │ │ │ └── Charword.java │ │ │ │ ├── exceptions │ │ │ │ └── CharacterNotFound.java │ │ │ │ ├── voice │ │ │ │ ├── VoicelineDetails.java │ │ │ │ ├── Voiceline.java │ │ │ │ └── VoicelineDetailMap.java │ │ │ │ └── character │ │ │ │ ├── Character.java │ │ │ │ └── CharacterMap.java │ │ ├── File.java │ │ ├── Github.java │ │ ├── SinoAlice.java │ │ ├── MirageMemorial.java │ │ ├── GirlsFrontline.java │ │ ├── SIFIdol.java │ │ ├── Arknights.java │ │ ├── GenshinImpact.java │ │ └── AzurLane.java │ └── IWaifuAdapter.java │ ├── entities │ ├── FunctionalInterfaces.java │ ├── exceptions │ │ ├── BrokenAdapterException.java │ │ └── StartFailedException.java │ ├── annotations │ │ └── Adapter.java │ ├── CommandOutput.java │ ├── Dialog.java │ ├── audio │ │ ├── Audio.java │ │ └── AudioPlayer.java │ ├── CommandExecutor.java │ ├── WaifuData.java │ ├── swing │ │ ├── Baloon.java │ │ ├── BootFailedFrame.java │ │ ├── SecretaryLabel.java │ │ └── Secretary.java │ └── Settings.java │ ├── utils │ ├── HWUtils.java │ ├── JarSpiFixer.java │ ├── FileWatcher.java │ ├── ReflectionUtils.java │ ├── BootProcedures.java │ └── Util.java │ └── Main.java ├── pom.xml ├── README.md └── LICENSE /.github/workflows/requirements.txt: -------------------------------------------------------------------------------- 1 | python-telegram-bot 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /config/ 3 | /resources/ 4 | /.idea/ 5 | /logs/ -------------------------------------------------------------------------------- /src/main/resources/utilfiles/battemplate: -------------------------------------------------------------------------------- 1 | cd {jarpath} 2 | start javaw -Xmx200m -jar {jarname} -------------------------------------------------------------------------------- /src/main/resources/images/error-waifu-lq.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KaikyuLotus/moe-moe-secretary/HEAD/src/main/resources/images/error-waifu-lq.png -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/adapters/impl/adapterentities/arknights/readme.txt: -------------------------------------------------------------------------------- 1 | Very basic mappings for https://github.com/Aceship/AN-EN-Tags 2 | Thank you Aceship -------------------------------------------------------------------------------- /src/main/resources/utilfiles/regtemplate: -------------------------------------------------------------------------------- 1 | Windows Registry Editor Version 5.00 2 | 3 | [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run] 4 | "Moe Moe Secretary"="{batpath}" -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/adapters/impl/adapterentities/arknights/skin/CharSkins.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.adapters.impl.adapterentities.arknights.skin; 2 | 3 | import java.util.HashMap; 4 | 5 | public class CharSkins extends HashMap { 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/adapters/impl/adapterentities/arknights/charword/CharWords.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.adapters.impl.adapterentities.arknights.charword; 2 | 3 | import java.util.HashMap; 4 | 5 | public class CharWords extends HashMap { 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/entities/FunctionalInterfaces.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.entities; 2 | 3 | public class FunctionalInterfaces { 4 | 5 | @FunctionalInterface 6 | public interface CheckedRunnable { 7 | void run() throws Exception; 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/entities/exceptions/BrokenAdapterException.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.entities.exceptions; 2 | 3 | public class BrokenAdapterException extends RuntimeException { 4 | 5 | public BrokenAdapterException(String message) { 6 | super(message); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/adapters/impl/adapterentities/arknights/exceptions/CharacterNotFound.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.adapters.impl.adapterentities.arknights.exceptions; 2 | 3 | public class CharacterNotFound extends RuntimeException { 4 | 5 | public CharacterNotFound(String msg) { 6 | super(msg); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/entities/annotations/Adapter.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.entities.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target(ElementType.TYPE) 10 | public @interface Adapter { } 11 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/adapters/impl/adapterentities/arknights/voice/VoicelineDetails.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.adapters.impl.adapterentities.arknights.voice; 2 | 3 | import java.util.Map; 4 | 5 | public class VoicelineDetails { 6 | 7 | private Map voiceline; 8 | 9 | public Map getVoiceline() { 10 | return voiceline; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/adapters/impl/adapterentities/arknights/voice/Voiceline.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.adapters.impl.adapterentities.arknights.voice; 2 | 3 | public class Voiceline { 4 | 5 | private String cn; 6 | private String en; 7 | private String jp; 8 | 9 | public String getCn() { 10 | return cn; 11 | } 12 | 13 | public String getEn() { 14 | return en; 15 | } 16 | 17 | public String getJp() { 18 | return jp; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/adapters/impl/adapterentities/arknights/character/Character.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.adapters.impl.adapterentities.arknights.character; 2 | 3 | public class Character { 4 | 5 | private String appellation; 6 | private String id; 7 | private String name; 8 | 9 | public void setId(String id) { 10 | this.id = id; 11 | } 12 | 13 | public String getAppellation() { 14 | return appellation; 15 | } 16 | 17 | public String getId() { 18 | return id; 19 | } 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/adapters/impl/adapterentities/arknights/voice/VoicelineDetailMap.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.adapters.impl.adapterentities.arknights.voice; 2 | 3 | import com.kitsunecode.mms.core.adapters.impl.adapterentities.arknights.character.Character; 4 | import com.kitsunecode.mms.core.utils.Util; 5 | 6 | import java.util.HashMap; 7 | 8 | public class VoicelineDetailMap extends HashMap { 9 | 10 | public static VoicelineDetailMap fromJson(String json) { 11 | return Util.getGSON().fromJson(json, VoicelineDetailMap.class); 12 | } 13 | 14 | public VoicelineDetails ofCharacter(Character character) { 15 | return get(character.getId()); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: kaikyulotus 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: kaikyulotus 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 13 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 14 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/adapters/impl/adapterentities/arknights/skin/Skin.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.adapters.impl.adapterentities.arknights.skin; 2 | 3 | public class Skin { 4 | 5 | private static final String SKIN_URL = "https://raw.githubusercontent.com/Aceship/Arknight-Images/main/characters/%s.png"; 6 | 7 | private String skinId; 8 | private String charId; 9 | 10 | public String getSkinId() { 11 | return skinId; 12 | } 13 | 14 | public String getCharId() { 15 | return charId; 16 | } 17 | 18 | public String composeUrl() { 19 | String url = String.format(SKIN_URL, skinId); 20 | if (url.contains("@")) { 21 | url = url.replace("@", "_").replace("#", "%23"); 22 | } else { 23 | url = url.replace("#", "_"); 24 | } 25 | return url; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/adapters/impl/adapterentities/arknights/charword/CharwordMap.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.adapters.impl.adapterentities.arknights.charword; 2 | 3 | import java.util.List; 4 | import java.util.stream.Collectors; 5 | 6 | import com.kitsunecode.mms.core.adapters.impl.adapterentities.arknights.character.Character; 7 | import com.kitsunecode.mms.core.utils.Util; 8 | 9 | public class CharwordMap { 10 | 11 | private CharWords charWords; 12 | 13 | public static CharwordMap fromJson(String json) { 14 | return Util.getGSON().fromJson(json, CharwordMap.class); 15 | } 16 | 17 | public List ofCharacter(Character character) { 18 | return charWords.entrySet().parallelStream() 19 | .filter(e -> e.getValue().getCharId().equalsIgnoreCase(character.getId())) 20 | .map(e -> e.getValue()) 21 | .collect(Collectors.toList()); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/adapters/impl/adapterentities/arknights/skin/SkinData.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.adapters.impl.adapterentities.arknights.skin; 2 | 3 | import com.kitsunecode.mms.core.adapters.impl.adapterentities.arknights.character.Character; 4 | import com.kitsunecode.mms.core.utils.Util; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | public class SkinData { 11 | 12 | private CharSkins charSkins; 13 | 14 | public static SkinData fromJson(String json) { 15 | return Util.getGSON().fromJson(json, SkinData.class); 16 | } 17 | 18 | public List ofCharacter(Character character) { 19 | List skins = new ArrayList<>(); 20 | for (Map.Entry skinSet : charSkins.entrySet()) { 21 | if (skinSet.getValue().getCharId().equalsIgnoreCase(character.getId())) { 22 | skins.add(skinSet.getValue()); 23 | } 24 | } 25 | return skins; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/entities/exceptions/StartFailedException.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.entities.exceptions; 2 | 3 | public class StartFailedException extends RuntimeException { 4 | 5 | private String httpHelpUrl = null; 6 | 7 | public StartFailedException(String message, Throwable e) { 8 | super(message, e); 9 | } 10 | 11 | public StartFailedException(String message) { 12 | super(message); 13 | } 14 | 15 | public StartFailedException(String message, Exception ex) { 16 | super(message, ex); 17 | } 18 | 19 | public StartFailedException(String message, String url, Exception ex) { 20 | super(message, ex); 21 | this.httpHelpUrl = url; 22 | } 23 | 24 | public StartFailedException(String message, String url) { 25 | super(message); 26 | this.httpHelpUrl = url; 27 | } 28 | 29 | public boolean hasHelpUrl() { 30 | return httpHelpUrl != null; 31 | } 32 | 33 | public String getHttpHelpUrl() { 34 | return httpHelpUrl; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/entities/CommandOutput.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.entities; 2 | 3 | public class CommandOutput { 4 | 5 | private String stdout; 6 | private String stderr; 7 | private int exitCode; 8 | private boolean hasException; 9 | private Throwable exception; 10 | 11 | public CommandOutput(String stdout, String stderr, int exitCode) { 12 | this.stderr = stderr; 13 | this.stdout = stdout; 14 | this.exitCode = exitCode; 15 | } 16 | 17 | public CommandOutput(Throwable exception) { 18 | this.exception = exception; 19 | this.hasException = true; 20 | } 21 | 22 | public String getStdout() { 23 | return stdout; 24 | } 25 | 26 | public String getStderr() { 27 | return stderr; 28 | } 29 | 30 | public int getExitCode() { 31 | return exitCode; 32 | } 33 | 34 | public boolean hasException() { 35 | return hasException; 36 | } 37 | 38 | public Throwable getException() { 39 | return exception; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/adapters/impl/adapterentities/arknights/character/CharacterMap.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.adapters.impl.adapterentities.arknights.character; 2 | 3 | import com.kitsunecode.mms.core.adapters.impl.adapterentities.arknights.exceptions.CharacterNotFound; 4 | import com.kitsunecode.mms.core.utils.Util; 5 | 6 | import java.util.HashMap; 7 | 8 | public class CharacterMap extends HashMap { 9 | 10 | public static CharacterMap fromJson(String json) { 11 | CharacterMap charList = Util.getGSON().fromJson(json, CharacterMap.class); 12 | for (Entry character : charList.entrySet()) { 13 | character.getValue().setId(character.getKey()); 14 | } 15 | return charList; 16 | } 17 | 18 | public Character getWithName(String name) { 19 | for (Entry character : entrySet()) { 20 | if (character.getValue().getName().equalsIgnoreCase(name)) { 21 | return character.getValue(); 22 | } 23 | } 24 | throw new CharacterNotFound("Character with name '" + name + "' not found"); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/entities/Dialog.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.entities; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | public class Dialog { 6 | 7 | @SerializedName("language") 8 | private String language; 9 | 10 | @SerializedName("dialog") 11 | private String dialog; 12 | 13 | @SerializedName("event") 14 | private String event; 15 | 16 | @SerializedName("audio") 17 | private String audio; 18 | 19 | private Dialog() { 20 | // Private impl 21 | } 22 | 23 | public Dialog(String language, String dialog, String event, String audio) { 24 | this.dialog = dialog; 25 | this.event = event; 26 | this.audio = audio; 27 | this.language = language; 28 | } 29 | 30 | public String getDialog() { 31 | return dialog; 32 | } 33 | 34 | public String getEvent() { 35 | return event; 36 | } 37 | 38 | public String getLanguage() { 39 | return language; 40 | } 41 | 42 | public String getAudio() { 43 | return audio; 44 | } 45 | 46 | public Dialog setDialog(String dialog) { 47 | this.dialog = dialog; 48 | return this; 49 | } 50 | 51 | public void setAudio(String audio) { 52 | this.audio = audio; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/adapters/impl/File.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.adapters.impl; 2 | 3 | import com.kitsunecode.mms.core.adapters.IWaifuAdapter; 4 | import com.kitsunecode.mms.core.entities.Dialog; 5 | import com.kitsunecode.mms.core.entities.annotations.Adapter; 6 | import com.kitsunecode.mms.core.entities.exceptions.StartFailedException; 7 | import com.kitsunecode.mms.core.entities.WaifuData; 8 | 9 | import java.io.IOException; 10 | import java.util.List; 11 | import java.util.stream.Collectors; 12 | 13 | @Adapter 14 | public class File extends IWaifuAdapter { 15 | 16 | public File(String shipName) throws IOException, StartFailedException { 17 | super(shipName); 18 | } 19 | 20 | @Override 21 | public void afterInit() { 22 | // Empty impl 23 | } 24 | 25 | @Override 26 | protected WaifuData loadFromCustomSource() { 27 | throw new StartFailedException("File adapter needs a configuration folder, please click here to open the guide!", 28 | "https://telegra.ph/Moe-Moe-Secretary-File-Adapter-Configuration-01-12"); 29 | } 30 | 31 | @Override 32 | public List getDialogs(String event) { 33 | return data.getDialogs().stream() 34 | .filter(d -> d.getEvent().equalsIgnoreCase(event)) 35 | .collect(Collectors.toList()); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/entities/audio/Audio.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.entities.audio; 2 | 3 | import java.io.File; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | public class Audio { 8 | 9 | private boolean isPlaying = false; 10 | 11 | private File file; 12 | 13 | private int volume; 14 | 15 | private List closeActions = new ArrayList<>(); 16 | 17 | public Audio(File file, int volume) { 18 | this.file = file; 19 | this.volume = volume; 20 | } 21 | 22 | public File getFile() { 23 | return file; 24 | } 25 | 26 | public int getVolume() { 27 | return volume; 28 | } 29 | 30 | public boolean isPlaying() { 31 | return isPlaying; 32 | } 33 | 34 | protected void start() { 35 | isPlaying = true; 36 | onStart(); 37 | } 38 | 39 | protected void finish() { 40 | isPlaying = false; 41 | onFinish(); 42 | closeActions.forEach(Runnable::run); 43 | } 44 | 45 | public void addCloseAction(Runnable runnable) { 46 | closeActions.add(runnable); 47 | } 48 | 49 | public void stop() { 50 | isPlaying = false; 51 | } 52 | 53 | public void onStart() { 54 | // Overrideable 55 | } 56 | 57 | public void onFinish() { 58 | // Overrideable 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/utils/HWUtils.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.utils; 2 | 3 | import com.kitsunecode.mms.core.entities.CommandExecutor; 4 | import com.kitsunecode.mms.core.entities.CommandOutput; 5 | 6 | import java.util.Collections; 7 | 8 | public final class HWUtils { 9 | 10 | private static final CommandExecutor EXECUTOR = new CommandExecutor(); 11 | 12 | private HWUtils() { 13 | // Private impl 14 | } 15 | 16 | private static int getBatteryPercentageWindows() { 17 | CommandOutput output = EXECUTOR.executeCommand("powershell", 18 | Collections.singletonList("((gwmi win32_battery)|% e*g)"), null, null); 19 | if (output.hasException()) { 20 | return -1; 21 | } 22 | return Integer.parseInt(output.getStdout().trim()); 23 | } 24 | 25 | // Not tested 26 | private static int getBatteryPercentageLinux() { 27 | CommandOutput output = EXECUTOR.executeCommand("cat", 28 | Collections.singletonList("/sys/class/power_supply/BAT1/capacity"), null, null); 29 | if (output.hasException()) { 30 | return -1; 31 | } 32 | return Integer.parseInt(output.getStdout().trim()); 33 | } 34 | 35 | public static int getBatteryPercentage() { 36 | return Util.isWindows() ? getBatteryPercentageWindows() : getBatteryPercentageLinux(); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /.github/workflows/maven-dev.yml: -------------------------------------------------------------------------------- 1 | name: Java CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - develop 7 | 8 | jobs: 9 | build: 10 | 11 | runs-on: ubuntu-latest 12 | 13 | env: # Or as an environment variable 14 | BOT_TOKEN: ${{ secrets.DEPLOY_BOT_TOKEN }} 15 | TARGET_CHAT_IDS: "[487353090]" 16 | COMMIT_MESSAGE: ${{ github.event.head_commit.message }} 17 | ARTIFACT: "target/moe-moe-secretary.jar" 18 | 19 | steps: 20 | - uses: actions/checkout@v3.3.0 21 | 22 | - name: Set up JDK 11 23 | uses: actions/setup-java@v3.9.0 24 | with: 25 | distribution: 'temurin' 26 | java-version: 11 27 | 28 | - name: Install Python 3.7 29 | uses: actions/setup-python@v4.5.0 30 | with: 31 | python-version: '3.7' 32 | 33 | - name: Install requirements 34 | run: python3 -m pip -q install -r .github/workflows/requirements.txt 35 | 36 | - name: Build with Maven 37 | run: mvn -q -ntp -B package 38 | 39 | - name: Maven build failed 40 | if: failure() 41 | run: python3 .github/workflows/deployer.py maven_build_failed 42 | 43 | - name: Upload artifact 44 | uses: actions/upload-artifact@v3.1.2 45 | with: 46 | name: "moe-moe-secretary.jar" 47 | path: "target/moe-moe-secretary.jar" 48 | 49 | - name: GitHub deploy failed 50 | if: failure() 51 | run: python3 .github/workflows/deployer.py github_deploy_failed 52 | -------------------------------------------------------------------------------- /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | name: Java CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | build: 10 | 11 | runs-on: ubuntu-latest 12 | 13 | env: # Or as an environment variable 14 | BOT_TOKEN: ${{ secrets.DEPLOY_BOT_TOKEN }} 15 | # TARGET_CHAT_IDS: "[487353090, -1001342632426]" 16 | TARGET_CHAT_IDS: "[487353090]" 17 | COMMIT_MESSAGE: ${{ github.event.head_commit.message }} 18 | ARTIFACT: "target/moe-moe-secretary.jar" 19 | 20 | steps: 21 | - uses: actions/checkout@v3.3.0 22 | 23 | - name: Set up JDK 11 24 | uses: actions/setup-java@v3.9.0 25 | with: 26 | distribution: 'temurin' 27 | java-version: 11 28 | 29 | - name: Install Python 3.7 30 | uses: actions/setup-python@v4.5.0 31 | with: 32 | python-version: '3.7' 33 | 34 | - name: Install requirements 35 | run: python3 -m pip -q install -r .github/workflows/requirements.txt 36 | 37 | - name: Build with Maven 38 | run: mvn -q -ntp -B package 39 | 40 | - name: Maven build failed 41 | if: failure() 42 | run: python3 .github/workflows/deployer.py maven_build_failed 43 | 44 | - name: Upload artifact 45 | uses: actions/upload-artifact@v3.1.2 46 | with: 47 | name: "moe-moe-secretary.jar" 48 | path: "target/moe-moe-secretary.jar" 49 | 50 | - name: GitHub deploy failed 51 | if: failure() 52 | run: python3 .github/workflows/deployer.py github_deploy_failed 53 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/adapters/impl/adapterentities/arknights/charword/Charword.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.adapters.impl.adapterentities.arknights.charword; 2 | 3 | import com.kitsunecode.mms.core.entities.Dialog; 4 | 5 | public class Charword { 6 | 7 | private static final String VOICE_URL = "https://raw.githubusercontent.com/Aceship/Arknight-voices/main/voice/%s.mp3"; 8 | 9 | private String charWordId; 10 | private String charId; 11 | private String voiceId; 12 | private String voiceText; 13 | private String voiceAsset; 14 | private String voiceTitle; 15 | 16 | public String getCharWordId() { 17 | return charWordId; 18 | } 19 | 20 | public String getCharId() { 21 | return charId; 22 | } 23 | 24 | public String getVoiceId() { 25 | return voiceId; 26 | } 27 | 28 | public String getVoiceText() { 29 | return voiceText; 30 | } 31 | 32 | public String getVoiceAsset() { 33 | return voiceAsset; 34 | } 35 | 36 | public String getVoiceTitle() { 37 | return voiceTitle; 38 | } 39 | 40 | public String getVoiceTitleMMSCompatible() { 41 | if (voiceTitle.contains("Greeting")) { 42 | return voiceTitle.replace("Greeting", "onLogin"); 43 | } 44 | return voiceTitle.replace(voiceTitle, "onClick"); 45 | } 46 | 47 | public String getVoiceUrl() { 48 | return String.format(VOICE_URL, voiceAsset); 49 | } 50 | 51 | public Dialog asDialog() { 52 | return new Dialog("en", getVoiceText(), getVoiceTitleMMSCompatible(), getVoiceUrl()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/Main.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core; 2 | 3 | import com.kitsunecode.mms.core.adapters.IWaifuAdapter; 4 | import com.kitsunecode.mms.core.utils.BootProcedures; 5 | import com.kitsunecode.mms.core.utils.FileWatcher; 6 | import com.kitsunecode.mms.core.entities.swing.Secretary; 7 | import com.kitsunecode.mms.core.entities.Settings; 8 | import com.kitsunecode.mms.core.utils.Util; 9 | 10 | import java.nio.file.Paths; 11 | 12 | public final class Main { 13 | 14 | private static Secretary secretary = null; 15 | 16 | private static final Object lock = new Object(); 17 | 18 | private Main() { 19 | // Private impl 20 | } 21 | 22 | private static void initialize() { 23 | synchronized (lock) { 24 | if (secretary != null) { 25 | secretary.lightClose(); 26 | } 27 | 28 | Settings.reload(); 29 | 30 | String adapter = Settings.getAdapter(); 31 | String name = Settings.getWaifuName(); 32 | 33 | System.out.println("Starting " + adapter + " with name " + name); 34 | 35 | Util.catchMoeMoeExceptionsAndExit(() -> { 36 | BootProcedures.startupProcedure(); 37 | IWaifuAdapter waifu = Util.getWaifuFromAdapterName(adapter, name); 38 | secretary = new Secretary(waifu); 39 | }); 40 | } 41 | } 42 | 43 | public static void main(String[] args) { 44 | Util.catchMoeMoeExceptionsAndExit(BootProcedures::logToFile); 45 | initialize(); 46 | new FileWatcher(Paths.get(Settings.configPath), Main::initialize).watch(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/utils/JarSpiFixer.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.utils; 2 | 3 | import java.io.IOException; 4 | import java.io.Writer; 5 | import java.net.URI; 6 | import java.nio.charset.StandardCharsets; 7 | import java.nio.file.*; 8 | import java.util.Collections; 9 | 10 | /** 11 | * I fucking hate javazoom.spi 12 | * Diocane. :) 13 | */ 14 | public final class JarSpiFixer { 15 | 16 | private static final String JAR_FILE = "target/moe-moe-secretary.jar"; 17 | private static final String CONV_PROVIDER_FILE = "META-INF/services/javax.sound.sampled.spi.FormatConversionProvider"; 18 | private static final String READER_FILE = "META-INF/services/javax.sound.sampled.spi.AudioFileReader"; 19 | 20 | private JarSpiFixer() { 21 | // Private impl 22 | } 23 | 24 | private static void writeFile(FileSystem fs, String file, String content) throws IOException { 25 | Path nf = fs.getPath(file); 26 | try (Writer writer = Files.newBufferedWriter(nf, StandardCharsets.UTF_8, StandardOpenOption.TRUNCATE_EXISTING)) { 27 | writer.write(content); 28 | } 29 | } 30 | 31 | public static void main(String[] args) throws IOException { 32 | System.out.println("[INFO] Editing file inside built jar"); 33 | 34 | String file1 = "javazoom.spi.mpeg.sampled.convert.MpegFormatConversionProvider\n" + 35 | "javazoom.spi.vorbis.sampled.convert.VorbisFormatConversionProvider\n"; 36 | String file2 = "javazoom.spi.mpeg.sampled.file.MpegAudioFileReader\n" + 37 | "javazoom.spi.vorbis.sampled.file.VorbisAudioFileReader\n"; 38 | 39 | URI uri = URI.create("jar:" + Paths.get(JAR_FILE).toUri()); 40 | try (FileSystem fs = FileSystems.newFileSystem(uri, Collections.emptyMap())) { 41 | writeFile(fs, CONV_PROVIDER_FILE, file1); 42 | writeFile(fs, READER_FILE, file2); 43 | } 44 | 45 | System.out.println("[INFO] javazoom.spi information updated correctly"); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/entities/CommandExecutor.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.entities; 2 | 3 | import com.kitsunecode.mms.core.entities.CommandOutput; 4 | import org.apache.commons.io.IOUtils; 5 | 6 | import java.io.File; 7 | import java.io.IOException; 8 | import java.nio.charset.StandardCharsets; 9 | import java.util.Arrays; 10 | import java.util.HashMap; 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | public class CommandExecutor { 15 | 16 | public CommandOutput executeCommand(String baseCommand, 17 | String... params) { 18 | return executeCommand(baseCommand, Arrays.asList(params), null, null); 19 | } 20 | 21 | public CommandOutput executeCommand(String baseCommand, 22 | List params, 23 | File workingDir, 24 | Map env) { 25 | Process process = null; 26 | try { 27 | 28 | String command = baseCommand + " " + String.join(" ", params); 29 | 30 | Map defaultEnv = new HashMap<>(System.getenv()); 31 | if (env != null) { 32 | defaultEnv.putAll(env); // Add the current system env 33 | } 34 | 35 | String[] envStrings = defaultEnv.entrySet().stream().map(e -> e.getKey() + "=" + e.getValue()).toArray(String[]::new); 36 | 37 | process = Runtime.getRuntime().exec(command, envStrings, workingDir); 38 | 39 | String stdout = IOUtils.toString(process.getInputStream(), StandardCharsets.UTF_8); 40 | String stderr = IOUtils.toString(process.getInputStream(), StandardCharsets.UTF_8); 41 | 42 | process.waitFor(); 43 | int statusCode = process.exitValue(); 44 | return new CommandOutput(stdout, stderr, statusCode); 45 | } catch (IOException | InterruptedException e) { 46 | e.printStackTrace(); 47 | if (process != null) { 48 | process.destroy(); 49 | } 50 | return new CommandOutput(e); 51 | } 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /.github/workflows/maven-tag.yml: -------------------------------------------------------------------------------- 1 | name: Java CI 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v*' 7 | 8 | jobs: 9 | build: 10 | 11 | runs-on: ubuntu-latest 12 | 13 | env: # Or as an environment variable 14 | BOT_TOKEN: ${{ secrets.DEPLOY_BOT_TOKEN }} 15 | TARGET_CHAT_IDS: "[487353090, -1001342632426]" 16 | COMMIT_MESSAGE: ${{ github.event.head_commit.message }} 17 | ARTIFACT: "target/moe-moe-secretary.jar" 18 | 19 | steps: 20 | - uses: actions/checkout@v3.3.0 21 | 22 | - name: Set up JDK 11 23 | uses: actions/setup-java@v3.9.0 24 | with: 25 | distribution: 'temurin' 26 | java-version: 11 27 | 28 | - name: Install Python 3.7 29 | uses: actions/setup-python@v4.5.0 30 | with: 31 | python-version: '3.7' 32 | 33 | - name: Install requirements 34 | run: python3 -m pip -q install -r .github/workflows/requirements.txt 35 | 36 | - name: Build with Maven 37 | run: mvn -q -ntp -B package 38 | 39 | - name: Maven build failed 40 | if: failure() 41 | run: python3 .github/workflows/deployer.py maven_build_failed 42 | 43 | - name: Upload artifact 44 | uses: actions/upload-artifact@v3.1.2 45 | with: 46 | name: "moe-moe-secretary.jar" 47 | path: "target/moe-moe-secretary.jar" 48 | 49 | - name: GitHub deploy failed 50 | if: failure() 51 | run: python3 .github/workflows/deployer.py github_deploy_failed 52 | 53 | - name: Create Release 54 | id: create_release 55 | uses: softprops/action-gh-release@v0.1.15 56 | env: 57 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 58 | with: 59 | tag_name: ${{ github.ref }} 60 | name: Release ${{ github.ref_name }} 61 | body: New Moe Moe Secretary release 62 | draft: false 63 | prerelease: false 64 | files: target/moe-moe-secretary.jar 65 | 66 | - name: Deploy to Telegram 67 | run: python3 .github/workflows/deployer.py deploy_to_telegram 68 | 69 | - name: Telegram deploy failed 70 | if: failure() 71 | run: python3 .github/workflows/deployer.py telegram_deploy_failed 72 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/adapters/impl/Github.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.adapters.impl; 2 | 3 | import com.kitsunecode.mms.core.adapters.IWaifuAdapter; 4 | import com.kitsunecode.mms.core.entities.Settings; 5 | import com.kitsunecode.mms.core.entities.WaifuData; 6 | import com.kitsunecode.mms.core.entities.annotations.Adapter; 7 | import com.kitsunecode.mms.core.entities.exceptions.StartFailedException; 8 | import com.kitsunecode.mms.core.utils.Util; 9 | import org.apache.http.client.utils.URIBuilder; 10 | 11 | import java.io.IOException; 12 | import java.net.URISyntaxException; 13 | 14 | @Adapter 15 | public class Github extends IWaifuAdapter { 16 | 17 | private String folderUrl; 18 | 19 | public Github(String name) throws IOException, URISyntaxException { 20 | super(name); 21 | folderUrl = createWaifuFolderUrl(); 22 | } 23 | 24 | @Override 25 | public void afterInit() { 26 | // Empty impl 27 | } 28 | 29 | private String createWaifuFolderUrl() throws URISyntaxException { 30 | String repo = Settings.getGithubRepo(); 31 | String branch = Settings.getGithubBranch(); 32 | if (repo == null || branch == null) { 33 | throw new StartFailedException("github.url or github.branch are not been set in the configuration file"); 34 | } 35 | return new URIBuilder("https://raw.githubusercontent.com/") 36 | .setPath(repo + "/" + branch + "/" + getName()) 37 | .build() 38 | .normalize() 39 | .toString(); 40 | } 41 | 42 | @Override 43 | public String getSkin(int skinNumber) { 44 | return folderUrl + "/" + data.getSkins().get(skinNumber); 45 | } 46 | 47 | @Override 48 | protected WaifuData loadFromCustomSource() throws Exception { 49 | folderUrl = createWaifuFolderUrl(); 50 | WaifuData data = Util.deserializeWaifu(Util.downloadString(folderUrl + "/data.yaml"), "YAML"); 51 | data.getDialogs() 52 | .stream() 53 | .filter((d) -> d.getAudio() != null) 54 | .forEach((d) -> d.setAudio(folderUrl + "/" + d.getAudio())); 55 | return data; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/entities/WaifuData.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.entities; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Data structure for waifus data files 9 | */ 10 | public class WaifuData { 11 | 12 | @SerializedName("dialogs") 13 | private List dialogs; 14 | 15 | @SerializedName("skins") 16 | private List skins; 17 | 18 | @SerializedName("lastPosition") 19 | private int position = 20; 20 | 21 | @SerializedName("skinIndex") 22 | private int skinIndex = 0; 23 | 24 | @SerializedName("mirrored") 25 | private boolean mirrored = false; 26 | 27 | @SerializedName("alwaysOnTop") 28 | private boolean alwaysOnTop = true; 29 | 30 | @SerializedName("floatingEnabled") 31 | private boolean floatingEnabled = true; 32 | 33 | private WaifuData() { 34 | // Private impl 35 | } 36 | 37 | public WaifuData(List dialogs, List skinUrls) { 38 | this.dialogs = dialogs; 39 | this.skins = skinUrls; 40 | } 41 | 42 | public List getDialogs() { 43 | return dialogs; 44 | } 45 | 46 | public List getSkins() { 47 | return skins; 48 | } 49 | 50 | public int getPosition() { 51 | return position; 52 | } 53 | 54 | public void setPosition(int position) { 55 | this.position = position; 56 | } 57 | 58 | public int getSkinIndex() { 59 | return skinIndex; 60 | } 61 | 62 | public boolean isMirrored() { 63 | return mirrored; 64 | } 65 | 66 | public boolean isAlwaysOnTop() { 67 | return alwaysOnTop; 68 | } 69 | 70 | public boolean isFloatingEnabled() { 71 | return floatingEnabled; 72 | } 73 | 74 | public void setSkinIndex(int skinIndex) { 75 | this.skinIndex = skinIndex; 76 | } 77 | 78 | public void setMirrored(boolean mirrored) { 79 | this.mirrored = mirrored; 80 | } 81 | 82 | public void setAlwaysOnTop(boolean alwaysOnTop) { 83 | this.alwaysOnTop = alwaysOnTop; 84 | } 85 | 86 | public void setFloatingEnabled(boolean floatingEnabled) { 87 | this.floatingEnabled = floatingEnabled; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/adapters/impl/SinoAlice.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.adapters.impl; 2 | 3 | import com.kitsunecode.mms.core.adapters.IWaifuAdapter; 4 | import com.kitsunecode.mms.core.entities.Settings; 5 | import com.kitsunecode.mms.core.entities.WaifuData; 6 | import com.kitsunecode.mms.core.entities.annotations.Adapter; 7 | import com.kitsunecode.mms.core.entities.exceptions.StartFailedException; 8 | import org.apache.http.client.utils.URIBuilder; 9 | import org.jsoup.Jsoup; 10 | import org.jsoup.nodes.Document; 11 | import org.jsoup.select.Selector; 12 | 13 | import java.io.IOException; 14 | import java.net.URISyntaxException; 15 | import java.util.Collections; 16 | 17 | @Adapter 18 | public class SinoAlice extends IWaifuAdapter { 19 | 20 | private static final String META_OGI_SELECTOR = "meta[property='og:image']"; 21 | 22 | private static final String WIKI_URL = "https://sinoalice.game-db.tw/"; 23 | 24 | private final String waifuId; 25 | 26 | public SinoAlice(String name) throws IOException { 27 | super(name); 28 | String charName = Settings.getWaifuName(); 29 | 30 | try { 31 | Document mainDoc = Jsoup.connect("https://sinoalice.game-db.tw/characters/" + charName).get(); 32 | waifuId = Selector.select(META_OGI_SELECTOR, mainDoc) 33 | .first() 34 | .attr("content") 35 | .split("\\.jpg")[0] 36 | .split("CharacterIcon")[1]; 37 | } catch (Exception e) { 38 | throw new StartFailedException("There was an error while trying to get the character.
\n" + 39 | "Please click here and search for your waifu, paste her name in waifu.name", 40 | "https://sinoalice.game-db.tw/characters/", e); 41 | } 42 | } 43 | 44 | @Override 45 | public void afterInit() { 46 | // Empty impl 47 | } 48 | 49 | @Override 50 | public String getName() { 51 | return waifuId; 52 | } 53 | 54 | @Override 55 | protected WaifuData loadFromCustomSource() throws URISyntaxException { 56 | // Creates an URL like https://sinoalice.game-db.tw/images/character_l/245.png 57 | String skinUrl = new URIBuilder(WIKI_URL).setPath("/images/character_l/" + getName() + ".png").build().toString(); 58 | return new WaifuData(Collections.emptyList(), Collections.singletonList(skinUrl)); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/entities/audio/AudioPlayer.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.entities.audio; 2 | 3 | import javax.sound.sampled.*; 4 | import javax.sound.sampled.DataLine.Info; 5 | import java.io.File; 6 | 7 | 8 | public class AudioPlayer { 9 | 10 | public void play(Audio audio) { 11 | new Thread(() -> playThread(audio)).start(); 12 | } 13 | 14 | private void playThread(Audio audio) { 15 | File audioFile = audio.getFile(); 16 | 17 | try (AudioInputStream in = AudioSystem.getAudioInputStream(audioFile)) { 18 | AudioFormat baseFormat = in.getFormat(); 19 | AudioFormat decodedFormat = new AudioFormat( 20 | AudioFormat.Encoding.PCM_SIGNED, 21 | baseFormat.getSampleRate(), 22 | 16, 23 | baseFormat.getChannels(), 24 | baseFormat.getChannels() * 2, 25 | baseFormat.getSampleRate(), 26 | false); 27 | 28 | // Get AudioInputStream that will be decoded by underlying VorbisSPI 29 | try (AudioInputStream din = AudioSystem.getAudioInputStream(decodedFormat, in)) { 30 | 31 | Info info = new Info(SourceDataLine.class, decodedFormat); 32 | 33 | try (SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info)) { 34 | // Start 35 | line.open(decodedFormat); 36 | line.start(); 37 | 38 | FloatControl gainControl = (FloatControl) line.getControl(FloatControl.Type.MASTER_GAIN); 39 | 40 | float volume = (gainControl.getMaximum() - -30.0f) / 100.0f * audio.getVolume() + -30.0f; 41 | gainControl.setValue(volume); 42 | 43 | audio.start(); 44 | 45 | byte[] data = new byte[128]; 46 | int nBytesRead = 0; 47 | while (nBytesRead != -1 && audio.isPlaying()) { 48 | nBytesRead = din.read(data, 0, data.length); 49 | if (nBytesRead != -1) line.write(data, 0, nBytesRead); 50 | } 51 | 52 | // Stop 53 | line.drain(); 54 | line.stop(); 55 | audio.finish(); 56 | } 57 | } 58 | } catch (Exception e) { 59 | e.printStackTrace(); 60 | audio.stop(); 61 | } 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/utils/FileWatcher.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.utils; 2 | 3 | import java.io.IOException; 4 | import java.nio.file.*; 5 | import java.util.concurrent.TimeUnit; 6 | 7 | public class FileWatcher { 8 | 9 | private final Runnable runnable; 10 | private final Path dir; 11 | 12 | private boolean running = true; 13 | 14 | public FileWatcher(Path dir, Runnable runnable) { 15 | this.dir = dir; 16 | this.runnable = runnable; 17 | } 18 | 19 | public void stop() { 20 | running = false; 21 | } 22 | 23 | public void watch() { 24 | Thread watcherThread = new Thread(() -> { 25 | try (WatchService watcher = FileSystems.getDefault().newWatchService()) { 26 | if (dir.toFile().isFile()) { 27 | dir.getParent().register(watcher, StandardWatchEventKinds.ENTRY_MODIFY); 28 | } else { 29 | dir.register(watcher, StandardWatchEventKinds.ENTRY_MODIFY); 30 | } 31 | 32 | while (running) { 33 | WatchKey key; 34 | 35 | try { 36 | key = watcher.poll(1, TimeUnit.SECONDS); 37 | } catch (InterruptedException e) { 38 | return; 39 | } 40 | 41 | if (key == null) { 42 | Thread.yield(); 43 | continue; 44 | } 45 | 46 | for (WatchEvent evt : key.pollEvents()) { 47 | Path filename = (Path) evt.context(); 48 | if (evt.count() > 1 || evt.kind() == StandardWatchEventKinds.OVERFLOW || !filename.toString().equals(dir.toFile().getName())) { 49 | Thread.yield(); 50 | continue; 51 | } 52 | System.out.println("File changed"); 53 | runnable.run(); 54 | } 55 | 56 | if (!key.reset()) { 57 | break; 58 | } 59 | 60 | Thread.yield(); 61 | } 62 | 63 | } catch (IOException e) { 64 | e.printStackTrace(); 65 | } 66 | 67 | 68 | }); 69 | 70 | // Stop the thread when execution finishes 71 | watcherThread.setDaemon(true); 72 | watcherThread.start(); 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/utils/ReflectionUtils.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.utils; 2 | 3 | import org.reflections.Reflections; 4 | import org.reflections.util.ClasspathHelper; 5 | import org.reflections.util.ConfigurationBuilder; 6 | 7 | import java.io.File; 8 | import java.lang.annotation.Annotation; 9 | import java.net.MalformedURLException; 10 | import java.net.URL; 11 | import java.net.URLClassLoader; 12 | import java.nio.file.Path; 13 | import java.nio.file.Paths; 14 | import java.util.Objects; 15 | import java.util.Set; 16 | 17 | public final class ReflectionUtils { 18 | 19 | private static final Path EXTERNAL_LIB_PATH = Paths.get("adapters"); 20 | 21 | private static Reflections reflections; 22 | 23 | private ReflectionUtils() { 24 | // Private impl 25 | } 26 | 27 | private synchronized static Reflections getReflect() { 28 | if (reflections == null) { 29 | ConfigurationBuilder config = new ConfigurationBuilder() 30 | .addUrls(ClasspathHelper.forJavaClassPath()) 31 | .addClassLoaders(getJarsClassLoader(), ReflectionUtils.class.getClassLoader()); 32 | 33 | for(URL jarUrl : getExternalJarLibs()) { 34 | config.addUrls(ClasspathHelper.forManifest(jarUrl)); 35 | } 36 | 37 | reflections = new Reflections(config); 38 | } 39 | return reflections; 40 | } 41 | 42 | private static URL asJarURL(File file) { 43 | try { 44 | return new URL("jar:" + file.toURI().toURL() + "!/"); 45 | } catch (MalformedURLException ex) { 46 | ex.printStackTrace(); // Should not happen 47 | return null; 48 | } 49 | } 50 | 51 | private static URL[] getExternalJarLibs() { 52 | return Util.listFiles(EXTERNAL_LIB_PATH).stream() 53 | .filter(e -> e.getName().endsWith(".jar")) 54 | .map(ReflectionUtils::asJarURL) 55 | .filter(Objects::nonNull) 56 | .toArray(URL[]::new); 57 | } 58 | 59 | private static URLClassLoader getJarsClassLoader() { 60 | return URLClassLoader.newInstance(getExternalJarLibs()); 61 | } 62 | 63 | public static Set> getAllClassesAnnotatedWith(Class annotation) { 64 | return getReflect().getTypesAnnotatedWith(annotation); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/adapters/impl/MirageMemorial.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.adapters.impl; 2 | 3 | import com.kitsunecode.mms.core.adapters.IWaifuAdapter; 4 | import com.kitsunecode.mms.core.entities.annotations.Adapter; 5 | import com.kitsunecode.mms.core.entities.exceptions.StartFailedException; 6 | import com.kitsunecode.mms.core.entities.WaifuData; 7 | import org.jsoup.Jsoup; 8 | import org.jsoup.nodes.Document; 9 | import org.jsoup.nodes.Element; 10 | import org.jsoup.select.Elements; 11 | import org.jsoup.select.Selector; 12 | 13 | import java.io.IOException; 14 | import java.util.Collections; 15 | import java.util.List; 16 | 17 | @Adapter 18 | public class MirageMemorial extends IWaifuAdapter { 19 | 20 | private static final String BASE_URL = "https://miragememorialglobal.fandom.com/wiki/"; 21 | private static final String PAGES = ".wikia-paginator .paginator-page:not(.active)"; 22 | 23 | private static final String IMAGE_SELECTOR = "#%s-png img"; 24 | 25 | public MirageMemorial(String name) throws IOException { 26 | super(name); 27 | } 28 | 29 | @Override 30 | public void afterInit() { 31 | // Empty impl 32 | } 33 | 34 | @Override 35 | protected WaifuData loadFromCustomSource() throws IOException { 36 | System.out.println("Getting servant from wiki"); 37 | Document skinsDoc = Jsoup.connect(BASE_URL + "Special:Images?file=" + getName() + ".png").get(); 38 | return new WaifuData(Collections.emptyList(), loadSkinUrls(skinsDoc)); 39 | } 40 | 41 | private List loadSkinUrls(Document doc) throws IOException { 42 | 43 | String url = getImageUrlFromDocument(doc); 44 | if (url != null) return Collections.singletonList(url); 45 | 46 | // Iterate all pages but this one 47 | Elements pages = Selector.select(PAGES, doc); 48 | for (Element pageBtn : pages) { 49 | String pageUrl = pageBtn.attr("href"); 50 | String image = getImageUrlFromDocument(Jsoup.connect(pageUrl).get()); 51 | if (image != null) return Collections.singletonList(image); 52 | } 53 | 54 | throw new StartFailedException("Cannot find servant named " + getName()); 55 | } 56 | 57 | private String getImageUrlFromDocument(Document doc) { 58 | Element image = Selector.select(String.format(IMAGE_SELECTOR, getName()), doc).first(); 59 | if (image == null) { 60 | return null; 61 | } 62 | return image.attr("src").split("\\.png")[0] + ".png"; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/entities/swing/Baloon.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.entities.swing; 2 | 3 | import com.kitsunecode.mms.core.entities.Settings; 4 | import com.kitsunecode.mms.core.utils.Util; 5 | 6 | import javax.swing.*; 7 | import java.awt.*; 8 | import java.awt.geom.RoundRectangle2D; 9 | 10 | public class Baloon extends JLabel { 11 | 12 | private boolean isVisible = false; 13 | 14 | // TODO fix this mess 15 | public Baloon(int windowWidth, int windowHeight) { 16 | 17 | setSize(Settings.getBaloonWidth(), Settings.getBaloonHeight()); 18 | setMinimumSize(new Dimension(Settings.getBaloonWidth(), Settings.getBaloonHeight())); 19 | setMaximumSize(new Dimension(Settings.getBaloonWidth(), Settings.getBaloonHeight() * 3)); 20 | 21 | setLocation((windowWidth / 2 - Settings.getBaloonWidth() / 2) + Settings.getBaloonXOffset(), 22 | windowHeight - Settings.getBaloonYOffset()); 23 | setForeground(Settings.getBaloonForeground()); 24 | setBackground(new Color(0, 0, 0, 0)); 25 | setOpaque(false); 26 | 27 | setFont(new Font(Settings.getBaloonFont("Arial"), Font.PLAIN, Settings.getBaloonFontSize())); 28 | setVerticalAlignment(SwingConstants.TOP); 29 | setHorizontalAlignment(SwingConstants.CENTER); 30 | } 31 | 32 | public Rectangle getDesiredSize(int leftOffset, int parentWidth, int parentHeight) { 33 | return new Rectangle( 34 | leftOffset + (parentWidth / 2 - Settings.getBaloonWidth() / 2) + Settings.getBaloonXOffset(), 35 | parentHeight - Settings.getBaloonYOffset(), 36 | Settings.getBaloonWidth(), 37 | Settings.getBaloonHeight() * 3 38 | ); 39 | } 40 | 41 | public void toggle(boolean visible) { 42 | isVisible = visible; 43 | setVisible(visible); 44 | } 45 | 46 | @Override 47 | public void paint(Graphics g) { 48 | if (isVisible) { 49 | 50 | setSize(getWidth(), getPreferredSize().height); 51 | 52 | Graphics2D g2d = (Graphics2D) g; 53 | 54 | boolean qualitySet = Settings.isBaloonHighQualityText(); 55 | 56 | if (qualitySet) { 57 | Util.setHighQuality(g2d); 58 | } 59 | 60 | g2d.setPaint(Settings.getBaloonBackground(Color.BLACK)); 61 | g2d.fill(new RoundRectangle2D.Double(0, 0, getWidth(), getHeight(), 10.0, 10.0)); 62 | 63 | if (Settings.isBaloonHighQualityText() && !qualitySet) { 64 | Util.setHighQuality(g2d); 65 | } 66 | 67 | super.paint(g2d); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /.github/workflows/deployer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | import asyncio 4 | import json 5 | import os 6 | import sys 7 | from random import choice 8 | 9 | from telegram import Bot 10 | 11 | mode = sys.argv[1] 12 | 13 | token = os.environ["BOT_TOKEN"] 14 | artifact = os.environ["ARTIFACT"] 15 | actor = os.environ["GITHUB_ACTOR"] 16 | commit_message = os.environ["COMMIT_MESSAGE"] 17 | short_commit = os.environ["GITHUB_SHA"][:7] 18 | target_chat_ids = json.loads(os.environ["TARGET_CHAT_IDS"]) 19 | 20 | # Stickers 21 | 22 | success_stickers = [ 23 | "CAACAgQAAxkBAAMSXizBH6EVAcELC6oDWD_TEeXZPsIAAuIBAAK6gRoGPKkaIcuBR1MYBA", 24 | "CAACAgQAAxkBAAMUXizBRicRjwzyVtNUNWhn0H_mbbAAAhUCAAK6gRoG7cgonAUMHpcYBA", 25 | "CAACAgIAAxkBAAMWXizBk1KXfmaN1iMaePxXZNYRwDgAAgkfAALgo4IHEHOZU6ZS6-MYBA", 26 | "CAACAgIAAxkBAAMXXizBo_k5PzSVorOq5vvR3afOy1IAAhIfAALgo4IHhx_wVc2O_C0YBA", 27 | "CAACAgQAAxkBAAMYXizBuRrzhY5ektJe7vi6BkhQsHMAAhQCAAK6gRoGU6MKcVTDAAFsGAQ" 28 | ] 29 | 30 | fail_stickers = [ 31 | "CAACAgUAAxkBAAMPXizAmFazxh4eyBrwPV477f9sNVgAAmgAAwM94R-m0c-xo2e6rxgE", 32 | "CAACAgUAAxkBAAMQXizAwPsfYxht2TY_aT6oITAozIYAAmcAAwM94R_zYjyOZ62F1BgE", 33 | "CAACAgQAAxkBAAMRXizBEDFfLZWkMWI3hW6wb_tZqdYAAhgCAAK6gRoGOiitY2QfK-IYBA", 34 | "CAACAgQAAxkBAAMTXizBNM7tAuwB48O3wbr9OVERjW8AAhICAAK6gRoGxqOdW8kSa0IYBA", 35 | "CAACAgUAAxkBAAMVXizBVrzA9F07fxdUCTEM6-X156sAAlAAA1rTAyifa33NO5J2LxgE" 36 | 37 | ] 38 | 39 | bot = Bot(token) 40 | 41 | 42 | async def deploy_to_telegram(): 43 | sticker = choice(success_stickers) 44 | print(f"Sending '{artifact}' to the following chat IDs: {target_chat_ids}") 45 | print(f"Issued by user {actor}") 46 | print(f"With commit message '{commit_message}'") 47 | 48 | caption = f"*New MMS release*\n\n" \ 49 | f"'{commit_message}'\n\n" \ 50 | f"Issued by `{actor}`\n" \ 51 | f"Short commit: `{short_commit}`" 52 | 53 | for target_chat_id in target_chat_ids: 54 | await bot.send_document( 55 | target_chat_id, open(artifact, 'rb'), 56 | caption=caption, 57 | parse_mode="markdown" 58 | ) 59 | await bot.send_sticker(target_chat_id, sticker) 60 | 61 | 62 | async def broadcast_message(fail_message): 63 | sticker = choice(fail_stickers) 64 | print(fail_message) 65 | for target_chat_id in target_chat_ids: 66 | await bot.send_message(target_chat_id, fail_message, parse_mode="markdown") 67 | await bot.send_sticker(target_chat_id, sticker) 68 | print("Notifications sent") 69 | 70 | 71 | async def telegram_deploy_failed(): 72 | await broadcast_message("Telegram deploy failed, please check the logs.") 73 | 74 | 75 | async def maven_build_failed(): 76 | await broadcast_message("Maven build failed, please check the logs.") 77 | 78 | 79 | async def github_deploy_failed(): 80 | await broadcast_message("GitHub deploy failed, please check the logs.") 81 | 82 | 83 | async def main(): 84 | if "DISABLE_TELEGRAM" in os.environ and os.environ["DISABLE_TELEGRAM"].lower() == "true": 85 | return 86 | 87 | if mode == "github_deploy_failed": 88 | await github_deploy_failed() 89 | elif mode == "maven_build_failed": 90 | await maven_build_failed() 91 | elif mode == "telegram_deploy_failed": 92 | await telegram_deploy_failed() 93 | elif mode == "deploy_to_telegram": 94 | await deploy_to_telegram() 95 | else: 96 | raise NotImplementedError(f"Mode '{mode}' is not implemented.") 97 | 98 | 99 | if __name__ == "__main__": 100 | asyncio.run(main()) 101 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/adapters/impl/GirlsFrontline.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.adapters.impl; 2 | 3 | import com.kitsunecode.mms.core.adapters.IWaifuAdapter; 4 | import com.kitsunecode.mms.core.entities.Dialog; 5 | import com.kitsunecode.mms.core.entities.WaifuData; 6 | import com.kitsunecode.mms.core.entities.annotations.Adapter; 7 | import org.jsoup.Jsoup; 8 | import org.jsoup.nodes.Document; 9 | import org.jsoup.nodes.Element; 10 | import org.jsoup.select.Elements; 11 | import org.jsoup.select.Selector; 12 | 13 | import java.io.IOException; 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | import java.util.stream.Collectors; 17 | 18 | @Adapter 19 | public class GirlsFrontline extends IWaifuAdapter { 20 | 21 | private static final String BASE_URL = "https://en.gfwiki.com"; 22 | 23 | private static final String IMAGES_URL_SELECTOR = "ul.gallery.mw-gallery-traditional > li > * a"; 24 | private static final String FULL_IMAGE_URL_SELECTOR = ".fullMedia > a"; 25 | private static final String QUOTE_ROWS = ".tabbertab > * tr"; 26 | private static final String ALL_TDS = "td"; 27 | private static final String SOUNDS = "span.audio-button"; 28 | 29 | private static final String WIKI_ON_CLICK_EVENT_KEY = "Secretary"; 30 | private static final String WIKI_ON_LOGIN_EVENT_KEY = "Greeting"; 31 | private static final String WIKI_ON_IDLE_EVENT_KEY = "Secretary"; 32 | 33 | public GirlsFrontline(String name) { 34 | super(name); 35 | } 36 | 37 | @Override 38 | public void afterInit() { 39 | // Empty impl 40 | } 41 | 42 | /** 43 | * Loads data from Wiki, we MUST use it only once in a while 44 | */ 45 | protected WaifuData loadFromCustomSource() throws IOException { 46 | System.out.println("Getting weapon home page"); 47 | Document mainDoc = Jsoup.connect(BASE_URL + "/wiki/" + getName()).get(); 48 | System.out.println("Getting weapon quotes"); 49 | Document quotesDoc = Jsoup.connect(BASE_URL + "/wiki/" + getName() + "/Quotes").get(); 50 | System.out.println("Parsing data..."); 51 | 52 | return new WaifuData(loadDialogs(quotesDoc), loadImageSources(mainDoc)); 53 | } 54 | 55 | private String getFullImageLink(String path) { 56 | try { 57 | Document imgDoc = Jsoup.connect(BASE_URL + path).get(); 58 | return BASE_URL + Selector.select(FULL_IMAGE_URL_SELECTOR, imgDoc).attr("href"); 59 | } catch (IOException e) { 60 | e.printStackTrace(); 61 | } 62 | return null; 63 | } 64 | 65 | private List loadDialogs(Document doc) { 66 | 67 | Elements rows = Selector.select(QUOTE_ROWS, doc); 68 | 69 | List dialogs = new ArrayList<>(); 70 | 71 | String lastEvent = ""; 72 | 73 | for (Element row : rows) { 74 | Elements tds = row.select(ALL_TDS); 75 | Elements sound = row.select(SOUNDS); 76 | 77 | if (tds.isEmpty()) { 78 | continue; // Skip tr(s) 79 | } 80 | if (tds.size() < 5) { 81 | // Create missing dialog td 82 | tds.add(0, new Element("td").text(lastEvent)); 83 | } 84 | 85 | lastEvent = tds.get(0).text(); 86 | String audioURl = null; 87 | String dialogString = tds.get(4).text(); 88 | 89 | if (!sound.isEmpty()) { 90 | audioURl = sound.attr("data-src"); 91 | } 92 | 93 | String mmsEventKey; 94 | if (lastEvent.equals(WIKI_ON_CLICK_EVENT_KEY)) { 95 | mmsEventKey = onTouchEventKey(); 96 | } else if (lastEvent.equals(WIKI_ON_LOGIN_EVENT_KEY)) { 97 | mmsEventKey = onLoginEventKey(); 98 | } else if (lastEvent.equals(WIKI_ON_IDLE_EVENT_KEY)) { // on idle key may change 99 | mmsEventKey = onIdleEventKey(); 100 | } else { 101 | continue; // We don't need this dialog 102 | } 103 | 104 | dialogs.add(new Dialog("english", dialogString, mmsEventKey, audioURl)); 105 | } 106 | 107 | return dialogs; 108 | } 109 | 110 | private List loadImageSources(Document doc) { 111 | return Selector.select(IMAGES_URL_SELECTOR, doc) 112 | .stream() 113 | .map(e -> e.attr("href")) 114 | .filter(a -> !a.contains("_S")) 115 | .filter(a -> a.contains(getName())) 116 | .map(this::getFullImageLink) 117 | .collect(Collectors.toList()); 118 | } 119 | 120 | @Override 121 | public List getDialogs(String event) { 122 | return data.getDialogs().stream().filter(d -> d.getEvent().equals(event)).collect(Collectors.toList()); 123 | } 124 | 125 | } 126 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/entities/swing/BootFailedFrame.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.entities.swing; 2 | 3 | import com.kitsunecode.mms.core.entities.exceptions.StartFailedException; 4 | import com.kitsunecode.mms.core.utils.Util; 5 | 6 | import javax.imageio.ImageIO; 7 | import javax.swing.*; 8 | import java.awt.*; 9 | import java.awt.event.MouseEvent; 10 | import java.awt.event.MouseListener; 11 | import java.io.IOException; 12 | import java.io.InputStream; 13 | import java.util.Objects; 14 | 15 | public class BootFailedFrame extends JDialog implements MouseListener { 16 | 17 | private static final int fullWidth = 565; 18 | private static final int fullHeight = 700; 19 | 20 | private static final int width = 565; 21 | private static final int height = 450; 22 | 23 | private static final int fontSize = 18; 24 | private static final Color msgBgColor = new Color(0.0f, 0.0f, 0.0f, 0.95f); 25 | private static final Color msgFgColor = new Color(1.0f, 1.0f, 1.0f, 0.60f); 26 | private static final String fontName = "Bahnschrift Light"; 27 | 28 | 29 | public BootFailedFrame(Exception ex) { 30 | 31 | String error = ex.getMessage() != null ? ex.getMessage() : "Null Pointer Exception"; 32 | 33 | setAlwaysOnTop(true); 34 | setLayout(null); 35 | setResizable(false); 36 | setSize(new Dimension(width, height + 200)); 37 | setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 38 | setUndecorated(true); 39 | setBackground(new Color(0, 0, 0, 0)); 40 | JLabel pane = new JLabel(); 41 | 42 | try (InputStream is = BootFailedFrame.class.getClassLoader().getResourceAsStream("images/error-waifu-lq.png")) { 43 | pane.setIcon(new ImageIcon(ImageIO.read(Objects.requireNonNull(is)))); 44 | pane.setVerticalAlignment(SwingConstants.TOP); 45 | } catch (IOException e) { 46 | e.printStackTrace(); 47 | } 48 | 49 | pane.setBounds(0, 0, fullWidth, fullHeight); 50 | pane.setSize(new Dimension(width, height)); 51 | 52 | String errorFull = "

An error occurred during the execution:
″" + error + "″

Click the nekogirl to close...

"; 53 | JLabel textMsg = setupTextMessage(errorFull, error); 54 | 55 | add(textMsg, BorderLayout.CENTER); 56 | add(pane, BorderLayout.CENTER); 57 | 58 | if (ex instanceof StartFailedException) { 59 | StartFailedException sfx = (StartFailedException) ex; 60 | if (sfx.hasHelpUrl()) { 61 | String helpUrl = sfx.getHttpHelpUrl(); 62 | textMsg.addMouseListener(new MouseListener() { 63 | @Override 64 | public void mouseClicked(MouseEvent mouseEvent) { 65 | Util.openUrl(helpUrl); 66 | } 67 | 68 | @Override 69 | public void mousePressed(MouseEvent mouseEvent) { 70 | // No action 71 | } 72 | 73 | @Override 74 | public void mouseReleased(MouseEvent mouseEvent) { 75 | // No action 76 | } 77 | 78 | @Override 79 | public void mouseEntered(MouseEvent mouseEvent) { 80 | // No action 81 | } 82 | 83 | @Override 84 | public void mouseExited(MouseEvent mouseEvent) { 85 | // No action 86 | } 87 | }); 88 | } 89 | } 90 | 91 | setLocationRelativeTo(null); 92 | addMouseListener(this); 93 | setModal(true); 94 | setVisible(true); 95 | } 96 | 97 | public final JLabel setupTextMessage(String message, String error) { 98 | JLabel textMsg = new JLabel(message, SwingConstants.CENTER); 99 | textMsg.setFont(new Font(fontName, Font.PLAIN, fontSize)); 100 | textMsg.setBackground(msgBgColor); 101 | textMsg.setForeground(msgFgColor); 102 | textMsg.setOpaque(true); 103 | textMsg.setVisible(true); 104 | textMsg.setBounds(0, 400, 564, (error.length() >= 100) ? 180 : 120); 105 | textMsg.setBorder(BorderFactory.createMatteBorder(2, 2, 2, 2, new Color(1, 1, 1, 0.5f))); 106 | return textMsg; 107 | } 108 | 109 | @Override 110 | public void mouseClicked(MouseEvent e) { 111 | dispose(); 112 | } 113 | 114 | @Override 115 | public void mousePressed(MouseEvent e) { 116 | // No action 117 | } 118 | 119 | @Override 120 | public void mouseReleased(MouseEvent e) { 121 | // No action 122 | } 123 | 124 | @Override 125 | public void mouseEntered(MouseEvent e) { 126 | // No action 127 | } 128 | 129 | @Override 130 | public void mouseExited(MouseEvent e) { 131 | // No action 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/entities/swing/SecretaryLabel.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.entities.swing; 2 | 3 | import com.kitsunecode.mms.core.entities.Settings; 4 | import com.kitsunecode.mms.core.utils.Util; 5 | 6 | import javax.swing.*; 7 | import java.awt.*; 8 | import java.util.concurrent.atomic.AtomicBoolean; 9 | 10 | public class SecretaryLabel extends JLabel { 11 | 12 | private boolean isSpeaking = false; 13 | private boolean isJumping = false; 14 | 15 | private final Secretary parentFrame; 16 | 17 | public SecretaryLabel(ImageIcon icn, Secretary parentFrame) { 18 | super(icn); 19 | this.parentFrame = parentFrame; 20 | } 21 | 22 | public Rectangle getDesiredBounds(int leftOffset, int parentWidth, int parentHeight) { 23 | return new Rectangle( 24 | leftOffset, 25 | parentHeight - this.getIcon().getIconHeight(), 26 | this.getIcon().getIconWidth(), 27 | this.getIcon().getIconHeight()); 28 | } 29 | 30 | public void speak(boolean s) { 31 | isSpeaking = s; 32 | } 33 | 34 | public boolean isSpeaking() { 35 | return isSpeaking; 36 | } 37 | 38 | public void startFloating() { 39 | 40 | AtomicBoolean raise = new AtomicBoolean(true); 41 | 42 | int stepSleep = Settings.getFloatingStepSleep(); 43 | int max = Settings.getFloatingPixelRange(); 44 | int increment = Settings.getFloatingPixelPerStep(); 45 | // int swapSleep = Settings.getFloatingSwapSleep(); 46 | int startY = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight() - parentFrame.getY(); 47 | int minY = startY - max; 48 | int maxY = startY + max * 2; 49 | int switchSleep = Settings.getFloatingSwitchSleep(); 50 | System.out.println(String.format("Min %s Max %s Current %s", minY, maxY, startY)); 51 | 52 | final int screenHeight = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight(); 53 | // 60 fps{ 54 | new Thread(() -> { 55 | while (true) { 56 | Util.sleep(stepSleep); 57 | 58 | if (isJumping || parentFrame.isDragging() || !parentFrame.isFloatingToggle()) { 59 | continue; 60 | } 61 | int position = screenHeight - parentFrame.getY(); 62 | 63 | if (raise.get()) { 64 | // Se sta salendo controlla se ha raggiunto il massimo 65 | if (position >= maxY) { 66 | // Ha raggiunto il massimo quindi inizia a scendere 67 | raise.set(false); 68 | } 69 | } else { 70 | if (position <= startY) { 71 | raise.set(true); 72 | Util.sleep(switchSleep); 73 | } 74 | } 75 | 76 | parentFrame.setLocation(parentFrame.getX(), parentFrame.getY() + (raise.get() ? -increment : increment)); 77 | } 78 | 79 | }).start(); 80 | } 81 | 82 | public void jumpAnimation() { 83 | int jumps = Settings.getJumpCount(); 84 | int stepSleep = Settings.getJumpSleep(); 85 | int step = Settings.getJumpPixelPerStep(); 86 | int max = Settings.getJumpPixelRange(); 87 | 88 | // int position = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight() - parentFrame.getY(); 89 | 90 | for (int j = 0; j < jumps; j++) { 91 | for (int i = 0; i < max / step; i++) { 92 | parentFrame.setLocation(parentFrame.getX(), parentFrame.getY() - step); 93 | Util.sleep(stepSleep); 94 | } 95 | 96 | for (int i = 0; i < max / step; i++) { 97 | parentFrame.setLocation(parentFrame.getX(), parentFrame.getY() + step); 98 | Util.sleep(stepSleep); 99 | } 100 | } 101 | } 102 | 103 | public void speakJump() { 104 | if (!isJumping && Settings.isJumpOnClick()) { 105 | new Thread(() -> { 106 | isJumping = true; 107 | jumpAnimation(); 108 | isJumping = false; 109 | }).start(); 110 | } 111 | } 112 | 113 | public void waitIdle() { 114 | int times = 0; 115 | int dialWait = Settings.getDialogsIdleFrequency() / 10; 116 | while (times < dialWait) { 117 | for (int i = 0; i < dialWait; i++) { 118 | Util.sleep(10); 119 | if (isJumping || isSpeaking) { 120 | times = 0; 121 | } else { 122 | times++; 123 | } 124 | } 125 | 126 | } 127 | } 128 | 129 | public void waitSpeak() { 130 | while (isSpeaking) { 131 | Util.sleep(10); 132 | } 133 | } 134 | 135 | 136 | public void onVisible() { 137 | // May be useful 138 | } 139 | 140 | public void paint(Graphics g) { 141 | g.clearRect(0, 0, this.getWidth(), this.getHeight()); 142 | Toolkit.getDefaultToolkit().sync(); 143 | super.paint(g); 144 | } 145 | 146 | // g.clearRect(0, 0, this.getWidth(), this.getHeight()); 147 | // Toolkit.getDefaultToolkit().sync(); 148 | } 149 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/adapters/impl/SIFIdol.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.adapters.impl; 2 | 3 | import com.kitsunecode.mms.core.adapters.IWaifuAdapter; 4 | import com.kitsunecode.mms.core.entities.Dialog; 5 | import com.kitsunecode.mms.core.entities.WaifuData; 6 | import com.kitsunecode.mms.core.entities.annotations.Adapter; 7 | import org.jsoup.Jsoup; 8 | import org.jsoup.nodes.Document; 9 | import org.jsoup.nodes.Element; 10 | import org.jsoup.select.Elements; 11 | import org.jsoup.select.Selector; 12 | 13 | import java.io.IOException; 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | import java.util.Locale; 17 | import java.util.stream.Collectors; 18 | 19 | @Adapter 20 | public class SIFIdol extends IWaifuAdapter { 21 | 22 | private static final String QUOTES_WIKI_URL = "https://decaf.kouhi.me/lovelive/index.php?title=%s"; 23 | 24 | private static final String BASE_URL = "https://schoolido.lu"; 25 | private static final String CARD_URL = BASE_URL + "/cards/%s/"; 26 | 27 | private static final String NAME_SELECTOR = "tr:nth-child(2) > td > strong"; 28 | private static final String SKIN_LINKS = "td > a"; 29 | private static final String QUOTES_SEL = "#mw-content-text > *"; 30 | 31 | private static final String WIKI_ON_CLICK_EVENT_KEY = "Tapping the Character"; 32 | private static final String WIKI_ON_LOGIN_EVENT_KEY = "Home Screen"; 33 | 34 | private String idolName; 35 | 36 | public SIFIdol(String code) throws IOException { 37 | super(code); 38 | } 39 | 40 | @Override 41 | public void afterInit() { 42 | // Empty impl 43 | } 44 | 45 | @Override 46 | protected WaifuData loadFromCustomSource() throws IOException { 47 | Document mainDoc = Jsoup.connect(String.format(CARD_URL, getName())).get(); 48 | this.idolName = getIdolName(mainDoc); 49 | 50 | List urls = getIdolSkinUrls(mainDoc); 51 | 52 | List dialogs = new ArrayList<>(); 53 | try { 54 | Document quotesDoc = Jsoup.connect(String.format(QUOTES_WIKI_URL, this.idolName)).get(); 55 | dialogs.addAll(getDialogsFromWiki(quotesDoc, WIKI_ON_LOGIN_EVENT_KEY, onLoginEventKey())); 56 | dialogs.addAll(getDialogsFromWiki(quotesDoc, WIKI_ON_LOGIN_EVENT_KEY, onIdleEventKey())); 57 | dialogs.addAll(getDialogsFromWiki(quotesDoc, WIKI_ON_CLICK_EVENT_KEY, onTouchEventKey())); 58 | } catch (Exception e) { 59 | System.out.println("Cannot load waifu dialogs..."); 60 | } 61 | return new WaifuData(dialogs, urls); 62 | } 63 | 64 | private String elaborateDialog(String dialog, String info, boolean hasJap) { 65 | String elaboratedDialog = dialog; 66 | if (hasJap) { 67 | if (!elaboratedDialog.contains(" ")) { 68 | return null; 69 | } 70 | elaboratedDialog = elaboratedDialog.split(" ", 2)[1]; 71 | } 72 | 73 | if (info != null && !"".equals(info) && info.contains("#") && !info.contains(getName())) { 74 | return null; 75 | } 76 | return elaboratedDialog; 77 | } 78 | 79 | private List getDialogsFromWiki(Document doc, String section, String mmsEventKey) { 80 | List dialogs = new ArrayList<>(); 81 | boolean isDialog = false; 82 | for (Element elem : Selector.select(QUOTES_SEL, doc)) { 83 | if (elem.text().trim().equalsIgnoreCase(section)) { 84 | isDialog = true; 85 | continue; 86 | } 87 | 88 | if ("h3".equals(elem.tag().getName())) { 89 | isDialog = false; 90 | continue; 91 | } 92 | 93 | if (isDialog) { 94 | Elements i = elem.select("i"); 95 | String infoText = null; 96 | if (i != null) { 97 | infoText = i.text(); 98 | i.remove(); 99 | } 100 | 101 | boolean hasJap = !elem.select("br").isEmpty(); 102 | String elaborated = elaborateDialog(elem.text().trim(), infoText, hasJap); 103 | if (elaborated != null) { 104 | dialogs.add(new Dialog("english", elaborated, mmsEventKey, null)); 105 | } 106 | } 107 | } 108 | return dialogs; 109 | } 110 | 111 | private List getIdolSkinUrls(Document doc) { 112 | return Selector.select(SKIN_LINKS, doc).stream() 113 | .filter(e -> e.text().toLowerCase(Locale.ENGLISH).contains("transparent: ")) 114 | .map(e -> "https:" + e.attr("href").split("\\?")[0]) 115 | .collect(Collectors.toList()); 116 | } 117 | 118 | private String getIdolName(Document doc) { 119 | Elements nameElem = Selector.select(NAME_SELECTOR, doc); 120 | return nameElem.isEmpty() ? null : nameElem.text(); 121 | } 122 | 123 | public String getIdolName() { 124 | return idolName; 125 | } 126 | 127 | @Override 128 | public List getDialogs(String event) { 129 | return this.data.getDialogs().stream() 130 | .filter(d -> d.getEvent().equalsIgnoreCase(event)) 131 | .collect(Collectors.toList()); 132 | } 133 | 134 | } 135 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/adapters/impl/Arknights.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.adapters.impl; 2 | 3 | import com.kitsunecode.mms.core.adapters.IWaifuAdapter; 4 | import com.kitsunecode.mms.core.adapters.impl.adapterentities.arknights.character.Character; 5 | import com.kitsunecode.mms.core.adapters.impl.adapterentities.arknights.character.CharacterMap; 6 | import com.kitsunecode.mms.core.adapters.impl.adapterentities.arknights.charword.Charword; 7 | import com.kitsunecode.mms.core.adapters.impl.adapterentities.arknights.charword.CharwordMap; 8 | import com.kitsunecode.mms.core.adapters.impl.adapterentities.arknights.skin.Skin; 9 | import com.kitsunecode.mms.core.adapters.impl.adapterentities.arknights.skin.SkinData; 10 | import com.kitsunecode.mms.core.entities.Dialog; 11 | import com.kitsunecode.mms.core.entities.WaifuData; 12 | import com.kitsunecode.mms.core.entities.annotations.Adapter; 13 | import com.kitsunecode.mms.core.entities.Settings; 14 | import com.kitsunecode.mms.core.utils.Util; 15 | 16 | import java.io.IOException; 17 | import java.util.Arrays; 18 | import java.util.Comparator; 19 | import java.util.List; 20 | import java.util.concurrent.atomic.AtomicReference; 21 | import java.util.regex.Matcher; 22 | import java.util.regex.Pattern; 23 | import java.util.stream.Collectors; 24 | 25 | @Adapter 26 | public class Arknights extends IWaifuAdapter { 27 | 28 | private static final String CHAR_DATA_URL = "https://raw.githubusercontent.com/Aceship/AN-EN-Tags/master/json/gamedata/en_US/gamedata/excel/character_table.json"; 29 | private static final String SKIN_DATA_URL = "https://raw.githubusercontent.com/Aceship/AN-EN-Tags/master/json/gamedata/en_US/gamedata/excel/skin_table.json"; 30 | private static final String CHWD_EN_DATA_URL = "https://raw.githubusercontent.com/Aceship/AN-EN-Tags/master/json/gamedata/en_US/gamedata/excel/charword_table.json"; 31 | 32 | public Arknights(String name) throws IOException { 33 | super(name); 34 | } 35 | 36 | @Override 37 | public void afterInit() { 38 | // Empty impl 39 | } 40 | 41 | @Override 42 | protected WaifuData loadFromCustomSource() throws InterruptedException { 43 | System.out.println("Getting Arknights character data"); 44 | AtomicReference characterMap = new AtomicReference<>(); 45 | AtomicReference skinData = new AtomicReference<>(); 46 | AtomicReference charwordMap = new AtomicReference<>(); 47 | 48 | // Maybe this is useless 49 | List runnables = Arrays.asList(() -> { 50 | try { 51 | System.out.println("Loading chwd data..."); 52 | charwordMap.set(CharwordMap.fromJson(Util.downloadString(CHWD_EN_DATA_URL))); 53 | System.out.println("chwd loaded"); 54 | } catch (IOException e) { 55 | e.printStackTrace(); 56 | } 57 | },() -> { 58 | try { 59 | System.out.println("Loading character data..."); 60 | characterMap.set(CharacterMap.fromJson(Util.downloadString(CHAR_DATA_URL))); 61 | System.out.println("Character data loaded"); 62 | } catch (IOException e) { 63 | e.printStackTrace(); 64 | } 65 | },() -> { 66 | try { 67 | System.out.println("Loading skins..."); 68 | skinData.set(SkinData.fromJson(Util.downloadString(SKIN_DATA_URL))); 69 | System.out.println("Skins loaded"); 70 | } catch (IOException e) { 71 | e.printStackTrace(); 72 | } 73 | }); 74 | 75 | List threads = runnables.stream().map(Thread::new).collect(Collectors.toList()); 76 | threads.forEach(Thread::start); 77 | for (Thread thread : threads) { 78 | thread.join(); 79 | } 80 | 81 | System.out.println("Parsing data..."); 82 | Character character = characterMap.get().getWithName(getName()); 83 | List skins = skinData.get().ofCharacter(character); 84 | List skinsUrls = skins.stream().map(Skin::composeUrl).collect(Collectors.toList()); 85 | List dialogs = charwordMap.get().ofCharacter(character).parallelStream().map(Charword::asDialog).collect(Collectors.toList()); 86 | return new WaifuData(dialogs, orderSkins(skinsUrls)); 87 | } 88 | 89 | @Override 90 | public List getDialogs(String event) { 91 | return super.getDialogs(event).stream() 92 | .filter(e -> e.getLanguage().equalsIgnoreCase(Settings.getArknightsLanguage())) 93 | .filter(e -> !"onLogin".equals(event) || e.getEvent().equalsIgnoreCase(event)) 94 | .map((e) -> e.setDialog(e.getDialog().replace("{@nickname}", Settings.getArknightsNickname()))) 95 | .collect(Collectors.toList()); 96 | } 97 | 98 | private double calculateSkinValue(String skinUrl) { 99 | Matcher matcher = Pattern.compile("_(\\d)(\\+*).png").matcher(skinUrl); 100 | if (!matcher.find()) return 20; // Extra skin 101 | double nValue = Double.parseDouble(matcher.group(1)); 102 | boolean hasPlus = !"".equals(matcher.group(2)); 103 | return (hasPlus) ? nValue + 0.5d : nValue; // Special skin with order or standard skin 104 | } 105 | 106 | private List orderSkins(List skins) { 107 | return skins.stream().sorted(Comparator.comparingDouble(this::calculateSkinValue)).collect(Collectors.toList()); 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/adapters/impl/GenshinImpact.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.adapters.impl; 2 | 3 | import com.kitsunecode.mms.core.adapters.IWaifuAdapter; 4 | import com.kitsunecode.mms.core.entities.Dialog; 5 | import com.kitsunecode.mms.core.entities.Settings; 6 | import com.kitsunecode.mms.core.entities.WaifuData; 7 | import com.kitsunecode.mms.core.entities.annotations.Adapter; 8 | import org.jsoup.Jsoup; 9 | import org.jsoup.nodes.Document; 10 | import org.jsoup.nodes.Element; 11 | import org.jsoup.select.Selector; 12 | 13 | import java.io.IOException; 14 | import java.util.*; 15 | import java.util.stream.Collectors; 16 | import java.util.stream.Stream; 17 | 18 | @Adapter 19 | public class GenshinImpact extends IWaifuAdapter { 20 | 21 | private static final String BASE_URL = "https://genshin-impact.fandom.com"; 22 | 23 | private static final String IMAGES_SELECTOR = "a[title='Wish'] img"; 24 | private static final String INGAME_IMAGE_SELECTOR = "a[title='In-Game'] img"; 25 | private static final String FEMALE_IMAGE_SELECTOR = "a[title='In-Game (Lumine)'] img"; 26 | private static final String MALE_IMAGE_SELECTOR = "a[title='In-Game (Aether)'] img"; 27 | 28 | public GenshinImpact(String name) { 29 | super(name); 30 | } 31 | 32 | @Override 33 | protected WaifuData loadFromCustomSource() throws Exception { 34 | System.out.println("Getting waifu image"); 35 | Document mainDoc = Jsoup.connect(BASE_URL + "/wiki/" + getName()).get(); 36 | Document outfitsDoc = Jsoup.connect(BASE_URL + "/wiki/" + getName() + "/Outfits").get(); 37 | Document dialogsDoc = Jsoup.connect(BASE_URL + "/wiki/" + getName() + "/Voice-Overs").get(); 38 | return new WaifuData(loadDialogs(dialogsDoc), loadSkinUrls(mainDoc, outfitsDoc)); 39 | } 40 | 41 | @Override 42 | public void afterInit() { 43 | // Empty impl 44 | } 45 | 46 | private List loadSkinUrls(Document mainDoc, Document outfitsDoc) { 47 | List urls = Stream.of( 48 | Selector.select(IMAGES_SELECTOR, mainDoc).first(), 49 | Selector.select(INGAME_IMAGE_SELECTOR, mainDoc).first(), 50 | Selector.select(MALE_IMAGE_SELECTOR, mainDoc).first(), 51 | Selector.select(FEMALE_IMAGE_SELECTOR, mainDoc).first() 52 | ).filter(Objects::nonNull) 53 | .map((e) -> e.attr("src").split("/revision/latest")[0]) 54 | .collect(Collectors.toList()); 55 | 56 | List rows = Selector.select("table.article-table", outfitsDoc) 57 | .first().getElementsByTag("tbody") 58 | .first().getElementsByTag("tr") 59 | .stream().skip(2) 60 | .collect(Collectors.toList()); 61 | 62 | if (!rows.isEmpty()) { 63 | for (Element row : rows) { 64 | String path = row.getElementsByTag("td").first().getElementsByTag("a").first().attr("href"); 65 | try { 66 | Document outfitDoc = Jsoup.connect(BASE_URL + path).get(); 67 | Element portraitElement = Selector.select("a[title='Wish']", outfitDoc).first(); 68 | if (portraitElement != null) { 69 | urls.add(portraitElement.attr("href").split("/revision")[0]); 70 | } 71 | Element ingameElement = Selector.select("a[title='In-Game']", outfitDoc).first(); 72 | if (ingameElement != null) { 73 | urls.add(ingameElement.attr("href").split("/revision")[0]); 74 | } 75 | } catch (IOException e) { 76 | e.printStackTrace(); 77 | } 78 | } 79 | } 80 | 81 | return urls; 82 | 83 | } 84 | 85 | private List loadDialogs(Document document) { 86 | 87 | List dialogs = new ArrayList<>(); 88 | 89 | List rows = Selector.select("table.wikitable", document) 90 | .first() 91 | .child(0) 92 | .getElementsByTag("tr") 93 | .stream() 94 | .skip(2) 95 | .collect(Collectors.toList()); 96 | 97 | for (Element row : rows) { 98 | Element td = row.getElementsByTag("td").first(); 99 | if(td == null) { 100 | continue; 101 | } 102 | Element audioSpan = td.getElementsByTag("span").stream().findAny().orElse(null); 103 | String audioUrl = null; 104 | if (audioSpan != null) { 105 | audioUrl = audioSpan.getElementsByTag("a").first().attr("href").split("/revision")[0]; 106 | audioSpan.remove(); 107 | } 108 | 109 | String dialog = row.getElementsByTag("td").text(); 110 | 111 | dialogs.add(new Dialog("en", dialog, onTouchEventKey(), audioUrl)); 112 | } 113 | 114 | return dialogs; 115 | 116 | } 117 | 118 | @Override 119 | public String getSkin(int skinIndex) { 120 | return this.data.getSkins().get(skinIndex); 121 | } 122 | 123 | @Override 124 | public int getSkinCount() { 125 | return this.data.getSkins().size(); 126 | } 127 | 128 | @Override 129 | public List getDialogs(String event) { 130 | if (event.equals(onLogoutEventKey())) return Collections.emptyList(); 131 | List dialogs = this.data.getDialogs(); 132 | if (Settings.isOnlyAudioDialogs()) { 133 | return dialogs.stream().filter((d) -> d.getAudio() != null).collect(Collectors.toList()); 134 | } 135 | return dialogs; 136 | } 137 | 138 | } 139 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/utils/BootProcedures.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.utils; 2 | 3 | import com.kitsunecode.mms.core.entities.CommandExecutor; 4 | import com.kitsunecode.mms.core.entities.Settings; 5 | 6 | import java.io.File; 7 | import java.io.IOException; 8 | import java.io.PrintStream; 9 | import java.net.URISyntaxException; 10 | import java.nio.file.Files; 11 | import java.nio.file.Path; 12 | import java.nio.file.Paths; 13 | import java.nio.file.StandardOpenOption; 14 | import java.text.ParsePosition; 15 | import java.text.SimpleDateFormat; 16 | import java.util.Arrays; 17 | import java.util.Comparator; 18 | import java.util.Date; 19 | import java.util.Locale; 20 | 21 | public final class BootProcedures { 22 | 23 | private BootProcedures() { 24 | // Private impl 25 | } 26 | 27 | public static void windowsRegiterAutoStartup() throws IOException, URISyntaxException { 28 | 29 | File mmsPath = Paths.get(System.getenv("APPDATA"), "mms").toFile(); 30 | File batRunnerFile = Paths.get(mmsPath.toString(), "Moe Moe Secretary.bat").toFile(); 31 | File jarPathName = new File(Util.class.getProtectionDomain().getCodeSource().getLocation().toURI()); 32 | Path regfilepath = Paths.get("regfile"); 33 | 34 | if (!mmsPath.exists() && !mmsPath.mkdir()) { 35 | throw new RuntimeException("Cannot create file in APPDATA (" + mmsPath.toString() + ")"); 36 | } 37 | 38 | String regString = Util.readResourceString("utilfiles/regtemplate"); 39 | String batString = Util.readResourceString("utilfiles/battemplate"); 40 | 41 | if (regString == null || batString == null) { 42 | throw new RuntimeException("Cannot read template files."); 43 | } 44 | 45 | if (!"25120671a9a31ccb19c4aac41bc13178".equals(Util.md5(regString)) 46 | || !"0f3aa7cbef25f2d25f0df1de6cafbef1".equals(Util.md5(batString))) { 47 | System.out.println("Corrupted resources found, skipping."); 48 | return; // Sometimes bugs can happen, just disable the functionality instead of crashing the waifu 49 | } 50 | 51 | regString = regString.replace("{batpath}", batRunnerFile.toString().replace("\\", "\\\\")); 52 | batString = batString.replace("{jarpath}", jarPathName.getParent()) 53 | .replace("{jarname}", jarPathName.getName()); 54 | 55 | Files.write(batRunnerFile.toPath(), batString.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); 56 | Files.write(regfilepath, regString.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); 57 | 58 | try { 59 | if (new CommandExecutor().executeCommand("reg", "IMPORT", regfilepath.toString()).getExitCode() != 0) { 60 | System.out.println("String used:\n" + regString); 61 | throw new RuntimeException("Cannot add the boot key to the registry"); 62 | } 63 | } finally { 64 | regfilepath.toFile().delete(); 65 | } 66 | System.out.println("Registered on boot"); 67 | } 68 | 69 | public static void windowsUnregisterAutoStartup() throws IOException { 70 | // Ignore command failure, if it fails we have nothing to do since the key is already not there 71 | new CommandExecutor().executeCommand("REG DELETE HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run /v \"Moe Moe Secretary\" /f"); 72 | Path mmsPath = Paths.get(System.getenv("APPDATA"), "mms"); 73 | Path batRunnerPath = Paths.get(mmsPath.toString(), "Moe Moe Secretary.bat"); 74 | Files.deleteIfExists(batRunnerPath); 75 | System.out.println("Unregistered from boot"); 76 | } 77 | 78 | public static void windowsStartupProcedure() throws IOException, URISyntaxException { 79 | if (Settings.isAutoStartupEnabled()) { 80 | windowsRegiterAutoStartup(); 81 | } else { 82 | windowsUnregisterAutoStartup(); 83 | } 84 | } 85 | 86 | public static void unixStartupProcedure() { 87 | System.out.println("NOT IMPLEMENTED YET"); 88 | } 89 | 90 | public static void startupProcedure() throws Exception { 91 | if (Util.isWindows()) { 92 | windowsStartupProcedure(); 93 | } else { 94 | unixStartupProcedure(); 95 | } 96 | } 97 | 98 | public static void logToFile() throws IOException { 99 | if (!Paths.get("logs").toFile().exists() && !Paths.get("logs").toFile().mkdir()) { 100 | System.out.println("Cannot create logs directory, check you MMS folder"); 101 | System.out.println("Logging to console or /dev/null if the console is not attached"); 102 | return; 103 | } 104 | 105 | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss.'log'", Locale.ENGLISH); 106 | Comparator fileDateComparator = (e1, e2) -> 107 | dateFormat.parse(e2.getName(), new ParsePosition(0)).compareTo(dateFormat.parse(e1.getName(), new ParsePosition(0))); 108 | 109 | File[] files = new File("logs").listFiles(); 110 | if (files != null) { 111 | Arrays.stream(files) 112 | .sorted(fileDateComparator) 113 | .skip(2) 114 | .forEach(File::delete); 115 | } 116 | 117 | // Creating a File object that represents the disk file. 118 | File output = new File("logs", dateFormat.format(new Date())); 119 | if (!output.createNewFile()) { 120 | System.out.println("Cannot create log file!"); 121 | return; 122 | } 123 | 124 | if (!System.getenv().containsKey("IDE")) { 125 | System.out.println("Sending logs to file: " + output.getAbsolutePath()); 126 | PrintStream o = new PrintStream(output); 127 | System.setOut(o); 128 | System.setErr(o); 129 | } 130 | } 131 | 132 | } 133 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/adapters/impl/AzurLane.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.adapters.impl; 2 | 3 | import com.kitsunecode.mms.core.adapters.IWaifuAdapter; 4 | import com.kitsunecode.mms.core.entities.Dialog; 5 | import com.kitsunecode.mms.core.entities.WaifuData; 6 | import com.kitsunecode.mms.core.entities.annotations.Adapter; 7 | import com.kitsunecode.mms.core.entities.Settings; 8 | import org.jsoup.Jsoup; 9 | import org.jsoup.nodes.Document; 10 | import org.jsoup.nodes.Element; 11 | import org.jsoup.select.Elements; 12 | import org.jsoup.select.Selector; 13 | 14 | import java.io.IOException; 15 | import java.util.ArrayList; 16 | import java.util.Arrays; 17 | import java.util.List; 18 | import java.util.Locale; 19 | import java.util.stream.Collectors; 20 | 21 | @Adapter 22 | public class AzurLane extends IWaifuAdapter { 23 | 24 | private static final String BASE_URL = "https://azurlane.koumakan.jp/wiki"; 25 | 26 | private static final String IMAGES_SELECTOR = "div[id='mw-content-text'] > div[class='mw-parser-output'] > div > section > article"; 27 | private static final String IMAGE_SELECTOR = "div.shipskin-image > a.image > img"; 28 | private static final String TABLE_ROWS_JAP = "article[data-title='Japanese Server'] > table:nth-child(3) > * tr"; 29 | private static final String TABLE_ROWS_CN = "article[data-title='Chinese Server'] > table:nth-child(3) > * tr"; 30 | private static final String TABLE_ROWS_EN = "article[data-title='English Server'] > table:nth-child(3) > * tr"; 31 | 32 | private static final String AUDIO_COL = "td:nth-child(2) > a"; 33 | private static final String EVENT_COL = "th:nth-child(1)"; 34 | private static final String DIALOG_COL = "td:nth-child(3)"; 35 | 36 | private static final String WIKI_ON_CLICK_EVENT_KEY = "Secretary (Touch)"; 37 | private static final String WIKI_ON_LOGIN_EVENT_KEY = "Login"; 38 | private static final String WIKI_ON_IDLE_EVENT_KEY = "Idle"; 39 | 40 | private static final String lang = Settings.getWaifuLanguage(); 41 | 42 | public AzurLane(String name) throws IOException { 43 | super(name); 44 | } 45 | 46 | @Override 47 | public void afterInit() { 48 | // Empty impl 49 | } 50 | 51 | @Override 52 | protected WaifuData loadFromCustomSource() throws IOException { 53 | System.out.println("Getting ship quotes"); 54 | Document quotesDoc = Jsoup.connect(BASE_URL + "/" + getName() + "/Quotes").get(); 55 | System.out.println("Getting ship images"); 56 | Document skinsDoc = Jsoup.connect(BASE_URL + "/" + getName() + "/Gallery").get(); 57 | System.out.println("Parsing data..."); 58 | return new WaifuData(loadDialogs(quotesDoc), loadSkinUrls(skinsDoc)); 59 | } 60 | 61 | private List loadSkinUrls(Document doc) { 62 | return Selector.select(IMAGES_SELECTOR, doc).stream() 63 | .map(e -> e.select(IMAGE_SELECTOR).first()) 64 | .map(e -> e.hasAttr("srcset") ? e.attr("srcset") : e.attr("src")) 65 | .map(set -> Arrays.stream(set.split(",")) 66 | .map(s -> s.trim().split(" ")[0]) 67 | .reduce((first, second) -> second) 68 | .orElse(null)) 69 | .collect(Collectors.toList()); 70 | } 71 | 72 | private List loadDialogs(Document doc) { 73 | System.out.println("Loading dialogs"); 74 | List dialogList = new ArrayList<>(); 75 | dialogList.addAll(loadDialogs(doc, TABLE_ROWS_CN, "Chinese")); 76 | dialogList.addAll(loadDialogs(doc, TABLE_ROWS_JAP, "Japanese")); 77 | dialogList.addAll(loadDialogs(doc, TABLE_ROWS_EN, "English")); 78 | return dialogList; 79 | } 80 | 81 | private List loadDialogs(Document doc, String selector, String lang) { 82 | List dialogList = new ArrayList<>(); 83 | 84 | System.out.println("Loading dialogs of language " + lang); 85 | 86 | Elements rows = Selector.select(selector, doc); 87 | // TODO: Find a better way 88 | // Some quote pages (for example Bremerton and Enterprise) have 89 | // an additional p tag and the table is shifted 90 | if (rows.size() == 0) { 91 | selector = selector.replace("(3)", "(4)"); 92 | rows = Selector.select(selector, doc); 93 | } 94 | rows.remove(0); 95 | 96 | for (Element row : rows) { 97 | if (row.childrenSize() < 3) { 98 | continue; 99 | } 100 | Element audioElem = row.select(AUDIO_COL).first(); 101 | String audioUrl = audioElem != null ? audioElem.attr("href") : ""; 102 | String eventText = row.selectFirst(EVENT_COL).text().trim(); 103 | if (eventText.contains("Idle")) { 104 | eventText = "Idle"; 105 | } 106 | 107 | // Replace event with our own 108 | eventText = eventText.replace(WIKI_ON_IDLE_EVENT_KEY, onIdleEventKey()) 109 | .replace(WIKI_ON_CLICK_EVENT_KEY, onTouchEventKey()) 110 | .replace(WIKI_ON_LOGIN_EVENT_KEY, onLoginEventKey()); 111 | 112 | String dialogText = row.selectFirst(DIALOG_COL).text(); 113 | 114 | if (!"".equals(dialogText)) { 115 | dialogList.add(new Dialog(lang, dialogText, eventText, audioUrl)); 116 | } 117 | } 118 | 119 | System.out.println("Found " + dialogList.size() + " dialogs"); 120 | return dialogList; 121 | } 122 | 123 | @Override 124 | public String getSkin(int skinIndex) { 125 | return this.data.getSkins().stream() 126 | .filter(e -> Settings.isAzurChibi() == e.toLowerCase(Locale.ENGLISH).contains("chibi")) 127 | .collect(Collectors.toList()).get(skinIndex); 128 | } 129 | 130 | @Override 131 | public int getSkinCount() { 132 | return (int) this.data.getSkins().stream() 133 | .filter(e -> Settings.isAzurChibi() == e.toLowerCase(Locale.ENGLISH).contains("chibi")) 134 | .count(); 135 | } 136 | 137 | @Override 138 | public List getDialogs(String event) { 139 | return this.data.getDialogs().stream() 140 | .filter(d -> d.getEvent().equals(event)) 141 | .filter(d -> d.getLanguage().equalsIgnoreCase(lang)) 142 | .collect(Collectors.toList()); 143 | } 144 | 145 | } 146 | -------------------------------------------------------------------------------- /src/main/resources/config/config.properties: -------------------------------------------------------------------------------- 1 | # ===================================================== Config file =============================================== # 2 | 3 | # Waifu will auto reload when this file is saved 4 | # Delete this file if you want to get the default settings file again 5 | # Version: 1.8 6 | 7 | # Arknights adapter now supports all character, skins, dialogs, audios...! 8 | # Also you can change arknights.nickname (bottom of the file) with your own nickname! 9 | 10 | # Adapters are made by @KaikyuLotus (Telegram) 11 | # You can ask him to add any game waifus! 12 | 13 | 14 | # ------------------------------------------------------ Adapters ------------------------------------------------------------ 15 | # | Adapter | Example Name | Help | 16 | # |----------------------------------------------------------------------------------------------------------------------------| 17 | # | GenshinImpact | Keqing | Use character name as waifu.name | 18 | # |----------------------------------------------------------------------------------------------------------------------------| 19 | # | GirlsFrontline | HK416 | Use weapon name as waifu.name | 20 | # | ---------------------------------------------------------------------------------------------------------------------------| 21 | # | AzurLane | Hatakaze | Use ship name as waifu.name | 22 | # | ---------------------------------------------------------------------------------------------------------------------------| 23 | # | File | | https://telegra.ph/Moe-Moe-Secretary-File-Adapter-Configuration-01-12 | 24 | # | ---------------------------------------------------------------------------------------------------------------------------| 25 | # | SIFIdol | 1712 | Use card ID from https://schoolido.lu/cards/ as waifu.name | 26 | # | ---------------------------------------------------------------------------------------------------------------------------| 27 | # | MirageMemorial | Confucius | Use servant name as waifu.name | 28 | # | ---------------------------------------------------------------------------------------------------------------------------| 29 | # | Arknights | Texas | Use operator name as waifu.name | 30 | # | ---------------------------------------------------------------------------------------------------------------------------| 31 | # | Github | VTuber/Hololive/Lamy | Use the folder path in the repo as waifu name | 32 | # | | | Also set github.repo=KaikyuDev/moe-moe-secretary-waifus and github.branch=master | 33 | # | | | You can create your own repository and set it here | 34 | # | ---------------------------------------------------------------------------------------------------------------------------| 35 | # | SinoAlice | レム/クラッシャー | Go to https://sinoalice.game-db.tw/characters/ and choose your waifu. | 36 | # | | | You'll get into a page with https://sinoalice.game-db.tw/characters/ as URL | 37 | # | | | Copy the Japanese name at the end of the URL into the waifu.name property | 38 | # | | | If you encounter issues, please sure that this file is saved as UTF-8 | 39 | # ---------------------------------------------------------------------------------------------------------------------------- 40 | 41 | 42 | # -------------- Commands ------------------------------- 43 | # | Key | Action | 44 | # |-------------------------------------------------------| 45 | # | k | Set next available skin | 46 | # | j | Set previous available skin | 47 | # | t | Toggle always on top | 48 | # | f | Toggle floating if enabled here | 49 | # | s | Horizontally flips the waifu | 50 | # | Mouse Wheel Click | Closes the waifu saving some data | 51 | # ------------------------------------------------------- 52 | 53 | 54 | # ================================================================================================================= # 55 | 56 | adapter=GenshinImpact 57 | adapter.file.format=YAML 58 | 59 | waifu.name=Keqing 60 | 61 | user.nickname=ChangeMe 62 | 63 | # Change this to true if you want your waifu on computer startup 64 | waifu.autoStartupEnabled=false 65 | waifu.height=680 66 | waifu.welcome.enabled=true 67 | waifu.welcome.delay=2000 68 | waifu.startY=auto 69 | 70 | # Only works on Windows 71 | waifu.active.opacity=100 72 | waifu.inactive.opacity=70 73 | 74 | # Y drag is on beta 75 | waifu.enableYdrag=false 76 | 77 | # The floating effect 78 | floating.stepSleep=30 79 | floating.pixelRange=16 80 | floating.pixelPerStep=1 81 | floating.switchSleep=400 82 | 83 | dialogs.enabled=true 84 | dialogs.onClick=true 85 | dialogs.onIdle=true 86 | dialogs.onlyAudioDialogs=true 87 | # How much to wait between idle dialogs ( seconds ) 88 | dialogs.idle.frequency=60000 89 | # Seconds 90 | dialogs.baloon.noVoiceDuration=6000 91 | 92 | # Baloon is showed only if dialogs are enabled 93 | baloon.formatString=


[[text]]

94 | baloon.font=Bahnschrift Light 95 | # From bottom 96 | baloon.yOffset=300 97 | # From center to right 98 | baloon.xOffset=0 99 | baloon.height=70 100 | baloon.width=350 101 | baloon.fontSize=18 102 | baloon.background=0,0,0,200 103 | baloon.foreground=200,200,200,255 104 | baloon.highQualityText=true 105 | # Voice settings 106 | voice.enabled=true 107 | voice.volume=60 108 | 109 | jump.onClick=true 110 | jump.pixelRange=40 111 | jump.stepSleep=15 112 | jump.pixelPerStep=3 113 | jump.count=1 114 | 115 | # Arknights Specific 116 | # Language still not implemented 117 | arknights.language=en 118 | arknights.nickname=Nickname 119 | 120 | # Azur Lane specific 121 | # Chibis are on beta 122 | azurlane.chibi=false 123 | # 'Chinese' or 'Chinese Native' 124 | azurlane.language=Chinese -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/adapters/IWaifuAdapter.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.adapters; 2 | 3 | import com.kitsunecode.mms.core.entities.Dialog; 4 | import com.kitsunecode.mms.core.entities.Settings; 5 | import com.kitsunecode.mms.core.entities.WaifuData; 6 | import com.kitsunecode.mms.core.entities.exceptions.StartFailedException; 7 | import com.kitsunecode.mms.core.utils.Util; 8 | import org.apache.commons.io.FileUtils; 9 | import org.jsoup.HttpStatusException; 10 | 11 | import java.io.File; 12 | import java.io.IOException; 13 | import java.nio.charset.StandardCharsets; 14 | import java.nio.file.Files; 15 | import java.nio.file.Paths; 16 | import java.util.List; 17 | import java.util.Locale; 18 | import java.util.stream.Collectors; 19 | 20 | 21 | public abstract class IWaifuAdapter { 22 | 23 | private static final String ON_IDLE_EVENT_KEY = "onIdle"; 24 | private static final String ON_LOGIN_EVENT_KEY = "onLogin"; 25 | private static final String ON_LOGOUT_EVENT_KEY = "onLogout"; 26 | private static final String ON_CLICK_EVENT_KEY = "onClick"; 27 | private static final String ON_LOW_BATTERY_EVENT_KEY = "onLowBattery"; 28 | private static final String ON_HIGH_CPU_USAGE_KEY = "onHighCpu"; 29 | 30 | private final long startTimeMillis; 31 | 32 | private final String configName; 33 | 34 | protected WaifuData data; 35 | 36 | protected abstract WaifuData loadFromCustomSource() throws Exception; 37 | 38 | public IWaifuAdapter(String name) { 39 | this.startTimeMillis = System.currentTimeMillis(); 40 | this.configName = name; 41 | } 42 | 43 | public final void init() { 44 | try { 45 | Util.checkFolders(getName()); 46 | 47 | if (hasSavedFile()) { 48 | data = getDataFromFile(); 49 | } else { 50 | data = loadFromCustomSource(); 51 | saveDataToFile(); 52 | } 53 | 54 | if (data.getSkins().isEmpty()) { 55 | throw new StartFailedException("No images found for this waifu"); 56 | } 57 | 58 | afterInit(); 59 | } catch (HttpStatusException e) { 60 | String message = "Wiki status code: " + e.getStatusCode(); 61 | if (e.getStatusCode() == 404) { 62 | message += ", probably this waifu does not exist"; 63 | } 64 | throw new StartFailedException(message, e); 65 | } catch (StartFailedException e) { 66 | throw e; 67 | } catch (Exception e) { 68 | throw new StartFailedException(e.getClass().getSimpleName() + ": " + e.getMessage(), e); 69 | } 70 | } 71 | 72 | public File getDataFile() { 73 | return Paths.get("resources", getName(), "data." + Settings.getFileFormat().toLowerCase(Locale.ENGLISH)).toFile(); 74 | } 75 | 76 | public final void saveDataToFile() throws IOException { 77 | File file = getDataFile(); 78 | WaifuData waifuData = getWaifuData(); 79 | System.out.println("Saving waifu " + getName() + " data..."); 80 | FileUtils.writeStringToFile(file, Util.serializeWaifuData(waifuData), "UTF-8"); 81 | } 82 | 83 | public final WaifuData getDataFromFile() throws IOException { 84 | File file = getDataFile(); 85 | System.out.println("Reading waifu " + getName() + " data..."); 86 | String jsonData = String.join("\n", Files.readAllLines(file.toPath(), StandardCharsets.UTF_8)); 87 | System.out.println("Readed " + (jsonData.length() * 2) + " bytes of waifu data!"); 88 | String fileFormat = Settings.getFileFormat(); 89 | return Util.deserializeWaifu(jsonData, fileFormat); 90 | } 91 | 92 | public final boolean hasSavedFile() { 93 | return getDataFile().exists(); 94 | } 95 | 96 | /** 97 | * Downloads a file only if it's not present in the folder 98 | *

99 | * If the file ends with .ogg it's an audio, otherwise it's a .png 100 | * If the file is already present the this method just reads and returns it 101 | * If something goes wrong throws an exception, really angery waifu incoming in that case <3 102 | * 103 | * @param url The file's url 104 | * @param fileName File's name 105 | * @return File's byte array 106 | */ 107 | public File downloadFile(String url, String fileName) { 108 | String specificFolder = (Util.isUrl(url)) ? (url.endsWith(".png") || url.endsWith(".jpg") ? "skins" : "audios") : ""; 109 | File resourceFile = Paths.get("resources", getName(), specificFolder, Util.safeFileName(fileName)).toFile(); 110 | 111 | // Use local if exists 112 | if (resourceFile.exists()) { 113 | return resourceFile; 114 | } 115 | 116 | // Try to download 117 | if (!Util.isUrl(url)) { 118 | throw new RuntimeException("Can't find file " + fileName + " from path " + url); 119 | } 120 | 121 | boolean downloaded = Util.downloadFile(url, resourceFile); 122 | 123 | if (!downloaded) { 124 | throw new RuntimeException("Can't download/find file " + fileName + " from url/path " + url); 125 | } 126 | 127 | return resourceFile; 128 | 129 | } 130 | 131 | public WaifuData getWaifuData() { 132 | return this.data; 133 | } 134 | 135 | public String getSkin(int skinNumber) { 136 | return this.data.getSkins().get(skinNumber); 137 | } 138 | 139 | public int getSkinCount() { 140 | return this.data.getSkins().size(); 141 | } 142 | 143 | public long getUptime() { 144 | return System.currentTimeMillis() - startTimeMillis; 145 | } 146 | 147 | public List

getDialogs() { 148 | return data.getDialogs(); 149 | } 150 | 151 | public List getDialogs(String event) { 152 | return this.data.getDialogs().stream().filter(e -> e.getEvent().equals(event)).collect(Collectors.toList()); 153 | } 154 | 155 | public String getShowableName() { 156 | return this.configName; 157 | } 158 | 159 | public String getName() { 160 | return configName; 161 | } 162 | 163 | public String onTouchEventKey() { 164 | return ON_CLICK_EVENT_KEY; 165 | } 166 | 167 | public String onIdleEventKey() { 168 | return ON_IDLE_EVENT_KEY; 169 | } 170 | 171 | public String onLogoutEventKey() { 172 | return ON_LOGOUT_EVENT_KEY; 173 | } 174 | 175 | public String onLowBatteryEventKey() { 176 | return ON_LOW_BATTERY_EVENT_KEY; 177 | } 178 | 179 | public String onHighCpuUsageKey() { 180 | return ON_HIGH_CPU_USAGE_KEY; 181 | } 182 | 183 | public String onLoginEventKey() { 184 | return ON_LOGIN_EVENT_KEY; 185 | } 186 | 187 | public abstract void afterInit(); 188 | } 189 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.kitsunecode 8 | moe-moe-secretary 9 | 1.2.3 10 | jar 11 | 12 | 13 | UTF-8 14 | 15 | 16 | 1.8 17 | 1.8 18 | 19 | ${target.version} 20 | ${source.version} 21 | 22 | 3.2.0 23 | 3.8.1 24 | 3.1.0 25 | 2.5.2 26 | 1.6.0 27 | 28 | 2.8.9 29 | 1.0.3.3 30 | 1.15.3 31 | 2.11.0 32 | 1.32 33 | 4.5.13 34 | 0.3.7-2 35 | 1.9.5-1 36 | 1.0.3-1 37 | 0.9.12 38 | 39 | 40 | com.kitsunecode.mms.core.utils.JarSpiFixer 41 | com.kitsunecode.mms.core.Main 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.jsoup 49 | jsoup 50 | ${jsoup.version} 51 | 52 | 53 | 54 | 55 | commons-io 56 | commons-io 57 | ${commons-io.version} 58 | 59 | 60 | 61 | 62 | com.google.code.gson 63 | gson 64 | ${gson.version} 65 | 66 | 67 | 68 | 69 | org.yaml 70 | snakeyaml 71 | ${snakeyaml.version} 72 | 73 | 74 | 75 | 76 | org.apache.httpcomponents 77 | httpclient 78 | ${httpclient.version} 79 | 80 | 81 | 82 | 83 | com.googlecode.soundlibs 84 | tritonus-share 85 | ${tritonus.version} 86 | 87 | 88 | 89 | 90 | com.googlecode.soundlibs 91 | mp3spi 92 | ${mp3spi.version} 93 | 94 | 95 | 96 | 97 | com.googlecode.soundlibs 98 | vorbisspi 99 | ${vorbisspi.version} 100 | 101 | 102 | 103 | 104 | org.reflections 105 | reflections 106 | ${reflections.version} 107 | 108 | 109 | 110 | 111 | 112 | src/main/java 113 | 114 | 115 | 116 | 117 | org.apache.maven.plugins 118 | maven-assembly-plugin 119 | ${maven-assembly-plugin.version} 120 | 121 | 122 | package 123 | 124 | single 125 | 126 | 127 | 128 | 129 | ${mms.mainclass} 130 | 131 | 132 | false 133 | false 134 | moe-moe-secretary 135 | 136 | jar-with-dependencies 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | org.apache.maven.plugins 145 | maven-source-plugin 146 | ${maven-source-plugin.version} 147 | 148 | 149 | attach-sources 150 | 151 | jar 152 | 153 | 154 | 155 | 156 | 157 | 158 | org.apache.maven.plugins 159 | maven-compiler-plugin 160 | ${maven-compiler-plugin.version} 161 | 162 | ${source.version} 163 | ${target.version} 164 | 165 | 166 | 167 | 168 | org.apache.maven.plugins 169 | maven-install-plugin 170 | ${maven-install-plugin.version} 171 | 172 | 173 | 174 | 175 | org.codehaus.mojo 176 | exec-maven-plugin 177 | ${maven-exec-plugin.version} 178 | 179 | 180 | package 181 | 182 | java 183 | 184 | 185 | ${spi.fixer.class} 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | kaikyu.lotus@gmail.com 197 | Kaikyu Lotus 198 | https://github.com/KaikyuDev 199 | 200 | 201 | 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

4 | 5 | ![CI Status](https://github.com/KaikyuDev/moe-moe-secretary/workflows/Java%20CI/badge.svg) 6 | [![Codacy Badge](https://app.codacy.com/project/badge/Grade/c2a2976174b94b11ae748978a211c9b2)](https://www.codacy.com/manual/kaikyu.lotus/moe-moe-secretary?utm_source=github.com&utm_medium=referral&utm_content=KaikyuLotus/moe-moe-secretary&utm_campaign=Badge_Grade) 7 | 8 | #### Moe Moe Secretary - Your waifu (almost) always with you! 9 | 10 | ### Index 11 | - [Installing](#installing) 12 | - [Usage](#usage) 13 | - [Configuration](#configuration) 14 | - [Adapters](#adapters) 15 | - [Help](#help) 16 | - [Contributing](#contributing) 17 | - [Screenshots](#screenshots) 18 | 19 | ### Installing 20 | In order to install Moe Moe Secretary, please download the latest jar from the [Github Releases](https://github.com/KaikyuLotus/moe-moe-secretary/releases/latest)\ 21 | You'll need a JRE (1.8+) installed, you can get it [here](https://adoptopenjdk.net/installation.html#x64_win-jre).\ 22 | Place the JAR file in a secure place, better if it's in a folder 23 | 24 | ### Usage 25 | All the key commands must be used after clicking the waifu in order to obtains window focus. 26 | - Double click the jar file to start Moe Moe Secretary,\ 27 | once started you'll find a waifu floating on your desktop (Ptilopsis from Arknights) 28 | - Move her around by dragging her 29 | - Click her to trigger "on click" dialogs 30 | - Close her by clicking the mouse wheel on her\ 31 | (if you don't have a mouse wheel, ALT F4 combination will do the job) 32 | - If the adapter supports skin, you can switch them pressing J and K keys 33 | - By default the waifu should be on always-on-top mode, to toggle it press the T key 34 | - Flip the waifu by pressing S key 35 | - Toggle floating effect by pressing the F key 36 | 37 | ### Configuration 38 | In the JAR file's folder, after starting MMS at least once, there will be a folder named "config",\ 39 | inside it you'll find a file named **config.properties**. 40 | 41 | **config.properties** file contains **all** the settings for your secretary. 42 | 43 | **TIP**: Saving this file will apply the changes to the secretary on the fly. 44 | 45 | Check the next table to see all the possible Adapters and adapter-configurations.\ 46 | All the other settings are self-explanatory. 47 | 48 | ### Adapters 49 | Adapters are used to access different waifus on the internet.\ 50 | Moe Moe Secretary uses public wikis data to download images and dialogs, where available.\ 51 | If you think that a wiki does not like this behaviour, please open an issue. 52 | 53 | The following table shows the adapter names to be used in the .properties file and their relative detailed chapter. 54 | 55 | | Adapter Name | Chapter | 56 | | :---: | :---: | 57 | | AzurLane | [Azur Lane Chapter](#azur-lane-adapter) | 58 | | GenshinImpact | [Genshin Impact Chapter](#genshin-impact-adapter) | 59 | | Arknights | [Arknights Chapter](#arknights-adapter) | 60 | | SinoAlice | [SinoAlice Chapter](#sinoalice-adapter) | 61 | | SIFIdol | [SIFIdol Chapter](#school-idol-festival-adapter) | 62 | | GirlsFrontline | [Girls Frontline Chapter](#girls-frontline-adapter) | 63 | | MirageMemorial | [Mirage Memorial Chapter](#mirage-memorial-adapter) | 64 | | Github | [Github Chapter](#github-adapter) | 65 | | **MMS Official Github** | [MMS Github Chapter](#mms-github-adapter) | 66 | | File | [File Chapter](#file-adapter) | 67 | 68 | ##### Features table 69 | | Feature | Azur Lane | Arknights | SINoALICE | SIFIdol | GirlsFrontline | MirageMemorial | 70 | | :--- | :---: | :---: | :---: | :---: | :---: | :---: | 71 | | Dialogs | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | 72 | | Voices | ✅ | ✅ | ❌ | ✅ | ✅ | ❌ | 73 | | Skins | ✅ | ✅ | ❌ | ✅ | ✅ | ❌ | 74 | 75 | #### Azur Lane Adapter 76 | This adapter takes the data from https://azurlane.koumakan.jp \ 77 | Ship names are the same as in-game names, if you can't really find one take a look [here](https://azurlane.koumakan.jp/List_of_Ships). 78 | 79 | #### Genshin Impact Adapter 80 | This adapter takes the data from https://genshin-impact.fandom.com \ 81 | Character names are the same as in-game names, if you can't really find one take a look [here](https://genshin-impact.fandom.com/wiki/Characters). 82 | 83 | 84 | #### Arknights Adapter 85 | This adapter takes the data from https://github.com/Aceship/AN-EN-Tags \ 86 | Operator names are the same as in-game names, if you can't really find one, search for it [here](https://aceship.github.io/AN-EN-Tags/akhrchars.html?opname=Ptilopsis) 87 | 88 | #### SinoAlice Adapter 89 | This adapter takes the data from https://sinoalice.game-db.tw \ 90 | Characters names are the same as in-game names, if you can't really find one take a look [here](https://sinoalice.game-db.tw/characters/). 91 | 92 | #### School Idol Festival Adapter 93 | This adapter takes card images from https://schoolido.lu and quotes from https://decaf.kouhi.me/lovelive/index.php \ 94 | This adapter requires the card ID as waifu.name in the config.properties, be sure to match the card ID from [here](https://schoolido.lu/cards/). 95 | 96 | #### Girls Frontline Adapter 97 | This adapter takes the data from https://en.gfwiki.com \ 98 | Weapon names are the same as in-game names, if you can't really find one take a look [here](https://en.gfwiki.com/wiki/T-Doll_Index) 99 | 100 | #### Mirage Memorial Adapter 101 | This adapter takes the data from https://miragememorialglobal.fandom.com/wiki \ 102 | Servant names are the same as in-game names, if you can't really find one take a look [here](https://miragememorialglobal.fandom.com/wiki/Special:Images):\ 103 | find your servant, click on the image and look at the URL, it'll end with "?file=Aristotle.png"\ 104 | use the string after = (without .png) (in this case Aristotle) 105 | 106 | #### Github Adapter 107 | Github adapter is the best one, but it has a cost: waifus must be implemented manually first.\ 108 | Moe Moe Secretary has an official repository for custom waifus (mostly VTubers), check the next chapter. 109 | 110 | Github adapter requires some additional parameters in the config.properties: 111 | ```properties 112 | adapter=Github 113 | waifu.name=path/Name 114 | adapter.file.format=format 115 | github.repo=Username/repo 116 | github.branch=branch 117 | ``` 118 | 119 | Those are the required parameters in order to use the github adapter,\ 120 | check the next chapter to see some example values. 121 | 122 | ##### Extra features 123 | - You can create your own waifus and host them on Github. 124 | 125 | This adapter supports all MMS features! 126 | 127 | #### MMS Github Adapter 128 | Moe Moe Secretary has its own [Github waifu repository](https://github.com/KaikyuLotus/moe-moe-secretary-waifus). 129 | 130 | In order to use it set the following values in your config.properties: 131 | ```properties 132 | adapter=Github 133 | waifu.name=VTuber/Hololive/Calliope 134 | adapter.file.format=YAML 135 | github.repo=KaikyuLotus/moe-moe-secretary-waifus 136 | github.branch=master 137 | ``` 138 | 139 | With those settings [Calliope-sama](https://twitter.com/moricalliope) should pop-up on your desktop! 140 | 141 | Want to add more waifus?\ 142 | Create an issue to add them or fork that repo and add them yourself, I'll accept PRs. 143 | 144 | #### File Adapter 145 | Please take a look at this link:\ 146 | https://telegra.ph/Moe-Moe-Secretary-File-Adapter-Configuration-01-12 \ 147 | It may be out of date, if so please open an issue or [contact me on Telegram](https://t.me/KaikyuLotus). 148 | 149 | ### Help 150 | If MMS crashes with a certain adapter or character you can open an issue or join the [official Telegram group](https://t.me/joinchat/HQxrAhRw3k8Zznib57V5Uw)!\ 151 | We also have a CI bot, so you can update your MMS version directly from Telegram!\ 152 | Also check the FAQs 153 | 154 | ### FAQ 155 | - **Q**: I want my waifu to start on my PC startup, how to do it?\ 156 | **A**: Set `waifu.autoStartupEnabled` to `true` in your config.properties 157 | - **Q**: MMS requires internet access to work?\ 158 | **A**: Yes, it does, if you don't want it you could use the file adapter. 159 | - **Q**: Can you add <**character name**>?\ 160 | **A**: Yes, most probably, please open an issue with some details of the requested character. 161 | 162 | ### Contributing 163 | Details on contributions will be added later. 164 | 165 | ### Screenshots 166 | 167 | ___ 168 | 169 | ![Ptilopsis from Arknights helping me with docs](https://i.imgur.com/06BgCqI.jpg) 170 | 171 | ![Fubuki and her conifguration](https://i.imgur.com/0iVkBUC.jpg) 172 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/entities/Settings.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.entities; 2 | 3 | import com.kitsunecode.mms.core.Main; 4 | import org.apache.commons.io.FileUtils; 5 | 6 | import java.awt.*; 7 | import java.io.File; 8 | import java.io.IOException; 9 | import java.io.InputStream; 10 | import java.io.InputStreamReader; 11 | import java.nio.charset.StandardCharsets; 12 | import java.nio.file.Files; 13 | import java.nio.file.Path; 14 | import java.nio.file.Paths; 15 | import java.util.Arrays; 16 | import java.util.Locale; 17 | import java.util.Objects; 18 | import java.util.Properties; 19 | import java.util.function.Function; 20 | 21 | public final class Settings { 22 | 23 | private static final String currentVersion = "1.8"; 24 | 25 | public static final String configFolder = "config"; 26 | public static final String configPath = "config/config.properties"; 27 | public static final String configBckPath = "config/config_bck.properties"; 28 | 29 | private static Properties properties = null; 30 | 31 | private Settings() { 32 | // Private impl 33 | } 34 | 35 | private static void load(InputStreamReader is) throws IOException { 36 | properties.load(is); 37 | } 38 | 39 | private static Properties get() { 40 | if (properties != null) { 41 | return properties; 42 | } 43 | 44 | try { 45 | properties = new Properties(); 46 | 47 | System.out.println("Loading default config first"); 48 | try (InputStream is = Main.class.getClassLoader().getResourceAsStream(configPath); 49 | InputStreamReader s = new InputStreamReader(Objects.requireNonNull(is), StandardCharsets.UTF_8)) { 50 | load(s); 51 | } 52 | 53 | File rf = Paths.get(configFolder).toFile(); 54 | if (!rf.exists() && !rf.mkdir()) { 55 | return properties; 56 | } 57 | 58 | Path config = Paths.get(configPath); 59 | if (config.toFile().exists()) { 60 | System.out.println("Found custom config file, loading it..."); 61 | try (InputStreamReader in = new InputStreamReader(Files.newInputStream(config), StandardCharsets.UTF_8)) { 62 | 63 | String currentFileContent = new String(Files.readAllBytes(config), StandardCharsets.UTF_8); 64 | 65 | boolean isCorrectVersion = currentFileContent.contains("Version: " + currentVersion); 66 | if (isCorrectVersion) { 67 | load(in); 68 | return properties; 69 | } else { 70 | // Backup old file 71 | Files.write(Paths.get(configBckPath), currentFileContent.getBytes(StandardCharsets.UTF_8)); 72 | config.toFile().delete(); 73 | } 74 | } 75 | } 76 | 77 | try (InputStream s = Main.class.getClassLoader().getResourceAsStream(configPath)) { 78 | FileUtils.copyInputStreamToFile(Objects.requireNonNull(s), config.toFile()); 79 | } 80 | 81 | return properties; 82 | } catch (IOException e) { 83 | throw new RuntimeException(e.getMessage(), e); 84 | } 85 | } 86 | 87 | public static void reload() { 88 | properties = null; 89 | } 90 | 91 | public static T getProperty(String property, T defaultValue, Function converter) { 92 | String stringValue = get().getProperty(property); 93 | if (stringValue == null) { 94 | if (defaultValue == null) { 95 | throw new RuntimeException("Cannot find property '" + property + "' in config"); 96 | } 97 | return defaultValue; 98 | } 99 | T value = converter.apply(stringValue); 100 | if (value == null) return defaultValue; 101 | return value; 102 | } 103 | 104 | public static String get(String property, String defVal) { 105 | return getProperty(property, defVal, (data) -> data); 106 | } 107 | 108 | private static Color get(String property, Color defVal) { 109 | return getProperty(property, defVal, (data) -> { 110 | String[] p = data.split(","); 111 | if (p.length != 4) { 112 | System.out.println("Invalid color: " + data); 113 | return null; 114 | } 115 | int[] c = Arrays.stream(p).map(String::trim).mapToInt(Integer::parseInt).toArray(); 116 | return new Color(c[0], c[1], c[2], c[3]); 117 | }); 118 | } 119 | 120 | private static int get(String property, int defVal) { 121 | return getProperty(property, defVal, Integer::parseInt); 122 | } 123 | 124 | private static long get(String property, long defVal) { 125 | return getProperty(property, defVal, Long::parseLong); 126 | } 127 | 128 | private static boolean get(String property, boolean defVal) { 129 | return getProperty(property, defVal, Boolean::parseBoolean); 130 | } 131 | 132 | private static float get(String property, float defVal) { 133 | return getProperty(property, defVal, Float::parseFloat); 134 | } 135 | 136 | private static String[] get(String property, String[] defVal, String divider) { 137 | return getProperty(property, defVal, (data) -> Arrays.stream(data.split(divider)).map(String::trim).toArray(String[]::new)); 138 | } 139 | 140 | private static int[] get(String property, int[] defVal, String divider) { 141 | return getProperty(property, defVal, (data) -> Arrays.stream(data.split(divider)).mapToInt(Integer::parseInt).toArray()); 142 | } 143 | 144 | private static double[] get(String property, double[] defVal, String divider) { 145 | return getProperty(property, defVal, (data) -> Arrays.stream(data.split(divider)).mapToDouble(Double::parseDouble).toArray()); 146 | } 147 | 148 | public static String getAdapter() { 149 | return get("adapter", "Ship"); 150 | } 151 | 152 | public static String getWaifuName() { 153 | return get("waifu.name", (String) null); 154 | } 155 | 156 | public static boolean isBaloonHighQualityText() { 157 | return get("baloon.highQualityText", true); 158 | } 159 | 160 | public static int getBaloonYOffset() { 161 | return get("baloon.yOffset", 300); 162 | } 163 | 164 | public static int getBaloonXOffset() { 165 | return get("baloon.xOffset", 0); 166 | } 167 | 168 | public static int getBaloonWidth() { 169 | return get("baloon.width", 400); 170 | } 171 | 172 | public static int getBaloonHeight() { 173 | return get("baloon.height", 100); 174 | } 175 | 176 | public static int getBaloonFontSize() { 177 | return get("baloon.fontSize", 15); 178 | } 179 | 180 | public static String getBaloonFont(String defaultValue) { 181 | return get("baloon.font", defaultValue); 182 | } 183 | 184 | public static Color getBaloonBackground(Color defaultValue) { 185 | return get("baloon.background", defaultValue); 186 | } 187 | 188 | public static Color getBaloonForeground() { 189 | return get("baloon.foreground", Color.WHITE); 190 | } 191 | 192 | public static int getWaifuHeight() { 193 | return get("waifu.height", 800); 194 | } 195 | 196 | public static boolean isWaifuWelcomeEnabled() { 197 | return get("waifu.welcome.enabled", true); 198 | } 199 | 200 | public static int getWaifuWelcomeDelay() { 201 | return get("waifu.welcome.delay", 5000); 202 | } 203 | 204 | public static int getWaifuEventsRefreshRate() { 205 | return get("waifu.events.rate", 1000); 206 | } 207 | 208 | public static boolean isVoiceEnabled() { 209 | return get("voice.enabled", true); 210 | } 211 | 212 | public static int getVoiceVolume() { 213 | return get("voice.volume", 50); 214 | } 215 | 216 | public static boolean isDialogsEnabled() { 217 | return get("dialogs.enabled", true); 218 | } 219 | 220 | public static boolean isDialogsOnClick() { 221 | return get("dialogs.onClick", true); 222 | } 223 | 224 | public static boolean isDialogsOnIdle() { 225 | return get("dialogs.onIdle", true); 226 | } 227 | 228 | public static boolean isOnlyAudioDialogs() { 229 | return get("dialogs.onlyAudioDialogs", false); 230 | } 231 | 232 | public static int getDialogsBaloonNoVoiceDuration() { 233 | return get("dialogs.baloon.noVoiceDuration", 3); 234 | } 235 | 236 | public static String getBaloonFormatString() { 237 | return get("baloon.formatString", "[[text]]"); 238 | } 239 | 240 | public static String getWaifuStartY() { 241 | return get("waifu.startY", "auto"); 242 | } 243 | 244 | public static int getFloatingPixelPerStep() { 245 | return get("floating.pixelPerStep", 1); 246 | } 247 | 248 | public static int getFloatingPixelRange() { 249 | return get("floating.pixelRange", 300); 250 | } 251 | 252 | public static int getFloatingStepSleep() { 253 | return get("floating.stepSleep", 16); 254 | } 255 | 256 | public static int getDialogsIdleFrequency() { 257 | return get("dialogs.idle.frequency", 60); 258 | } 259 | 260 | public static boolean isJumpOnClick() { 261 | return get("jump.onClick", true); 262 | } 263 | 264 | public static int getJumpCount() { 265 | return get("jump.count", 2); 266 | } 267 | 268 | public static int getJumpPixelPerStep() { 269 | return get("jump.pixelPerStep", 5); 270 | } 271 | 272 | public static int getJumpSleep() { 273 | return get("jump.stepSleep", 15); 274 | } 275 | 276 | public static int getJumpPixelRange() { 277 | return get("jump.pixelRange", 40); 278 | } 279 | 280 | public static int getFloatingSwitchSleep() { 281 | return get("floating.switchSleep", 10); 282 | } 283 | 284 | public static String getWaifuLanguage() { 285 | return get("azurlane.language", "Chinese"); 286 | } 287 | 288 | public static String getFileFormat() { 289 | String format = get("adapter.file.format", "JSON").toUpperCase(Locale.ENGLISH); 290 | if (!"JSON".equals(format) && !"YAML".equals(format)) { 291 | throw new IllegalArgumentException("adapter.file.format must be JSON or YAML"); 292 | } 293 | return format; 294 | } 295 | 296 | public static float getWaifuActiveOpacity() { 297 | return get("waifu.active.opacity", 100.0f); 298 | } 299 | 300 | public static float getWaifuInactiveOpacity() { 301 | return get("waifu.inactive.opacity", 100.0f); 302 | } 303 | 304 | public static boolean isAzurChibi() { 305 | return get("azurlane.chibi", false); 306 | } 307 | 308 | public static boolean isWaifuYDragEnabled() { 309 | return get("waifu.enableYdrag", false); 310 | } 311 | 312 | public static String getArknightsLanguage() { 313 | return get("arknights.language", "en"); 314 | } 315 | 316 | public static String getArknightsNickname() { 317 | return get("arknights.nickname", "Doctah"); 318 | } 319 | 320 | public static boolean isAutoStartupEnabled() { 321 | return get("waifu.autoStartupEnabled", true); 322 | } 323 | 324 | public static String getGithubRepo() { 325 | return get("github.repo", (String) null); 326 | } 327 | 328 | public static String getGithubBranch() { 329 | return get("github.branch", (String) null); 330 | } 331 | 332 | public static String getUserNickname() { 333 | return get("user.nickname", ""); 334 | } 335 | 336 | public static boolean isLogoutDialogEnabled() { 337 | return get("waifu.logout.dialog.enabled", true); 338 | } 339 | 340 | } 341 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/utils/Util.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.utils; 2 | 3 | import com.google.gson.Gson; 4 | import com.kitsunecode.mms.core.Main; 5 | import com.kitsunecode.mms.core.adapters.IWaifuAdapter; 6 | import com.kitsunecode.mms.core.entities.FunctionalInterfaces; 7 | import com.kitsunecode.mms.core.entities.Settings; 8 | import com.kitsunecode.mms.core.entities.WaifuData; 9 | import com.kitsunecode.mms.core.entities.annotations.Adapter; 10 | import com.kitsunecode.mms.core.entities.exceptions.BrokenAdapterException; 11 | import com.kitsunecode.mms.core.entities.exceptions.StartFailedException; 12 | import com.kitsunecode.mms.core.entities.swing.BootFailedFrame; 13 | import org.apache.commons.io.IOUtils; 14 | import org.apache.http.HttpEntity; 15 | import org.apache.http.client.methods.CloseableHttpResponse; 16 | import org.apache.http.client.methods.HttpGet; 17 | import org.apache.http.impl.client.CloseableHttpClient; 18 | import org.apache.http.impl.client.HttpClients; 19 | import org.yaml.snakeyaml.DumperOptions; 20 | import org.yaml.snakeyaml.Yaml; 21 | import org.yaml.snakeyaml.introspector.BeanAccess; 22 | 23 | import javax.swing.*; 24 | import java.awt.*; 25 | import java.awt.geom.AffineTransform; 26 | import java.awt.geom.Area; 27 | import java.awt.geom.GeneralPath; 28 | import java.awt.image.AffineTransformOp; 29 | import java.awt.image.BufferedImage; 30 | import java.io.File; 31 | import java.io.FileOutputStream; 32 | import java.io.IOException; 33 | import java.io.InputStream; 34 | import java.lang.reflect.InvocationTargetException; 35 | import java.net.HttpURLConnection; 36 | import java.net.URI; 37 | import java.net.URISyntaxException; 38 | import java.net.URL; 39 | import java.nio.charset.Charset; 40 | import java.nio.charset.StandardCharsets; 41 | import java.nio.file.Files; 42 | import java.nio.file.Path; 43 | import java.nio.file.Paths; 44 | import java.security.MessageDigest; 45 | import java.security.NoSuchAlgorithmException; 46 | import java.util.Arrays; 47 | import java.util.Collections; 48 | import java.util.Locale; 49 | import java.util.Set; 50 | import java.util.stream.Collectors; 51 | 52 | public final class Util { 53 | 54 | private static final Gson GSON = generateGson(); 55 | 56 | private static final Yaml YAML = generateYaml(); 57 | 58 | private static final String AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"; 59 | 60 | private Util() { 61 | // Private impl 62 | } 63 | 64 | private static Gson generateGson() { 65 | return new Gson(); 66 | } 67 | 68 | private static Yaml generateYaml() { 69 | DumperOptions dumperOptions = new DumperOptions(); 70 | dumperOptions.setPrettyFlow(true); 71 | dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); 72 | dumperOptions.setIndent(4); 73 | dumperOptions.setIndicatorIndent(2); 74 | 75 | Yaml yaml = new Yaml(dumperOptions); 76 | yaml.setBeanAccess(BeanAccess.FIELD); 77 | 78 | return yaml; 79 | } 80 | 81 | public static Gson getGSON() { 82 | return GSON; 83 | } 84 | 85 | public static Yaml getYAML() { 86 | return YAML; 87 | } 88 | 89 | public static void sleep(long millDurationFloat) { 90 | try { 91 | Thread.sleep(millDurationFloat); 92 | } catch (InterruptedException e) { 93 | e.printStackTrace(); 94 | } 95 | } 96 | 97 | public static BufferedImage flipImage(BufferedImage image) { 98 | // Flip the image horizontally 99 | AffineTransform tx = AffineTransform.getScaleInstance(-1, 1); 100 | tx.translate(-image.getWidth(null), 0); 101 | AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BICUBIC); 102 | return op.filter(image, null); 103 | } 104 | 105 | public static Dimension getScreenSize() { 106 | return Toolkit.getDefaultToolkit().getScreenSize(); 107 | } 108 | 109 | public static int getYStartPosition(int height) { 110 | return (int) getScreenSize().getHeight() - height; 111 | } 112 | 113 | public static Graphics2D setHighQuality(Graphics2D g2d) { 114 | g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 115 | g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); 116 | g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); 117 | g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); 118 | return g2d; 119 | } 120 | 121 | /** 122 | * Warning, this function does not check if the file already exists, do it before calling it! 123 | */ 124 | public static boolean downloadFile(String url, File resourceFile) { 125 | try { 126 | if (!Util.isUrl(url)) { 127 | // Not an URL! 128 | return false; 129 | } 130 | 131 | System.out.println("Downloading: " + url + " to " + resourceFile); 132 | if (resourceFile.createNewFile()) { 133 | try (FileOutputStream fos = new FileOutputStream(resourceFile.getAbsoluteFile())) { 134 | URL myURL = new URL(url); 135 | HttpURLConnection connection = (HttpURLConnection) myURL.openConnection(); 136 | connection.setRequestProperty("User-Agent", AGENT); 137 | byte[] data = IOUtils.toByteArray(connection.getInputStream()); 138 | fos.write(data); 139 | return true; 140 | } 141 | } 142 | } catch (IOException e) { 143 | e.printStackTrace(); 144 | } 145 | // Oh no, I failed... 146 | return false; 147 | } 148 | 149 | public static void checkFolders(String name) throws IOException { 150 | Files.createDirectories(Paths.get("resources", name, "skins")); 151 | Files.createDirectories(Paths.get("resources", name, "audios")); 152 | } 153 | 154 | public static String fileFromUrl(String url) { 155 | if (url != null && url.startsWith("http")) { 156 | String[] urlParts = url.split("/"); 157 | return urlParts[urlParts.length - 1]; 158 | } 159 | return url; 160 | } 161 | 162 | public static WaifuData deserializeWaifu(String data, String fileFormat) { 163 | if ("YAML".equals(fileFormat)) { 164 | return YAML.loadAs(data, WaifuData.class); 165 | } else if ("JSON".equals(fileFormat)) { 166 | return GSON.fromJson(data, WaifuData.class); 167 | } else { 168 | throw new IllegalArgumentException("Invalid adapter file type"); 169 | } 170 | } 171 | 172 | public static String serializeWaifuData(WaifuData data) { 173 | String fileFormat = Settings.getFileFormat(); 174 | if ("YAML".equals(fileFormat)) { 175 | return YAML.dump(data); 176 | } else if ("JSON".equals(fileFormat)) { 177 | return GSON.toJson(data); 178 | } else { 179 | throw new IllegalArgumentException("Invalid adapter file type"); 180 | } 181 | } 182 | 183 | public static boolean isWindows() { 184 | return System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("win"); 185 | } 186 | 187 | public static void openUrl(String url) { 188 | if (Desktop.isDesktopSupported()) { 189 | try { 190 | Desktop.getDesktop().browse(new URI(url)); 191 | } catch (IOException | URISyntaxException e) { /* TODO: error handling */ } 192 | } else { /* TODO: error handling */ } 193 | } 194 | 195 | public static boolean isUrl(String url) { 196 | return url.startsWith("http"); 197 | } 198 | 199 | public static BufferedImage toBufferedImage(ImageIcon icon) { 200 | BufferedImage bufferedImage = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); 201 | 202 | Graphics graphics = bufferedImage.createGraphics(); 203 | icon.paintIcon(null, graphics, 0, 0); 204 | graphics.dispose(); 205 | 206 | return bufferedImage; 207 | } 208 | 209 | public static String downloadString(String url) throws IOException { 210 | CloseableHttpClient client = HttpClients.createDefault(); 211 | try (CloseableHttpResponse response = client.execute(new HttpGet(url))) { 212 | int statusCode = response.getStatusLine().getStatusCode(); 213 | if (statusCode != 200) { 214 | throw new RuntimeException(url + " returned status code " + statusCode); 215 | } 216 | HttpEntity entity = response.getEntity(); 217 | if (entity != null) { 218 | return IOUtils.toString(entity.getContent(), Charset.defaultCharset()); 219 | } 220 | } 221 | throw new RuntimeException(); 222 | } 223 | 224 | public static IWaifuAdapter getWaifuFromAdapterName(String adapterName, String shipName) { 225 | try { 226 | Set> adapterClasses = ReflectionUtils.getAllClassesAnnotatedWith(Adapter.class); 227 | for (Class clazz : adapterClasses) { 228 | if (!IWaifuAdapter.class.isAssignableFrom(clazz)) { 229 | throw new BrokenAdapterException( 230 | "Found class '" + clazz.getName() + "' annotated with @Adapter but that does not extend IWaifuAdapter"); 231 | } 232 | if (adapterName.equals(clazz.getSimpleName())) { 233 | IWaifuAdapter adapter = (IWaifuAdapter) clazz.getConstructor(String.class).newInstance(shipName); 234 | adapter.init(); 235 | return adapter; 236 | } 237 | } 238 | throw new StartFailedException("The chosen adapter is not a WaifuAdapter!"); 239 | } catch (NoSuchMethodException e) { 240 | throw new StartFailedException("Adapter has no constructor that takes the name as parameter", e); 241 | } catch (IllegalAccessException | InstantiationException e) { 242 | throw new StartFailedException("Critical error while instancing the waifu", e); 243 | } catch (InvocationTargetException e) { 244 | if (e.getCause() instanceof StartFailedException) { 245 | throw (StartFailedException) e.getCause(); // Throw already handled exception 246 | } 247 | throw new StartFailedException(e.getCause().getMessage(), e); 248 | } catch (Exception e) { 249 | throw new StartFailedException("Critical error while creating the adapter: " + e.getMessage(), e); 250 | } 251 | } 252 | 253 | public static byte[] getShipImage(IWaifuAdapter waifuAdapter, int skinIndex) throws IOException { 254 | System.out.println("Getting skin index: " + skinIndex); 255 | String url = waifuAdapter.getSkin(skinIndex); 256 | String fileName = Util.fileFromUrl(url); 257 | return Files.readAllBytes(waifuAdapter.downloadFile(url, fileName).toPath()); 258 | } 259 | 260 | public static Area getOutline(BufferedImage i, int targetTransp) { 261 | 262 | // construct the GeneralPath 263 | GeneralPath gp = new GeneralPath(); 264 | gp.moveTo(0, 0); 265 | 266 | boolean drawing = false; 267 | for (int y = 0; y < i.getHeight(); y++) { 268 | for (int x = 0; x < i.getWidth(); x++) { 269 | 270 | int rgb = i.getRGB(x, y); 271 | boolean isTransp = (rgb >>> 24) <= targetTransp; 272 | 273 | if (isTransp) { 274 | if (drawing) { 275 | gp.closePath(); 276 | } 277 | drawing = false; 278 | } else { 279 | drawing = true; 280 | gp.moveTo(x, y); 281 | gp.lineTo(x + 1, y); 282 | gp.lineTo(x + 1, y + 1); 283 | gp.lineTo(x, y + 1); 284 | gp.moveTo(x, y); 285 | } 286 | } 287 | gp.closePath(); 288 | } 289 | gp.closePath(); 290 | // construct the Area from the GP & return it 291 | return new Area(gp); 292 | } 293 | 294 | public static java.util.List listFiles(Path path) { 295 | File[] files = path.toFile().listFiles(); 296 | if (files == null) { 297 | return Collections.emptyList(); 298 | } 299 | 300 | return Arrays.stream(files).filter(File::isFile).collect(Collectors.toList()); 301 | } 302 | 303 | public static String parseDialog(String dialog) { 304 | String parsedDialog = dialog; 305 | if (dialog.contains("{@battery.level}")) { 306 | parsedDialog = parsedDialog.replace("{@battery.level}", HWUtils.getBatteryPercentage() + ""); 307 | } 308 | parsedDialog = parsedDialog.replace("{@user.nickname}", Settings.getUserNickname()); 309 | return parsedDialog; 310 | } 311 | 312 | public static String md5(String message) { 313 | try { 314 | 315 | byte[] hash = MessageDigest.getInstance("MD5") 316 | .digest(message.replace("\r", "") // Ignore carriage return 317 | .getBytes(StandardCharsets.UTF_8)); 318 | //converting byte array to Hexadecimal String 319 | StringBuilder sb = new StringBuilder(); 320 | for (byte b : hash) { 321 | sb.append(String.format("%02x", b & 0xff)); 322 | } 323 | return sb.toString(); 324 | } catch (NoSuchAlgorithmException ex) { 325 | ex.printStackTrace(); 326 | } 327 | return null; 328 | } 329 | 330 | public static String readResourceString(String resourceFile) throws IOException { 331 | try (InputStream is = Main.class.getClassLoader().getResourceAsStream(resourceFile)) { 332 | if (is == null) return null; 333 | return IOUtils.toString(is, StandardCharsets.UTF_8); 334 | } 335 | } 336 | 337 | public static void catchMoeMoeExceptionsAndExit(FunctionalInterfaces.CheckedRunnable runnable) { 338 | try { 339 | runnable.run(); 340 | } catch (Exception e) { 341 | e.printStackTrace(); 342 | new BootFailedFrame(e); 343 | System.exit(7); 344 | } 345 | } 346 | 347 | public static String safeFileName(String fileName) { 348 | char[] chars = new char[]{'#', '<', '$', '+', '%', '>', '!', 349 | '`', '&', '*', '\'', '|', '\\', '/', '{', '}', '?', '"', '=', ':', ' ', '@'}; 350 | for (char c : chars) { 351 | fileName = fileName.replace(c, '_'); 352 | } 353 | return fileName; 354 | } 355 | 356 | } 357 | -------------------------------------------------------------------------------- /src/main/java/com/kitsunecode/mms/core/entities/swing/Secretary.java: -------------------------------------------------------------------------------- 1 | package com.kitsunecode.mms.core.entities.swing; 2 | 3 | import com.kitsunecode.mms.core.adapters.IWaifuAdapter; 4 | import com.kitsunecode.mms.core.entities.Dialog; 5 | import com.kitsunecode.mms.core.entities.Settings; 6 | import com.kitsunecode.mms.core.entities.WaifuData; 7 | import com.kitsunecode.mms.core.entities.audio.Audio; 8 | import com.kitsunecode.mms.core.entities.audio.AudioPlayer; 9 | import com.kitsunecode.mms.core.utils.Util; 10 | 11 | import javax.imageio.ImageIO; 12 | import javax.swing.*; 13 | import java.awt.*; 14 | import java.awt.event.*; 15 | import java.awt.geom.Area; 16 | import java.awt.image.BufferedImage; 17 | import java.io.ByteArrayInputStream; 18 | import java.io.File; 19 | import java.io.IOException; 20 | import java.net.URL; 21 | import java.util.List; 22 | import java.util.Locale; 23 | import java.util.Random; 24 | 25 | public class Secretary extends JFrame implements MouseListener, MouseMotionListener, 26 | MouseWheelListener, KeyListener, WindowListener { 27 | 28 | private final AudioPlayer audioPlayer = new AudioPlayer(); 29 | 30 | private final IWaifuAdapter waifuInterface; 31 | 32 | private boolean floatingToggle; 33 | 34 | private int xClickPosition; 35 | private int yClickPosition; 36 | private int dragDiffX = 0; 37 | private int dragDiffY = 0; 38 | 39 | private boolean running; 40 | private boolean alwaysOnTop; 41 | private boolean mirrored; 42 | 43 | private int skinIndex; 44 | 45 | private int leftOffset; 46 | 47 | private Baloon baloon; 48 | private SecretaryLabel secretaryLabel; 49 | 50 | private BufferedImage buffImage; 51 | 52 | private boolean isManual = false; 53 | private boolean isDragging = false; 54 | 55 | private Audio currentAudio; 56 | 57 | /** 58 | * Application start point 59 | * 60 | * @param waifu Your initialized waifu 61 | * @throws Exception Something went wrong while starting the ship 62 | */ 63 | public Secretary(IWaifuAdapter waifu) throws Exception { 64 | 65 | waifuInterface = waifu; 66 | WaifuData data = waifu.getWaifuData(); 67 | skinIndex = data.getSkinIndex(); 68 | alwaysOnTop = data.isAlwaysOnTop(); 69 | floatingToggle = data.isFloatingEnabled(); 70 | mirrored = data.isMirrored(); 71 | 72 | swingSetup(); 73 | 74 | secretaryLabel.startFloating(); 75 | 76 | if (Settings.isDialogsOnIdle()) { 77 | idle(); 78 | } 79 | 80 | if (Settings.isWaifuWelcomeEnabled()) { 81 | onLogin(); // Say Hi! 82 | } 83 | 84 | } 85 | 86 | @Override 87 | public void paint(Graphics g) { 88 | g.clearRect(0, 0, this.getWidth(), this.getHeight()); 89 | super.paint(g); 90 | if (!isManual) { 91 | new Thread(() -> { 92 | BufferedImage image = getScreenShot(this); 93 | Area area = Util.getOutline(image, 0); 94 | setShape(area); 95 | }).start(); 96 | } 97 | } 98 | 99 | public BufferedImage getScreenShot(Component component) { 100 | BufferedImage image = new BufferedImage( 101 | component.getWidth(), 102 | component.getHeight(), 103 | BufferedImage.TYPE_INT_ARGB 104 | ); 105 | setShape(null); 106 | isManual = true; 107 | Graphics graphics = image.getGraphics(); 108 | if (graphics != null) { 109 | component.printAll(graphics); 110 | } 111 | isManual = false; 112 | 113 | // Debug screenshot 114 | // try { 115 | // ImageIO.write(image, "PNG", Paths.get("resources", "screen.png").toFile()); 116 | // } catch (IOException e) { 117 | // e.printStackTrace(); 118 | // } 119 | 120 | return image; 121 | } 122 | 123 | private void idle() { 124 | new Thread(() -> { 125 | Util.sleep(5000); // Wait 5 seconds before starting idle loop 126 | while (running) { 127 | secretaryLabel.waitIdle(); 128 | if (!running) return; 129 | speak(waifuInterface.getDialogs(waifuInterface.onIdleEventKey()), null); 130 | secretaryLabel.waitSpeak(); 131 | } 132 | }).start(); 133 | } 134 | 135 | private void onLogin() { 136 | new Thread(() -> { 137 | Util.sleep(Math.max(Settings.getWaifuWelcomeDelay(), 1000)); 138 | if (!running) return; 139 | speak(waifuInterface.getDialogs(waifuInterface.onLoginEventKey()), null); 140 | }).start(); 141 | } 142 | 143 | private Image loadSkin(int index) throws IOException { 144 | int updatedIndex = index; 145 | if (updatedIndex < 0) { 146 | updatedIndex = waifuInterface.getSkinCount() - 1; 147 | } else if (updatedIndex >= waifuInterface.getSkinCount()) { 148 | updatedIndex = 0; 149 | } 150 | 151 | skinIndex = updatedIndex; 152 | 153 | byte[] imgData = Util.getShipImage(waifuInterface, updatedIndex); 154 | 155 | buffImage = ImageIO.read(new ByteArrayInputStream(imgData)); 156 | if (mirrored) { 157 | buffImage = Util.flipImage(buffImage); 158 | } 159 | 160 | Image i = buffImage; 161 | if (Settings.getWaifuHeight() != 0) { 162 | i = buffImage.getScaledInstance(-1, Settings.getWaifuHeight(), Image.SCALE_AREA_AVERAGING); 163 | } 164 | 165 | int width = Math.max(Settings.getBaloonWidth(), i.getWidth(null)); 166 | leftOffset = (int) ((width - i.getWidth(null)) / 2f); 167 | 168 | setSize(width, i.getHeight(null)); 169 | setLocation(leftOffset + getX(), Util.getYStartPosition(i.getHeight(null))); 170 | 171 | return i; 172 | } 173 | 174 | public void flipSkin() { 175 | System.out.println("Flipping skin"); 176 | buffImage = Util.flipImage(Util.toBufferedImage((ImageIcon) secretaryLabel.getIcon())); 177 | secretaryLabel.setIcon(new ImageIcon(buffImage)); 178 | mirrored = !mirrored; 179 | } 180 | 181 | public final int getStartY() { 182 | int y = Util.getScreenSize().height - getHeight(); 183 | String settingPos = Settings.getWaifuStartY().toLowerCase(Locale.ENGLISH); 184 | if (!"auto".equals(settingPos) && settingPos.matches("-?\\d+")) { 185 | y += Integer.parseInt(settingPos); 186 | } 187 | 188 | return y; 189 | } 190 | 191 | private void swingSetup() throws IOException { 192 | setTitle(waifuInterface.getShowableName()); 193 | 194 | setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); 195 | 196 | // Listeners 197 | addMouseListener(this); 198 | addMouseMotionListener(this); 199 | addMouseWheelListener(this); 200 | addKeyListener(this); 201 | addWindowListener(this); 202 | 203 | setLayout(null); 204 | setUndecorated(true); 205 | setBackground(new Color(0, 0, 0, 0)); 206 | 207 | ImageIcon icn = new ImageIcon(loadSkin(skinIndex)); 208 | secretaryLabel = new SecretaryLabel(icn, this); 209 | secretaryLabel.setBounds(secretaryLabel.getDesiredBounds(leftOffset, icn.getIconWidth(), icn.getIconHeight())); 210 | 211 | baloon = new Baloon(getWidth(), getHeight()); 212 | baloon.setBounds(baloon.getDesiredSize(leftOffset, icn.getIconWidth(), icn.getIconHeight())); 213 | 214 | add(baloon); 215 | add(secretaryLabel); 216 | 217 | URL ico = this.getClass().getResource("/icon.png"); 218 | if (ico != null) { 219 | setIconImage(new ImageIcon(ico).getImage()); 220 | } 221 | 222 | setAlwaysOnTop(alwaysOnTop); 223 | setLocation(waifuInterface.getWaifuData().getPosition(), getStartY()); 224 | setType(Util.isWindows() ? Type.UTILITY : Type.POPUP); 225 | 226 | setVisible(true); 227 | 228 | secretaryLabel.onVisible(); 229 | 230 | System.out.println("Swing setup done"); 231 | running = true; 232 | } 233 | 234 | public void toggleAlwaysOnTop() { 235 | alwaysOnTop = !alwaysOnTop; 236 | setAlwaysOnTop(alwaysOnTop); 237 | System.out.println("Always on top: " + alwaysOnTop); 238 | } 239 | 240 | public void toggleFloating() { 241 | floatingToggle = !floatingToggle; 242 | System.out.println("Floating: " + floatingToggle); 243 | } 244 | 245 | public void reloadSkin() throws IOException { 246 | if (waifuInterface.getSkinCount() == 1) return; 247 | secretaryLabel.setIcon(new ImageIcon(loadSkin(skinIndex))); 248 | secretaryLabel.setBounds(secretaryLabel.getDesiredBounds( 249 | leftOffset, 250 | secretaryLabel.getIcon().getIconWidth(), 251 | secretaryLabel.getIcon().getIconHeight()) 252 | ); 253 | baloon.setBounds(baloon.getDesiredSize( 254 | leftOffset, 255 | secretaryLabel.getIcon().getIconWidth(), 256 | secretaryLabel.getIcon().getIconHeight()) 257 | ); 258 | setLocation(getX(), getStartY()); 259 | } 260 | 261 | private void speakStateChanged(boolean speaking) { 262 | if (!speaking) { 263 | baloon.toggle(false); 264 | } 265 | secretaryLabel.speak(speaking); 266 | } 267 | 268 | private void speakNoVoice() { 269 | new Thread(() -> { 270 | speakStateChanged(true); 271 | Util.sleep(Settings.getDialogsBaloonNoVoiceDuration()); 272 | speakStateChanged(false); 273 | }).start(); 274 | } 275 | 276 | private void internalSpeak(Dialog dialog, Runnable optionalCallback) { 277 | String text = Util.parseDialog(dialog.getDialog()); 278 | if (!"".equals(text)) { 279 | baloon.toggle(true); 280 | baloon.setText(Settings.getBaloonFormatString().replace("[[text]]", text + "
‌")); 281 | } 282 | 283 | if (!Settings.isVoiceEnabled() || dialog.getAudio() == null || "".equals(dialog.getAudio())) { 284 | speakNoVoice(); 285 | return; 286 | } 287 | 288 | String fileName = Util.fileFromUrl(dialog.getAudio()); 289 | File audioFile = waifuInterface.downloadFile(dialog.getAudio(), fileName); 290 | 291 | Audio audio = new Audio(audioFile, Settings.getVoiceVolume()) { 292 | @Override 293 | public void onStart() { 294 | speakStateChanged(true); 295 | } 296 | 297 | @Override 298 | public void onFinish() { 299 | speakStateChanged(false); 300 | currentAudio = null; 301 | if (optionalCallback != null) { 302 | optionalCallback.run(); 303 | } 304 | } 305 | }; 306 | currentAudio = audio; 307 | audioPlayer.play(audio); 308 | } 309 | 310 | public void speak(List dialogs, Runnable optionalCallback) { 311 | 312 | if (secretaryLabel.isSpeaking() || !Settings.isDialogsEnabled() || dialogs.isEmpty()) { 313 | if (optionalCallback != null) { 314 | optionalCallback.run(); 315 | } 316 | return; 317 | } 318 | 319 | Dialog dialog = dialogs.get(new Random().nextInt(dialogs.size())); 320 | internalSpeak(dialog, optionalCallback); 321 | } 322 | 323 | public boolean isDragging() { 324 | return isDragging; 325 | } 326 | 327 | private void internalCloseExit() { 328 | internalClose(true); 329 | } 330 | 331 | private void internalClose() { 332 | internalClose(false); 333 | } 334 | 335 | private void internalClose(boolean exit) { 336 | try { 337 | this.running = false; 338 | waifuInterface.getWaifuData().setPosition(getX()); 339 | waifuInterface.getWaifuData().setAlwaysOnTop(alwaysOnTop); 340 | waifuInterface.getWaifuData().setFloatingEnabled(floatingToggle); 341 | waifuInterface.getWaifuData().setMirrored(mirrored); 342 | waifuInterface.getWaifuData().setSkinIndex(skinIndex); 343 | waifuInterface.saveDataToFile(); 344 | } catch (IOException ex) { 345 | ex.printStackTrace(); 346 | } 347 | 348 | 349 | dispose(); 350 | if (exit) { 351 | System.exit(0); 352 | } 353 | } 354 | 355 | public void lightClose() { 356 | boolean wasSpeaking = currentAudio != null && currentAudio.isPlaying(); 357 | if (wasSpeaking) { 358 | currentAudio.stop(); 359 | } 360 | running = false; 361 | dispose(); 362 | } 363 | 364 | public void close() { 365 | boolean wasSpeaking = currentAudio != null && currentAudio.isPlaying(); 366 | 367 | List logoutDialogs = waifuInterface.getDialogs(waifuInterface.onLogoutEventKey()); 368 | 369 | if (logoutDialogs.size() == 0 || !Settings.isLogoutDialogEnabled()) { 370 | if (wasSpeaking) { 371 | currentAudio.stop(); 372 | } 373 | internalCloseExit(); 374 | return; 375 | } 376 | 377 | if (wasSpeaking) { 378 | currentAudio.addCloseAction(() -> speak(logoutDialogs, this::internalCloseExit)); 379 | currentAudio.stop(); 380 | return; 381 | } 382 | 383 | speak(logoutDialogs, this::internalCloseExit); 384 | } 385 | 386 | private void onClick() { 387 | if (Settings.isDialogsOnClick()) { 388 | speak(waifuInterface.getDialogs(waifuInterface.onTouchEventKey()), null); 389 | } 390 | } 391 | 392 | // Region: Swing Mouse Events 393 | @Override 394 | public void mousePressed(MouseEvent e) { 395 | xClickPosition = e.getXOnScreen(); 396 | yClickPosition = e.getYOnScreen(); 397 | dragDiffX = xClickPosition - getX(); 398 | dragDiffY = yClickPosition - getY(); 399 | } 400 | 401 | @Override 402 | public void mouseReleased(MouseEvent e) { 403 | isDragging = false; 404 | if (e.getButton() == 2) { 405 | dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); 406 | return; 407 | } 408 | if (xClickPosition == e.getXOnScreen() && yClickPosition == e.getYOnScreen()) { 409 | secretaryLabel.speakJump(); 410 | onClick(); 411 | } 412 | } 413 | 414 | @Override 415 | public void mouseDragged(MouseEvent e) { 416 | isDragging = true; 417 | setLocation(e.getXOnScreen() - dragDiffX, Settings.isWaifuYDragEnabled() ? e.getYOnScreen() - dragDiffY : getY()); 418 | } 419 | 420 | @Override 421 | public void keyTyped(KeyEvent e) { 422 | try { 423 | switch (Character.toLowerCase(e.getKeyChar())) { 424 | case 'k': 425 | skinIndex++; 426 | reloadSkin(); 427 | break; 428 | case 'j': 429 | skinIndex--; 430 | reloadSkin(); 431 | break; 432 | case 't': 433 | toggleAlwaysOnTop(); 434 | break; 435 | case 'f': 436 | toggleFloating(); 437 | break; 438 | case 's': 439 | flipSkin(); 440 | break; 441 | default: 442 | break; 443 | } 444 | } catch (IOException ex) { 445 | ex.printStackTrace(); 446 | } 447 | } 448 | 449 | @Override 450 | public void mouseClicked(MouseEvent e) { 451 | if (e.getButton() == 2) { 452 | dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); 453 | } 454 | } 455 | 456 | @Override 457 | public void mouseEntered(MouseEvent e) { 458 | // No action 459 | } 460 | 461 | @Override 462 | public void mouseExited(MouseEvent e) { 463 | // No action 464 | } 465 | 466 | @Override 467 | public void mouseMoved(MouseEvent e) { 468 | // No action 469 | } 470 | 471 | @Override 472 | public void mouseWheelMoved(MouseWheelEvent e) { 473 | // No action 474 | } 475 | 476 | @Override 477 | public void keyPressed(KeyEvent e) { 478 | // No action 479 | } 480 | 481 | @Override 482 | public void keyReleased(KeyEvent e) { 483 | // No action 484 | } 485 | 486 | @Override 487 | public void windowOpened(WindowEvent e) { 488 | long waifuUptime = waifuInterface.getUptime(); 489 | long waifuStartTimeSeconds = (waifuUptime / 1000000); 490 | long waifuStartTimeMillis = waifuUptime - waifuStartTimeSeconds; 491 | System.out.println("Secretary up and running in " + waifuStartTimeSeconds + "." + waifuStartTimeMillis + " seconds"); 492 | } 493 | 494 | @Override 495 | public void windowClosing(WindowEvent e) { 496 | close(); 497 | } 498 | 499 | @Override 500 | public void windowClosed(WindowEvent e) { 501 | // No action 502 | } 503 | 504 | @Override 505 | public void windowIconified(WindowEvent e) { 506 | // No action 507 | } 508 | 509 | @Override 510 | public void windowDeiconified(WindowEvent e) { 511 | // No action 512 | } 513 | 514 | @Override 515 | public void windowActivated(WindowEvent e) { 516 | if (Util.isWindows()) { 517 | setOpacity(Settings.getWaifuActiveOpacity() / 100.0f); 518 | } 519 | } 520 | 521 | @Override 522 | public void windowDeactivated(WindowEvent e) { 523 | if (Util.isWindows()) { 524 | setOpacity(Settings.getWaifuInactiveOpacity() / 100.0f); 525 | } 526 | } 527 | 528 | // Endregion 529 | 530 | public boolean isFloatingToggle() { 531 | return floatingToggle; 532 | } 533 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . --------------------------------------------------------------------------------