Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
4b889141
Commit
4b889141
authored
Aug 28, 2019
by
Him188moe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enhanced ConfigSection
parent
114e6528
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
23 deletions
+38
-23
mirai-core/src/main/java/net/mamoe/mirai/Robot.java
mirai-core/src/main/java/net/mamoe/mirai/Robot.java
+7
-7
mirai-core/src/main/java/net/mamoe/mirai/network/RobotNetworkHandler.kt
.../main/java/net/mamoe/mirai/network/RobotNetworkHandler.kt
+1
-1
mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiConfigSection.java
...java/net/mamoe/mirai/utils/config/MiraiConfigSection.java
+30
-15
No files found.
mirai-core/src/main/java/net/mamoe/mirai/Robot.java
View file @
4b889141
...
...
@@ -12,7 +12,7 @@ public class Robot {
private
final
int
qq
;
private
final
String
password
;
private
final
RobotNetworkHandler
handler
;
private
final
RobotNetworkHandler
handler
;
/**
* Ref list
...
...
@@ -20,7 +20,7 @@ public class Robot {
@Getter
private
final
List
<
String
>
owners
;
public
boolean
isOwnBy
(
String
ownerName
){
public
boolean
isOwnBy
(
String
ownerName
)
{
return
owners
.
contains
(
ownerName
);
}
...
...
@@ -29,28 +29,28 @@ public class Robot {
this
(
data
.
getIntOrThrow
(
"account"
,
()
->
new
Exception
(
"can not parse QQ account"
)),
data
.
getStringOrThrow
(
"password"
,
()
->
new
Exception
(
"can not parse QQ password"
)),
data
.
getAsOrDefault
(
"owners"
,
new
ArrayList
<>()
)
data
.
getAsOrDefault
(
"owners"
,
ArrayList:
:
new
)
);
}
public
Robot
(
int
qq
,
String
password
,
List
<
String
>
owners
){
public
Robot
(
int
qq
,
String
password
,
List
<
String
>
owners
)
{
this
.
qq
=
qq
;
this
.
password
=
password
;
this
.
owners
=
Collections
.
unmodifiableList
(
owners
);
this
.
handler
=
new
RobotNetworkHandler
(
this
.
qq
,
this
.
password
);
this
.
handler
=
new
RobotNetworkHandler
(
this
.
qq
,
this
.
password
);
}
public
void
connect
(){
public
void
connect
()
{
}
public
void
onPacketReceive
(){
public
void
onPacketReceive
()
{
}
...
...
mirai-core/src/main/java/net/mamoe/mirai/network/RobotNetworkHandler.kt
View file @
4b889141
...
...
@@ -18,7 +18,7 @@ import java.net.InetSocketAddress
import
java.util.*
/**
* A
robotNetworkHandler account
.
* A
RobotNetworkHandler is used to connect with Tencent servers
.
*
* @author Him188moe
*/
...
...
mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiConfigSection.java
View file @
4b889141
package
net.mamoe.mirai.utils.config
;
import
org.jetbrains.annotations.Nullable
;
import
java.util.IllegalFormatException
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
import
java.util.concurrent.Callable
;
import
java.util.function.Supplier
;
public
class
MiraiConfigSection
<
T
>
extends
MiraiSynchronizedLinkedListMap
<
String
,
T
>
{
...
...
@@ -12,18 +13,18 @@ public class MiraiConfigSection<T> extends MiraiSynchronizedLinkedListMap<String
super
();
}
public
MiraiConfigSection
(
LinkedHashMap
<
String
,
T
>
map
)
{
super
(
map
);
public
MiraiConfigSection
(
Map
<
String
,
T
>
copyOfMap
)
{
super
(
new
LinkedHashMap
<>(
copyOfMap
)
);
}
public
int
getInt
(
String
key
){
return
Integer
.
valueOf
(
this
.
get
(
key
).
toString
());
return
Integer
.
parseInt
(
this
.
get
(
key
).
toString
());
}
public
int
getIntOrDefault
(
String
key
,
int
defaultV
){
Object
result
=
this
.
getOrDefault
(
key
,
null
);
try
{
return
result
==
null
?
defaultV
:
Integer
.
valueOf
(
result
.
toString
());
return
result
==
null
?
defaultV
:
Integer
.
parseInt
(
result
.
toString
());
}
catch
(
NumberFormatException
ignored
){
return
defaultV
;
}
...
...
@@ -35,20 +36,20 @@ public class MiraiConfigSection<T> extends MiraiSynchronizedLinkedListMap<String
throw
throwableCallable
.
call
();
}
try
{
return
Integer
.
valueOf
(
result
.
toString
());
return
Integer
.
parseInt
(
result
.
toString
());
}
catch
(
NumberFormatException
ignored
){
throw
throwableCallable
.
call
();
}
}
public
double
getDouble
(
String
key
){
return
Double
.
valueOf
(
this
.
get
(
key
).
toString
());
return
Double
.
parseDouble
(
this
.
get
(
key
).
toString
());
}
public
double
getDoubleOrDefault
(
String
key
,
double
defaultV
){
Object
result
=
this
.
getOrDefault
(
key
,
null
);
try
{
return
result
==
null
?
defaultV:
Double
.
valueOf
(
result
.
toString
());
return
result
==
null
?
defaultV
:
Double
.
parseDouble
(
result
.
toString
());
}
catch
(
NumberFormatException
ignored
){
return
defaultV
;
}
...
...
@@ -60,20 +61,20 @@ public class MiraiConfigSection<T> extends MiraiSynchronizedLinkedListMap<String
throw
throwableCallable
.
call
();
}
try
{
return
Double
.
valueOf
(
result
.
toString
());
return
Double
.
parseDouble
(
result
.
toString
());
}
catch
(
NumberFormatException
ignored
){
throw
throwableCallable
.
call
();
}
}
public
float
getFloat
(
String
key
){
return
Float
.
valueOf
(
this
.
get
(
key
).
toString
());
return
Float
.
parseFloat
(
this
.
get
(
key
).
toString
());
}
public
float
getFloatOrDefault
(
String
key
,
float
defaultV
){
Object
result
=
this
.
getOrDefault
(
key
,
null
);
try
{
return
result
==
null
?
defaultV
:
Float
.
valueOf
(
result
.
toString
());
return
result
==
null
?
defaultV
:
Float
.
parseFloat
(
result
.
toString
());
}
catch
(
NumberFormatException
ignored
){
return
defaultV
;
}
...
...
@@ -85,20 +86,20 @@ public class MiraiConfigSection<T> extends MiraiSynchronizedLinkedListMap<String
throw
throwableCallable
.
call
();
}
try
{
return
Float
.
valueOf
(
result
.
toString
());
return
Float
.
parseFloat
(
result
.
toString
());
}
catch
(
NumberFormatException
ignored
){
throw
throwableCallable
.
call
();
}
}
public
long
getLong
(
String
key
){
return
Long
.
valueOf
(
this
.
get
(
key
).
toString
());
return
Long
.
parseLong
(
this
.
get
(
key
).
toString
());
}
public
long
getLongOrDefault
(
String
key
,
long
defaultV
){
Object
result
=
this
.
getOrDefault
(
key
,
null
);
try
{
return
result
==
null
?
defaultV
:
Long
.
valueOf
(
result
.
toString
());
return
result
==
null
?
defaultV
:
Long
.
parseLong
(
result
.
toString
());
}
catch
(
NumberFormatException
ignored
){
return
defaultV
;
}
...
...
@@ -110,7 +111,7 @@ public class MiraiConfigSection<T> extends MiraiSynchronizedLinkedListMap<String
throw
throwableCallable
.
call
();
}
try
{
return
Long
.
valueOf
(
result
.
toString
());
return
Long
.
parseLong
(
result
.
toString
());
}
catch
(
NumberFormatException
ignored
){
throw
throwableCallable
.
call
();
}
...
...
@@ -161,4 +162,18 @@ public class MiraiConfigSection<T> extends MiraiSynchronizedLinkedListMap<String
public
<
D
extends
T
>
D
getAsOrDefault
(
String
key
,
D
defaultV
){
return
(
D
)
this
.
getOrDefault
(
key
,
defaultV
);
}
@SuppressWarnings
(
"unchecked"
)
public
<
D
extends
T
>
D
getAsOrDefault
(
String
key
,
Supplier
<
D
>
supplier
)
{
D
d
=
(
D
)
this
.
get
(
key
);
if
(
d
!=
null
)
{
return
d
;
}
return
supplier
.
get
();
}
@SuppressWarnings
(
"unchecked"
)
public
<
D
extends
T
>
D
getAs
(
String
key
)
{
return
(
D
)
this
.
get
(
key
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment