Skip to content

Commit

Permalink
feat(adapter): add basic support for bot.kickGuildMember()
Browse files Browse the repository at this point in the history
also bot.muteGuildMember() and bot.muteChannel() but not widely supported
  • Loading branch information
shigma committed May 3, 2022
1 parent de9b6cf commit b85397f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/core/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,13 @@ export namespace Bot {
// guild member
getGuildMember(guildId: string, userId: string): Promise<GuildMember>
getGuildMemberList(guildId: string): Promise<GuildMember[]>
kickGuildMember(guildId: string, userId: string, permanent?: boolean): Promise<void>
muteGuildMember(guildId: string, userId: string, duration: number, reason?: string): Promise<void>

// channel
getChannel(channelId: string, guildId?: string): Promise<Channel>
getChannelList(guildId: string): Promise<Channel[]>
muteChannel(channelId: string, guildId?: string, enable?: boolean): Promise<void>

// request
handleFriendRequest(messageId: string, approve: boolean, comment?: string): Promise<void>
Expand Down
4 changes: 4 additions & 0 deletions plugins/adapter/discord/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ export class DiscordBot extends Bot<BotConfig> {
}
}

async kickGuildMember(guildId: string, userId: string) {
return this.internal.removeGuildMember(guildId, userId)
}

async getGuild(guildId: string) {
const data = await this.internal.getGuild(guildId)
return adaptGuild(data)
Expand Down
12 changes: 12 additions & 0 deletions plugins/adapter/onebot/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ export class OneBotBot extends Bot<BotConfig> {
return data.map(OneBot.adaptGuildMember)
}

async kickGuildMember(guildId: string, userId: string, permanent?: boolean) {
return this.internal.setGroupKick(guildId, userId, permanent)
}

async muteGuildMember(guildId: string, userId: string, duration: number) {
return this.internal.setGroupBan(guildId, userId, duration / 1000)
}

async muteChannel(channelId: string, guildId?: string, enable?: boolean) {
return this.internal.setGroupWholeBan(channelId, enable)
}

protected async sendGuildMessage(guildId: string, channelId: string, content: string) {
const session = await this.session({ content, subtype: 'group', guildId, channelId })
if (!session?.content) return []
Expand Down
12 changes: 11 additions & 1 deletion plugins/adapter/telegram/src/bot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Adapter, assertProperty, Bot, Dict, Logger, Quester, renameProperty, Schema } from 'koishi'
import { Adapter, assertProperty, Bot, Dict, Logger, Quester, renameProperty, Schema, Time } from 'koishi'
import * as Telegram from './types'
import { AdapterConfig, adaptGuildMember, adaptUser } from './utils'
import { Sender } from './sender'
Expand Down Expand Up @@ -137,6 +137,16 @@ export class TelegramBot extends Bot<BotConfig> {
return data.map(adaptGuildMember)
}

async kickGuildMember(chat_id: string, user_id: string | number, permanent?: boolean) {
user_id = +user_id
await this.internal.banChatMember({
chat_id,
user_id,
until_date: Date.now() + (permanent ? 0 : Time.minute),
revoke_messages: true,
})
}

setGroupLeave(chat_id: string) {
return this.internal.leaveChat({ chat_id })
}
Expand Down

0 comments on commit b85397f

Please sign in to comment.