Skip to content

Commit

Permalink
Merge pull request #34 from infra-workshop/33-future-disable-upload-t…
Browse files Browse the repository at this point in the history
…o-youtube

disable upload to youtube
  • Loading branch information
anatawa12 authored Mar 8, 2020
2 parents 5cacf44 + a024753 commit 04c6238
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"gulp-sourcemaps": "^2.6.5",
"gulp-typescript": "^5.0.1",
"mocha": "^6.2.0",
"typescript": "^3.5.3",
"typescript": "^3.8.3",
"vinyl-source-stream": "latest"
}
}
15 changes: 11 additions & 4 deletions ts/discord-controller/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,14 @@ class CommandError extends Error {
clientSecret: tokens.google.secret,
});

const youtube = new youtube_v3.Youtube({
auth: googleClient
});
let youtube: youtube_v3.Youtube | null;
if (process.env["YOUTUBE_DISABLED"]) {
youtube = null;
} else {
youtube = new youtube_v3.Youtube({
auth: googleClient
});
}
console.log(`google OK`);
await client.login(tokens.discord);
console.log(`login success!`);
Expand Down Expand Up @@ -226,7 +231,7 @@ class CommandError extends Error {
const data = await recorderController.stop();
const date = recorderController.startAt;

const uploadPromise: GaxiosPromise<youtube_v3.Schema$Video> = youtube.videos.insert({
const uploadPromise: GaxiosPromise<youtube_v3.Schema$Video>|null = youtube?.videos?.insert({
stabilize: false,
media: {
mimeType: "video/webm",
Expand All @@ -249,6 +254,8 @@ class CommandError extends Error {
await message.reply("recorder successfully stopped!");

try {
if (uploadPromise == null)
throw new Error("upload is disabled");
const result = await uploadPromise;

await message.reply(`record is uploaded to https://youtu.be/${result.data.id}`);
Expand Down
10 changes: 5 additions & 5 deletions ts/markdown/writer/snowflakes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {CustomWriter} from "./CustomWriter";
import {DiscordSnowflakeToken} from "../Tokens";
import {escapeHtml} from "../util";
import {GuildChannel, Message} from "discord.js";
import {Message} from "discord.js";
import {Env} from "../env";

function wrapMentionSpan(content: string, colorInt?: number) {
Expand All @@ -28,11 +28,11 @@ export const snowflake_user: CustomWriter<DiscordSnowflakeToken> = function snow
const id = token.snowflake;

let userViewName: string;
if (msg.channel.type === 'dm' || msg.channel.type === 'group') {
if (msg.channel.type === 'dm') {
let user = msg.client.users.resolve(id);
userViewName = user != null ? `@${user.username}` : token.content;
} else {
const member = (msg.channel as GuildChannel).guild.members.resolve(id);
const member = msg.channel.guild.members.resolve(id);
if (member) {
if (member.nickname) userViewName = `@${member.nickname}`;
else userViewName = `@${member.user.username}`;
Expand All @@ -57,7 +57,7 @@ export const snowflake_role: CustomWriter<DiscordSnowflakeToken> = function snow
const id = token.snowflake;
let userViewName: string;
let color: number | undefined = undefined;
if (msg.channel.type === 'dm' || msg.channel.type === 'group') {
if (msg.channel.type === 'dm') {
userViewName = token.content;
} else {
const role = msg.guild.roles.resolve(id);
Expand All @@ -74,7 +74,7 @@ export const snowflake_role: CustomWriter<DiscordSnowflakeToken> = function snow
export const snowflake_emoji: CustomWriter<DiscordSnowflakeToken> = function snowflake_emoji(writer, token, env): void {
const msg = getMsg(env);
const id = token.snowflake;
if (msg.channel.type === 'dm' || msg.channel.type === 'group') token.content;
if (msg.channel.type === 'dm') token.content;
const emoji = msg.guild.emojis.resolve(id);

writer.append(emoji ? `<img alt=":${emoji.name}:" src="${emoji.url}" class="emoji">` : escapeHtml(token.content));
Expand Down

0 comments on commit 04c6238

Please sign in to comment.