├── .gitignore ├── gradle.properties ├── settings.gradle ├── src └── main │ ├── resources │ ├── META-INF │ │ └── services │ │ │ └── net.mamoe.mirai.console.plugin.jvm.JvmPlugin │ ├── bg.png │ └── missing.png │ └── java │ └── org │ └── zrnq │ ├── Questioner.java │ ├── PluginData.kt │ ├── Answer.java │ ├── Session.java │ ├── Question.java │ ├── Wiki.kt │ ├── R.java │ ├── QuestionListHolder.java │ ├── PluginImageHolder.java │ ├── SerializableImage.java │ ├── Util.java │ └── PluginCommand.kt ├── Wiki.iml ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew.bat ├── README.md ├── gradlew └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle/ 2 | build/ 3 | .idea/ -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.code.style=official -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'Wiki' 2 | 3 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/services/net.mamoe.mirai.console.plugin.jvm.JvmPlugin: -------------------------------------------------------------------------------- 1 | org.zrnq.Wiki -------------------------------------------------------------------------------- /Wiki.iml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/main/resources/bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Under-estimate/Mirai-wiki/HEAD/src/main/resources/bg.png -------------------------------------------------------------------------------- /src/main/resources/missing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Under-estimate/Mirai-wiki/HEAD/src/main/resources/missing.png -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Under-estimate/Mirai-wiki/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /src/main/java/org/zrnq/Questioner.java: -------------------------------------------------------------------------------- 1 | package org.zrnq; 2 | 3 | import java.io.Serializable; 4 | 5 | public class Questioner implements Serializable { 6 | public final String name; 7 | public final long id; 8 | public Questioner(String name, long id){ 9 | this.name=name; 10 | this.id=id; 11 | } 12 | @Override 13 | public String toString(){ 14 | return name+"("+id+")"; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/zrnq/PluginData.kt: -------------------------------------------------------------------------------- 1 | package org.zrnq 2 | 3 | import net.mamoe.mirai.console.data.AutoSavePluginConfig 4 | import net.mamoe.mirai.console.data.AutoSavePluginData 5 | import net.mamoe.mirai.console.data.value 6 | 7 | object PluginData : AutoSavePluginData("MiraiWikiData"){ 8 | var questionIdPointer : Int by value(0) 9 | var imageIdPointer : Int by value(0) 10 | } 11 | object PluginConfig : AutoSavePluginConfig("MiraiWikiConfig"){ 12 | var queryResultBg : String by value("") 13 | } -------------------------------------------------------------------------------- /src/main/java/org/zrnq/Answer.java: -------------------------------------------------------------------------------- 1 | package org.zrnq; 2 | 3 | import java.io.Serializable; 4 | import java.util.ArrayList; 5 | 6 | public class Answer implements Serializable { 7 | public String name; 8 | public long id; 9 | public final long time=System.currentTimeMillis(); 10 | public boolean accepted=false; 11 | public String text; 12 | public final ArrayList images=new ArrayList<>(); 13 | public String getStatusBarText(){ 14 | return "回答者: "+name 15 | +" 时间: "+Util.parseTime(time) 16 | +(accepted?"[已被采纳]":""); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/org/zrnq/Session.java: -------------------------------------------------------------------------------- 1 | package org.zrnq; 2 | 3 | import net.mamoe.mirai.contact.Group; 4 | import net.mamoe.mirai.contact.Member; 5 | import net.mamoe.mirai.event.events.GroupMessageEvent; 6 | import org.jetbrains.annotations.NotNull; 7 | import java.util.ArrayList; 8 | /** 9 | * 一个Session代表与某个群成员的会话,不同群、不同群成员的会话是互相隔离的. 10 | * */ 11 | public class Session { 12 | Group group; 13 | Member member; 14 | State state=State.Null; 15 | ArrayList queryData=null; 16 | Question currentQuestion=null; 17 | String text=null; 18 | Answer currentAnswer=null; 19 | boolean viewDetail = false; 20 | public Session(@NotNull GroupMessageEvent event){ 21 | this.group=event.getGroup(); 22 | this.member=event.getSender(); 23 | } 24 | /** 25 | * 当前会话的状态. 26 | * */ 27 | public enum State{ 28 | Search_Question, 29 | Write_Question, 30 | My_Questions, 31 | My_Answers, 32 | View_Unsolved, 33 | View_All, 34 | Write_Answer, 35 | Null 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/zrnq/Question.java: -------------------------------------------------------------------------------- 1 | package org.zrnq; 2 | 3 | import java.io.Serializable; 4 | import java.util.ArrayList; 5 | 6 | public class Question implements Serializable { 7 | public Questioner questioner; 8 | public final long time=System.currentTimeMillis(); 9 | public String title=null; 10 | public String text=null; 11 | public long groupId; 12 | public final ArrayList images=new ArrayList<>(); 13 | public final ArrayList answererList=new ArrayList<>(); 14 | public int questionId; 15 | public boolean requireFurtherInfo=false; 16 | public boolean haveAccepted(){ 17 | if(answererList.size()<=0)return false; 18 | for (Answer answerer : answererList) { 19 | if (answerer.accepted) return true; 20 | } 21 | return false; 22 | } 23 | public String getStatusBarText(){ 24 | return "提问者: "+questioner.name 25 | +" 时间: "+ Util.parseTime(time) 26 | +" 回答数: "+answererList.size() 27 | +" 状态: "+(haveAccepted()?"解决": 28 | answererList.size()<=0?"等待": 29 | requireFurtherInfo?"追问":"未读"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/zrnq/Wiki.kt: -------------------------------------------------------------------------------- 1 | package org.zrnq 2 | 3 | import net.mamoe.mirai.console.command.CommandManager 4 | import net.mamoe.mirai.console.extension.PluginComponentStorage 5 | import net.mamoe.mirai.console.permission.Permission 6 | import net.mamoe.mirai.console.permission.PermissionService 7 | import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescriptionBuilder 8 | import net.mamoe.mirai.console.plugin.jvm.KotlinPlugin 9 | 10 | object Wiki : KotlinPlugin( 11 | JvmPluginDescriptionBuilder("org.zrnq.wiki", R.version) 12 | .author("ZRnQ") 13 | .name(R.name) 14 | .info("QQ群内问答系统") 15 | .build() 16 | ) { 17 | lateinit var adminPerm : Permission 18 | override fun PluginComponentStorage.onLoad() { 19 | R.logger = logger 20 | R.logger.info(R.name + R.version + "正在预加载") 21 | } 22 | 23 | override fun onEnable() { 24 | R.logger.info(R.name + R.version + "正在加载") 25 | PluginData.reload() 26 | PluginConfig.reload() 27 | CommandManager.registerCommand(PluginCommand, true) 28 | adminPerm = PermissionService.INSTANCE.register(permissionId("admin"), "问答系统管理员权限", parentPermission) 29 | R.systemCheck() 30 | R.initResources() 31 | Util.initImageStub() 32 | } 33 | 34 | override fun onDisable() { 35 | R.logger.info(R.name + R.version + "正在停止") 36 | CommandManager.unregisterCommand(PluginCommand) 37 | } 38 | } -------------------------------------------------------------------------------- /src/main/java/org/zrnq/R.java: -------------------------------------------------------------------------------- 1 | package org.zrnq; 2 | 3 | import net.mamoe.mirai.utils.MiraiLogger; 4 | 5 | import java.awt.*; 6 | import java.io.File; 7 | import java.util.HashMap; 8 | 9 | public class R { 10 | public static final String name="MiraiWiki"; 11 | public static final String version ="2.0.4"; 12 | public static MiraiLogger logger; 13 | public static final HashMap> sessions=new HashMap<>(); 14 | public static final Font F = new Font("Microsoft YaHei",Font.PLAIN,30); 15 | public static final Color hover = new Color(0,0,0,100); 16 | public static final Color skyBlue = new Color(0, 100, 255); 17 | public static final Color orange = new Color(255,100,0); 18 | public static void systemCheck(){ 19 | if(!System.getProperty("os.name").toLowerCase().contains("win")) 20 | logger.warning("检测到正在非Windows系统上运行,请安装字体\"Microsoft YaHei\"以便汉字能够正常显示。"); 21 | GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment(); 22 | Font[] f=ge.getAllFonts(); 23 | for(Font temp:f){ 24 | String name = temp.getName(); 25 | if(Util.matchesAny(name,"微软雅黑","msyh","Microsoft YaHei"))return; 26 | } 27 | logger.error("没有找到字体\"Microsoft YaHei\",汉字可能不会被正确显示。"); 28 | } 29 | public static void initResources(){ 30 | File imageFolder = Wiki.INSTANCE.resolveDataFile("images\\"); 31 | if(!imageFolder.exists()) 32 | if(!imageFolder.mkdirs()) 33 | logger.error("创建图片文件夹失败。"); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/zrnq/QuestionListHolder.java: -------------------------------------------------------------------------------- 1 | package org.zrnq; 2 | 3 | import java.io.*; 4 | import java.util.ArrayList; 5 | import java.util.HashMap; 6 | import java.util.function.Consumer; 7 | 8 | public class QuestionListHolder { 9 | private HashMap> questionList; 10 | public static final QuestionListHolder INSTANCE = getInstance(); 11 | private static File storage; 12 | private QuestionListHolder(){ 13 | 14 | } 15 | @SuppressWarnings("unchecked") 16 | private static QuestionListHolder getInstance(){ 17 | QuestionListHolder holder = new QuestionListHolder(); 18 | storage = Wiki.INSTANCE.resolveDataFile("questions.bin"); 19 | if(storage.exists()){ 20 | try{ 21 | ObjectInputStream ois = new ObjectInputStream(new FileInputStream(storage)); 22 | holder.questionList = (HashMap>) ois.readObject(); 23 | }catch (Exception e){ 24 | R.logger.error("读取问题列表失败,正在使用空的问题列表。",e); 25 | holder.questionList = new HashMap<>(); 26 | } 27 | }else{ 28 | holder.questionList = new HashMap<>(); 29 | } 30 | return holder; 31 | } 32 | public ArrayList getListOf(long group){ 33 | if(!questionList.containsKey(group)) 34 | questionList.put(group,new ArrayList<>()); 35 | return questionList.get(group); 36 | } 37 | public void RWAccessor(long group, Consumer> rwAction){ 38 | ArrayList list = getListOf(group); 39 | rwAction.accept(list); 40 | saveQuestions(); 41 | } 42 | public void saveQuestions(){ 43 | try{ 44 | ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(storage)); 45 | oos.writeObject(questionList); 46 | }catch (Exception e){ 47 | R.logger.error("保存问题列表失败。",e); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/zrnq/PluginImageHolder.java: -------------------------------------------------------------------------------- 1 | package org.zrnq; 2 | 3 | import javax.imageio.ImageIO; 4 | import java.awt.image.BufferedImage; 5 | import java.io.ByteArrayInputStream; 6 | import java.io.ByteArrayOutputStream; 7 | import java.util.HashMap; 8 | 9 | public class PluginImageHolder { 10 | public static final PluginImageHolder INSTANCE = getInstance(); 11 | private HashMap data; 12 | private PluginImageHolder(){ 13 | 14 | } 15 | private static PluginImageHolder getInstance() { 16 | PluginImageHolder holder = new PluginImageHolder(); 17 | holder.data = new HashMap<>(); 18 | holder.readImages(); 19 | return holder; 20 | } 21 | public void putImage(String name, byte[] byteArray){ 22 | data.put(name + "A",byteArray); 23 | data.put(name + "B",toBufferedImage(byteArray)); 24 | } 25 | @SuppressWarnings("unused") 26 | public void putImage(String name, BufferedImage bi){ 27 | data.put(name + "A",toByteArray(bi)); 28 | data.put(name + "B",bi); 29 | } 30 | public BufferedImage getBufferedImage(String name){ 31 | return (BufferedImage) data.get(name + "B"); 32 | } 33 | public byte[] getByteArray(String name){ 34 | return (byte[]) data.get(name + "A"); 35 | } 36 | private void readImages(){ 37 | putImage("bg",Util.readPackageResource("bg.png")); 38 | putImage("missing",Util.readPackageResource("missing.png")); 39 | } 40 | public static BufferedImage toBufferedImage(byte[] byteArray){ 41 | try{ 42 | ByteArrayInputStream bis = new ByteArrayInputStream(byteArray); 43 | return ImageIO.read(bis); 44 | }catch (Exception e){ 45 | R.logger.error("无法将给定的byte数组转换为BufferedImage",e); 46 | return null; 47 | } 48 | } 49 | public static byte[] toByteArray(BufferedImage bi){ 50 | try{ 51 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); 52 | ImageIO.write(bi, "png", bos); 53 | return bos.toByteArray(); 54 | }catch (Exception e){ 55 | R.logger.error("无法将给定的BufferedImage转换为byte数组",e); 56 | return null; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/zrnq/SerializableImage.java: -------------------------------------------------------------------------------- 1 | package org.zrnq; 2 | 3 | import org.jetbrains.annotations.Nullable; 4 | 5 | import javax.imageio.ImageIO; 6 | import java.awt.image.BufferedImage; 7 | import java.io.*; 8 | import java.net.URL; 9 | 10 | /** 11 | * 因为BufferedImage不可序列化,故创建了这个能够保存BufferedImage的工具类. 12 | * */ 13 | public class SerializableImage implements Externalizable { 14 | private int imageId=-1; 15 | private transient File storage; 16 | private static final Object lock = new Object(); 17 | public SerializableImage(String url){ 18 | synchronized (lock){ 19 | imageId=PluginData.INSTANCE.getImageIdPointer(); 20 | PluginData.INSTANCE.setImageIdPointer(imageId+1); 21 | } 22 | storage = Wiki.INSTANCE.resolveDataFile("images\\"+imageId+".png"); 23 | try{ 24 | URL u=new URL(url); 25 | BufferedImage bi = ImageIO.read(u); 26 | ImageIO.write(bi, "png", storage); 27 | }catch (Exception e){ 28 | e.printStackTrace(); 29 | } 30 | } 31 | public SerializableImage() { 32 | 33 | } 34 | @Nullable 35 | public static File getImage(int id){ 36 | File image = Wiki.INSTANCE.resolveDataFile("images\\"+id+".png"); 37 | if(image.exists()) 38 | return image; 39 | else 40 | return null; 41 | } 42 | public BufferedImage getImage(){ 43 | File img = getImage(imageId); 44 | if(img==null){ 45 | R.logger.warning("找不到id为"+imageId+"的图片,使用丢失图片材质。"); 46 | return PluginImageHolder.INSTANCE.getBufferedImage("missing"); 47 | } 48 | try{ 49 | return ImageIO.read(img); 50 | }catch (Exception e){ 51 | R.logger.error("读取图片失败:"+img.getAbsolutePath()+",使用丢失图片材质。"); 52 | return PluginImageHolder.INSTANCE.getBufferedImage("missing"); 53 | } 54 | } 55 | public int getImageId(){ 56 | return imageId; 57 | } 58 | @Override 59 | public void writeExternal(ObjectOutput out) throws IOException { 60 | out.writeObject(imageId); 61 | } 62 | 63 | @Override 64 | public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { 65 | imageId=(int)in.readObject(); 66 | storage = Wiki.INSTANCE.resolveDataFile("images\\"+imageId+".png"); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS="-Xmx64m" 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Mirai-wiki 2 | [![mirai](https://img.shields.io/badge/mirai-v2.16.0-brightgreen)](https://github.com/mamoe/mirai ) 3 | 基于[mirai](https://github.com/mamoe/mirai )的QQ群内问答系统插件 4 | 5 | > 关于Linux运行环境 6 | > 如果你正在使用Linux而不是Windows来运行Mirai,请确保Microsoft YaHei字体(msyh.ttc)已安装到你的系统中,否则汉字可能不会被正常显示。 7 | 8 | ## 如何安装 9 | 1. 在[这里](https://github.com/Under-estimate/Mirai-wiki/releases/ )下载最新的插件文件。 10 | > 使用`.mirai.jar`还是`.mirai2.jar`: 11 | > `mirai-console`自`2.11.0`版本起支持了[新的插件加载方式](https://github.com/mamoe/mirai/releases/tag/v2.11.0-M1),如果您正在使用高版本`mirai-console`,则可以使用`.mirai2.jar`以避免可能的插件间依赖冲突;`.mirai.jar`为兼容插件格式,大多数版本的`mirai-console`均能使用。 12 | 2. 将插件文件放入[mirai-console](https://github.com/mamoe/mirai-console )运行生成的`plugins`文件夹中。 13 | 3. 如果您还未安装[chat-command](https://github.com/project-mirai/chat-command )插件(添加聊天环境中使用命令的功能),你可以从下面选择一种方法安装此插件: 14 | > 1. 如果您正在使用[Mirai Console Loader](https://github.com/iTXTech/mirai-console-loader )来启动[mirai-console](https://github.com/mamoe/mirai-console ),您可以运行以下命令来安装[chat-command](https://github.com/project-mirai/chat-command )插件: 15 | > `./mcl --update-package net.mamoe:chat-command --channel stable --type plugin` 16 | > 2. 如果您没有使用[Mirai Console Loader](https://github.com/iTXTech/mirai-console-loader ),您可以在[这里](https://github.com/project-mirai/chat-command/releases )下载最新的[chat-command](https://github.com/project-mirai/chat-command )插件文件,并将其一同放入[mirai-console](https://github.com/mamoe/mirai-console )运行生成的`plugins`文件夹中。 17 | 4. 启动[mirai-console](https://github.com/mamoe/mirai-console )之后,在后台命令行输入以下命令授予相关用户使用此插件命令的权限: 18 | > - 如果您希望所有群的群员都可以使用此插件,请输入: 19 | > `/perm grant m* org.zrnq.wiki:command.wiki` 20 | > - 如果您希望只授予某一个群的群员使用此插件的权限,请输入: 21 | > `/perm grant m.* org.zrnq.wiki:command.wiki` 22 | > - 如果您希望只授予某一个群的特定群员使用此插件的权限,请输入: 23 | > `/perm grant m.<群员QQ号> org.zrnq.wiki:command.wiki` 24 | > - 如果你希望了解更多高级权限设置方法,请参阅[mirai-console的权限文档](https://github.com/mamoe/mirai-console/blob/master/docs/Permissions.md ) 25 | 5. 安装完成。 26 | ## 权限列表 27 | *有关权限部分的说明,参见[mirai-console的权限文档](https://github.com/mamoe/mirai-console/blob/master/docs/Permissions.md )* 28 | 根权限: `org.zrnq.wiki:*` 29 | 基本操作权限: `org.zrnq.wiki:command.wiki` 30 | - 包含所有命令执行的权限。 31 | 32 | 管理员权限: `org.zrnq.wiki:admin` 33 | - 拥有管理员权限的用户可以删除其他人的问题/回答,标记问题为"解决"或"追问" 34 | ## 命令列表 35 | *提示: <尖括号>中的参数必填,(圆括号)中的参数可以不填* 36 | ### 任何情况下都能够使用的指令 37 | wiki search <关键词> 搜索有关问题 38 | wiki question <标题> 提出新的问题 39 | wiki myquestion 查看自己提出的问题列表 40 | wiki myanswer 查看自己回答过的问题列表 41 | wiki unsolved 查看本群中未解决的问题列表 42 | wiki all 查看本群所有问题列表 43 | wiki about 查看本插件的相关信息 44 | wiki viewimage <序号> 查看指定序号的图片原图 45 | ### 在一定上下文中能够使用的指令 46 | wiki page <页码> 跳转到指定页 47 | wiki view <序号> 查看列表中指定问题的详细信息 48 | wiki answer (序号) 为指定的问题写回答。若不加序号参数,则为刚刚查看过详细信息的问题写回答。 49 | wiki text <文本> 为问题/回答添加文本 50 | wiki image <图片> 为问题/回答添加图片(不能是表情) 51 | wiki submit 提交问题/回答 52 | wiki abort 终止提出问题/写回答 53 | wiki deleteq (序号) 删除列表中指定的问题。若不加序号参数,则删除刚刚查看过详细信息的问题。删除的问题必须是用户自己提出的。 54 | wiki deletea (问题序号) <回答序号> 删除列表中指定问题下的指定回答。若不加问题序号参数,则删除刚刚查看过详细信息的问题下指定序号的回答。删除的回答必须是用户自己提供的。 55 | wiki accept <回答序号> 接受刚刚查看过详细信息的问题中的指定回答并标记问题为"解决" 56 | wiki further 将刚刚查看过详细信息的问题标记为"追问" 57 | 58 | ## FAQ 59 | ### Q: 后台命令行或私聊机器人输入指令后提示"参数错误" 60 | A: 目前只支持在QQ群中发送命令,因为每次提问/回答需要记录执行该操作的用户。提示参数错误是因为插件限制了命令执行者只能为QQ群成员。 61 | ### Q: 在QQ群中发送命令没反应 62 | A: 请检查是否安装了[chat-command](https://github.com/project-mirai/chat-command )插件,如果没有安装请看[这里](#如何安装 ) -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS='"-Xmx64m"' 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /src/main/java/org/zrnq/Util.java: -------------------------------------------------------------------------------- 1 | package org.zrnq; 2 | 3 | import net.mamoe.mirai.Bot; 4 | import net.mamoe.mirai.contact.Group; 5 | import net.mamoe.mirai.event.events.GroupMessageEvent; 6 | import net.mamoe.mirai.message.data.*; 7 | import net.mamoe.mirai.utils.ExternalResource; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | import javax.imageio.ImageIO; 11 | import java.awt.*; 12 | import java.awt.image.BufferedImage; 13 | import java.io.*; 14 | import java.net.URL; 15 | import java.text.SimpleDateFormat; 16 | import java.util.*; 17 | import java.util.List; 18 | 19 | public class Util { 20 | /** 21 | * 在当前群的问题数据中搜索指定的关键词. 22 | * @return 搜索到的问题列表,按相关度降序排列。如果没有搜索到,返回空列表. 23 | * */ 24 | public static @NotNull ArrayList search(String keyword, long groupId){ 25 | ArrayList groupQuestions=QuestionListHolder.INSTANCE.getListOf(groupId); 26 | if(groupQuestions.size()<=0) 27 | return new ArrayList<>(); 28 | HashMap searchCache=new HashMap<>(); 29 | Iterator questionIterator=groupQuestions.iterator(); 30 | Question tempQuestion; 31 | int match; 32 | while(questionIterator.hasNext()){ 33 | tempQuestion=questionIterator.next(); 34 | match=0; 35 | for(int i=0;i0)searchCache.put(tempQuestion.questionId,match); 40 | } 41 | Integer[] result= searchCache.keySet().toArray(new Integer[0]); 42 | Arrays.sort(result, (o1, o2) -> searchCache.get(o2)-searchCache.get(o1)); 43 | ArrayList resultList=new ArrayList<>(); 44 | for(Integer questionId:result) 45 | resultList.add(get(groupId,questionId)); 46 | return resultList; 47 | } 48 | /** 49 | * 在当前群的问题数据中搜索指定成员提出的问题. 50 | * */ 51 | public static @NotNull ArrayList myQuestions(long groupId, long userId){ 52 | ArrayList groupQuestions=QuestionListHolder.INSTANCE.getListOf(groupId); 53 | ArrayList result=new ArrayList<>(); 54 | if(groupQuestions==null)return result; 55 | for(Question q:groupQuestions) 56 | if(q.questioner.id==userId)result.add(q); 57 | return result; 58 | } 59 | /** 60 | * 在当前群的问题数据中搜索指定成员回答过的问题. 61 | * */ 62 | public static @NotNull ArrayList myAnswers(long groupId, long userId){ 63 | ArrayList groupQuestions=QuestionListHolder.INSTANCE.getListOf(groupId); 64 | ArrayList result=new ArrayList<>(); 65 | if(groupQuestions==null)return result; 66 | for(Question q:groupQuestions){ 67 | for (Answer answerer : q.answererList) 68 | if (answerer.id == userId) result.add(q); 69 | } 70 | return result; 71 | } 72 | /** 73 | * 在当前群的问题数据中搜索标记为"等待"或"追问"的问题. 74 | * */ 75 | public static @NotNull ArrayList unsolvedQuestions(long groupId){ 76 | ArrayList groupQuestions=QuestionListHolder.INSTANCE.getListOf(groupId); 77 | ArrayList result=new ArrayList<>(); 78 | if(groupQuestions==null)return result; 79 | for(Question q:groupQuestions) 80 | if(q.requireFurtherInfo||q.answererList.size()<=0)result.add(q); 81 | return result; 82 | } 83 | /** 84 | * 生成问题搜索结果图像. 85 | * 每页10个问题. 86 | * */ 87 | public static byte[] generateResultImage(@NotNull ArrayList searchResult, int page, String title, String subtitle1, String subtitle2){ 88 | if(page*10>=searchResult.size())throw new IllegalArgumentException("Page out of bound. Page:"+page+". Total size:"+searchResult.size()); 89 | int startPoint=page*10; 90 | int endPoint=Math.min(searchResult.size(),page*10+10); 91 | int height=600+(endPoint-startPoint)*50; 92 | BufferedImage result=new BufferedImage(700,height,BufferedImage.TYPE_3BYTE_BGR); 93 | Graphics2D g=(Graphics2D)result.getGraphics(); 94 | g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); 95 | g.drawImage(PluginImageHolder.INSTANCE.getBufferedImage("bg"), 0,0,null); 96 | g.setColor(new Color(0,0,0,100)); 97 | g.fillRect(0,0,700,height); 98 | g.setColor(Color.white); 99 | g.setFont(R.F); 100 | g.drawString(title,10,30); 101 | g.setColor(Color.lightGray); 102 | g.setFont(R.F.deriveFont(20f)); 103 | g.drawString(subtitle1,10,60); 104 | g.drawString(subtitle2,10,80); 105 | g.setColor(Color.white); 106 | g.drawString("序号",10,110); 107 | g.drawString("标题",60,110); 108 | g.drawString("回答",600,110); 109 | g.drawString("状态",650,110); 110 | g.drawLine(10,130,690,130); 111 | for(int i=startPoint;i textList = new ArrayList<>(); 150 | //10px padding 151 | textList.add(preCalculate(stub,"#"+question.questionId,width)); 152 | textList.add(preCalculate(stub,question.title,width)); 153 | //5px interval 154 | textList.add(preCalculate(stub, question.getStatusBarText(), width)); 155 | //5px interval 156 | textList.add(preCalculate(stub, question.text, width)); 157 | //5px interval 158 | //Image grid 159 | //5px interval 160 | for (int i = 0; i < question.answererList.size(); i++) { 161 | Answer answer = question.answererList.get(i); 162 | //5px line separator 163 | textList.add(preCalculate(stub,answer.getStatusBarText(),width)); 164 | //5px interval 165 | textList.add(preCalculate(stub, answer.text, width)); 166 | //5px interval 167 | //Image grid 168 | height +=((answer.images.size()+2)/3)*imageGridSize; 169 | //5px interval 170 | } 171 | //10px padding 172 | textList.add(preCalculate(stub,R.name+" "+R.version+" UI",width)); 173 | //5px interval 174 | 175 | height += 45 + ((question.images.size()+2)/3)*imageGridSize + question.answererList.size()*25; 176 | for(RenderedText text : textList) 177 | height += text.height; 178 | 179 | //Post Load - paint texts and images at calculated position 180 | BufferedImage result = new BufferedImage(width+100,height,BufferedImage.TYPE_3BYTE_BGR); 181 | int yPos = 10; 182 | int textMargin = 80; 183 | int avatarMargin = 10; 184 | int avatarSize = 60; 185 | Iterator it = textList.iterator(); 186 | RenderedText tmp; 187 | Graphics2D g = result.createGraphics(); 188 | g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON); 189 | g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BICUBIC); 190 | g.setColor(Color.WHITE); 191 | g.fillRect(0,0,width+100,height); 192 | g.setFont(R.F.deriveFont(20f)); 193 | 194 | g.setColor(R.orange); 195 | doDraw(g,tmp=it.next(),textMargin,yPos); 196 | yPos += tmp.height; 197 | 198 | g.setColor(Color.BLACK); 199 | doDraw(g,tmp=it.next(),textMargin,yPos); 200 | doDraw(g,"提问",getAvatarOf(question.groupId, question.questioner.id),avatarMargin,yPos,avatarSize); 201 | yPos += tmp.height; 202 | yPos +=5; 203 | 204 | g.setColor(R.skyBlue); 205 | doDraw(g,tmp=it.next(),textMargin,yPos); 206 | yPos += tmp.height; 207 | yPos +=5; 208 | 209 | g.setColor(Color.BLACK); 210 | doDraw(g,tmp=it.next(),textMargin,yPos); 211 | yPos += tmp.height; 212 | yPos +=5; 213 | 214 | doDraw(g, question.images, textMargin,yPos,imageGridSize); 215 | yPos += ((question.images.size()+2)/3)*imageGridSize; 216 | yPos +=5; 217 | 218 | for (int i = 0; i < question.answererList.size(); i++) { 219 | Answer answer = question.answererList.get(i); 220 | g.setColor(Color.LIGHT_GRAY); 221 | g.drawLine(textMargin,yPos,textMargin+width,yPos); 222 | yPos+=5; 223 | 224 | g.setColor(R.skyBlue); 225 | doDraw(g,tmp=it.next(),textMargin,yPos); 226 | doDraw(g,"A"+i,getAvatarOf(question.groupId,answer.id),avatarMargin,yPos,avatarSize); 227 | yPos += tmp.height; 228 | yPos += 5; 229 | 230 | g.setColor(Color.BLACK); 231 | doDraw(g,tmp=it.next(),textMargin,yPos); 232 | yPos += tmp.height; 233 | yPos += 5; 234 | 235 | doDraw(g,answer.images,textMargin,yPos,imageGridSize); 236 | yPos += ((answer.images.size()+2)/3)*imageGridSize; 237 | yPos += 5; 238 | } 239 | 240 | yPos += 10; 241 | g.setColor(Color.darkGray); 242 | doDraw(g,it.next(),avatarMargin,yPos); 243 | 244 | return PluginImageHolder.toByteArray(result); 245 | } 246 | /** 247 | * 获取指定群中指定ID的问题. 248 | * */ 249 | public static @NotNull Question get(long group, long questionId){ 250 | ArrayList groupQuestions = QuestionListHolder.INSTANCE.getListOf(group); 251 | Iterator it=groupQuestions.iterator(); 252 | Question tempQuestion; 253 | while(it.hasNext()){ 254 | tempQuestion=it.next(); 255 | if(tempQuestion.questionId==questionId)return tempQuestion; 256 | } 257 | throw new IllegalArgumentException("Question ID:"+questionId+" not found."); 258 | } 259 | public static void sendMes(@NotNull GroupMessageEvent event, Message message){ 260 | QuoteReply quote=new QuoteReply(event.getMessage()); 261 | event.getGroup().sendMessage(quote.plus(message)); 262 | } 263 | public static void sendMes(@NotNull GroupMessageEvent event, String message){ 264 | sendMes(event,new PlainText(message)); 265 | } 266 | public static void sendMes(@NotNull GroupMessageEvent event, byte[] image){ 267 | ExternalResource resource = ExternalResource.create(image, "png"); 268 | sendMes(event,event.getGroup().uploadImage(resource)); 269 | try { 270 | resource.close(); 271 | } catch (IOException e) { 272 | R.logger.error("关闭ExternalResource失败",e); 273 | } 274 | } 275 | public static void sendMes(@NotNull GroupMessageEvent event, File image){ 276 | ExternalResource resource = ExternalResource.create(image, "png"); 277 | sendMes(event,event.getGroup().uploadImage(resource)); 278 | try { 279 | resource.close(); 280 | } catch (IOException e) { 281 | R.logger.error("关闭ExternalResource失败",e); 282 | } 283 | } 284 | /** 285 | * 限制字符串的长度,过长的部分截去并用"..."代替. 286 | * */ 287 | public static String limitString(@NotNull String original, int maxLength){ 288 | return original.length()<=maxLength?original:original.substring(0,maxLength)+"..."; 289 | } 290 | /** 291 | * 由millisecond表示的时间生成正常的时间表示字符串. 292 | * */ 293 | public static @NotNull String parseTime(long time){ 294 | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 295 | return format.format(new Date(time)); 296 | } 297 | /** 298 | * 判断字符串中是否equalsIgnoreCase给定字符串组中的至少一个. 299 | * */ 300 | public static boolean matchesAny(String target,String... matchers){ 301 | for(String s:matchers){ 302 | if(target.equalsIgnoreCase(s))return true; 303 | } 304 | return false; 305 | } 306 | public static byte[] streamToByteArray(InputStream is)throws Exception{ 307 | ByteArrayOutputStream bos=new ByteArrayOutputStream(); 308 | byte[] buf=new byte[1024]; 309 | int len; 310 | while((len=is.read(buf))!=-1) 311 | bos.write(buf,0,len); 312 | return bos.toByteArray(); 313 | } 314 | public static byte[] readPackageResource(String name){ 315 | InputStream is = Wiki.INSTANCE.getResourceAsStream(name); 316 | if(is == null){ 317 | R.logger.error("找不到包内资源文件:"+name); 318 | }else{ 319 | try{ 320 | return Util.streamToByteArray(is); 321 | }catch (Exception e){ 322 | R.logger.error("读取包内资源文件时出错:"+name,e); 323 | } 324 | } 325 | return null; 326 | } 327 | 328 | public static RenderedText preCalculate(Graphics2D g, String text, int w){ 329 | RenderedText rendered = new RenderedText(); 330 | FontMetrics fm=g.getFontMetrics(); 331 | //Preventing characters overflow 332 | w -= fm.charWidth('啊'); 333 | int lineCount = 1; 334 | int lastDraw=0; 335 | rendered.linebreaks.add(0); 336 | for (int i = 1; i < text.length(); i++) { 337 | if(text.charAt(i)=='\n'||fm.stringWidth(text.substring(lastDraw,i))>w){ 338 | rendered.linebreaks.add(i); 339 | lineCount++; 340 | lastDraw=i; 341 | } 342 | } 343 | rendered.linebreaks.add(text.length()); 344 | rendered.ascent = fm.getAscent(); 345 | rendered.lineHeight = fm.getHeight(); 346 | rendered.height = lineCount*fm.getHeight(); 347 | rendered.text = text; 348 | return rendered; 349 | } 350 | 351 | public static void doDraw(Graphics2D g, RenderedText text, int x, int y){ 352 | for (int i = 1; i < text.linebreaks.size(); i++) { 353 | g.drawString(text.text.substring(text.linebreaks.get(i-1),text.linebreaks.get(i)), 354 | x,y+text.ascent+text.lineHeight*(i-1)); 355 | } 356 | } 357 | 358 | public static void doDraw(Graphics2D g, ArrayList images, int x,int y,int a){ 359 | int xPos,yPos; 360 | int w,h; 361 | String ids; 362 | FontMetrics metric = g.getFontMetrics(); 363 | for(int i=0;i< images.size();i++){ 364 | BufferedImage entity = images.get(i).getImage(); 365 | xPos = x + a * (i % 3); 366 | yPos = y + a * (i / 3); 367 | w=entity.getWidth(); 368 | h=entity.getHeight(); 369 | if(w>h){ 370 | h = h * a / w; 371 | w = a; 372 | g.drawImage(entity,xPos,yPos+(a-h)/2,w,h,null); 373 | }else{ 374 | w = w * a / h; 375 | h = a; 376 | g.drawImage(entity,xPos+(a-w)/2,yPos,w,h,null); 377 | } 378 | ids = "@" + images.get(i).getImageId(); 379 | g.setColor(R.hover); 380 | g.fillRect(xPos,yPos,metric.stringWidth(ids),metric.getHeight()); 381 | g.setColor(Color.CYAN); 382 | g.drawString(ids,xPos,yPos+metric.getAscent()); 383 | g.setColor(R.skyBlue); 384 | g.drawRect(xPos,yPos,a,a); 385 | } 386 | } 387 | 388 | public static void doDraw(Graphics2D g, String append, BufferedImage avatar, int x, int y, int a){ 389 | FontMetrics metric = g.getFontMetrics(); 390 | g.drawImage(avatar,x,y,a,a,null); 391 | g.setColor(R.hover); 392 | g.fillRect(x,y,metric.stringWidth(append),metric.getHeight()); 393 | g.setColor(Color.WHITE); 394 | g.drawString(append,x,y+metric.getAscent()); 395 | g.setColor(R.skyBlue); 396 | g.drawRect(x,y,a,a); 397 | } 398 | 399 | public static BufferedImage getAvatarOf(long groupId, long userId){ 400 | List botList = Bot.getInstances(); 401 | Group targetGroup = null; 402 | for(Bot bot : botList){ 403 | if((targetGroup=bot.getGroup(groupId))!=null) 404 | break; 405 | } 406 | if(targetGroup == null){ 407 | R.logger.warning("找不到群组:"+groupId+",使用丢失图片材质。"); 408 | return PluginImageHolder.INSTANCE.getBufferedImage("missing"); 409 | } 410 | if(targetGroup.contains(userId)){ 411 | try{ 412 | URL url = new URL(targetGroup.getOrFail(userId).getAvatarUrl()); 413 | return ImageIO.read(url); 414 | }catch (Exception e){ 415 | R.logger.warning("下载用户("+userId+")的头像失败,使用丢失图片材质。"); 416 | return PluginImageHolder.INSTANCE.getBufferedImage("missing"); 417 | } 418 | }else{ 419 | return PluginImageHolder.INSTANCE.getBufferedImage("missing"); 420 | } 421 | } 422 | 423 | public static class RenderedText{ 424 | int height; 425 | int lineHeight; 426 | int ascent; 427 | String text; 428 | final ArrayList linebreaks = new ArrayList<>(); 429 | } 430 | } 431 | -------------------------------------------------------------------------------- /src/main/java/org/zrnq/PluginCommand.kt: -------------------------------------------------------------------------------- 1 | package org.zrnq 2 | 3 | import net.mamoe.mirai.console.command.CompositeCommand 4 | import net.mamoe.mirai.console.command.MemberCommandSenderOnMessage 5 | import net.mamoe.mirai.console.permission.PermissionService.Companion.testPermission 6 | import net.mamoe.mirai.console.permission.PermitteeId.Companion.permitteeId 7 | import net.mamoe.mirai.contact.nameCardOrNick 8 | import net.mamoe.mirai.message.data.Image 9 | import net.mamoe.mirai.message.data.Image.Key.queryUrl 10 | import java.lang.IllegalStateException 11 | import java.lang.UnsupportedOperationException 12 | import kotlin.reflect.KProperty 13 | 14 | @Suppress("RedundantSuspendModifier") 15 | object PluginCommand : CompositeCommand( 16 | Wiki,"wiki", 17 | description = "MiraiWiki相关指令"){ 18 | private var MemberCommandSenderOnMessage.session by SessionDelegate() 19 | private fun MemberCommandSenderOnMessage.disposeSession(){ 20 | R.sessions[group.id]?.remove(user.id) 21 | } 22 | private fun Session.State.toStateString() : String{ 23 | return when(this){ 24 | Session.State.Search_Question -> "搜索问题" 25 | Session.State.Write_Question -> "创建新问题" 26 | Session.State.My_Questions -> "查看\"我提出的问题\"" 27 | Session.State.My_Answers -> "查看\"我回答过的问题\"" 28 | Session.State.View_Unsolved -> "查看本群未解决的问题" 29 | Session.State.View_All -> "查看本群所有问题" 30 | Session.State.Write_Answer -> "为问题写解答" 31 | Session.State.Null -> "[上下文无效]" 32 | } 33 | } 34 | private fun MemberCommandSenderOnMessage.checkApplicability(acceptTheseStates : Boolean, vararg states : Session.State) : Boolean{ 35 | if(acceptTheseStates xor (session.state in states) || session.state == Session.State.Null){ 36 | Util.sendMes(fromEvent, "在${session.state.toStateString()}时不能执行该操作") 37 | return false 38 | } 39 | return true 40 | } 41 | private fun MemberCommandSenderOnMessage.checkApplicability(acceptTheseStates: Boolean, acceptViewDetail : Boolean, vararg states: Session.State) : Boolean{ 42 | if(acceptViewDetail xor session.viewDetail){ 43 | Util.sendMes(fromEvent,"${if(session.viewDetail) "" else "不" }在查看问题详细信息时不能执行该操作,或指令缺少[列表中的序号]参数") 44 | return false 45 | } 46 | return checkApplicability(acceptTheseStates, *states) 47 | } 48 | private fun MemberCommandSenderOnMessage.checkPermission(question : Question) : Boolean{ 49 | if(question.questioner.id != user.id && !Wiki.adminPerm.testPermission(user.permitteeId)){ 50 | Util.sendMes(fromEvent, "你不能在${question.questioner.name}提出的问题中执行该操作") 51 | return false 52 | } 53 | return true 54 | } 55 | private fun MemberCommandSenderOnMessage.checkPermission(answer : Answer) : Boolean{ 56 | if(answer.id != user.id && !Wiki.adminPerm.testPermission(user.permitteeId)){ 57 | Util.sendMes(fromEvent, "你不能对${answer.name}的回答执行该操作") 58 | return false 59 | } 60 | return true 61 | } 62 | @SubCommand 63 | @Description("搜索当前群聊中的有关问题") 64 | suspend fun MemberCommandSenderOnMessage.search(keyword : String){ 65 | session.queryData=Util.search(keyword, group.id) 66 | if(session.queryData.size<=0){ 67 | Util.sendMes(fromEvent, "什么都没找到...请尝试换一个关键词或者发起提问") 68 | disposeSession() 69 | return 70 | } 71 | session.state = Session.State.Search_Question 72 | session.text = keyword 73 | val image = Util.generateResultImage(session.queryData,0, 74 | "搜索结果", 75 | "关键词: $keyword", 76 | "用户: ${user.nameCardOrNick}") 77 | Util.sendMes(fromEvent,image) 78 | } 79 | @SubCommand 80 | @Description("创建新的问题") 81 | suspend fun MemberCommandSenderOnMessage.question(title : String){ 82 | session.currentQuestion = Question() 83 | session.currentQuestion.title = title 84 | session.currentQuestion.questioner = Questioner(user.nameCardOrNick, user.id) 85 | session.state = Session.State.Write_Question 86 | Util.sendMes(fromEvent, "开始创建新的问题") 87 | } 88 | @SubCommand 89 | @Description("查看当前用户提出的问题列表") 90 | suspend fun MemberCommandSenderOnMessage.myquestion(){ 91 | session.queryData = Util.myQuestions(group.id,user.id) 92 | if(session.queryData.size<=0){ 93 | Util.sendMes(fromEvent, "你还没有提出过问题呢") 94 | disposeSession() 95 | return 96 | } 97 | session.state = Session.State.My_Questions 98 | val image = Util.generateResultImage(session.queryData, 0, 99 | "我提出的问题", 100 | "用户: ${user.nameCardOrNick}", 101 | "") 102 | Util.sendMes(fromEvent,image) 103 | } 104 | @SubCommand 105 | @Description("查看当前用户回答过的问题列表") 106 | suspend fun MemberCommandSenderOnMessage.myanswer(){ 107 | session.queryData = Util.myAnswers(group.id,user.id) 108 | if(session.queryData.size<=0){ 109 | Util.sendMes(fromEvent, "你还没有回答过问题呢") 110 | disposeSession() 111 | return 112 | } 113 | session.state = Session.State.My_Answers 114 | val image = Util.generateResultImage(session.queryData,0, 115 | "我回答过的问题", 116 | "用户: ${user.nameCardOrNick}", 117 | "") 118 | Util.sendMes(fromEvent,image) 119 | } 120 | @SubCommand 121 | @Description("查看本群未解决的问题") 122 | suspend fun MemberCommandSenderOnMessage.unresolved(){ 123 | session.queryData = Util.unsolvedQuestions(group.id) 124 | if(session.queryData.size<=0){ 125 | Util.sendMes(fromEvent, "现在还没有未解决的问题哦") 126 | disposeSession() 127 | return 128 | } 129 | session.state = Session.State.View_Unsolved 130 | val image = Util.generateResultImage(session.queryData,0, 131 | "本群未解决的问题", 132 | "用户: ${user.nameCardOrNick}", 133 | "") 134 | Util.sendMes(fromEvent,image) 135 | } 136 | @SubCommand 137 | @Description("查看本群的所有问题") 138 | suspend fun MemberCommandSenderOnMessage.all(){ 139 | if(QuestionListHolder.INSTANCE.getListOf(group.id).size<=0){ 140 | Util.sendMes(fromEvent, "本群还没有人提过问题") 141 | disposeSession() 142 | return 143 | } 144 | session.queryData = ArrayList() 145 | session.queryData = QuestionListHolder.INSTANCE.getListOf(group.id) 146 | session.state = Session.State.View_All 147 | val image = Util.generateResultImage(session.queryData,0, 148 | "本群所有问题", 149 | "用户: ${user.nameCardOrNick}", 150 | "") 151 | Util.sendMes(fromEvent,image) 152 | } 153 | @SubCommand 154 | @Description("显示版本信息") 155 | suspend fun MemberCommandSenderOnMessage.about(){ 156 | Util.sendMes(fromEvent,"${R.name}版本${R.version}\n项目地址https://github.com/Under-estimate/Mirai-wiki") 157 | } 158 | @SubCommand 159 | @Description("在多页结果中翻页") 160 | suspend fun MemberCommandSenderOnMessage.page(page : Int){ 161 | if(!checkApplicability(false, 162 | Session.State.Write_Answer, 163 | Session.State.Write_Question)) 164 | return 165 | val lim = (session.queryData.size-1)/10 166 | if(page !in 0..lim){ 167 | Util.sendMes(fromEvent,"给定的页码[$page]超出范围[0,$lim]") 168 | return 169 | } 170 | val image = when(session.state){ 171 | Session.State.Search_Question -> Util.generateResultImage(session.queryData,page,"搜索结果","关键词: ${session.text}","用户: ${user.nameCardOrNick}") 172 | Session.State.My_Questions -> Util.generateResultImage(session.queryData,page,"我提出的问题","用户: ${user.nameCardOrNick}","") 173 | Session.State.My_Answers -> Util.generateResultImage(session.queryData,page,"我回答过的问题","用户: ${user.nameCardOrNick}","") 174 | Session.State.View_Unsolved -> Util.generateResultImage(session.queryData,page,"本群未解决的问题","用户: ${user.nameCardOrNick}","") 175 | Session.State.View_All -> Util.generateResultImage(session.queryData,page,"本群所有问题","用户: ${user.nameCardOrNick}","") 176 | else -> throw IllegalStateException("An unexpected exception has occurred: Theoretically unreachable statement at command [page]") 177 | } 178 | Util.sendMes(fromEvent,image) 179 | } 180 | @SubCommand 181 | @Description("查看列表中指定问题的详细信息") 182 | suspend fun MemberCommandSenderOnMessage.view(item : Int){ 183 | if(!checkApplicability(false, 184 | Session.State.Write_Answer, 185 | Session.State.Write_Question)) 186 | return 187 | if(item !in 0 until session.queryData.size){ 188 | Util.sendMes(fromEvent,"给定的序号[$item]超出范围[0,${session.queryData.size})") 189 | return 190 | } 191 | session.currentQuestion = session.queryData[item] 192 | session.viewDetail = true 193 | val image = Util.generateDetailImage(session.queryData[item]) 194 | Util.sendMes(fromEvent,image) 195 | } 196 | @SubCommand 197 | @Description("查看指定序号的图片") 198 | suspend fun MemberCommandSenderOnMessage.viewimage(imageId : Int){ 199 | val image = SerializableImage.getImage(imageId) 200 | if(image == null) { 201 | Util.sendMes(fromEvent, PluginImageHolder.INSTANCE.getByteArray("missing")) 202 | return 203 | } 204 | Util.sendMes(fromEvent,image) 205 | } 206 | @SubCommand 207 | @Description("为列表中指定的问题写回答") 208 | suspend fun MemberCommandSenderOnMessage.answer(question : Int){ 209 | if(!checkApplicability(false, 210 | Session.State.Write_Answer, 211 | Session.State.Write_Question)) 212 | return 213 | if(question !in 0 until session.queryData.size){ 214 | Util.sendMes(fromEvent,"给定的序号[$question]超出范围[0,${session.queryData.size})") 215 | return 216 | } 217 | session.currentQuestion = session.queryData[question] 218 | session.currentAnswer = Answer() 219 | session.currentAnswer.id = user.id 220 | session.currentAnswer.name = user.nameCardOrNick 221 | session.state = Session.State.Write_Answer 222 | Util.sendMes(fromEvent,"开始为问题[${session.currentQuestion.title}]写回答") 223 | } 224 | @SubCommand 225 | @Description("为刚刚查看过的问题写回答") 226 | suspend fun MemberCommandSenderOnMessage.answer(){ 227 | if(!checkApplicability(false,true, 228 | Session.State.Write_Answer, 229 | Session.State.Write_Question)) 230 | return 231 | session.currentAnswer = Answer() 232 | session.currentAnswer.id = user.id 233 | session.currentAnswer.name = user.nameCardOrNick 234 | session.state = Session.State.Write_Answer 235 | Util.sendMes(fromEvent,"开始为问题[${session.currentQuestion.title}]写回答") 236 | } 237 | @SubCommand 238 | @Description("为问题/回答追加文本") 239 | suspend fun MemberCommandSenderOnMessage.text(text : String){ 240 | if(!checkApplicability(true, 241 | Session.State.Write_Answer, 242 | Session.State.Write_Question)) 243 | return 244 | if(session.state == Session.State.Write_Question) 245 | session.currentQuestion.text = (session.currentQuestion.text ?: "") + text 246 | else 247 | session.currentAnswer.text = (session.currentAnswer.text ?: "") + text 248 | Util.sendMes(fromEvent,"文本追加成功") 249 | } 250 | @SubCommand 251 | @Description("为问题/回答追加图片") 252 | suspend fun MemberCommandSenderOnMessage.image(image : Image){ 253 | if(!checkApplicability(true, 254 | Session.State.Write_Answer, 255 | Session.State.Write_Question)) 256 | return 257 | val url = image.queryUrl() 258 | if(session.state == Session.State.Write_Question) 259 | session.currentQuestion.images.add(SerializableImage(url)) 260 | else 261 | session.currentAnswer.images.add(SerializableImage(url)) 262 | Util.sendMes(fromEvent,"图片追加成功") 263 | } 264 | @SubCommand 265 | @Description("提交问题/回答") 266 | suspend fun MemberCommandSenderOnMessage.submit(){ 267 | if(!checkApplicability(true, 268 | Session.State.Write_Answer, 269 | Session.State.Write_Question)) 270 | return 271 | if(session.state == Session.State.Write_Question){ 272 | if(session.currentQuestion.text.isNullOrBlank()){ 273 | Util.sendMes(fromEvent,"问题未设置文本,使用\"wiki text <文本>\"来追加文本") 274 | return 275 | } 276 | session.currentQuestion.questionId = PluginData.questionIdPointer++ 277 | session.currentQuestion.groupId = group.id 278 | session.currentQuestion.questioner = Questioner(user.nameCardOrNick, user.id) 279 | QuestionListHolder.INSTANCE.RWAccessor(group.id) 280 | { list : ArrayList -> 281 | list.add(session.currentQuestion) 282 | } 283 | Util.sendMes(fromEvent, "问题提交成功") 284 | }else{ 285 | if(session.currentAnswer.text.isNullOrBlank()){ 286 | Util.sendMes(fromEvent, "回答未设置文本,使用\"wiki text <文本>\"来追加文本") 287 | return 288 | } 289 | session.currentQuestion.answererList.add(session.currentAnswer) 290 | if(user.id != session.currentQuestion.questioner.id) 291 | session.currentQuestion.requireFurtherInfo = false 292 | QuestionListHolder.INSTANCE.saveQuestions() 293 | Util.sendMes(fromEvent, "回答提交成功") 294 | } 295 | disposeSession() 296 | } 297 | @SubCommand 298 | @Description("中止写问题/回答") 299 | suspend fun MemberCommandSenderOnMessage.abort(){ 300 | if(!checkApplicability(true, 301 | Session.State.Write_Answer, 302 | Session.State.Write_Question)) 303 | return 304 | Util.sendMes(fromEvent, "已中止${session.state.toStateString()}") 305 | disposeSession() 306 | } 307 | @SubCommand 308 | @Description("删除列表中指定的问题(只能是你自己的)") 309 | suspend fun MemberCommandSenderOnMessage.deleteq(question : Int){ 310 | if(!checkApplicability(false, 311 | Session.State.Write_Answer, 312 | Session.State.Write_Question)) 313 | return 314 | if(question !in 0 until session.queryData.size){ 315 | Util.sendMes(fromEvent, "给定的序号[$question]超出范围[0,${session.queryData.size})") 316 | return 317 | } 318 | val questionE = session.queryData[question] 319 | if(!checkPermission(questionE)) 320 | return 321 | QuestionListHolder.INSTANCE.RWAccessor(group.id) 322 | { list : ArrayList -> 323 | list.remove(questionE) 324 | } 325 | disposeSession() 326 | Util.sendMes(fromEvent, "删除问题成功") 327 | } 328 | @SubCommand 329 | @Description("删除刚刚查看过的问题(只能是你自己的)") 330 | suspend fun MemberCommandSenderOnMessage.deleteq(){ 331 | if(!checkApplicability(false,true, 332 | Session.State.Write_Answer, 333 | Session.State.Write_Question)) 334 | return 335 | if(!checkPermission(session.currentQuestion)) 336 | return 337 | QuestionListHolder.INSTANCE.RWAccessor(group.id) 338 | { list : ArrayList -> 339 | list.remove(session.currentQuestion) 340 | } 341 | disposeSession() 342 | Util.sendMes(fromEvent, "删除问题成功") 343 | } 344 | @SubCommand 345 | @Description("删除列表中指定问题下指定序号的回答(只能是你的回答)") 346 | suspend fun MemberCommandSenderOnMessage.deletea(question : Int, answer : Int){ 347 | if(!checkApplicability(false, 348 | Session.State.Write_Answer, 349 | Session.State.Write_Question)) 350 | return 351 | if(question !in 0 until session.queryData.size){ 352 | Util.sendMes(fromEvent, "给定的序号[$question]超出范围[0,${session.queryData.size})") 353 | return 354 | } 355 | if(answer !in 0 until session.queryData[question].answererList.size){ 356 | Util.sendMes(fromEvent, "给定的序号[$answer]超出范围[0,${session.queryData[question].answererList.size})") 357 | return 358 | } 359 | if(!checkPermission(session.queryData[question].answererList[answer])) 360 | return 361 | session.queryData[question].answererList.removeAt(answer) 362 | Util.sendMes(fromEvent, "删除回答成功") 363 | } 364 | @SubCommand 365 | @Description("删除刚刚查看的问题下指定序号的回答(只能是你的回答)") 366 | suspend fun MemberCommandSenderOnMessage.deletea(answer : Int){ 367 | if(!checkApplicability(false, 368 | Session.State.Write_Answer, 369 | Session.State.Write_Question)) 370 | return 371 | if(answer !in 0 until session.currentQuestion.answererList.size){ 372 | Util.sendMes(fromEvent, "给定的序号[$answer]超出范围[0,${session.currentQuestion.answererList.size})") 373 | return 374 | } 375 | if(!checkPermission(session.currentQuestion.answererList[answer])) 376 | return 377 | session.currentQuestion.answererList.removeAt(answer) 378 | Util.sendMes(fromEvent, "删除回答成功") 379 | } 380 | @SubCommand 381 | @Description("采纳指定的回答(只能在你提出的问题中)") 382 | suspend fun MemberCommandSenderOnMessage.accept(answer : Int){ 383 | if(!checkApplicability(false, true, 384 | Session.State.Write_Answer, 385 | Session.State.Write_Question)) 386 | return 387 | if(answer !in 0 until session.currentQuestion.answererList.size){ 388 | Util.sendMes(fromEvent, "给定的序号[$answer]超出范围[0,${session.currentQuestion.answererList.size})") 389 | return 390 | } 391 | if(!checkPermission(session.currentQuestion)) 392 | return 393 | session.currentQuestion.answererList[answer].accepted = true 394 | session.currentQuestion.requireFurtherInfo = false 395 | Util.sendMes(fromEvent, "成功采纳了${session.currentQuestion.answererList[answer].name}的回答") 396 | QuestionListHolder.INSTANCE.saveQuestions() 397 | } 398 | @SubCommand 399 | @Description("标记指定问题需要更多信息(只能在你提出的问题中)") 400 | suspend fun MemberCommandSenderOnMessage.further(question : Int){ 401 | if(!checkApplicability(false, 402 | Session.State.Write_Answer, 403 | Session.State.Write_Question)) 404 | return 405 | if(question !in 0 until session.queryData.size){ 406 | Util.sendMes(fromEvent, "给定的序号[$question]超出范围[0,${session.queryData.size})") 407 | return 408 | } 409 | val questionE = session.queryData[question] 410 | if(!checkPermission(questionE)) 411 | return 412 | questionE.requireFurtherInfo = true 413 | Util.sendMes(fromEvent, "成功标记该问题为\"追问\"") 414 | QuestionListHolder.INSTANCE.saveQuestions() 415 | } 416 | @SubCommand 417 | @Description("标记刚刚查看过的问题需要更多信息(只能是你提出的问题)") 418 | suspend fun MemberCommandSenderOnMessage.further(){ 419 | if(!checkApplicability(false, true, 420 | Session.State.Write_Answer, 421 | Session.State.Write_Question)) 422 | return 423 | if(!checkPermission(session.currentQuestion)) 424 | return 425 | session.currentQuestion.requireFurtherInfo = true 426 | Util.sendMes(fromEvent, "成功标记该问题为\"追问\"") 427 | QuestionListHolder.INSTANCE.saveQuestions() 428 | } 429 | } 430 | 431 | class SessionDelegate{ 432 | operator fun getValue(thisRef: MemberCommandSenderOnMessage, property: KProperty<*>): Session { 433 | if(!R.sessions.containsKey(thisRef.group.id)) 434 | R.sessions[thisRef.group.id] = HashMap() 435 | val map = R.sessions[thisRef.group.id]!! 436 | if(!map.containsKey(thisRef.user.id)) 437 | map[thisRef.user.id] = Session(thisRef.fromEvent) 438 | return map[thisRef.user.id]!! 439 | } 440 | 441 | operator fun setValue(thisRef: MemberCommandSenderOnMessage, property: KProperty<*>, value: Session) { 442 | throw UnsupportedOperationException("Modifying session reference is not allowed.") 443 | } 444 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 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 Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | --------------------------------------------------------------------------------