Browse Source

Add default aliases and extract them.

Change-Id: If6079d951f7b6b5379043ffb9772d757fef9837b
Reviewed-on: http://gerrit.dmdirc.com/3563
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
pull/1/head
Chris Smith 10 years ago
parent
commit
79cf2aeefd

+ 6
- 1
src/com/dmdirc/commandparser/aliases/AliasesModule.java View File

@@ -54,8 +54,13 @@ public class AliasesModule {
54 54
     }
55 55
 
56 56
     @Provides(type = Provides.Type.SET)
57
-    public Migrator getMigrator(final ActionAliasMigrator migrator) {
57
+    public Migrator getActionMigrator(final ActionAliasMigrator migrator) {
58 58
         return migrator;
59 59
     }
60 60
 
61
+    @Provides(type = Provides.Type.SET)
62
+    public Migrator getDefaultsMigrator(@Directory(DirectoryType.BASE) final String directory) {
63
+        return new DefaultAliasInstaller(Paths.get(directory, "aliases.yml"));
64
+    }
65
+
61 66
 }

+ 58
- 0
src/com/dmdirc/commandparser/aliases/DefaultAliasInstaller.java View File

@@ -0,0 +1,58 @@
1
+/*
2
+ * Copyright (c) 2006-2014 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.commandparser.aliases;
24
+
25
+import com.dmdirc.interfaces.Migrator;
26
+import com.dmdirc.logger.ErrorLevel;
27
+import com.dmdirc.logger.Logger;
28
+
29
+import java.io.IOException;
30
+import java.nio.file.Files;
31
+import java.nio.file.Path;
32
+
33
+/**
34
+ * Migrator that installs the default aliases file if the user does not currently have one.
35
+ */
36
+public class DefaultAliasInstaller implements Migrator {
37
+
38
+    private final Path target;
39
+
40
+    public DefaultAliasInstaller(final Path target) {
41
+        this.target = target;
42
+    }
43
+
44
+    @Override
45
+    public boolean needsMigration() {
46
+        return !Files.exists(target);
47
+    }
48
+
49
+    @Override
50
+    public void migrate() {
51
+        try {
52
+            Files.copy(getClass().getResourceAsStream("defaults.yml"), target);
53
+        } catch (IOException ex) {
54
+            Logger.appError(ErrorLevel.MEDIUM, "Unable to extract default aliases", ex);
55
+        }
56
+    }
57
+
58
+}

+ 23
- 0
src/com/dmdirc/commandparser/aliases/defaults.yml View File

@@ -0,0 +1,23 @@
1
+- name: deop
2
+  min_arguments: 1
3
+  substitution: mode -ooooooooooooooo $1-
4
+- name: devoice
5
+  min_arguments: 1
6
+  substitution: mode -vvvvvvvvvvvvvvv $1-
7
+- name: kickban
8
+  min_arguments: 1
9
+  substitution: |-
10
+    ban $1
11
+    kick $1-
12
+- name: op
13
+  min_arguments: 1
14
+  substitution: mode +ooooooooooooooo $1-
15
+- name: voice
16
+  min_arguments: 1
17
+  substitution: mode +vvvvvvvvvvvvvvv $1-
18
+- name: quote
19
+  min_arguments: 1
20
+  substitution: raw $1-
21
+- name: unset
22
+  min_arguments: 2
23
+  substitution: set --unset $1-

Loading…
Cancel
Save