new trick: leaving rooms
This commit is contained in:
parent
b6ee0f901e
commit
f19f7e8511
4 changed files with 27 additions and 0 deletions
|
|
@ -287,6 +287,23 @@ func apiv0_sendmessage(cid C.int, data *C.char) *C.char {
|
||||||
return C.CString(s)
|
return C.CString(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//export apiv0_leaveroom
|
||||||
|
func apiv0_leaveroom(cid C.int, roomid *C.char) *C.char {
|
||||||
|
cli, err := getClient(int(cid))
|
||||||
|
if err != nil {
|
||||||
|
return C.CString(fmt.Sprintf("ERR: %v", err))
|
||||||
|
}
|
||||||
|
_, err = cli.LeaveRoom(context.Background(), id.RoomID(C.GoString(roomid)))
|
||||||
|
if err != nil {
|
||||||
|
return C.CString(fmt.Sprintf("ERR: %v", err))
|
||||||
|
}
|
||||||
|
_, err = cli.ForgetRoom(context.Background(), id.RoomID(C.GoString(roomid)))
|
||||||
|
if err != nil {
|
||||||
|
return C.CString(fmt.Sprintf("ERR: %v", err))
|
||||||
|
}
|
||||||
|
return C.CString("SUCCESS.")
|
||||||
|
}
|
||||||
|
|
||||||
//export apiv0_removeclient
|
//export apiv0_removeclient
|
||||||
func apiv0_removeclient(cid C.int) C.int {
|
func apiv0_removeclient(cid C.int) C.int {
|
||||||
return 0
|
return 0
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ ffibuilder.cdef(
|
||||||
extern char* apiv0_startclient(int cid);
|
extern char* apiv0_startclient(int cid);
|
||||||
extern char* apiv0_stopclient(int cid);
|
extern char* apiv0_stopclient(int cid);
|
||||||
extern char* apiv0_sendmessage(int cid, char* data);
|
extern char* apiv0_sendmessage(int cid, char* data);
|
||||||
|
extern char* apiv0_leaveroom(int cid, char* roomid);
|
||||||
extern int apiv0_removeclient(int cid);
|
extern int apiv0_removeclient(int cid);
|
||||||
extern char* apiv0_listclients();
|
extern char* apiv0_listclients();
|
||||||
extern char* apiv0_getoptions(int cid);
|
extern char* apiv0_getoptions(int cid);
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,11 @@ class DemoBot(SMALBot):
|
||||||
self.stop()
|
self.stop()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if msg["content"]["body"] == "!leave":
|
||||||
|
logger.info(f"leaving room {msg['roomid']}")
|
||||||
|
self.leaveroom(msg["roomid"])
|
||||||
|
return
|
||||||
|
|
||||||
if msg["content"]["body"].startswith("!echo"):
|
if msg["content"]["body"].startswith("!echo"):
|
||||||
logger.error(f"reply to this: {msg}")
|
logger.error(f"reply to this: {msg}")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,10 @@ class _MXClient:
|
||||||
result = checkApiError(r)
|
result = checkApiError(r)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def leaveroom(self, roomid):
|
||||||
|
r = lib.apiv0_leaveroom(self.client_id, roomid.encode(encoding="utf-8"))
|
||||||
|
checkApiError(r)
|
||||||
|
|
||||||
def process_event(self, evt):
|
def process_event(self, evt):
|
||||||
if hasattr(self, "on_event") and callable(self.on_event):
|
if hasattr(self, "on_event") and callable(self.on_event):
|
||||||
self.on_event(evt)
|
self.on_event(evt)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue